index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import MHeader from '@/components/m-header';
  2. import { defineComponent, onMounted, reactive } from 'vue';
  3. import {
  4. Button,
  5. Cell,
  6. CellGroup,
  7. Field,
  8. Image,
  9. Popup,
  10. Radio,
  11. RadioGroup,
  12. Tag,
  13. showToast
  14. } from 'vant';
  15. import styles from './index.module.less';
  16. import iconRefunding from './images/icon_refunding.svg';
  17. import icon_success from './images/icon_success.svg';
  18. import iconClose from './images/icon_close.svg';
  19. import iconTradeing from './images/icon_tradeing.svg';
  20. import { useRoute, useRouter } from 'vue-router';
  21. import { browser, moneyFormat } from '@/helpers/utils';
  22. import { useEventListener, useWindowScroll } from '@vueuse/core';
  23. import {
  24. api_userPaymentOrderCancelRefund,
  25. api_userPaymentOrderDetail,
  26. api_userPaymentOrderRefundDetail,
  27. api_userPaymentOrderRefundPayment
  28. } from '../collection-record/api';
  29. import * as detailState from '@/state';
  30. export default defineComponent({
  31. name: 'collection-record-detail',
  32. setup() {
  33. const route = useRoute();
  34. const router = useRouter();
  35. // 判断是否是退款详情
  36. const isRefund = route.query.userRefundOrderId ? true : false;
  37. const state = reactive({
  38. refundAudit: '' as any, // 退款审核状态
  39. refundOrderId: '', // 退款订单id
  40. orders: {} as any,
  41. goodsInfos: [] as any,
  42. background: 'transparent',
  43. color: '#fff',
  44. backIconColor: 'white' as any,
  45. timer: null as any,
  46. timerCount: 0 // 执行次数
  47. });
  48. const getDetails = async () => {
  49. let res = null as any;
  50. try {
  51. // 退款详情
  52. if (isRefund) {
  53. res = await api_userPaymentOrderRefundDetail(
  54. route.query.userRefundOrderId
  55. );
  56. } else {
  57. // 订单详情
  58. res = await api_userPaymentOrderDetail(route.query.orderNo);
  59. }
  60. } catch {}
  61. if (res?.code !== 200) return;
  62. state.orders = res.data || {};
  63. const tempGoods =
  64. (isRefund ? res.data.studentRefundOrderDetails : res.data.goodsInfos) ||
  65. [];
  66. tempGoods.forEach((item: any) => {
  67. const img = item.goodsUrl ? item.goodsUrl.split(',')[0] : '';
  68. item.goodsUrl = img;
  69. item.brandName = item.brandName
  70. ? item.brandName
  71. : goodsType[item.goodsType];
  72. });
  73. state.goodsInfos = tempGoods;
  74. if (isRefund) {
  75. state.refundAudit = res.data.refundAudit || '';
  76. state.refundOrderId = res.data.userRefundOrderId || '';
  77. state.orders.status = state.refundAudit;
  78. }
  79. };
  80. // 定时任务
  81. const onTimeout = async () => {
  82. // 判断订单状态,如果未支付则刷新
  83. if (
  84. ['WAIT_PAY', 'PAYING'].includes(state.orders.status) &&
  85. state.timerCount <= 10
  86. ) {
  87. state.timer = setTimeout(async () => {
  88. state.timerCount += 1;
  89. await getDetails();
  90. onTimeout();
  91. }, 3000);
  92. } else {
  93. clearTimeout(state.timer);
  94. }
  95. };
  96. const formatImg = (type: any) => {
  97. const template: any = {
  98. WAIT_PAY: iconTradeing,
  99. PAYING: iconTradeing,
  100. PAID: icon_success,
  101. TIMEOUT: iconClose,
  102. FAIL: iconClose,
  103. CLOSED: iconClose,
  104. ING: iconRefunding,
  105. REFUNDING: iconRefunding,
  106. REFUNDED: icon_success
  107. };
  108. return template[type] || icon_success;
  109. };
  110. const formatOrderStatus = (status: string) => {
  111. const temp: any = {
  112. WAIT_PAY: '支付中',
  113. PAYING: '支付中',
  114. PAID: '支付成功',
  115. TIMEOUT: '订单超时',
  116. FAIL: '支付失败',
  117. CLOSED: '已关闭',
  118. ING: '退款申请中',
  119. PASS: '已退款',
  120. REJECT: '退款失败',
  121. REFUNDING: '退款中',
  122. REFUNDED: '已退款'
  123. };
  124. return temp[status];
  125. };
  126. const goodsType: any = {
  127. VIP: '数字化乐器学练工具',
  128. INSTRUMENTS: '乐器购买',
  129. TEXTBOOK: '教材'
  130. };
  131. onMounted(async () => {
  132. await getDetails();
  133. await onTimeout();
  134. useEventListener(document, 'scroll', () => {
  135. const { y } = useWindowScroll();
  136. if (y.value > 52) {
  137. state.background = '#fff';
  138. state.color = '#323333';
  139. state.backIconColor = 'black';
  140. } else {
  141. state.background = 'transparent';
  142. state.color = '#fff';
  143. state.backIconColor = 'white';
  144. }
  145. });
  146. });
  147. /** 取消退款申请 */
  148. const handleBack = async () => {
  149. await api_userPaymentOrderCancelRefund(state.refundOrderId);
  150. showToast('撤销退款成功');
  151. await getDetails();
  152. };
  153. return () => (
  154. <div class={styles.paymentResult}>
  155. <div class={[styles.paymentTitle]}>
  156. <MHeader
  157. title={isRefund ? '申请退款' : '订单详情'}
  158. background="transparent"
  159. />
  160. {state.orders.id && (
  161. <>
  162. <div class={styles.orderType}>
  163. <Image
  164. class={styles.img}
  165. src={formatImg(state.orders.status)}
  166. />
  167. <div class={styles.orderInfo}>
  168. <span>{formatOrderStatus(state.orders.status)}</span>
  169. {state.orders.status === 'PAID' ? (
  170. <div class={styles.orderPrice}>
  171. 实付金额:¥ {moneyFormat(state.orders.paymentCashAmount)}
  172. </div>
  173. ) : null}
  174. {['ING', 'PASS', 'REJECT', 'REFUNDED'].includes(
  175. state.orders.status
  176. ) && (
  177. <div class={styles.orderPrice}>
  178. 退款金额:¥ {moneyFormat(state.orders.paymentCashAmount)}
  179. </div>
  180. )}
  181. {['CLOSED'].includes(state.orders.status) && (
  182. <div class={styles.orderPrice}>
  183. 实付金额:¥ {moneyFormat(state.orders.paymentCashAmount)}
  184. </div>
  185. )}
  186. </div>
  187. </div>
  188. </>
  189. )}
  190. </div>
  191. <CellGroup inset class={[styles.cellGroup, styles.mTop]}>
  192. <Cell>
  193. {{
  194. title: () => '付款时间',
  195. value: () => (
  196. <span>
  197. {state.orders.payTime || state.orders.refundTime || '--'}
  198. </span>
  199. )
  200. }}
  201. </Cell>
  202. <Cell>
  203. {{
  204. title: () => '订单编号',
  205. value: () => <span>{state.orders.orderNo}</span>
  206. }}
  207. </Cell>
  208. </CellGroup>
  209. <CellGroup inset class={styles.cellGroup}>
  210. <div class={styles.buyDetail}>
  211. <div class={styles.buyDetailTitle}>
  212. <i></i> 购买详情
  213. </div>
  214. </div>
  215. {state.goodsInfos.map((goods: any) => (
  216. <Cell>
  217. {{
  218. icon: () => (
  219. <Image class={styles.buyImg} src={goods.goodsUrl} />
  220. ),
  221. title: () => (
  222. <div class={styles.buyContent}>
  223. <p class={styles.goodsTitle}>{goods.goodsName}</p>
  224. <Tag class={styles.brandName}>
  225. {state.orders.orderType === 'VIP'
  226. ? '12个月'
  227. : goods.brandName}
  228. </Tag>
  229. </div>
  230. ),
  231. value: () => <span>x {goods.goodsNum}</span>
  232. }}
  233. </Cell>
  234. ))}
  235. </CellGroup>
  236. {state.refundAudit === 'ING' && (
  237. <Button
  238. class={styles.cancelBtn}
  239. block
  240. round
  241. type="primary"
  242. onClick={() => handleBack()}>
  243. 撤销退款
  244. </Button>
  245. )}
  246. </div>
  247. );
  248. }
  249. });