| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 | 
							- // pages/orders/order-detail.ts
 
- import drawQrcode from "../../utils/weapp.qrcode.esm";
 
- import { api_userPaymentCancelRefund, api_userPaymentOrderDetail } from "../../api/login";
 
- // 获取应用实例
 
- Page({
 
-   /**
 
-    * 页面的初始数据
 
-    */
 
-   data: {
 
-     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,
 
-     serviceShow: true,
 
-     refoundStatus: false,
 
-     cancelRefoundStatus: false
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面加载
 
-    */
 
-   onLoad(options: any) {
 
-     if (options.orderNo) {
 
-       this.setData({
 
-         orderNo: options.orderNo,
 
-         tabIdx: options.tabIdx,
 
-       }, () => {
 
-         this.getDetail(this.onTimeout)
 
-       });
 
-     }
 
-   },
 
-   onShow() {
 
-     this.setData({
 
-       serviceShow: true
 
-     })
 
-     if(this.data.orderNo) {
 
-       this.getDetail(this.onTimeout)
 
-     }
 
-   },
 
-   onHide() {
 
-     this.setData({
 
-       serviceShow: false
 
-     })
 
-   },
 
-   async getDetail(callback?: any) {
 
-     try {
 
-       const { data } = await api_userPaymentOrderDetail(this.data.orderNo);
 
-       if (data.code == 200) {
 
-         const result = data.data || {}
 
-         const goodsInfos = result.goodsInfos || []
 
-         const tempGoods: any = []
 
-         goodsInfos.forEach((item: any) => {
 
-           const prices: any = this.formatPrice(item.paymentCashAmount)
 
-         
 
-           tempGoods.push({
 
-             ...item,
 
-             integerPart: prices.integerPart,
 
-             decimalPart: prices.decimalPart,
 
-             shortUrl: item.activationCodeInfo.shortUrl,
 
-             code: item.activationCodeInfo.activationCode,
 
-             originalPrice: this.formatPrice(item.paymentCashAmount, 'ALL'),
 
-             typeName: this.formatPeriod(item.activationCodeInfo?.times || 1, item.activationCodeInfo.type)
 
-           })
 
-         })
 
-         let refundStyleStr = ''
 
-         if(result.refundStyle === 'TURN_BACK') {
 
-           refundStyleStr = '原路返回'
 
-         } else if(result.refundStyle === 'OFFLINE') {
 
-           refundStyleStr = '线下'
 
-         }
 
-         const firstGoods = tempGoods[0]
 
-         const goodsInfo = {
 
-           orderNo: result.orderNo,
 
-           createTime: result.createTime,
 
-           wechatStatus: result.wechatStatus,
 
-           goods: tempGoods,
 
-           code: firstGoods.code || '',
 
-           refundOrderId: result.refundOrderId,
 
-           refundTime: result.refundTime,
 
-           refundAmount: this.formatPrice(result.refundAmount || 0, 'ALL'),
 
-           refundStyleStr
 
-         }
 
-         this.setData({
 
-           goodsInfo,
 
-           status: result.wechatStatus
 
-         }, () => {
 
-           callback && typeof callback === 'function' && callback()
 
-         })
 
-         if(result.wechatStatus != 'CLOSED' || result.wechatStatus != 'WAIT_PAY') {
 
-           const firstGoods = tempGoods[0]
 
-           if(firstGoods?.shortUrl) {
 
-             this.setData({
 
-               showCanvas: true
 
-             }, () => {
 
-               this.createQrCode(firstGoods?.shortUrl, 'canvasCode')
 
-             })
 
-           }
 
-         }
 
-       }
 
-     } catch (error) {
 
-       console.log(error, "error");
 
-     }
 
-   },
 
-   // 格式化价格
 
-   formatPrice(price: number, type?: string) {
 
-     const amountStr = price.toFixed(2)
 
-     const [integerPart, decimalPart] = amountStr.split('.');
 
-     if(type === 'ALL') {
 
-       return amountStr
 
-     }
 
-     return {
 
-       integerPart,
 
-       decimalPart
 
-     }
 
-   },
 
-   // 格式化类型
 
-   formatPeriod(num: number, type: string) {
 
-     const template: any = {
 
-       DAY: "天卡",
 
-       MONTH: "月卡",
 
-       YEAR: "年卡"
 
-     }
 
-     if(type === "YEAR" && num >= 99) {
 
-       return '永久卡'
 
-     }
 
-     return num + template[type]
 
-   },
 
-   onSubmit() {
 
-     wx.redirectTo({
 
-       url: '../index/index'
 
-     })
 
-   },
 
-   setCanvasSize: function () {
 
-     const size = {} as any;
 
-     try {
 
-       const res = wx.getWindowInfo()
 
-       const scale = 750 / 300; //不同屏幕下canvas的适配比例;设计稿是750宽
 
-       const width = res.windowWidth / scale;
 
-       const height = width; //canvas画布为正方形
 
-       size.w = width;
 
-       size.h = height;
 
-     } catch (e) {
 
-       // Do something when catch error
 
-       console.log("获取设备信息失败" + e);
 
-     }
 
-     return size;
 
-   },
 
-   createQrCode(content: any, canvasId: any) {
 
-     const size = this.setCanvasSize();
 
-     drawQrcode({
 
-       width: size.w,
 
-       height: size.h,
 
-       canvasId: canvasId,
 
-       text: content,
 
-       callback: () => {
 
-         // 安卓机上不准确,生成的二维码无法扫描,加延时解决
 
-         setTimeout(() => {
 
-           wx.canvasToTempFilePath(
 
-             {
 
-               canvasId: canvasId,
 
-               success: (res) => {
 
-                 this.setData({
 
-                   canvasImg: res.tempFilePath,
 
-                 });
 
-               },
 
-             },
 
-             this
 
-           );
 
-         }, 0);
 
-       },
 
-     });
 
-   },
 
-   onTimeout() {
 
-     // 轮询10次查询订单状态
 
-     const goodsInfo = this.data.goodsInfo
 
-     const timerCount = this.data.timerCount
 
-     const timer = this.data.timer
 
-     if(goodsInfo.wechatStatus === 'WAIT_PAY' && timerCount <= 10) {
 
-       let count = timerCount
 
-       const tempT = setTimeout(async () => {
 
-         count += 1
 
-         await this.getDetail()
 
-         this.setData({
 
-           timer: tempT,
 
-           timerCount: count
 
-         }, () => {
 
-           this.onTimeout()
 
-         })
 
-       }, 3000);
 
-     } else {
 
-       clearTimeout(timer)
 
-     }
 
-   },
 
-   /** 申请退款 */
 
-   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',
 
-         });
 
-       }
 
-     })
 
-   },
 
-   onShareAppMessage() {
 
-     return {
 
-       title: '音乐数字AI器乐工具',
 
-       path: '/pages/index/index',
 
-       imageUrl: 'https://oss.dayaedu.com/ktyq/1733311074676.png'
 
-     }
 
-   }
 
- })
 
 
  |