order-result.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // pages/orders/order-detail.ts
  2. import { api_userPaymentOrderDetail } from "../../api/login";
  3. import { formatPrice, GRADE_ENUM } from "../../utils/util";
  4. // 获取应用实例
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. status: 'WAIT_PAY',
  11. statusList: {
  12. WAIT_PAY: {
  13. logo: './images/ing.png',
  14. title: '等待付款',
  15. content: '请尽快完成支付,以便我们为您处理订单'
  16. },
  17. PAID: {
  18. logo: './images/success.png',
  19. title: '交易完成',
  20. content: '登录「音乐数字课堂」APP使用AI学练'
  21. },
  22. CLOSED: {
  23. logo: './images/error.png',
  24. title: '交易取消',
  25. content: '您的交易订单已关闭'
  26. },
  27. WAIT_USE: {
  28. logo: './images/wait.png',
  29. title: '等待使用',
  30. content: '请尽快扫描下方二维码进行激活'
  31. },
  32. REFUNDING: {
  33. logo: './images/refounding.png',
  34. title: '退款中',
  35. content: '您的退款申请正在处理,预计7个工作日内完成审核'
  36. },
  37. REFUNDED: {
  38. logo: './images/refounded.png',
  39. title: '退款成功',
  40. content: '您的退款已成功处理,感谢您的理解和支持'
  41. }
  42. },
  43. timerCount: 0,
  44. timer: null as any,
  45. goodsInfo: {} as any,
  46. orderNo: "" as string,
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad(options: any) {
  52. if (options.orderNo) {
  53. this.setData({
  54. orderNo: options.orderNo
  55. });
  56. }
  57. },
  58. onShow() {
  59. if(this.data.orderNo) {
  60. this.getDetail(this.onTimeout)
  61. }
  62. },
  63. async getDetail(callback?: any) {
  64. try {
  65. const { data } = await api_userPaymentOrderDetail(this.data.orderNo);
  66. if (data.code == 200) {
  67. const result = data.data || {}
  68. const goodsInfos = result.goodsInfos || []
  69. const tempGoods: any = []
  70. goodsInfos.forEach((item: any) => {
  71. tempGoods.push({
  72. ...item,
  73. // originalPrice: formatPrice(item.originalPrice, 'ALL'),
  74. typeName: this.formatPeriod(item.activationCodeInfo?.times || 1, item.activationCodeInfo?.type)
  75. })
  76. })
  77. const addresses = {
  78. id: result.addresses?.id,
  79. name: result.addresses?.name,
  80. phoneNumber: result.addresses?.phoneNumber,
  81. addressDetail: result.addresses?.detailAddress
  82. }
  83. const tempSchoolAddress = [result.beneficiary?.provinceName || '', result.beneficiary?.cityName || '', result.beneficiary?.regionName || '', result.beneficiary?.schoolAreaName, GRADE_ENUM[result.beneficiary?.currentGradeNum], result.beneficiary?.currentClass + '班']
  84. const beneficiary = {
  85. id: result.beneficiary?.schoolAreaId,
  86. name: result.beneficiary?.name,
  87. phoneNumber: result.beneficiary?.phone,
  88. schoolInfo: tempSchoolAddress.join('')
  89. }
  90. const allDiscountPrice: any = formatPrice(result.originalPrice - result.paymentCashAmount)
  91. const allAfterPrice: any = formatPrice(result.paymentCashAmount)
  92. const goodsInfo = {
  93. discountIntegerPart: allDiscountPrice.integerPart,
  94. discountDecimalPart: allDiscountPrice.decimalPart,
  95. paymentCashAmount: result.paymentCashAmount,
  96. originalPrice: result.originalPrice,
  97. integerPart: allAfterPrice.integerPart,
  98. decimalPart: allAfterPrice.decimalPart,
  99. orderNo: result.orderNo,
  100. createTime: result.createTime,
  101. wechatStatus: result.wechatStatus,
  102. goods: tempGoods,
  103. addresses,
  104. beneficiary
  105. }
  106. console.log(goodsInfos, "goodsInfo")
  107. this.setData({
  108. goodsInfo,
  109. status: result.wechatStatus
  110. }, () => {
  111. callback && typeof callback === 'function' && callback()
  112. })
  113. }
  114. } catch (error) {
  115. console.log(error, "error");
  116. }
  117. },
  118. // 格式化类型
  119. formatPeriod(num: number, type: string) {
  120. if (!num || !type) {
  121. return ''
  122. }
  123. const template: any = {
  124. DAY: "天",
  125. MONTH: "个月",
  126. YEAR: "年"
  127. }
  128. if (type === "YEAR" && num >= 99) {
  129. return '永久'
  130. }
  131. return num + template[type]
  132. },
  133. onSubmit() {
  134. wx.redirectTo({
  135. url: '../index/index'
  136. })
  137. },
  138. onTimeout() {
  139. // 轮询10次查询订单状态
  140. // const goodsInfo = this.data.goodsInfo
  141. // const timerCount = this.data.timerCount
  142. // const timer = this.data.timer
  143. // if(goodsInfo.wechatStatus === 'WAIT_PAY' && timerCount <= 10) {
  144. // let count = timerCount
  145. // const tempT = setTimeout(async () => {
  146. // count += 1
  147. // await this.getDetail()
  148. // this.setData({
  149. // timer: tempT,
  150. // timerCount: count
  151. // }, () => {
  152. // this.onTimeout()
  153. // })
  154. // }, 3000);
  155. // } else {
  156. // clearTimeout(timer)
  157. // }
  158. },
  159. onCopy(e: { currentTarget: any }) {
  160. wx.setClipboardData({
  161. data: e.currentTarget.dataset.orderno,
  162. success: () => {
  163. wx.showToast({title: '复制成功', icon: 'none'})
  164. },
  165. fail: () => {
  166. wx.showToast({title: '复制失败,请稍后再试', icon: 'none'})
  167. }
  168. })
  169. },
  170. onShareAppMessage() {
  171. return {
  172. title: '器乐数字AI工具',
  173. path: '/pages/index/index',
  174. imageUrl: 'https://oss.dayaedu.com/ktyq/1733312164991.png'
  175. }
  176. }
  177. })