index.tsx 6.8 KB

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