order-result.ts 8.0 KB

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