123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- <template>
- <view>
- <Loading :type="3" :loadStatus="loadStatus" :showText="errorText" />
- <zj-page-layout :hasFooter="true" v-if="detail">
- <view style="padding: 1rpx 30rpx">
- <view class="materials-container card mt30">
- <view class="title">
- <view class="t1">支付金额</view>
- <view class="t2"
- >¥<text>{{ detail.totalAmount | priceFilter }}</text></view
- >
- </view>
- <view class="id"><text>订单号:</text>{{ detail.orderId }}</view>
- <view class="product">
- <view class="it" v-for="(item, index) in detail.workerOrderItems" :key="index">
- <view class="name"
- >{{ item.goodsName }}<text>×{{ item.num }}{{ item.unit }}</text></view
- >
- <view class="price">¥{{ item.totalAmount | priceFilter }}</view>
- </view>
- <view class="total">
- <view class="text">合计:</view>
- <view class="price">¥{{ detail.totalAmount | priceFilter }}</view>
- </view>
- </view>
- <view class="row"><text>备注:</text>{{ detail.remark }}</view>
- <view class="row"><text>操作人:</text>{{ detail.workerName }}</view>
- </view>
- </view>
- <template slot="footer">
- <view class="footer-btn-group">
- <u-button v-if="detail.ifCancel" text="取消订单" @click="cancelOrder"></u-button>
- <!-- <u-button text="扫码支付" type="primary" @click="scanCode"></u-button> -->
- <u-button text="线下支付" type="primary" @click="scanCodeXX"></u-button>
- </view>
- </template>
- </zj-page-layout>
- <zhifutanchuan
- v-if="state > 0"
- :detail="detail"
- :orderId="orderId"
- :state="state"
- @scan="scan"
- @back="back"
- @offTiming="offTiming"
- />
- </view>
- </template>
- <script>
- import { wxScanCode } from '@/common/utils/util.js'
- import zhifutanchuan from '@/components/zhifutanchuan.vue'
- export default {
- data() {
- return {
- orderId: null,
- refresherTriggered: false,
- loadStatus: 0,
- errorText: '',
- detail: null,
- canScanCode: 0,
- timeout: null,
- timeoutNum: 0,
- payType: 1,
- state: 0
- }
- },
- components: {
- zhifutanchuan
- },
- onLoad({ handleOrderId }) {
- this.orderId = handleOrderId
- this.getDetail()
- this.crossPage.$on('reScanCode', () => {
- this.scanCode()
- })
- },
- onUnload() {
- if (this.timeout) {
- clearTimeout(this.timeout)
- }
- },
- methods: {
- scan() {
- this.state = 0
- if (this.timeout) {
- clearTimeout(this.timeout)
- }
- this.scanCode()
- },
- back() {
- this.state = 0
- if (this.timeout) {
- clearTimeout(this.timeout)
- }
- this.$navToPage(
- {
- url: `/packageMaterial/pages/index?type=P`
- },
- 'reLaunch'
- )
- },
- getDetail(cb) {
- let url = '/pay/getOrder'
- let params = {}
- params.orderId = this.orderId
- this.$api
- .post(url, params)
- .then(res => {
- this.detail = res.data
- this.loadStatus = 0
- cb?.()
- })
- .catch(res => {
- this.errorText = res.message
- this.loadStatus = 2
- })
- .finally(res => {
- this.refresherTriggered = false
- })
- },
- // 取消订单
- cancelOrder() {
- this.$modal({
- content: '确认取消订单吗?'
- })
- .then(() => {
- this.$api
- .post('/pay/cancel', {
- orderId: this.orderId
- })
- .then(res => {
- this.$successToast()
- this.$navToPage(
- {
- delta: 1
- },
- 'navigateBack'
- )
- })
- })
- .catch(() => {})
- },
- // 扫码
- async scanCode() {
- if (this.canScanCode > 0) return this.$toast(`请等待${this.canScanCode}秒后重试`)
- var codeVal = await wxScanCode(['qrCode'])
- this.submitData(codeVal)
- },
- // 下单
- submitData(code) {
- let url = '/pay/paid'
- this.$api
- .post(url, {
- authCode: code,
- orderId: this.orderId,
- payType: 'WECHAT'
- })
- .then(res => {
- this.orderId = res.data.orderId
- if (res.data.payStatus == 'PAID') {
- // 支付成功
- this.getDetail(() => {
- this.state = 2
- })
- } else {
- // 支付失败
- this.getDetail(() => {
- this.state = 4
- })
- }
- })
- .catch(res => {
- // 等待支付
- var [USERPAYING, orderId] = res.message.split('|')
- if (~USERPAYING.indexOf('USERPAYING') && !!orderId) {
- this.orderId = orderId
- if (this.state == 0) {
- this.state = 1
- }
- this.getDetail__()
- } else {
- this.$tips(res.message)
- }
- })
- },
- scanCodeXX() {
- this.$api
- .post('/pay/paid', {
- orderId: this.orderId,
- payType: 'LINE'
- })
- .then(res => {
- this.orderId = res.data.orderId
- if (res.data.payStatus == 'PAID') {
- // 支付成功
- this.state = 2
- } else {
- // 支付失败
- this.state = 4
- }
- })
- .catch(res => {})
- },
- offTiming() {
- if (this.timeout) {
- clearTimeout(this.timeout)
- }
- },
- getDetail__(cb) {
- this.$api
- .post('/pay/getOrder', {
- orderId: this.orderId
- })
- .then(res => {
- this.detail = res.data
- if (res.data.payStatus == 'PAID') {
- this.state = 2
- } else {
- this.timeout = setTimeout(() => {
- this.getDetail__(cb)
- }, 1000)
- }
- cb?.()
- })
- .catch(res => {})
- .finally(res => {})
- },
- confirmPay() {
- let url = '/pay/paid'
- this.$api
- .post(url, {
- authCode: '',
- orderId: this.orderId,
- payType: 'LINE'
- })
- .then(res => {
- if (res.data) {
- this.$navToPage({
- url: `/packageMaterial/pages/newSale/result?handleOrderId=${this.orderId}&result=1`
- })
- } else {
- this.$navToPage({
- url: `/packageMaterial/pages/newSale/result?handleOrderId=${this.orderId}&result=0`
- })
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .card {
- @include zj-card;
- }
- .materials-container {
- padding: 30rpx;
- .title {
- text-align: center;
- margin-top: 30rpx;
- .t1 {
- font-size: 32rpx;
- font-weight: 500;
- }
- .t2 {
- font-size: 40rpx;
- color: $minor-color;
- margin-top: 20rpx;
- text {
- font-size: 56rpx;
- font-weight: 500;
- }
- }
- }
- .id {
- margin-top: 50rpx;
- text {
- color: $sec-font;
- }
- }
- .product {
- background: #f5f5f5;
- border-radius: 12rpx;
- padding: 20rpx;
- margin-top: 20rpx;
- .it {
- display: flex;
- align-items: flex-end;
- margin-bottom: 20rpx;
- .name {
- flex: 1;
- font-size: 28rpx;
- font-weight: 500;
- text {
- color: $sec-font;
- margin-left: 12rpx;
- font-weight: normal;
- }
- }
- .price {
- margin-left: 30rpx;
- font-size: 28rpx;
- font-weight: 500;
- }
- }
- .total {
- display: flex;
- align-items: center;
- justify-content: flex-end;
- margin-top: 30rpx;
- .text {
- font-size: 28rpx;
- color: $sec-font;
- }
- .price {
- font-size: 28rpx;
- color: $minor-color;
- font-weight: 500;
- }
- }
- }
- .row {
- margin-top: 20rpx;
- line-height: 40rpx;
- display: flex;
- font-size: 28rpx;
- text {
- color: $sec-font;
- flex-shrink: 0;
- line-height: 40rpx;
- }
- }
- }
- .pay-container {
- padding: 30rpx;
- .top {
- margin-bottom: 40rpx;
- }
- .item {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin: 30rpx 0;
- .left {
- display: flex;
- align-items: center;
- .iconfont {
- font-size: 44rpx;
- color: #43c93e;
- }
- .text {
- margin-left: 18rpx;
- font-size: 32rpx;
- }
- }
- .right {
- .iconfont {
- font-size: 40rpx;
- color: $sec-font;
- &.active {
- color: $theme-color;
- }
- }
- }
- }
- }
- </style>
|