order-result.ts 6.0 KB

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