// pages/orders/order-detail.ts // import drawQrcode from "../../utils/weapp.qrcode.esm"; import { api_userPaymentCancelRefund, api_userPaymentOrderDetail } from "../../api/login"; import { formatPrice, GRADE_ENUM } from "../../utils/util"; // 获取应用实例 Page({ /** * 页面的初始数据 */ data: { serviceShow: true, status: 'WAIT_PAY', statusList: { WAIT_PAY: { logo: './images/ing.png', title: '待付款', content: '请尽快完成支付,以便我们为您处理订单' }, PAID: { logo: './images/success.png', title: '已完成', content: '登录「音乐数字课堂」APP使用AI学练' }, CLOSED: { logo: './images/error.png', title: '已取消', content: '您的交易订单已关闭' }, WAIT_USE: { logo: './images/wait.png', title: '待使用', content: '请尽快扫描下方二维码进行激活' }, REFUNDING: { logo: './images/refounding.png', title: '退款中', content: '您的退款申请正在处理,预计7个工作日内完成审核' }, REFUNDED: { logo: './images/refounded.png', title: '退款成功', content: '您的退款已成功处理,感谢您的理解和支持' } }, timerCount: 0, timer: null as any, goodsInfo: {} as any, // tabIdx: 0, // 当前是从哪个tab来的 orderNo: "" as string, showCanvas: false, // 是否显示二维码 canvasImg: "" as string, refoundStatus: false, cancelRefoundStatus: false, }, /** * 生命周期函数--监听页面加载 */ onLoad(options: any) { if (options.orderNo) { this.setData({ orderNo: options.orderNo, // tabIdx: options.tabIdx }); } }, onShow() { this.setData({ serviceShow: true }) if (this.data.orderNo) { this.getDetail() } }, onHide() { this.setData({ serviceShow: false }) }, async getDetail() { try { const { data } = await api_userPaymentOrderDetail(this.data.orderNo, { version: 'V2' }); if (data.code == 200) { const result = data.data || {} const goodsInfos = result.goodsInfos || [] const tempGoods: any = [] goodsInfos.forEach((item: any) => { const prices: any = formatPrice(item.paymentCashAmount || 0); tempGoods.push({ ...item, integerPart: prices.integerPart, decimalPart: prices.decimalPart, originalPrice: formatPrice(item.originalPrice, 'ALL'), }) }) const addresses = { id: result.addresses?.id, name: result.addresses?.name, phoneNumber: result.addresses?.phoneNumber, addressDetail: result.addresses?.detailAddress } const tempSchoolAddress = [result.beneficiary?.provinceName, result.beneficiary?.cityName, result.beneficiary?.regionName, result.beneficiary?.schoolAreaName, GRADE_ENUM[result.beneficiary?.currentGradeNum], result.beneficiary?.currentClass + '班'] const beneficiary = { id: result.beneficiary?.schoolAreaId, name: result.beneficiary?.name, phoneNumber: result.beneficiary?.phone, schoolInfo: tempSchoolAddress.join('') } const allDiscountPrice = formatPrice(result.originalPrice - result.paymentCashAmount, 'ALL') as string const allAfterPrice: any = formatPrice(result.paymentCashAmount) const goodsInfo = { allDiscountPrice, paymentCashAmount: result.paymentCashAmount, originalPrice: result.originalPrice, integerPart: allAfterPrice.integerPart, decimalPart: allAfterPrice.decimalPart, orderNo: result.orderNo, createTime: result.createTime, wechatStatus: result.wechatStatus, goods: tempGoods, addresses, beneficiary } this.setData({ goodsInfo, status: result.wechatStatus }) } } catch (error) { console.log(error, "error"); } }, // 格式化类型 formatPeriod(num: number, type: string) { if (!num || !type) { return '' } const template: any = { DAY: "天卡", MONTH: "月卡", YEAR: "年卡" } if (type === "YEAR" && num >= 99) { return '永久卡' } return num + template[type] }, onSubmit() { wx.redirectTo({ url: '../index/index' }) }, /** 申请退款 */ async cancelRefound() { this.setData({ cancelRefoundStatus: true }, async () => { try { const { data } = await api_userPaymentCancelRefund(this.data.goodsInfo.refundOrderId) // console.log(data, 'data') if (data.code == 200) { wx.showToast({ title: '取消退款成功', icon: 'none' }) this.getDetail() } else { wx.showToast({ title: data.message, icon: 'none' }) } setTimeout(() => { this.setData({ cancelRefoundStatus: false }) }, 500); } catch { } }) }, /** 申请退款 */ useRefound() { this.setData({ refoundStatus: true }) }, changeRefoundStatus(e: { detail: any }) { this.setData({ refoundStatus: e.detail }) }, onRefoundComfirm() { this.setData({ refoundStatus: false }) // wx.navigateBack({ // delta: 1 // }) this.getDetail() }, onCopy(e: { currentTarget: any }) { wx.setClipboardData({ data: e.currentTarget.dataset.orderno, success: () => { wx.showToast({ title: '复制成功', icon: 'none' }) }, fail: () => { wx.showToast({ title: '复制失败,请稍后再试', icon: 'none' }) } }) }, onActivation(e: { currentTarget: any }) { const code = e.currentTarget.dataset.code || '' if (!code) { wx.showToast({ title: '暂无法激活', icon: 'none' }) return } wx.navigateTo({ url: '../protocol/register?type=activation&code=' + code }) }, onDownload() { wx.saveImageToPhotosAlbum({ filePath: this.data.canvasImg, success: () => { wx.showToast({ title: '保存成功', icon: 'success', }); }, fail: () => { wx.showToast({ title: '保存失败', icon: 'none', }); } }) }, onDownloadApp() { wx.navigateTo({ url: '../download/download' }) }, onShareAppMessage() { return { title: '音乐数字AI', path: '/pages/index/index', imageUrl: 'https://oss.dayaedu.com/ktyq/1739870592907.png' } }, })