index.tsx 6.9 KB

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