import ColHeader from '@/components/col-header' import { Button, Cell, CellGroup, Col, Image, Popup, Row } from 'vant' import { defineComponent } from 'vue' import styles from './trade-detail.module.less' import { goodsType } from '@/constant' import iconTeacher from '@common/images/icon_teacher.png' import request from '@/helpers/request' import Payment from '../order-detail/payment' import { orderStatus } from '../order-detail/orderStatus' import { state } from '@/state' export const getAssetsHomeFile = (fileName: string) => { const path = `./images/${fileName}` const modules = import.meta.globEager('./images/*') return modules[path].default } // WAIT_PAY 待支付 PAYING 支付中 PAID 已付款 CLOSE 已关闭 FAIL 支付失败 type orderType = 'WAIT_PAY' | 'PAYING' | 'PAID' | 'CLOSE' | 'FAIL' export default defineComponent({ name: 'tradeDetail', data() { const query = this.$route.query return { type: (query.type as string) || 'ING', path: query.path, // 来源 orderNo: query.orderNo || '', paymentStatus: false, order: { ING: { img: getAssetsHomeFile('icon_paying.png'), background: '#FF802C', title: '支付中' }, SUCCESS: { img: getAssetsHomeFile('icon_success.png'), background: state.projectType === 'tenant' ? '#FF5461' : 'var(--van-primary)', title: '支付成功' }, FAILED: { img: getAssetsHomeFile('icon_close.png'), background: '#BDBDBD', title: '支付失败' }, CLOSE: { img: getAssetsHomeFile('icon_close.png'), background: '#BDBDBD', title: '订单关闭' } }, result: {} as any, loading: true, timerOut: null as any, timer: 3 } }, computed: { orderDetailList() { const result: any = this.result return result.orderDetailList || [] } }, async mounted() { setTimeout(async () => { this.loading = true this.orderNo && (await this.getOrder()) this.loading = false this.type === 'ING' && this.path !== 'tradeRecord' && this.interval() }, 0) }, unmounted() { clearInterval(this.timerOut) }, methods: { onRePay() { orderStatus.orderInfo = { orderNo: this.result.orderNo, actualPrice: this.result.actualPrice, payStatus: true } this.paymentStatus = true this.interval() }, interval() { let countTime = 0 this.timerOut = setInterval(async () => { countTime === 25 && clearInterval(this.timerOut) await this.getOrder(true) countTime++ }, 5000) }, async getOrder(status?: true) { try { const urlFix = state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student' const res = await request.get( `${urlFix}/userOrder/detailByOrderNo/${this.orderNo}`, { hideLoading: status } ) this.result = res.data // WAIT_PAY 待支付 PAYING 支付中 PAID 已付款 CLOSE 已关闭 FAIL 支付失败 this.type = this.formatType(this.result.status) this.type !== 'ING' && clearInterval(this.timerOut) } catch {} }, formatType(type: orderType) { let str = 'PAYING' switch (type) { case 'WAIT_PAY': case 'PAYING': str = 'ING' break case 'PAID': str = 'SUCCESS' break case 'CLOSE': str = 'CLOSE' break case 'FAIL': str = 'FAILED' break default: str = 'ING' break } return str } }, render() { return (