order-result.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // pages/orders/order-detail.ts
  2. import drawQrcode from "../../utils/weapp.qrcode.esm";
  3. import { api_userPaymentCancelRefund, api_userPaymentOrderDetail, api_userPaymentOrderRefundPayment } from "../../api/login";
  4. import { formatPrice } from "../../utils/util";
  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: '登录「音乐数字课堂」APP使用AI学练'
  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. showCanvas: false, // 是否显示二维码
  49. tabIdx: 0, // 当前是从哪个tab来的
  50. canvasImg: "" as string,
  51. showService: false,
  52. refoundStatus: false,
  53. cancelRefoundStatus: false,
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad(options: any) {
  59. if (options.orderNo) {
  60. this.setData({
  61. orderNo: options.orderNo,
  62. tabIdx: options.tabIdx
  63. });
  64. }
  65. },
  66. onShow() {
  67. if(this.data.orderNo) {
  68. this.getDetail(this.onTimeout)
  69. }
  70. },
  71. async getDetail(callback?: any) {
  72. try {
  73. const { data } = await api_userPaymentOrderDetail(this.data.orderNo);
  74. if (data.code == 200) {
  75. const result = data.data || {}
  76. const goodsInfos = result.goodsInfos || []
  77. const tempGoods: any = []
  78. goodsInfos.forEach((item: any) => {
  79. tempGoods.push({
  80. ...item,
  81. // shortUrl: item.activationCodeInfo.shortUrl,
  82. // code: item.activationCodeInfo.activationCode,
  83. originalPrice: formatPrice(item.paymentCashAmount, 'ALL'),
  84. // typeName: this.formatPeriod(item.activationCodeInfo?.times || 1, item.activationCodeInfo.type)
  85. })
  86. })
  87. const firstGoods = tempGoods[0]
  88. const goodsInfo = {
  89. orderNo: result.orderNo,
  90. createTime: result.createTime,
  91. wechatStatus: result.wechatStatus,
  92. goods: tempGoods,
  93. code: firstGoods.code || ''
  94. }
  95. this.setData({
  96. goodsInfo,
  97. status: result.wechatStatus
  98. }, () => {
  99. callback && typeof callback === 'function' && callback()
  100. })
  101. }
  102. } catch (error) {
  103. console.log(error, "error");
  104. }
  105. },
  106. // 格式化类型
  107. formatPeriod(num: number, type: string) {
  108. if (!num || !type) {
  109. return ''
  110. }
  111. const template: any = {
  112. DAY: "天",
  113. MONTH: "个月",
  114. YEAR: "年"
  115. }
  116. if (type === "YEAR" && num >= 99) {
  117. return '永久'
  118. }
  119. return num + template[type]
  120. },
  121. onSubmit() {
  122. wx.redirectTo({
  123. url: '../index/index'
  124. })
  125. },
  126. onTimeout() {
  127. // 轮询10次查询订单状态
  128. const goodsInfo = this.data.goodsInfo
  129. const timerCount = this.data.timerCount
  130. const timer = this.data.timer
  131. if(goodsInfo.wechatStatus === 'WAIT_PAY' && timerCount <= 10) {
  132. let count = timerCount
  133. const tempT = setTimeout(async () => {
  134. count += 1
  135. await this.getDetail()
  136. this.setData({
  137. timer: tempT,
  138. timerCount: count
  139. }, () => {
  140. this.onTimeout()
  141. })
  142. }, 3000);
  143. } else {
  144. clearTimeout(timer)
  145. }
  146. },
  147. /** 客服 */
  148. onService() {
  149. this.setData({
  150. showService: true
  151. })
  152. },
  153. changePop(event: { detail: any }) {
  154. this.setData({
  155. showService: event.detail
  156. })
  157. },
  158. /** 申请退款 */
  159. async cancelRefound() {
  160. this.setData({
  161. cancelRefoundStatus: true
  162. }, async () => {
  163. try {
  164. const {data} = await api_userPaymentCancelRefund(this.data.goodsInfo.refundOrderId)
  165. // console.log(data, 'data')
  166. if(data.code == 200) {
  167. wx.showToast({ title: '取消退款成功', icon: 'none' })
  168. this.getDetail()
  169. } else {
  170. wx.showToast({ title: data.message, icon: 'none' })
  171. }
  172. setTimeout(() => {
  173. this.setData({
  174. cancelRefoundStatus: false
  175. })
  176. }, 500);
  177. } catch {}
  178. })
  179. },
  180. /** 申请退款 */
  181. useRefound() {
  182. this.setData({
  183. refoundStatus: true
  184. })
  185. },
  186. changeRefoundStatus(e: {detail: any}) {
  187. this.setData({
  188. refoundStatus: e.detail
  189. })
  190. },
  191. onRefoundComfirm() {
  192. this.setData({
  193. refoundStatus: false
  194. })
  195. // wx.navigateBack({
  196. // delta: 1
  197. // })
  198. this.getDetail()
  199. },
  200. onCopy(e: { currentTarget: any }) {
  201. wx.setClipboardData({
  202. data: e.currentTarget.dataset.orderno,
  203. success: () => {
  204. wx.showToast({title: '复制成功', icon: 'none'})
  205. },
  206. fail: () => {
  207. wx.showToast({title: '复制失败,请稍后再试', icon: 'none'})
  208. }
  209. })
  210. },
  211. onActivation(e: { currentTarget: any }) {
  212. const code = e.currentTarget.dataset.code || ''
  213. if(!code) {
  214. wx.showToast({
  215. title: '暂无法激活',
  216. icon: 'none'
  217. })
  218. return
  219. }
  220. wx.navigateTo({
  221. url: '../protocol/register?type=activation&code=' + code
  222. })
  223. },
  224. onDownload() {
  225. wx.saveImageToPhotosAlbum({
  226. filePath: this.data.canvasImg,
  227. success: () => {
  228. wx.showToast({
  229. title: '保存成功',
  230. icon: 'success',
  231. });
  232. },
  233. fail: () => {
  234. wx.showToast({
  235. title: '保存失败',
  236. icon: 'none',
  237. });
  238. }
  239. })
  240. },
  241. onShareAppMessage() {
  242. return {
  243. title: '器乐数字AI工具',
  244. path: '/pages/index/index',
  245. imageUrl: 'https://oss.dayaedu.com/ktyq/1733312164991.png'
  246. }
  247. }
  248. })