| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 | import { api_executePayment, api_queryByParamName, api_studentOrderPage, api_userPaymentCancelRefund, api_userPaymentOrderUnpaid } from "../../api/login";// 获取应用实例const app = getApp<IAppOption>()Page({  /**   * 页面的初始数据   */  data: {    tabList: [      {        id: 0,        label: "全部订单",      },      {        id: 1,        label: "待支付",      },      // {      //   id: 2,      //   label: "待使用",      // },      {        id: 3,        label: "已完成",      },      {        id: 4,        label: "已取消",      },      // {      //   id: 5,      //   label: "售后",      // },      // {      //   id: 6,      //   label: "已退款",      // },    ],    tabIdx: 0, // 当前选中的tab索引    page: 1,    rows: 10,    recordList: [],    maxPage: 1, // 总分页数    serviceShow: true,    refoundStatus: false,    cancelRefoundStatus: false,    goodsInfo: {}, // 选中的数据  },  /**   * 生命周期函数--监听页面加载   */  onLoad() {  },  onShow() {    this.setData({      serviceShow: true,      page: 1,      maxPage: 1,      recordList: [],    }, () => {      this.getList()    })  },  onHide() {    this.setData({      serviceShow: false    })  },  /** 切换分类 */  switchTab(e: { currentTarget: { dataset: { idx: any } } }) {    const idx = e.currentTarget.dataset.idx;    if (idx != this.data.tabIdx) {      this.setData(        {          tabIdx: idx,          page: 1,          maxPage: 1,          recordList: [],        },        () => {          this.getList();        }      );    }  },  async getList() {    wx.showLoading({      mask: true,      title: "加载中...",    });    const currentPage = this.data.page,      currentRow = this.data.rows,      tabIdx = this.data.tabIdx;    try {      // @ApiModelProperty("订单状态 WAIT_PAY:待付款,WAIT_USE:待使用,SUCCESS:已完成,CLOSE:已取消")      const { data } = await api_studentOrderPage({        "version": "V2",        openId: app.globalData.userInfo?.liteOpenid,        page: currentPage,        rows: this.data.rows,        wechatOrderStatus: tabIdx == 0 ? "" : tabIdx == 1 ? "WAIT_PAY" : tabIdx == 2 ? "WAIT_USE" : tabIdx == 3 ? "PAID" : tabIdx == 4 ? "CLOSED" : tabIdx == 5 ? 'SALE_AFTER' : "",      })      if (data.code == 200) {        const { rows, total } = data.data;        rows.forEach((item: any) => {          item.amount = this.formatPrice(item.paymentCashAmount, 'ALL')          item.statusName = this.formatOrderStatus(item.wechatStatus)          const studentPaymentOrderDetails = item.studentPaymentOrderDetails || [];          studentPaymentOrderDetails.forEach((student: any) => {            student.originalPrice = this.formatPrice(student.paymentCashAmount, 'ALL');            const prices: any = this.formatPrice(student.paymentCashAmount)            student.integerPart = prices.integerPart            student.decimalPart = prices.decimalPart            student.typeName = this.formatPeriod(student.activationCodeInfo?.times || 1, student.activationCodeInfo?.type);          })          item.studentPaymentOrderDetails = studentPaymentOrderDetails        });        const newList = this.data.recordList.concat(rows);        this.setData(          {            recordList: newList,            maxPage: Math.ceil(total / currentRow),          },          () => wx.hideLoading()        );      } else {        wx.hideLoading();      }    } catch (e) {      console.log(e, 'e')      wx.hideLoading()    }  },  // 格式化中文  formatOrderStatus(status: string) {    // 订单状态 WAIT_PAY:待付款,  WAIT_USE:待使用, SUCCESS:已完成, CLOSE:已取消    const template: any = {      WAIT_PAY: '待支付',      WAIT_USE: '待使用',      PAID: '已完成',      CLOSED: '已取消',      REFUNDING: '退款中',      REFUNDED: '已退款'    }    return template[status]  },  // 格式化价格  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) {    if (!num || !type) {      return ''    }    const template: any = {      DAY: "天卡",      MONTH: "月卡",      YEAR: "年卡"    }    if (type === "YEAR" && num >= 99) {      return '永久卡'    }    return num + template[type]  },  /** 加载更多 */  loadMore() {    const currentPage = this.data.page;    if (this.data.page >= this.data.maxPage) {      // wx.showToast({      //   title: "没有更多数据了",      //   icon: "none",      //   duration: 1000,      // });    } else {      this.setData(        {          page: currentPage + 1,        },        () => {          this.getList();        }      );    }  },  onPay(e: any) {    const { dataset } = e.currentTarget    const item: any = this.data.recordList.find((item: any) => item.id === dataset.id)    if (item) {      this.onSubmit({        orderNo: item.orderNo      })    }  },  onOne() {    wx.redirectTo({      url: '../index/index',    })  },  onDetail(e: any) {    const { dataset } = e.currentTarget    wx.navigateTo({      url: `../orders/order-result?orderNo=${dataset.orderno}&tabIdx=${this.data.tabIdx}`    })    // if (dataset.wechatstatus === "WAIT_PAY") {    //   this.onSubmit({ orderNo: dataset.orderno })    // } else {    //   wx.navigateTo({    //     url: `../orders/order-result?orderNo=${dataset.orderno}&tabIdx=${this.data.tabIdx}`    //   })    // }  },  // 购买  async onSubmit(goodsInfo: any) {    wx.showLoading({      mask: true,      title: "订单提交中...",    });    try {      const { orderNo } = goodsInfo      const { data } = await api_userPaymentOrderUnpaid({        orderNo: orderNo,        paymentType: 'WECHAT_MINI'      })      if (data.code === 200) {        const { paymentConfig, paymentType, orderNo } = data.data.paymentConfig        this.onExecutePay(paymentConfig, paymentType, orderNo)      } else {        this.onPayError()        this.getList()      }    } catch {      wx.hideLoading()    }  },  async onExecutePay(paymentConfig: any, paymentType: string, orderNo: string) {    wx.login({      success: async (wxres: any) => {        const res = await api_executePayment({          merOrderNo: paymentConfig.merOrderNo,          paymentChannel: this.data.paymentChannel || 'wx_lite',          paymentType,          userId: app.globalData.userInfo?.id,          code: wxres.code,          wxMiniAppId: app.globalData.appId        })        wx.hideLoading()        if (res.data.code === 200) {          this.onPaying(paymentType, res.data.data.reqParams, orderNo)        } else {          this.onPayError(res.data.message)        }      },      fail: () => {        this.onPayError()      }    })  },  onPaying(paymentType: string, paymentConfig: any, orderNo: string) {    const isYeePay = paymentType.indexOf('yeepay') !== -1    const prePayInfo = isYeePay ? JSON.parse(paymentConfig.prePayTn)      : paymentConfig?.expend        ? JSON.parse(paymentConfig?.expend?.pay_info)        : paymentConfig    const that = this    wx.requestPayment({      timeStamp: prePayInfo.timeStamp,      nonceStr: prePayInfo.nonceStr,      package: prePayInfo.package ? prePayInfo.package : prePayInfo.packageValue,      paySign: prePayInfo.paySign,      signType: prePayInfo.signType ? prePayInfo.signType : 'MD5',      success() {        wx.showToast({ title: '支付成功', icon: 'success' });        // that.onRefoundComfirm()      },      fail(ressonInfo) {        console.log('支付失败', ressonInfo)        that.onPayError()      }    })  },  // 获取后台配置的支付方式  async queryPayType() {    try {      // wxlite_payment_service_provider      const { data } = await api_queryByParamName({        paramName: app.globalData.appId      });      if (data.code == 200) {        const paramValue = data.data.paramValue ? JSON.parse(data.data.paramValue) : {}        this.setData({          paymentType: paramValue.vendor,          paymentChannel: paramValue.channel        });      }    } catch (error) {      console.log(error, "error");    }  },  onPayError(message?: string) {    wx.hideLoading()    wx.showToast({      title: message || '支付取消',      icon: 'none'    })  },  async onRefounded(e: any) {    const { dataset } = e.currentTarget    const item: any = this.data.recordList.find((item: any) => item.id === dataset.id)    console.log(dataset, item, 'item')    if (!item) {      return    }    if (item.wechatStatus === "REFUNDING") {      this.setData({        cancelRefoundStatus: true      }, async () => {        try {          const refundOrderId = item.refundOrderId          const { data } = await api_userPaymentCancelRefund(refundOrderId)          console.log(data, 'data')          if (data.code == 200) {            wx.showToast({ title: '你已成功取消退款', icon: 'none' })            this.onRefoundComfirm()          } else {            wx.showToast({ title: data.message, icon: 'none' })            this.setData({              cancelRefoundStatus: false            })          }        } catch { }      })    } else {      const { orderNo, studentPaymentOrderDetails } = item      const goodsInfo: any = {        orderNo,        goods: []      }      if (Array.isArray(studentPaymentOrderDetails)) {        studentPaymentOrderDetails.forEach((item: any) => {          goodsInfo.goods.push({            ...item,            id: item.userPaymentOrderDetailId,            currentPrice: item.paymentCashAmount          })        })      }      this.setData({        goodsInfo,        cancelRefoundStatus: true,        refoundStatus: true      })    }  },  changeRefoundStatus(e: { detail: any }) {    this.setData({      refoundStatus: e.detail,      cancelRefoundStatus: false,    })  },  onRefoundComfirm() {    const that = this    this.setData({      refoundStatus: false,    })    setTimeout(() => {      that.setData({        page: 1,        maxPage: 1,        recordList: [],        cancelRefoundStatus: false,      }, () => {        this.getList()      })    }, 1500);  },  onShareAppMessage() {    return {      title: '音乐数字AI器乐工具',      path: '/pages/index/index',      imageUrl: 'https://oss.dayaedu.com/ktyq/1733311074676.png'    }  }})
 |