order-result.ts 5.9 KB

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