// pages/merchant-order-detail/merchant-order-detail.js - 商家订单详情(完整版,已添加罚款/退款操作及教程按钮) const app = getApp() import request from '../../utils/request.js' import PopupService from '../../services/popupService.js' // 新增:导入弹窗服务 import connectionManager from '../../utils/xiaoxilj.js' import { STAFF_API, isStaffMode, syncStaffUi, getStaffContext, staffCan } from '../../utils/staff-api.js' /** 可申请罚款的订单状态:进行中/已完成/退款中/已退款/退款失败/结算中 */ const PENALTY_APPLY_ORDER_STATUSES = [2, 3, 4, 5, 6, 8] function canApplyOrderPenalty({ zhuangtai, dashouYonghuid, fadanData, canPenalty }) { return canPenalty && !fadanData && dashouYonghuid && PENALTY_APPLY_ORDER_STATUSES.includes(Number(zhuangtai)) } Page({ data: { jibenShuju: { dingdan_id: '', tupian: '', jieshao: '', create_time: '', jine: '', nicheng: '', beizhu: '', waibu_dingdan_id: '', zhuangtai: 0, fadanpingtai: 0 }, dashouInfo: { yonghuid: '', nicheng: '', avatar: '' }, dispatchStaff: null, dispatchStaffAvatar: '', xiangxiShuju: { dashou_jiaofu: [], dashou_liuyan: '', tuikuan_liyou: '', shangjia_liuyan: '' }, fadanData: null, fenhongLilv: 0, xinDingdanId: '', zhuangtaiYanseMap: { 1: '#E8F5E9', 2: '#E3F2FD', 3: '#F3E5F5', 4: '#FFF3E0', 5: '#FFEBEE', 6: '#EFEBE9', 7: '#E0F7FA', 8: '#FFF8E1' }, zhuangtaiWenziMap: { 1: '已下单', 2: '进行中', 3: '已完成', 4: '退款中', 5: '已退款', 6: '退款失败', 7: '指定中', 8: '结算中' }, isLoading: true, showChexiaoModal: false, chexiaoLiyou: '', isChexiaoLoading: false, showTuikuanModal: false, tuikuanLiyou: '', isTuikuanLoading: false, showFakuanModal: false, fakuanLiyou: '', fakuanJine: '', yingxiangQiangdan: true, isFakuanLoading: false, showGhDashouModal: false, isGhDashouLoading: false, showJiesuanConfirm: false, isJiesuanLoading: false, jiesuanPingfen: 0, jiesuanLiuyan: '', xingxingData: [ { id: 1, active: false }, { id: 2, active: false }, { id: 3, active: false }, { id: 4, active: false }, { id: 5, active: false } ], currentIMUserId: '', // ========== 新增:罚单/订单操作弹窗控制 ========== showModifyFakuanModal: false, // 修改罚款弹窗 modifyFakuanLiyou: '', // 修改后的罚款理由 modifyFakuanJine: '', // 修改后的罚款金额 showCancelFakuanModal: false, // 撤销罚款弹窗 cancelFakuanLiyou: '', // 撤销驳回理由 showResubmitFakuanModal: false, // 再次申请罚款弹窗 resubmitFakuanLiyou: '', // 再次申请的理由 resubmitFakuanJine: '', // 再次申请的金额 showCancelTuikuanModal: false, // 撤销退款申请弹窗 cancelTuikuanLiyou: '', // 撤销退款理由 showModifyTuikuanModal: false, // 修改退款理由弹窗 modifyTuikuanLiyou: '', // 修改后的退款理由 // 教程按钮状态 tutorialBtnHidden: false, canCancel: true, canRefund: true, canSettle: true, canPenalty: true, canPenaltyManage: true, canShowPenaltyApply: false, }, refreshPenaltyApplyBtn() { const { jibenShuju, dashouInfo, fadanData, canPenalty } = this.data this.setData({ canShowPenaltyApply: canApplyOrderPenalty({ zhuangtai: jibenShuju.zhuangtai, dashouYonghuid: dashouInfo.yonghuid, fadanData, canPenalty, }), }) }, onLoad(options) { wx.setNavigationBarTitle({ title: '订单详情' }) syncStaffUi(this) this.ensureIMConnection() this.jiexiTiaozhuanCanshu(options) // 新增:启动教程按钮定时器 this.startTutorialBtnTimer() }, onShow() { this.registerNotificationComponent() syncStaffUi(this) this.refreshPenaltyApplyBtn() this.ensureIMConnection() }, onHide() { // 页面隐藏时重置弹窗服务状态,避免影响其他页面 PopupService.reset() }, onUnload() { // 清除缩进定时器,避免内存泄漏 if (this.tutorialTimer) { clearTimeout(this.tutorialTimer) } // 页面卸载时重置弹窗服务 PopupService.reset() }, registerNotificationComponent() { const notificationComp = this.selectComponent('#global-notification') if (notificationComp && notificationComp.showNotification) { app.globalData.globalNotification = { show: (data) => notificationComp.showNotification(data), hide: () => notificationComp.hideNotification() } } }, ensureIMConnection() { const uid = wx.getStorageSync('uid') if (!uid) return const targetUserId = 'Sj' + uid if (wx.goEasy && wx.goEasy.getConnectionStatus) { const status = wx.goEasy.getConnectionStatus() if (status === 'connected' || status === 'reconnected') { const currentUserId = wx.goEasy.im ? wx.goEasy.im.userId : null if (currentUserId === targetUserId) { this.setData({ currentIMUserId: targetUserId }) return } else { wx.goEasy.disconnect() } } } this.connectGoEasy(targetUserId) }, connectGoEasy(userId) { let currentUser = app.globalData.currentUser if (!currentUser) { const uid = wx.getStorageSync('uid') currentUser = { id: uid, name: '用户' + (uid ? uid.substring(0, 6) : ''), avatar: app.globalData.ossImageUrl + app.globalData.morentouxiang } } const staffCtx = isStaffMode() ? getStaffContext() : null let imName = currentUser.name || wx.getStorageSync('nicheng') || '商家' if (staffCtx) { const roleLabel = staffCtx.role_name || '客服' const nick = staffCtx.display_name || wx.getStorageSync('nicheng') || '' imName = nick ? `${nick}(${roleLabel})` : roleLabel } wx.goEasy.connect({ id: userId, data: { name: imName, avatar: currentUser.avatar || (app.globalData.ossImageUrl + app.globalData.morentouxiang) }, onSuccess: () => { this.setData({ currentIMUserId: userId }) try { wx.setStorageSync('savedGoEasyConnection', JSON.stringify({ userId, identityType: 'shangjia', lastConnectTime: Date.now() })) wx.setStorageSync('goEasyUserId', userId) } catch (e) {} }, onFailed: (error) => { if (error.code === 408) { this.setData({ currentIMUserId: userId }) } else { console.error('IM连接失败', error) } } }) }, jiexiTiaozhuanCanshu(options) { const directId = options.dingdan_id || options.dingdanId || '' if (directId) { this.setData({ 'jibenShuju.dingdan_id': directId, isLoading: false, }) this.jiazaiXiangxiShuju(directId) return } try { const dingdanDataStr = options.dingdanData || '' if (!dingdanDataStr) { wx.showToast({ title: '订单数据错误', icon: 'none' }) setTimeout(() => wx.navigateBack(), 1500) return } const dingdanData = JSON.parse(decodeURIComponent(dingdanDataStr)) let tupianUrl = dingdanData.tupian || '' if (!tupianUrl) tupianUrl = this.getTupianUrl() let jine = parseFloat(dingdanData.jine || 0) if (isNaN(jine)) jine = 0 this.setData({ 'jibenShuju.dingdan_id': dingdanData.dingdan_id || '', 'jibenShuju.tupian': tupianUrl, 'jibenShuju.jieshao': dingdanData.jieshao || '', 'jibenShuju.create_time': dingdanData.create_time || '', 'jibenShuju.jine': jine.toFixed(2), 'jibenShuju.nicheng': dingdanData.nicheng || '', 'jibenShuju.beizhu': dingdanData.beizhu || '', 'jibenShuju.zhuangtai': dingdanData.zhuangtai || 0, 'jibenShuju.fadanpingtai': dingdanData.fadanpingtai || 0, isLoading: false }) this.jiazaiXiangxiShuju(dingdanData.dingdan_id) } catch (error) { console.error('解析订单数据失败', error) wx.showToast({ title: '数据解析失败', icon: 'none' }) setTimeout(() => wx.navigateBack(), 1500) } }, getTupianUrl() { const cacheTouxiang = wx.getStorageSync('touxiang') || '' let tupianPath = cacheTouxiang || app.globalData.morentouxiang || '' const ossImageUrl = app.globalData.ossImageUrl || '' if (tupianPath && ossImageUrl) { if (tupianPath.startsWith('/')) tupianPath = tupianPath.substring(1) return ossImageUrl + tupianPath } return '' }, async jiazaiXiangxiShuju(dingdanId) { if (!dingdanId) return try { const res = await request({ url: isStaffMode() ? STAFF_API.orderDetail : '/dingdan/sjddxq', method: 'POST', data: { dingdan_id: dingdanId }, header: { 'content-type': 'application/json' } }) if (res && res.data.code === 0 && res.data.data) { const d = res.data.data let jiaofuList = d.dashou_jiaofu || [] jiaofuList = jiaofuList.map(url => { if (url && !url.startsWith('http')) { const oss = app.globalData.ossImageUrl || '' return oss + url } return url }) let dashouAvatar = d.dashou_avatar || '' if (dashouAvatar && !dashouAvatar.startsWith('http')) { dashouAvatar = (app.globalData.ossImageUrl || '') + dashouAvatar } let dispatchStaffAvatar = (d.dispatch_staff && d.dispatch_staff.dispatch_staff_avatar) || '' if (dispatchStaffAvatar && !dispatchStaffAvatar.startsWith('http')) { const oss = app.globalData.ossImageUrl || '' dispatchStaffAvatar = oss + (dispatchStaffAvatar.startsWith('/') ? dispatchStaffAvatar.slice(1) : dispatchStaffAvatar) } this.setData({ 'dashouInfo.yonghuid': d.dashou_yonghuid || '', 'dashouInfo.nicheng': d.dashou_nicheng || '', 'dashouInfo.avatar': dashouAvatar, dispatchStaff: d.dispatch_staff || null, dispatchStaffAvatar: dispatchStaffAvatar || '/images/default-avatar.png', 'xiangxiShuju.dashou_jiaofu': jiaofuList, 'xiangxiShuju.dashou_liuyan': d.dashou_liuyan || '', 'xiangxiShuju.tuikuan_liyou': d.tuikuan_liyou || '', 'xiangxiShuju.shangjia_liuyan': d.shangjia_liuyan || '', fadanData: d.fadan || null, fenhongLilv: parseFloat(d.fenhong_lilv) || 0, xinDingdanId: d.xin_dingdan_id || '', 'jibenShuju.zhuangtai': d.zhuangtai || this.data.jibenShuju.zhuangtai, 'jibenShuju.waibu_dingdan_id': d.waibu_dingdan_id || '', }) this.refreshPenaltyApplyBtn() } else { wx.showToast({ title: res?.data?.msg || '获取详情失败', icon: 'none' }) } } catch (err) { console.error('加载详情失败', err) wx.showToast({ title: '网络错误', icon: 'none' }) } }, fuzhiWenben(e) { const text = e.currentTarget.dataset.text if (!text) return wx.setClipboardData({ data: text }) wx.showToast({ title: '已复制', icon: 'success' }) }, yulanTupian(e) { const current = e.currentTarget.dataset.url const urls = e.currentTarget.dataset.urls || [current] wx.previewImage({ current, urls }) }, goToKefu() { const kefuLink = app.globalData.kefuConfig?.link || '' const corpId = app.globalData.kefuConfig?.enterpriseId || '' if (!kefuLink || !corpId) { wx.showToast({ title: '客服配置未加载', icon: 'none' }) return } wx.openCustomerServiceChat({ extInfo: { url: kefuLink }, corpId: corpId, success: (res) => console.log('跳转客服成功', res), fail: (err) => { console.error('跳转客服失败', err) wx.showToast({ title: '暂时无法连接客服', icon: 'none' }) } }) }, // ===== 联系打手(订单群 groupId = 订单号) ===== goToChatWithDashou() { if (isStaffMode() && !staffCan('imChat')) { wx.showToast({ title: '当前角色无订单聊天权限', icon: 'none' }) return } const uid = wx.getStorageSync('uid') if (!uid) return const orderId = this.data.jibenShuju.dingdan_id if (!orderId) { wx.showToast({ title: '订单ID缺失', icon: 'none' }) return } const groupName = this.data.jibenShuju.nicheng + '的订单群' const isCross = this.data.jibenShuju.fadanpingtai || 0 const dashouUid = this.data.dashouInfo.yonghuid const that = this const openGroupChat = () => { connectionManager.connectToGroupChat({ identityType: 'shangjia', userId: 'Sj' + uid, orderId: orderId, partnerUid: dashouUid, fadanPingtai: this.data.jibenShuju.fadanpingtai || 0, groupName, isCross, }).catch((err) => { console.error('跳转群聊失败', err) wx.showToast({ title: '跳转聊天失败', icon: 'none' }) }) } if (dashouUid) { that.bangDashouDingyue(orderId, dashouUid) .then(openGroupChat) .catch((err) => { console.error('替打手订阅失败,仍可进入群聊', err) wx.showToast({ title: '通知接单员可能失败', icon: 'none' }) openGroupChat() }) } else { openGroupChat() } }, // 帮打手订阅群组 + 发送机器人消息 bangDashouDingyue(orderId, dashouUid) { return new Promise((resolve, reject) => { const dashouImId = 'Ds' + dashouUid const appkey = 'BC-32e2991c69bc47e1b538e73aaed37fc1' // 你的GoEasy AppKey const restHost = 'https://rest-hz.goeasy.io' // 1. 通过 REST API 为打手订阅群组 wx.request({ url: restHost + '/v2/im/subscribe-groups', method: 'POST', header: { 'content-type': 'application/json' }, data: { appkey: appkey, userIds: [dashouImId], groupIds: [orderId] }, success: (res) => { if (res.data.code === 200) { // 2. 订阅成功后,以打手身份发送一条系统消息 wx.request({ url: restHost + '/v2/im/message', method: 'POST', header: { 'content-type': 'application/json' }, data: { appkey: appkey, senderId: dashouImId, senderData: { name: '系统通知', avatar: '' }, to: { type: 'group', id: orderId, data: { name: '订单群', avatar: '' } }, type: 'text', payload: '此消息为系统自动发送,接单员看到后会尽快回复您。' }, success: (msgRes) => { if (msgRes.data.code === 200) { resolve() } else { reject(new Error('发送消息失败')) } }, fail: reject }) } else { reject(new Error('订阅打手失败')) } }, fail: reject }) }) }, // ========== 以下所有业务功能完全保持不变 ========== showGhDashouConfirm() { this.setData({ showGhDashouModal: true }) }, closeGhDashouModal() { this.setData({ showGhDashouModal: false }) }, async tijiaoGhDashou() { if (this.data.isGhDashouLoading) return this.setData({ isGhDashouLoading: true }) wx.showLoading({ title: '更换中...', mask: true }) try { const res = await request({ url: isStaffMode() ? STAFF_API.changePlayer : '/dingdan/zxsjghds', method: 'POST', data: { dingdan_id: this.data.jibenShuju.dingdan_id }, header: { 'content-type': 'application/json' } }) wx.hideLoading() this.setData({ isGhDashouLoading: false, showGhDashouModal: false }) if (res && res.data.code === 0) { this.setData({ xinDingdanId: res.data.data?.xin_dingdan_id || '' }) wx.showToast({ title: '更换成功', icon: 'success' }) this.jiazaiXiangxiShuju(this.data.jibenShuju.dingdan_id) } else { wx.showToast({ title: res?.data?.msg || '更换失败', icon: 'none' }) } } catch (err) { wx.hideLoading() this.setData({ isGhDashouLoading: false, showGhDashouModal: false }) wx.showToast({ title: '网络错误', icon: 'none' }) } }, showFakuanModal() { const dingdanId = this.data.jibenShuju.dingdan_id if (dingdanId) { this.jiazaiXiangxiShuju(dingdanId) } this.setData({ showFakuanModal: true, fakuanLiyou: '', fakuanJine: '', yingxiangQiangdan: true }) }, closeFakuanModal() { this.setData({ showFakuanModal: false }) }, inputFakuanLiyou(e) { this.setData({ fakuanLiyou: e.detail.value.slice(0, 50) }) }, inputFakuanJine(e) { this.setData({ fakuanJine: e.detail.value }) }, toggleQiangdan() { this.setData({ yingxiangQiangdan: !this.data.yingxiangQiangdan }) }, jisuanFenhong() { const jine = parseFloat(this.data.fakuanJine) if (isNaN(jine) || jine <= 0) return '0.00' return (jine * this.data.fenhongLilv).toFixed(2) }, async tijiaoFakuan() { const { fakuanLiyou, fakuanJine, jibenShuju, dashouInfo } = this.data if (!fakuanLiyou.trim()) { wx.showToast({ title: '请输入罚款原因', icon: 'none' }); return } const jineNum = parseFloat(fakuanJine) if (isNaN(jineNum) || jineNum <= 0) { wx.showToast({ title: '请输入正确的罚款金额', icon: 'none' }); return } if (this.data.isFakuanLoading) return this.setData({ isFakuanLoading: true }) wx.showLoading({ title: '提交中...', mask: true }) try { const res = await request({ url: isStaffMode() ? STAFF_API.penaltyApply : '/dingdan/sjfksq', method: 'POST', data: { dingdan_id: jibenShuju.dingdan_id, chufa_liyou: fakuanLiyou, fakuanjine: jineNum.toFixed(2), yingxiang_qiangdan: this.data.yingxiangQiangdan ? 1 : 0, dashou_id: dashouInfo.yonghuid }, header: { 'content-type': 'application/json' } }) wx.hideLoading() this.setData({ isFakuanLoading: false }) if (res && res.data.code === 0) { wx.showToast({ title: '罚款申请已提交', icon: 'success' }) this.setData({ showFakuanModal: false }) this.jiazaiXiangxiShuju(jibenShuju.dingdan_id) } else { wx.showToast({ title: res?.data?.msg || '提交失败', icon: 'none' }) } } catch (err) { wx.hideLoading() this.setData({ isFakuanLoading: false }) wx.showToast({ title: '网络错误', icon: 'none' }) } }, showChexiaoBtn() { this.setData({ showChexiaoModal: true, chexiaoLiyou: '' }) }, closeChexiaoModal() { this.setData({ showChexiaoModal: false }) }, shuruChexiaoLiyou(e) { this.setData({ chexiaoLiyou: e.detail.value.slice(0, 50) }) }, async tijiaoChexiao() { if (this.data.isChexiaoLoading) return const { chexiaoLiyou, jibenShuju } = this.data if (!chexiaoLiyou.trim()) { wx.showToast({ title: '请输入撤销原因', icon: 'none' }); return } this.setData({ isChexiaoLoading: true }) wx.showLoading({ title: '撤销中...', mask: true }) try { const res = await request({ url: isStaffMode() ? STAFF_API.orderCancel : '/dingdan/sjchexiao', method: 'POST', data: { dingdan_id: jibenShuju.dingdan_id, chexiao_liyou: chexiaoLiyou }, header: { 'content-type': 'application/json' } }) wx.hideLoading() this.setData({ isChexiaoLoading: false }) if (res && res.data.code === 0) { this.setData({ 'jibenShuju.zhuangtai': 5, showChexiaoModal: false }) this.refreshPenaltyApplyBtn() wx.showToast({ title: '撤销成功', icon: 'success' }) } else { wx.showToast({ title: res?.data?.msg || '撤销失败', icon: 'none' }) } } catch (err) { wx.hideLoading() this.setData({ isChexiaoLoading: false }) wx.showToast({ title: '网络错误', icon: 'none' }) } }, showTuikuanBtn() { this.setData({ showTuikuanModal: true, tuikuanLiyou: '' }) }, closeTuikuanModal() { this.setData({ showTuikuanModal: false }) }, shuruTuikuanLiyou(e) { this.setData({ tuikuanLiyou: e.detail.value.slice(0, 50) }) }, async tijiaoTuikuan() { if (this.data.isTuikuanLoading) return const { tuikuanLiyou, jibenShuju } = this.data if (!tuikuanLiyou.trim()) { wx.showToast({ title: '请输入退款原因', icon: 'none' }); return } this.setData({ isTuikuanLoading: true }) wx.showLoading({ title: '提交中...', mask: true }) try { const res = await request({ url: isStaffMode() ? STAFF_API.orderRefund : '/dingdan/sjtkshenqing', method: 'POST', data: { dingdan_id: jibenShuju.dingdan_id, tuikuan_liyou: tuikuanLiyou }, header: { 'content-type': 'application/json' } }) wx.hideLoading() this.setData({ isTuikuanLoading: false }) if (res && res.data.code === 0) { this.setData({ 'jibenShuju.zhuangtai': 4, showTuikuanModal: false }) this.refreshPenaltyApplyBtn() wx.showToast({ title: '退款申请已提交', icon: 'success' }) } else { wx.showToast({ title: res?.data?.msg || '失败', icon: 'none' }) } } catch (err) { wx.hideLoading() this.setData({ isTuikuanLoading: false }) wx.showToast({ title: '网络错误', icon: 'none' }) } }, dianjiXingxing(e) { const pf = e.currentTarget.dataset.index const newStars = this.data.xingxingData.map((item, idx) => ({ ...item, active: idx < pf })) this.setData({ xingxingData: newStars, jiesuanPingfen: pf }) }, shuruLiuyan(e) { this.setData({ jiesuanLiuyan: e.detail.value.slice(0, 50) }) }, showJiesuanConfirm() { this.setData({ showJiesuanConfirm: true }) }, closeJiesuanConfirm() { this.setData({ showJiesuanConfirm: false }) }, async tijiaoJiesuan() { if (this.data.isJiesuanLoading) return this.setData({ isJiesuanLoading: true }) wx.showLoading({ title: '结算中...', mask: true }) try { const res = await request({ url: isStaffMode() ? STAFF_API.orderSettle : '/dingdan/sjjiesuan', method: 'POST', data: { dingdan_id: this.data.jibenShuju.dingdan_id, pingfen: this.data.jiesuanPingfen, liuyan: this.data.jiesuanLiuyan }, header: { 'content-type': 'application/json' } }) wx.hideLoading() this.setData({ isJiesuanLoading: false, showJiesuanConfirm: false }) if (res && res.data.code === 0) { this.setData({ 'jibenShuju.zhuangtai': 3 }) this.refreshPenaltyApplyBtn() wx.showToast({ title: '结算成功', icon: 'success' }) } else { wx.showToast({ title: res?.data?.msg || '结算失败', icon: 'none' }) } } catch (err) { wx.hideLoading() this.setData({ isJiesuanLoading: false }) wx.showToast({ title: '网络错误', icon: 'none' }) } }, // ========== 新增:罚款操作(修改/撤销/再次申请) ========== // 显示修改罚款弹窗(仅当状态为待缴纳 或 申诉中 时可用) showModifyFakuan() { const status = this.data.fadanData?.zhuangtai; if (status !== 1 && status !== 3) { wx.showToast({ title: '当前状态不可修改罚款', icon: 'none' }); return; } this.setData({ showModifyFakuanModal: true, modifyFakuanLiyou: this.data.fadanData?.chufaliyou || '', modifyFakuanJine: this.data.fadanData?.fakuanjine || '' }); }, closeModifyFakuanModal() { this.setData({ showModifyFakuanModal: false }); }, inputModifyFakuanLiyou(e) { this.setData({ modifyFakuanLiyou: e.detail.value.slice(0, 100) }); }, inputModifyFakuanJine(e) { this.setData({ modifyFakuanJine: e.detail.value }); }, async submitModifyFakuan() { const { modifyFakuanLiyou, modifyFakuanJine, fadanData, jibenShuju } = this.data; if (!modifyFakuanLiyou.trim()) { wx.showToast({ title: '请输入罚款理由', icon: 'none' }); return; } const jine = parseFloat(modifyFakuanJine); if (isNaN(jine) || jine <= 0) { wx.showToast({ title: '请输入正确的罚款金额', icon: 'none' }); return; } wx.showLoading({ title: '提交中...', mask: true }); try { const res = await request({ url: isStaffMode() ? STAFF_API.penaltyManage : '/dingdan/sjfkxgycx', method: 'POST', data: { operation: 'modify_penalty', fadan_id: fadanData.id, dingdan_id: jibenShuju.dingdan_id, liyou: modifyFakuanLiyou, jine: jine.toFixed(2) } }); wx.hideLoading(); if (res && res.data.code === 0) { wx.showToast({ title: '修改成功', icon: 'success' }); this.setData({ showModifyFakuanModal: false }); this.jiazaiXiangxiShuju(jibenShuju.dingdan_id); // 刷新数据 } else { wx.showToast({ title: res?.data?.msg || '修改失败', icon: 'none' }); } } catch (err) { wx.hideLoading(); wx.showToast({ title: '网络错误', icon: 'none' }); } }, // 显示撤销罚款弹窗(待缴纳/申诉中 可撤销,变为已驳回) showCancelFakuan() { const status = this.data.fadanData?.zhuangtai; if (status !== 1 && status !== 3) { wx.showToast({ title: '当前状态不可撤销罚款', icon: 'none' }); return; } this.setData({ showCancelFakuanModal: true, cancelFakuanLiyou: '' }); }, closeCancelFakuanModal() { this.setData({ showCancelFakuanModal: false }); }, inputCancelFakuanLiyou(e) { this.setData({ cancelFakuanLiyou: e.detail.value.slice(0, 100) }); }, async submitCancelFakuan() { const { cancelFakuanLiyou, fadanData, jibenShuju } = this.data; if (!cancelFakuanLiyou.trim()) { wx.showToast({ title: '请输入驳回理由', icon: 'none' }); return; } wx.showLoading({ title: '提交中...', mask: true }); try { const res = await request({ url: isStaffMode() ? STAFF_API.penaltyManage : '/dingdan/sjfkxgycx', method: 'POST', data: { operation: 'cancel_penalty', fadan_id: fadanData.id, dingdan_id: jibenShuju.dingdan_id, liyou: cancelFakuanLiyou } }); wx.hideLoading(); if (res && res.data.code === 0) { wx.showToast({ title: '已撤销', icon: 'success' }); this.setData({ showCancelFakuanModal: false }); this.jiazaiXiangxiShuju(jibenShuju.dingdan_id); } else { wx.showToast({ title: res?.data?.msg || '撤销失败', icon: 'none' }); } } catch (err) { wx.hideLoading(); wx.showToast({ title: '网络错误', icon: 'none' }); } }, // 显示再次申请罚款弹窗(仅当状态为已驳回时可用) showResubmitFakuan() { if (this.data.fadanData?.zhuangtai !== 4) { wx.showToast({ title: '当前状态不可再次申请', icon: 'none' }); return; } this.setData({ showResubmitFakuanModal: true, resubmitFakuanLiyou: '', resubmitFakuanJine: '' }); }, closeResubmitFakuanModal() { this.setData({ showResubmitFakuanModal: false }); }, inputResubmitFakuanLiyou(e) { this.setData({ resubmitFakuanLiyou: e.detail.value.slice(0, 100) }); }, inputResubmitFakuanJine(e) { this.setData({ resubmitFakuanJine: e.detail.value }); }, async submitResubmitFakuan() { const { resubmitFakuanLiyou, resubmitFakuanJine, fadanData, jibenShuju } = this.data; if (!resubmitFakuanLiyou.trim()) { wx.showToast({ title: '请输入罚款理由', icon: 'none' }); return; } const jine = parseFloat(resubmitFakuanJine); if (isNaN(jine) || jine <= 0) { wx.showToast({ title: '请输入正确的罚款金额', icon: 'none' }); return; } wx.showLoading({ title: '提交中...', mask: true }); try { const res = await request({ url: isStaffMode() ? STAFF_API.penaltyManage : '/dingdan/sjfkxgycx', method: 'POST', data: { operation: 'resubmit_penalty', fadan_id: fadanData.id, dingdan_id: jibenShuju.dingdan_id, liyou: resubmitFakuanLiyou, jine: jine.toFixed(2) } }); wx.hideLoading(); if (res && res.data.code === 0) { wx.showToast({ title: '申请成功', icon: 'success' }); this.setData({ showResubmitFakuanModal: false }); this.jiazaiXiangxiShuju(jibenShuju.dingdan_id); } else { wx.showToast({ title: res?.data?.msg || '申请失败', icon: 'none' }); } } catch (err) { wx.hideLoading(); wx.showToast({ title: '网络错误', icon: 'none' }); } }, // ========== 新增:订单退款操作(撤销/修改理由) ========== showCancelTuikuan() { if (this.data.jibenShuju.zhuangtai !== 4) { wx.showToast({ title: '只有退款中的订单可撤销', icon: 'none' }); return; } this.setData({ showCancelTuikuanModal: true, cancelTuikuanLiyou: '' }); }, closeCancelTuikuanModal() { this.setData({ showCancelTuikuanModal: false }); }, inputCancelTuikuanLiyou(e) { this.setData({ cancelTuikuanLiyou: e.detail.value.slice(0, 100) }); }, async submitCancelTuikuan() { const { cancelTuikuanLiyou, jibenShuju } = this.data; if (!cancelTuikuanLiyou.trim()) { wx.showToast({ title: '请输入撤销理由', icon: 'none' }); return; } wx.showLoading({ title: '撤销中...', mask: true }); try { const res = await request({ url: isStaffMode() ? STAFF_API.penaltyManage : '/dingdan/sjfkxgycx', method: 'POST', data: { operation: 'cancel_refund', dingdan_id: jibenShuju.dingdan_id, liyou: cancelTuikuanLiyou } }); wx.hideLoading(); if (res && res.data.code === 0) { wx.showToast({ title: '已撤销退款申请', icon: 'success' }); this.setData({ showCancelTuikuanModal: false }); this.jiazaiXiangxiShuju(jibenShuju.dingdan_id); } else { wx.showToast({ title: res?.data?.msg || '撤销失败', icon: 'none' }); } } catch (err) { wx.hideLoading(); wx.showToast({ title: '网络错误', icon: 'none' }); } }, showModifyTuikuan() { if (this.data.jibenShuju.zhuangtai !== 4) { wx.showToast({ title: '只有退款中的订单可修改理由', icon: 'none' }); return; } this.setData({ showModifyTuikuanModal: true, modifyTuikuanLiyou: this.data.xiangxiShuju.tuikuan_liyou || '' }); }, closeModifyTuikuanModal() { this.setData({ showModifyTuikuanModal: false }); }, inputModifyTuikuanLiyou(e) { this.setData({ modifyTuikuanLiyou: e.detail.value.slice(0, 100) }); }, async submitModifyTuikuan() { const { modifyTuikuanLiyou, jibenShuju } = this.data; if (!modifyTuikuanLiyou.trim()) { wx.showToast({ title: '请输入退款理由', icon: 'none' }); return; } wx.showLoading({ title: '修改中...', mask: true }); try { const res = await request({ url: isStaffMode() ? STAFF_API.penaltyManage : '/dingdan/sjfkxgycx', method: 'POST', data: { operation: 'modify_refund_reason', dingdan_id: jibenShuju.dingdan_id, liyou: modifyTuikuanLiyou } }); wx.hideLoading(); if (res && res.data.code === 0) { wx.showToast({ title: '修改成功', icon: 'success' }); this.setData({ showModifyTuikuanModal: false }); this.jiazaiXiangxiShuju(jibenShuju.dingdan_id); } else { wx.showToast({ title: res?.data?.msg || '修改失败', icon: 'none' }); } } catch (err) { wx.hideLoading(); wx.showToast({ title: '网络错误', icon: 'none' }); } }, // ========== 新增:教程按钮 ========== startTutorialBtnTimer() { if (this.tutorialTimer) clearTimeout(this.tutorialTimer); this.tutorialTimer = setTimeout(() => { this.setData({ tutorialBtnHidden: true }); }, 5000); }, resetTutorialBtn() { if (this.data.tutorialBtnHidden) { this.setData({ tutorialBtnHidden: false }); } if (this.tutorialTimer) clearTimeout(this.tutorialTimer); this.tutorialTimer = setTimeout(() => { this.setData({ tutorialBtnHidden: true }); }, 5000); }, onTutorialBtnTap() { this.resetTutorialBtn(); PopupService.checkAndShow(this, 'sjddxq1'); } })