| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- import { getAfterSaleDetailMethod, cancelAfterSaleMethod, applyAfterSaleMethod, updateAfterSaleMethod } from "../../request";
- // progress 数字转页面状态
- const progressToState: Record<string, string> = {
- '0': 'processing',
- '1': 'revoked',
- '2': 'rejected',
- '3': 'approved',
- '4': 'completed',
- };
- Page({
- data: {
- id: '',
- recordId: '',
- aftersaleId: '',
- pageTitle: '商家处理',
- refundState: '',
- days: '00',
- hours: '00',
- minutes: '00',
- seconds: '00',
- goods: {
- name: "",
- meta1: "",
- price: "",
- image: "",
- },
- refundDetail: {
- reason: "",
- amount: "",
- finishTime: "",
- applyTime: "",
- refundNo: "",
- updateTime:""
- },
- // 协商历史标题和内容
- negotiateTitle: "",
- negotiateContent: "",
- // 拒绝状态处理截止时间
- handleEndTime: "",
- refundDestination: {
- type: '退回微信',
- account: '',
- },
- // 弹窗状态
- refundReasonPopupVisible: false,
- refundConfirmPopupVisible: false,
- refundProofPopupVisible: false,
- refundStatus: '',
- refundAction: '', // 'modify' 修改申请 | 'reApply' 再次申请
- refundMaxAmount: '0',
- refundProofImages: [] as string[],
- refundDesc: '',
- // 接口提交所需原始字段
- rawDetail: {} as any,
- },
- timer: null as any,
- onLoad(options: any) {
- if (options.id) {
- this.setData({ id: options.id, recordId: options.recordId || '' });
- this.loadDetail(options.id);
- }
- },
- onShow() {
- if (this.data.id && this.data.refundState) {
- this.loadDetail(this.data.id);
- }
- },
- async loadDetail(id: string) {
- wx.showLoading({ title: '加载中' });
- try {
- const res = await getAfterSaleDetailMethod(id);
- const detail = (res as any)?.data;
- if (!detail) return;
- const refundState = progressToState[String(detail.progress)] || 'processing';
- this.setData({
- rawDetail: detail,
- aftersaleId: detail.id || '',
- refundState,
- goods: {
- name: detail.conditioningProgramName || '',
- meta1: detail.convertDose ? `${detail.convertDose}${detail.convertUnit || '次'}` : '',
- price: String(detail.applyAmount || 0),
- image: detail.conditioningProgramPhoto || '',
- },
- refundDetail: {
- reason: detail.reason || '',
- amount: String(detail.applyAmount || 0),
- finishTime: detail.finishTime || '',
- applyTime: detail.applyTime || '',
- refundNo: detail.ref || '',
- updateTime:detail.updateTime || ''
- },
- negotiateTitle: detail.title || '',
- negotiateContent: (() => {
- const c = detail.content || '';
- try { if (c && JSON.parse(c)) return ''; } catch (e) { /* 不是JSON,保留原文 */ }
- return c;
- })(),
- handleEndTime: detail.handleEndTime || '',
- refundMaxAmount: String(detail.applyAmount || 0),
- refundProofImages: detail.voucherImgs || [],
- refundDesc: detail.remark || '',
- });
- this.updatePageTitle();
- if (refundState === 'processing' || refundState === 'rejected') {
- this.startCountdown();
- }
- } catch (error: any) {
- wx.showToast({ title: error.errMsg || '获取详情失败', icon: 'none' });
- }
- wx.hideLoading();
- },
- updatePageTitle() {
- let title = '商家处理';
- if (this.data.refundState === 'revoked') {
- title = '撤销申请';
- } else if (this.data.refundState === 'completed') {
- title = '退款完成';
- }
- this.setData({ pageTitle: title });
- },
- onUnload() {
- if (this.timer) {
- clearInterval(this.timer);
- }
- },
- startCountdown() {
- if (this.timer) clearInterval(this.timer);
- const setTime = (diff: number) => {
- if (diff <= 0) {
- this.setData({ days: '00', hours: '00', minutes: '00', seconds: '00' });
- if (this.timer) {
- clearInterval(this.timer);
- this.timer = null;
- }
- // 拒绝状态倒计时结束,清除截止时间,触发按钮切换
- if (this.data.refundState === 'rejected' && this.data.handleEndTime) {
- this.setData({ handleEndTime: '' });
- }
- return;
- }
- const d = Math.floor(diff / (1000 * 60 * 60 * 24));
- const h = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
- const m = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
- const s = Math.floor((diff % (1000 * 60)) / 1000);
- this.setData({
- days: d < 10 ? '0' + d : String(d),
- hours: h < 10 ? '0' + h : String(h),
- minutes: m < 10 ? '0' + m : String(m),
- seconds: s < 10 ? '0' + s : String(s),
- });
- };
- if (this.data.refundState === 'rejected' && this.data.handleEndTime) {
- // rejected:倒计时到处理截止时间
- const target = new Date(this.data.handleEndTime.replace(/-/g, '/')).getTime();
- const update = () => setTime(target - new Date().getTime());
- update();
- this.timer = setInterval(update, 1000);
- } else {
- // processing:已过去的时间
- const applyTime = new Date(this.data.refundDetail.applyTime.replace(/-/g, '/')).getTime();
- const update = () => setTime(new Date().getTime() - applyTime);
- update();
- this.timer = setInterval(update, 1000);
- }
- },
- // 修改申请:打开确认弹窗
- onModify() {
- this.setData({ refundAction: 'modify', refundConfirmPopupVisible: true });
- },
- onRefundConfirmClose() {
- this.setData({ refundConfirmPopupVisible: false });
- },
- onChangeRefundStatus(e: any) {
- this.setData({ refundStatus: e.detail.status });
- },
- onOpenRefundReasonAgain() {
- this.setData({
- refundConfirmPopupVisible: false,
- refundReasonPopupVisible: true
- });
- },
- onOpenRefundProofEditor() {
- this.setData({
- refundConfirmPopupVisible: false,
- refundProofPopupVisible: true
- });
- },
- onRefundAmountConfirm(e: any) {
- this.setData({
- ['refundDetail.amount']: e.detail.amount
- });
- },
- async onSubmitRefundApply() {
- if (!this.data.refundProofImages.length) {
- wx.showToast({ title: '请上传凭证图片', icon: 'none' });
- return;
- }
- wx.showLoading({ title: '正在提交' });
- const { rawDetail, refundStatus, refundDetail, refundProofImages, refundDesc, recordId, id, aftersaleId, refundAction } = this.data;
- const params = {
- patientConditioningRecordId: recordId,
- patientConditioningProgramId: id,
- type: rawDetail.type,
- ...(rawDetail.sellType === '1' ? { receiptStatus: refundStatus || rawDetail.receiptStatus } : {}),
- reason: refundDetail.reason,
- applyAmount: Number(refundDetail.amount) || 0,
- voucherImgs: refundProofImages,
- remark: refundDesc,
- };
- try {
- if (refundAction === 'modify') {
- await updateAfterSaleMethod(Number(aftersaleId), params);
- } else {
- await applyAfterSaleMethod(params);
- }
- this.setData({ refundConfirmPopupVisible: false });
- wx.navigateTo({
- url: '/module/order/pages/refund-success/refund-success'
- });
- } catch (error: any) {
- wx.showToast({ title: error.errMsg || '提交失败', icon: 'none' });
- }
- wx.hideLoading();
- },
- onRefundReasonPopupClose() {
- this.setData({ refundReasonPopupVisible: false });
- },
- onRefundReasonNext(e: any) {
- this.setData({
- ['refundDetail.reason']: e.detail.reason,
- refundReasonPopupVisible: false,
- refundConfirmPopupVisible: true
- });
- },
- onRefundProofPopupClose() {
- this.setData({ refundProofPopupVisible: false, refundConfirmPopupVisible: true });
- },
- onRefundProofSubmit(e: any) {
- this.setData({
- refundProofImages: e.detail.images,
- refundDesc: e.detail.desc || '',
- refundProofPopupVisible: false,
- refundConfirmPopupVisible: true
- });
- },
- onViewHistory() {
- wx.navigateTo({
- url: `/module/order/pages/negotiation-history/negotiation-history?id=${this.data.aftersaleId}`
- });
- },
- onCopyRefundNo() {
- wx.setClipboardData({
- data: this.data.refundDetail.refundNo,
- success: () => {
- wx.showToast({ title: '已复制', icon: 'none' });
- }
- });
- },
- onCallService() {
- wx.makePhoneCall({
- phoneNumber: '400-123-4567',
- fail: () => { }
- });
- },
- onReApply() {
- this.setData({ refundAction: 'reApply', refundConfirmPopupVisible: true });
- },
- onRevoke() {
- wx.showModal({
- title: '撤销退款申请',
- content: '撤销退款申请后,可以再次发起退款申请(总共可发起2次)',
- confirmText: '确定撤销',
- cancelText: '暂不撤销',
- success: async (res) => {
- if (res.confirm) {
- try {
- await cancelAfterSaleMethod(Number(this.data.aftersaleId));
- wx.showToast({ title: '已撤销', icon: 'success' });
- setTimeout(() => {
- wx.redirectTo({
- url: '/module/article/pages/success-page/success-page?title=撤销退款申请成功'
- });
- }, 1500);
- } catch (error: any) {
- wx.showToast({ title: error.errMsg || '撤销失败', icon: 'none' });
- }
- }
- }
- });
- }
- });
|