order-result.ts 5.6 KB

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