order-result.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // pages/orders/order-detail.ts
  2. // import drawQrcode from "../../utils/weapp.qrcode.esm";
  3. import { api_userPaymentCancelRefund, api_userPaymentOrderDetail } from "../../api/login";
  4. import { formatPrice, GRADE_ENUM } from "../../utils/util";
  5. // 获取应用实例
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. serviceShow: true,
  12. status: 'WAIT_PAY',
  13. statusList: {
  14. WAIT_PAY: {
  15. logo: './images/ing.png',
  16. title: '待付款',
  17. content: '请尽快完成支付,以便我们为您处理订单'
  18. },
  19. PAID: {
  20. logo: './images/success.png',
  21. title: '已完成',
  22. content: '登录「音乐数字课堂」APP使用AI学练'
  23. },
  24. CLOSED: {
  25. logo: './images/error.png',
  26. title: '已取消',
  27. content: '您的交易订单已关闭'
  28. },
  29. WAIT_USE: {
  30. logo: './images/wait.png',
  31. title: '待使用',
  32. content: '请尽快扫描下方二维码进行激活'
  33. },
  34. REFUNDING: {
  35. logo: './images/refounding.png',
  36. title: '退款中',
  37. content: '您的退款申请正在处理,预计7个工作日内完成审核'
  38. },
  39. REFUNDED: {
  40. logo: './images/refounded.png',
  41. title: '退款成功',
  42. content: '您的退款已成功处理,感谢您的理解和支持'
  43. }
  44. },
  45. timerCount: 0,
  46. timer: null as any,
  47. goodsInfo: {} as any,
  48. // tabIdx: 0, // 当前是从哪个tab来的
  49. orderNo: "" as string,
  50. showCanvas: false, // 是否显示二维码
  51. canvasImg: "" as string,
  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. this.setData({
  68. serviceShow: true
  69. })
  70. if (this.data.orderNo) {
  71. this.getDetail()
  72. }
  73. },
  74. onHide() {
  75. this.setData({
  76. serviceShow: false
  77. })
  78. },
  79. async getDetail() {
  80. try {
  81. const { data } = await api_userPaymentOrderDetail(this.data.orderNo, {
  82. version: 'V2'
  83. });
  84. if (data.code == 200) {
  85. const result = data.data || {}
  86. const goodsInfos = result.goodsInfos || []
  87. const tempGoods: any = []
  88. goodsInfos.forEach((item: any) => {
  89. const prices: any = formatPrice(item.paymentCashAmount || 0);
  90. tempGoods.push({
  91. ...item,
  92. integerPart: prices.integerPart,
  93. decimalPart: prices.decimalPart,
  94. originalPrice: formatPrice(item.paymentCashAmount, 'ALL'),
  95. })
  96. })
  97. const addresses = {
  98. id: result.addresses?.id,
  99. name: result.addresses?.name,
  100. phoneNumber: result.addresses?.phoneNumber,
  101. addressDetail: result.addresses?.detailAddress
  102. }
  103. const tempSchoolAddress = [result.beneficiary?.provinceName, result.beneficiary?.cityName, result.beneficiary?.regionName, result.beneficiary?.schoolAreaName, GRADE_ENUM[result.beneficiary?.currentGradeNum], result.beneficiary?.currentClass + '班']
  104. const beneficiary = {
  105. id: result.beneficiary?.schoolAreaId,
  106. name: result.beneficiary?.name,
  107. phoneNumber: result.beneficiary?.phone,
  108. schoolInfo: tempSchoolAddress.join('')
  109. }
  110. const allDiscountPrice = formatPrice(result.originalPrice - result.paymentCashAmount, 'ALL') as string
  111. const allAfterPrice: any = formatPrice(result.paymentCashAmount)
  112. const goodsInfo = {
  113. allDiscountPrice,
  114. paymentCashAmount: result.paymentCashAmount,
  115. originalPrice: result.originalPrice,
  116. integerPart: allAfterPrice.integerPart,
  117. decimalPart: allAfterPrice.decimalPart,
  118. orderNo: result.orderNo,
  119. createTime: result.createTime,
  120. wechatStatus: result.wechatStatus,
  121. goods: tempGoods,
  122. addresses,
  123. beneficiary
  124. }
  125. this.setData({
  126. goodsInfo,
  127. status: result.wechatStatus
  128. })
  129. }
  130. } catch (error) {
  131. console.log(error, "error");
  132. }
  133. },
  134. // 格式化类型
  135. formatPeriod(num: number, type: string) {
  136. if (!num || !type) {
  137. return ''
  138. }
  139. const template: any = {
  140. DAY: "天卡",
  141. MONTH: "月卡",
  142. YEAR: "年卡"
  143. }
  144. if (type === "YEAR" && num >= 99) {
  145. return '永久卡'
  146. }
  147. return num + template[type]
  148. },
  149. onSubmit() {
  150. wx.redirectTo({
  151. url: '../index/index'
  152. })
  153. },
  154. /** 申请退款 */
  155. async cancelRefound() {
  156. this.setData({
  157. cancelRefoundStatus: true
  158. }, async () => {
  159. try {
  160. const { data } = await api_userPaymentCancelRefund(this.data.goodsInfo.refundOrderId)
  161. // console.log(data, 'data')
  162. if (data.code == 200) {
  163. wx.showToast({ title: '取消退款成功', icon: 'none' })
  164. this.getDetail()
  165. } else {
  166. wx.showToast({ title: data.message, icon: 'none' })
  167. }
  168. setTimeout(() => {
  169. this.setData({
  170. cancelRefoundStatus: false
  171. })
  172. }, 500);
  173. } catch { }
  174. })
  175. },
  176. /** 申请退款 */
  177. useRefound() {
  178. this.setData({
  179. refoundStatus: true
  180. })
  181. },
  182. changeRefoundStatus(e: { detail: any }) {
  183. this.setData({
  184. refoundStatus: e.detail
  185. })
  186. },
  187. onRefoundComfirm() {
  188. this.setData({
  189. refoundStatus: false
  190. })
  191. // wx.navigateBack({
  192. // delta: 1
  193. // })
  194. this.getDetail()
  195. },
  196. onCopy(e: { currentTarget: any }) {
  197. wx.setClipboardData({
  198. data: e.currentTarget.dataset.orderno,
  199. success: () => {
  200. wx.showToast({ title: '复制成功', icon: 'none' })
  201. },
  202. fail: () => {
  203. wx.showToast({ title: '复制失败,请稍后再试', icon: 'none' })
  204. }
  205. })
  206. },
  207. onActivation(e: { currentTarget: any }) {
  208. const code = e.currentTarget.dataset.code || ''
  209. if (!code) {
  210. wx.showToast({
  211. title: '暂无法激活',
  212. icon: 'none'
  213. })
  214. return
  215. }
  216. wx.navigateTo({
  217. url: '../protocol/register?type=activation&code=' + code
  218. })
  219. },
  220. onDownload() {
  221. wx.saveImageToPhotosAlbum({
  222. filePath: this.data.canvasImg,
  223. success: () => {
  224. wx.showToast({
  225. title: '保存成功',
  226. icon: 'success',
  227. });
  228. },
  229. fail: () => {
  230. wx.showToast({
  231. title: '保存失败',
  232. icon: 'none',
  233. });
  234. }
  235. })
  236. },
  237. onDownloadApp() {
  238. wx.navigateTo({
  239. url: '../download/download'
  240. })
  241. },
  242. onShareAppMessage() {
  243. return {
  244. title: '音乐数字AI',
  245. path: '/pages/index/index',
  246. imageUrl: 'https://oss.dayaedu.com/ktyq/1733309357691.png'
  247. }
  248. },
  249. })