order-result.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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: '您的交易订单已完成,感谢您的选择'
  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. isExpanded: false // 是否展开
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad(options: any) {
  53. if (options.orderNo) {
  54. this.setData({
  55. orderNo: options.orderNo
  56. });
  57. }
  58. },
  59. onShow() {
  60. if(this.data.orderNo) {
  61. this.getDetail(this.onTimeout)
  62. }
  63. },
  64. async getDetail(callback?: any) {
  65. try {
  66. const { data } = await api_userPaymentOrderDetail(this.data.orderNo, {
  67. version: 'V2'
  68. });
  69. if (data.code == 200) {
  70. const result = data.data || {}
  71. const goodsInfos = result.goodsInfos || []
  72. const tempGoods: any = []
  73. goodsInfos.forEach((item: any) => {
  74. tempGoods.push({
  75. ...item,
  76. originalPrice: formatPrice(item.originalPrice, 'ALL'),
  77. typeName: this.formatPeriod(item.activationCodeInfo?.times || 1, item.activationCodeInfo?.type)
  78. })
  79. })
  80. const addresses = {
  81. id: result.addresses?.id,
  82. name: result.addresses?.name,
  83. phoneNumber: result.addresses?.phoneNumber,
  84. addressDetail: result.addresses?.detailAddress
  85. }
  86. const tempSchoolAddress = [result.beneficiary?.provinceName || '', result.beneficiary?.cityName || '', result.beneficiary?.regionName || '', result.beneficiary?.schoolAreaName, GRADE_ENUM[result.beneficiary?.currentGradeNum], result.beneficiary?.currentClass + '班']
  87. const beneficiary = {
  88. id: result.beneficiary?.schoolAreaId,
  89. name: result.beneficiary?.name,
  90. phoneNumber: result.beneficiary?.phone,
  91. schoolInfo: tempSchoolAddress.join('')
  92. }
  93. const allDiscountPrice: any = formatPrice(result.originalPrice - result.paymentCashAmount)
  94. const allAfterPrice: any = formatPrice(result.paymentCashAmount)
  95. const goodsInfo = {
  96. discountIntegerPart: allDiscountPrice.integerPart,
  97. discountDecimalPart: allDiscountPrice.decimalPart,
  98. paymentCashAmount: result.paymentCashAmount,
  99. originalPrice: result.originalPrice,
  100. integerPart: allAfterPrice.integerPart,
  101. decimalPart: allAfterPrice.decimalPart,
  102. orderNo: result.orderNo,
  103. createTime: result.createTime,
  104. wechatStatus: result.wechatStatus,
  105. goods: tempGoods,
  106. addresses,
  107. beneficiary
  108. }
  109. console.log(goodsInfos, "goodsInfo")
  110. this.setData({
  111. goodsInfo,
  112. status: result.wechatStatus
  113. }, () => {
  114. callback && typeof callback === 'function' && callback()
  115. })
  116. }
  117. } catch (error) {
  118. console.log(error, "error");
  119. }
  120. },
  121. // 格式化类型
  122. formatPeriod(num: number, type: string) {
  123. if (!num || !type) {
  124. return ''
  125. }
  126. const template: any = {
  127. DAY: "天卡",
  128. MONTH: "月卡",
  129. YEAR: "年卡"
  130. }
  131. if (type === "YEAR" && num >= 99) {
  132. return '永久卡'
  133. }
  134. return num + template[type]
  135. },
  136. onSubmit() {
  137. wx.redirectTo({
  138. url: '../index/index'
  139. })
  140. },
  141. onExpanded() {
  142. this.setData({
  143. isExpanded: !this.data.isExpanded
  144. })
  145. },
  146. onTimeout() {
  147. // 轮询10次查询订单状态
  148. // const goodsInfo = this.data.goodsInfo
  149. // const timerCount = this.data.timerCount
  150. // const timer = this.data.timer
  151. // if(goodsInfo.wechatStatus === 'WAIT_PAY' && timerCount <= 10) {
  152. // let count = timerCount
  153. // const tempT = setTimeout(async () => {
  154. // count += 1
  155. // await this.getDetail()
  156. // this.setData({
  157. // timer: tempT,
  158. // timerCount: count
  159. // }, () => {
  160. // this.onTimeout()
  161. // })
  162. // }, 3000);
  163. // } else {
  164. // clearTimeout(timer)
  165. // }
  166. },
  167. onCopy(e: { currentTarget: any }) {
  168. wx.setClipboardData({
  169. data: e.currentTarget.dataset.orderno,
  170. success: () => {
  171. wx.showToast({title: '复制成功', icon: 'none'})
  172. },
  173. fail: () => {
  174. wx.showToast({title: '复制失败,请稍后再试', icon: 'none'})
  175. }
  176. })
  177. },
  178. onShareAppMessage() {
  179. return {
  180. title: '翼时代器乐数字Ai',
  181. path: '/pages/index/index',
  182. imageUrl: 'https://oss.dayaedu.com/ktyq/1739865626350.png'
  183. }
  184. }
  185. })