refund-processing.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import { getAfterSaleDetailMethod, cancelAfterSaleMethod, updateAfterSaleMethod } from "../../request";
  2. // progress 数字转页面状态
  3. const progressToState: Record<string, string> = {
  4. '0': 'processing',
  5. '1': 'revoked',
  6. '2': 'rejected',
  7. '3': 'approved',
  8. '4': 'completed',
  9. };
  10. Page({
  11. data: {
  12. id: '',
  13. aftersaleId: '',
  14. pageTitle: '商家处理',
  15. refundState: '',
  16. days: '00',
  17. hours: '00',
  18. minutes: '00',
  19. seconds: '00',
  20. goods: {
  21. name: "",
  22. meta1: "",
  23. price: "",
  24. image: "",
  25. },
  26. refundDetail: {
  27. reason: "",
  28. amount: "",
  29. finishTime: "",
  30. applyTime: "",
  31. refundNo: "",
  32. },
  33. // 协商历史标题和内容
  34. negotiateTitle: "",
  35. negotiateContent: "",
  36. // 拒绝状态处理截止时间
  37. handleEndTime: "",
  38. refundDestination: {
  39. type: '退回微信',
  40. account: '',
  41. },
  42. // 弹窗状态
  43. refundReasonPopupVisible: false,
  44. refundConfirmPopupVisible: false,
  45. refundProofPopupVisible: false,
  46. refundStatus: '',
  47. refundMaxAmount: '0',
  48. refundProofImages: [] as string[],
  49. },
  50. timer: null as any,
  51. onLoad(options: any) {
  52. if (options.id) {
  53. this.setData({ id: options.id });
  54. this.loadDetail(options.id);
  55. }
  56. },
  57. onShow() {
  58. if (this.data.id && this.data.refundState) {
  59. this.loadDetail(this.data.id);
  60. }
  61. },
  62. async loadDetail(id: string) {
  63. wx.showLoading({ title: '加载中' });
  64. try {
  65. const res = await getAfterSaleDetailMethod(id);
  66. const detail = (res as any)?.data;
  67. if (!detail) return;
  68. const refundState = progressToState[String(detail.progress)] || 'processing';
  69. this.setData({
  70. aftersaleId: detail.id || '',
  71. refundState,
  72. goods: {
  73. name: detail.conditioningProgramName || '',
  74. meta1: detail.convertDose ? `${detail.convertDose}${detail.convertUnit || '次'}` : '',
  75. price: String(detail.applyAmount || 0),
  76. image: detail.conditioningProgramPhoto || '',
  77. },
  78. refundDetail: {
  79. reason: detail.reason || '',
  80. amount: String(detail.reviewAmount || detail.applyAmount || 0),
  81. finishTime: detail.finishTime || '',
  82. applyTime: detail.applyTime || '',
  83. refundNo: detail.ref || '',
  84. },
  85. negotiateTitle: detail.title || '',
  86. negotiateContent: detail.content || '',
  87. handleEndTime: detail.handleEndTime || '',
  88. refundMaxAmount: String(detail.applyAmount || 0),
  89. refundProofImages: detail.voucherImgs || [],
  90. });
  91. this.updatePageTitle();
  92. if (refundState === 'processing' || refundState === 'rejected') {
  93. this.startCountdown();
  94. }
  95. } catch (error: any) {
  96. wx.showToast({ title: error.errMsg || '获取详情失败', icon: 'none' });
  97. }
  98. wx.hideLoading();
  99. },
  100. updatePageTitle() {
  101. let title = '商家处理';
  102. if (this.data.refundState === 'revoked') {
  103. title = '撤销申请';
  104. } else if (this.data.refundState === 'completed') {
  105. title = '退款完成';
  106. }
  107. this.setData({ pageTitle: title });
  108. },
  109. onUnload() {
  110. if (this.timer) {
  111. clearInterval(this.timer);
  112. }
  113. },
  114. startCountdown() {
  115. if (this.timer) clearInterval(this.timer);
  116. const setTime = (diff: number) => {
  117. if (diff <= 0) {
  118. this.setData({ days: '00', hours: '00', minutes: '00', seconds: '00' });
  119. return;
  120. }
  121. const d = Math.floor(diff / (1000 * 60 * 60 * 24));
  122. const h = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  123. const m = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
  124. const s = Math.floor((diff % (1000 * 60)) / 1000);
  125. this.setData({
  126. days: d < 10 ? '0' + d : String(d),
  127. hours: h < 10 ? '0' + h : String(h),
  128. minutes: m < 10 ? '0' + m : String(m),
  129. seconds: s < 10 ? '0' + s : String(s),
  130. });
  131. };
  132. if (this.data.refundState === 'rejected' && this.data.handleEndTime) {
  133. // rejected:倒计时到处理截止时间
  134. const target = new Date(this.data.handleEndTime.replace(/-/g, '/')).getTime();
  135. const update = () => setTime(target - new Date().getTime());
  136. update();
  137. this.timer = setInterval(update, 1000);
  138. } else {
  139. // processing:已过去的时间
  140. const applyTime = new Date(this.data.refundDetail.applyTime.replace(/-/g, '/')).getTime();
  141. const update = () => setTime(new Date().getTime() - applyTime);
  142. update();
  143. this.timer = setInterval(update, 1000);
  144. }
  145. },
  146. // 修改申请:打开确认弹窗
  147. onModify() {
  148. this.setData({ refundConfirmPopupVisible: true });
  149. },
  150. onRefundConfirmClose() {
  151. this.setData({ refundConfirmPopupVisible: false });
  152. },
  153. onChangeRefundStatus(e: any) {
  154. this.setData({ refundStatus: e.detail.status });
  155. },
  156. onOpenRefundReasonAgain() {
  157. this.setData({
  158. refundConfirmPopupVisible: false,
  159. refundReasonPopupVisible: true
  160. });
  161. },
  162. onOpenRefundProofEditor() {
  163. this.setData({
  164. refundConfirmPopupVisible: false,
  165. refundProofPopupVisible: true
  166. });
  167. },
  168. onRefundAmountConfirm(e: any) {
  169. this.setData({
  170. ['refundDetail.amount']: e.detail.amount
  171. });
  172. },
  173. onSubmitRefundApply() {
  174. this.setData({ refundConfirmPopupVisible: false });
  175. wx.showLoading({ title: '正在提交' });
  176. setTimeout(() => {
  177. wx.hideLoading();
  178. wx.navigateTo({
  179. url: '/module/order/pages/refund-success/refund-success'
  180. });
  181. }, 1000);
  182. },
  183. onRefundReasonPopupClose() {
  184. this.setData({ refundReasonPopupVisible: false });
  185. },
  186. onRefundReasonNext(e: any) {
  187. this.setData({
  188. ['refundDetail.reason']: e.detail.reason,
  189. refundReasonPopupVisible: false,
  190. refundConfirmPopupVisible: true
  191. });
  192. },
  193. onRefundProofPopupClose() {
  194. this.setData({ refundProofPopupVisible: false });
  195. },
  196. onRefundProofSubmit(e: any) {
  197. this.setData({
  198. refundProofImages: e.detail.images,
  199. refundProofPopupVisible: false,
  200. refundConfirmPopupVisible: true
  201. });
  202. },
  203. onViewHistory() {
  204. wx.navigateTo({
  205. url: `/module/order/pages/negotiation-history/negotiation-history?id=${this.data.aftersaleId}`
  206. });
  207. },
  208. onCopyRefundNo() {
  209. wx.setClipboardData({
  210. data: this.data.refundDetail.refundNo,
  211. success: () => {
  212. wx.showToast({ title: '已复制', icon: 'none' });
  213. }
  214. });
  215. },
  216. onCallService() {
  217. wx.makePhoneCall({
  218. phoneNumber: '400-123-4567',
  219. fail: () => { }
  220. });
  221. },
  222. onRevoke() {
  223. wx.showModal({
  224. title: '撤销退款申请',
  225. content: '撤销退款申请后,可以再次发起退款申请(总共可发起2次)',
  226. confirmText: '确定撤销',
  227. cancelText: '暂不撤销',
  228. success: async (res) => {
  229. if (res.confirm) {
  230. try {
  231. await cancelAfterSaleMethod(Number(this.data.aftersaleId));
  232. wx.showToast({ title: '已撤销', icon: 'success' });
  233. setTimeout(() => {
  234. wx.redirectTo({
  235. url: '/module/article/pages/success-page/success-page?title=撤销退款申请成功'
  236. });
  237. }, 1500);
  238. } catch (error: any) {
  239. wx.showToast({ title: error.errMsg || '撤销失败', icon: 'none' });
  240. }
  241. }
  242. }
  243. });
  244. }
  245. });