123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- // pages/orders/order-detail.ts
- import { api_userPaymentOrderDetail } from "../../api/login";
- import { formatPrice, GRADE_ENUM } from "../../utils/util";
- // 获取应用实例
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- status: 'WAIT_PAY',
- statusList: {
- WAIT_PAY: {
- logo: './images/ing.png',
- title: '待付款',
- content: '请尽快完成支付,以便我们为您处理订单'
- },
- PAID: {
- logo: './images/success.png',
- title: '已完成',
- content: '您的交易订单已完成,感谢您的选择'
- },
- 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,
- orderNo: "" as string,
- isExpanded: false // 是否展开
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options: any) {
- if (options.orderNo) {
- this.setData({
- orderNo: options.orderNo
- });
- }
- },
- onShow() {
- if(this.data.orderNo) {
- this.getDetail(this.onTimeout)
- }
- },
- async getDetail(callback?: any) {
- 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) => {
- tempGoods.push({
- ...item,
- originalPrice: formatPrice(item.originalPrice, 'ALL'),
- typeName: this.formatPeriod(item.activationCodeInfo?.times || 1, item.activationCodeInfo?.type)
- })
- })
- 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: any = formatPrice(result.originalPrice - result.paymentCashAmount)
- const allAfterPrice: any = formatPrice(result.paymentCashAmount)
-
- const goodsInfo = {
- discountIntegerPart: allDiscountPrice.integerPart,
- discountDecimalPart: allDiscountPrice.decimalPart,
- 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
- }
- console.log(goodsInfos, "goodsInfo")
- this.setData({
- goodsInfo,
- status: result.wechatStatus
- }, () => {
- callback && typeof callback === 'function' && callback()
- })
- }
- } 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'
- })
- },
- onExpanded() {
- this.setData({
- isExpanded: !this.data.isExpanded
- })
- },
- 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)
- // }
- },
- onCopy(e: { currentTarget: any }) {
- wx.setClipboardData({
- data: e.currentTarget.dataset.orderno,
- success: () => {
- wx.showToast({title: '复制成功', icon: 'none'})
- },
- fail: () => {
- wx.showToast({title: '复制失败,请稍后再试', icon: 'none'})
- }
- })
- },
- onShareAppMessage() {
- return {
- title: '翼时代器乐数字Ai',
- path: '/pages/index/index',
- imageUrl: 'https://oss.dayaedu.com/ktyq/1739865626350.png'
- }
- }
- })
|