| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- import { getAfterSaleDetailMethod, cancelAfterSaleMethod, updateAfterSaleMethod } from "../../request";
- // progress 数字转页面状态
- const progressToState: Record<string, string> = {
- '0': 'processing',
- '1': 'revoked',
- '2': 'rejected',
- '3': 'approved',
- '4': 'completed',
- };
- Page({
- data: {
- id: '',
- aftersaleId: '',
- pageTitle: '商家处理',
- refundState: '',
- days: '00',
- hours: '00',
- minutes: '00',
- seconds: '00',
- goods: {
- name: "",
- meta1: "",
- price: "",
- image: "",
- },
- refundDetail: {
- reason: "",
- amount: "",
- finishTime: "",
- applyTime: "",
- refundNo: "",
- },
- // 协商历史标题和内容
- negotiateTitle: "",
- negotiateContent: "",
- // 拒绝状态处理截止时间
- handleEndTime: "",
- refundDestination: {
- type: '退回微信',
- account: '',
- },
- // 弹窗状态
- refundReasonPopupVisible: false,
- refundConfirmPopupVisible: false,
- refundProofPopupVisible: false,
- refundStatus: '',
- refundMaxAmount: '0',
- refundProofImages: [] as string[],
- },
- timer: null as any,
- onLoad(options: any) {
- if (options.id) {
- this.setData({ id: options.id });
- 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({
- 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.reviewAmount || detail.applyAmount || 0),
- finishTime: detail.finishTime || '',
- applyTime: detail.applyTime || '',
- refundNo: detail.ref || '',
- },
- negotiateTitle: detail.title || '',
- negotiateContent: detail.content || '',
- handleEndTime: detail.handleEndTime || '',
- refundMaxAmount: String(detail.applyAmount || 0),
- refundProofImages: detail.voucherImgs || [],
- });
- 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' });
- 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({ 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
- });
- },
- onSubmitRefundApply() {
- this.setData({ refundConfirmPopupVisible: false });
- wx.showLoading({ title: '正在提交' });
- setTimeout(() => {
- wx.hideLoading();
- wx.navigateTo({
- url: '/module/order/pages/refund-success/refund-success'
- });
- }, 1000);
- },
- onRefundReasonPopupClose() {
- this.setData({ refundReasonPopupVisible: false });
- },
- onRefundReasonNext(e: any) {
- this.setData({
- ['refundDetail.reason']: e.detail.reason,
- refundReasonPopupVisible: false,
- refundConfirmPopupVisible: true
- });
- },
- onRefundProofPopupClose() {
- this.setData({ refundProofPopupVisible: false });
- },
- onRefundProofSubmit(e: any) {
- this.setData({
- refundProofImages: e.detail.images,
- 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: () => { }
- });
- },
- 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' });
- }
- }
- }
- });
- }
- });
|