index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import MHeader from '@/components/m-header';
  2. import { defineComponent, onMounted, reactive } from 'vue';
  3. import { Button, Cell, CellGroup, Image, Tag } from 'vant';
  4. import styles from './index.module.less';
  5. import iconRefunding from './images/icon_refunding.png';
  6. import icon_success from './images/icon_success.png';
  7. import iconClose from './images/icon_close.png';
  8. import iconTradeing from './images/icon_tradeing.png';
  9. import request from '@/helpers/request';
  10. import { useRoute, useRouter } from 'vue-router';
  11. import { browser, moneyFormat } from '@/helpers/utils';
  12. import { useEventListener, useWindowScroll } from '@vueuse/core';
  13. export default defineComponent({
  14. name: 'payment-result',
  15. setup() {
  16. const route = useRoute();
  17. const router = useRouter();
  18. const state = reactive({
  19. refund: route.query.refund,
  20. orders: {} as any,
  21. goodsInfos: [] as any,
  22. background: 'transparent',
  23. color: '#fff',
  24. backIconColor: 'white' as any,
  25. timer: null as any,
  26. timerCount: 0 // 执行次数
  27. });
  28. const form = reactive({
  29. resionList: [] as any,
  30. refundStatus: false,
  31. resion: null,
  32. refundSelect: {} as any,
  33. checked: null as any
  34. });
  35. const getDetails = async () => {
  36. try {
  37. if (!route.query.orderNo) return;
  38. const { data } = await request.post(
  39. '/edu-app/open/userOrder/paymentStatus/' + route.query.orderNo
  40. );
  41. state.orders = data || {};
  42. // state.orders.status = 'REFUNDED'
  43. const tempGoods = data.goodsInfos || [];
  44. tempGoods.forEach((item: any) => {
  45. const img = item.goodsUrl ? item.goodsUrl.split(',')[0] : '';
  46. item.goodsUrl = img;
  47. });
  48. state.goodsInfos = tempGoods;
  49. } catch {
  50. //
  51. }
  52. };
  53. // 定时任务
  54. const onTimeout = async () => {
  55. // 判断订单状态,如果未支付则刷新
  56. if (
  57. ['WAIT_PAY', 'PAYING'].includes(state.orders.status) &&
  58. state.timerCount <= 10
  59. ) {
  60. state.timer = setTimeout(async () => {
  61. state.timerCount += 1;
  62. await getDetails();
  63. onTimeout();
  64. }, 3000);
  65. } else {
  66. clearTimeout(state.timer);
  67. }
  68. };
  69. const formatImg = (type: any) => {
  70. const template: any = {
  71. WAIT_PAY: iconTradeing,
  72. PAYING: iconTradeing,
  73. PAID: icon_success,
  74. TIMEOUT: iconClose,
  75. FAIL: iconClose,
  76. CLOSED: iconClose,
  77. REFUNDING: iconRefunding,
  78. REFUNDED: icon_success
  79. };
  80. return template[type] || icon_success;
  81. };
  82. const formatOrderStatus = (status: string) => {
  83. const temp: any = {
  84. WAIT_PAY: '支付中',
  85. PAYING: '支付中',
  86. PAID: '支付成功',
  87. TIMEOUT: '订单超时',
  88. FAIL: '支付失败',
  89. CLOSED: '订单关闭',
  90. REFUNDING: '退款中',
  91. REFUNDED: '已退款'
  92. };
  93. return temp[status];
  94. };
  95. onMounted(async () => {
  96. await getDetails();
  97. await onTimeout();
  98. useEventListener(document, 'scroll', () => {
  99. const { y } = useWindowScroll();
  100. if (y.value > 52) {
  101. state.background = '#fff';
  102. state.color = '#323333';
  103. state.backIconColor = 'black';
  104. } else {
  105. state.background = 'transparent';
  106. state.color = '#fff';
  107. state.backIconColor = 'white';
  108. }
  109. });
  110. });
  111. return () => (
  112. <div class={styles.paymentResult}>
  113. <div class={[styles.paymentTitle]}>
  114. {browser().isApp && (
  115. <MHeader
  116. border={false}
  117. background={state.background}
  118. color={state.color}
  119. />
  120. )}
  121. {state.orders.id && (
  122. <>
  123. <div class={styles.orderType}>
  124. <Image
  125. class={styles.img}
  126. src={formatImg(state.orders.status)}
  127. />
  128. <div class={styles.orderInfo}>
  129. <span>{formatOrderStatus(state.orders.status)}</span>
  130. {state.orders.status === 'PAID' ||
  131. state.orders.status === 'REFUNDING' ? (
  132. <div class={styles.orderPrice}>
  133. 实付金额:¥ {moneyFormat(state.orders.paymentCashAmount)}
  134. </div>
  135. ) : (
  136. ''
  137. )}
  138. {state.orders.status === 'REFUNDED' && (
  139. <div class={styles.orderPrice}>
  140. 退款金额:¥ {moneyFormat(state.orders.paymentCashAmount)}
  141. </div>
  142. )}
  143. </div>
  144. </div>
  145. </>
  146. )}
  147. </div>
  148. <CellGroup inset class={[styles.cellGroup, styles.mTop]}>
  149. <Cell>
  150. {{
  151. title: () => '付款时间',
  152. value: () => <span>{state.orders.payTime || '--'}</span>
  153. }}
  154. </Cell>
  155. <Cell>
  156. {{
  157. title: () => '订单编号',
  158. value: () => <span>{state.orders.orderNo}</span>
  159. }}
  160. </Cell>
  161. </CellGroup>
  162. <CellGroup inset class={styles.cellGroup}>
  163. <div class={styles.buyDetail}>
  164. <div class={styles.buyDetailTitle}>
  165. <i></i> 购买详情
  166. </div>
  167. </div>
  168. {state.goodsInfos.map((goods: any) => (
  169. <Cell>
  170. {{
  171. icon: () => (
  172. <Image class={styles.buyImg} src={goods.goodsUrl} />
  173. ),
  174. title: () => (
  175. <div class={styles.buyContent}>
  176. <p class={styles.goodsTitle}>{goods.goodsName}</p>
  177. <Tag class={styles.brandName}>
  178. {state.orders.orderType === 'VIP'
  179. ? '12个月'
  180. : goods.brandName}
  181. </Tag>
  182. </div>
  183. ),
  184. value: () => <span>x {goods.goodsNum}</span>
  185. }}
  186. </Cell>
  187. ))}
  188. </CellGroup>
  189. </div>
  190. );
  191. }
  192. });