trade-detail.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import ColHeader from '@/components/col-header'
  2. import { Button, Cell, CellGroup, Col, Image, Popup, Row } from 'vant'
  3. import { defineComponent } from 'vue'
  4. import styles from './trade-detail.module.less'
  5. import { goodsType } from '@/constant'
  6. import iconTeacher from '@common/images/icon_teacher.png'
  7. import request from '@/helpers/request'
  8. import Payment from '../order-detail/payment'
  9. import { orderStatus } from '../order-detail/orderStatus'
  10. import { state } from '@/state'
  11. export const getAssetsHomeFile = (fileName: string) => {
  12. const path = `./images/${fileName}`
  13. const modules = import.meta.globEager('./images/*')
  14. return modules[path].default
  15. }
  16. // WAIT_PAY 待支付 PAYING 支付中 PAID 已付款 CLOSE 已关闭 FAIL 支付失败
  17. type orderType = 'WAIT_PAY' | 'PAYING' | 'PAID' | 'CLOSE' | 'FAIL'
  18. export default defineComponent({
  19. name: 'tradeDetail',
  20. data() {
  21. const query = this.$route.query
  22. return {
  23. type: (query.type as string) || 'ING',
  24. path: query.path, // 来源
  25. orderNo: query.orderNo || '',
  26. paymentStatus: false,
  27. order: {
  28. ING: {
  29. img: getAssetsHomeFile('icon_paying.png'),
  30. background: '#FF802C',
  31. title: '支付中'
  32. },
  33. SUCCESS: {
  34. img: getAssetsHomeFile('icon_success.png'),
  35. background:
  36. state.projectType === 'tenant' ? '#FF5461' : 'var(--van-primary)',
  37. title: '支付成功'
  38. },
  39. FAILED: {
  40. img: getAssetsHomeFile('icon_close.png'),
  41. background: '#BDBDBD',
  42. title: '支付失败'
  43. },
  44. CLOSE: {
  45. img: getAssetsHomeFile('icon_close.png'),
  46. background: '#BDBDBD',
  47. title: '订单关闭'
  48. }
  49. },
  50. result: {} as any,
  51. loading: true,
  52. timerOut: null as any,
  53. timer: 3
  54. }
  55. },
  56. computed: {
  57. orderDetailList() {
  58. const result: any = this.result
  59. return result.orderDetailList || []
  60. }
  61. },
  62. async mounted() {
  63. setTimeout(async () => {
  64. this.loading = true
  65. this.orderNo && (await this.getOrder())
  66. this.loading = false
  67. this.type === 'ING' && this.path !== 'tradeRecord' && this.interval()
  68. }, 0)
  69. },
  70. unmounted() {
  71. clearInterval(this.timerOut)
  72. },
  73. methods: {
  74. onRePay() {
  75. orderStatus.orderInfo = {
  76. orderNo: this.result.orderNo,
  77. actualPrice: this.result.actualPrice,
  78. payStatus: true
  79. }
  80. this.paymentStatus = true
  81. this.interval()
  82. },
  83. interval() {
  84. let countTime = 0
  85. this.timerOut = setInterval(async () => {
  86. countTime === 25 && clearInterval(this.timerOut)
  87. await this.getOrder(true)
  88. countTime++
  89. }, 5000)
  90. },
  91. async getOrder(status?: true) {
  92. try {
  93. const urlFix =
  94. state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student'
  95. const res = await request.get(
  96. `${urlFix}/userOrder/detailByOrderNo/${this.orderNo}`,
  97. {
  98. hideLoading: status
  99. }
  100. )
  101. this.result = res.data
  102. // WAIT_PAY 待支付 PAYING 支付中 PAID 已付款 CLOSE 已关闭 FAIL 支付失败
  103. this.type = this.formatType(this.result.status)
  104. this.type !== 'ING' && clearInterval(this.timerOut)
  105. } catch {}
  106. },
  107. formatType(type: orderType) {
  108. let str = 'PAYING'
  109. switch (type) {
  110. case 'WAIT_PAY':
  111. case 'PAYING':
  112. str = 'ING'
  113. break
  114. case 'PAID':
  115. str = 'SUCCESS'
  116. break
  117. case 'CLOSE':
  118. str = 'CLOSE'
  119. break
  120. case 'FAIL':
  121. str = 'FAILED'
  122. break
  123. default:
  124. str = 'ING'
  125. break
  126. }
  127. return str
  128. }
  129. },
  130. render() {
  131. return (
  132. <div class={[styles.tradeDetail, styles[this.type]]}>
  133. {!this.loading && (
  134. <>
  135. <ColHeader
  136. background={this.order[this.type].background}
  137. color="#fff"
  138. title="交易详情"
  139. backIconColor="white"
  140. border={false}
  141. />
  142. <div
  143. class={styles.orderType}
  144. style={{
  145. backgroundColor:
  146. state.projectType === 'tenant'
  147. ? '#FF5461'
  148. : 'var(--van-primary)'
  149. }}
  150. >
  151. <p>
  152. <Image
  153. class={styles.orderImg}
  154. src={this.order[this.type].img}
  155. fit="cover"
  156. />
  157. <span>{this.order[this.type].title}</span>
  158. </p>
  159. </div>
  160. <CellGroup
  161. border={false}
  162. class={[
  163. styles.orderContent,
  164. state.projectType === 'tenant' && styles.orderContentTenant,
  165. 'mb12'
  166. ]}
  167. >
  168. <Cell
  169. v-slots={{
  170. title: () => (
  171. <div class={styles.payPrice}>
  172. <span>¥</span>
  173. {(this as any).$filters.moneyFormat(
  174. this.result.actualPrice
  175. )}
  176. </div>
  177. )
  178. }}
  179. />
  180. {this.orderDetailList.map((item: any) => (
  181. <Cell
  182. border={false}
  183. style={{ paddingBottom: '15px' }}
  184. v-slots={{
  185. icon: () => (
  186. <Image
  187. class={styles.tradeLogo}
  188. src={item.goodUrl || iconTeacher}
  189. fit="cover"
  190. />
  191. ),
  192. title: () => (
  193. <div class={styles.title}>
  194. <span>{item.goodName}</span>
  195. <span class={styles.desc}>
  196. {goodsType[item.goodType]}
  197. </span>
  198. </div>
  199. ),
  200. default: () => (
  201. <div class={styles.content}>
  202. <span class={styles.price}>
  203. {(this as any).$filters.moneyFormat(item.expectPrice)}
  204. </span>
  205. <span class={styles.num}>x{1}</span>
  206. </div>
  207. )
  208. }}
  209. />
  210. ))}
  211. <Row class={styles.optionRow}>
  212. <Col span="8" offset={1}>
  213. 订单号:
  214. </Col>
  215. <Col span="14">{this.result.orderNo}</Col>
  216. <Col span="1"> </Col>
  217. </Row>
  218. <Row class={styles.optionRow}>
  219. <Col span="8" offset={1}>
  220. 交易流水号:
  221. </Col>
  222. <Col span="14">{this.result.transNo}</Col>
  223. <Col span="1"> </Col>
  224. </Row>
  225. <Row class={styles.optionRow}>
  226. <Col span="8" offset={1}>
  227. 创建时间:
  228. </Col>
  229. <Col span="14">{this.result.createTime}</Col>
  230. <Col span="1"> </Col>
  231. </Row>
  232. <Row class={styles.optionRow}>
  233. <Col span="8" offset={1}>
  234. 付款时间:
  235. </Col>
  236. <Col span="14">{this.result.payTime}</Col>
  237. <Col span="1"> </Col>
  238. </Row>
  239. </CellGroup>
  240. {/* {this.type === 'ING' && this.path === 'tradeRecord' && (
  241. <div class="btnGroup">
  242. <Button type="primary" round block onClick={this.onRePay}>
  243. 重新支付
  244. </Button>
  245. </div>
  246. )}
  247. <Popup
  248. show={this.paymentStatus}
  249. closeOnClickOverlay={false}
  250. position="bottom"
  251. round
  252. closeOnPopstate
  253. safeAreaInsetBottom
  254. style={{ minHeight: '30%' }}
  255. >
  256. <Payment
  257. v-model={this.paymentStatus}
  258. orderInfo={orderStatus.orderInfo}
  259. />
  260. </Popup> */}
  261. </>
  262. )}
  263. </div>
  264. )
  265. }
  266. })