order-result.ts 5.7 KB

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