index.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import dayjs from 'dayjs'
  2. //@ts-ignore
  3. // import Toast from 'tdesign-miniprogram/toast/index'
  4. import GoodApi from '../../../../services/good'
  5. import checkauth from '../../../../utils/checkauth'
  6. import Navi from '../../../../utils/navi'
  7. // pages/mine/myorder/detail/index.ts
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. code: '',
  14. orderDate: '',
  15. followDate: '',
  16. showConfirm: false,
  17. },
  18. behaviors: [checkauth],
  19. init() {
  20. this.setData({
  21. wait: true,
  22. })
  23. GoodApi.GetOrderDetail({
  24. code: this.data.code,
  25. })
  26. .then((rsp) => {
  27. if (rsp.result) {
  28. const orderDate = dayjs(rsp.result.status.orderDate).format('YYYY-MM-DD HH:mm:ss')
  29. let followDate = rsp.result.status.followDate
  30. if (followDate && followDate.length > 0) {
  31. followDate = dayjs(followDate).format('YYYY-MM-DD HH:mm:ss')
  32. }
  33. this.setData({
  34. ...rsp.result,
  35. orderDate,
  36. followDate,
  37. wait: false,
  38. })
  39. }
  40. })
  41. .catch(() => {
  42. this.setData({
  43. wait: false,
  44. })
  45. })
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. //@ts-ignore
  51. onLoad(query: { code: string }) {
  52. const { code = '' } = query
  53. this.setData({
  54. code,
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady() {},
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow() {
  65. const self = this
  66. //@ts-ignore
  67. this.afterAuth(() => {
  68. self.init()
  69. })
  70. },
  71. /**
  72. * 生命周期函数--监听页面隐藏
  73. */
  74. onHide() {},
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload() {},
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh() {},
  83. /**
  84. * 页面上拉触底事件的处理函数
  85. */
  86. onReachBottom() {},
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage() {},
  91. onCopyCode(e: WechatMiniprogram.CustomEvent<{}, {}, { code: string }>) {
  92. const { code = '' } = e.currentTarget.dataset
  93. if (code && code.length > 0) {
  94. wx.setClipboardData({
  95. data: code,
  96. // success() {
  97. // Toast({
  98. // context: this,
  99. // selector: '#t-toast',
  100. // message: '已复制到剪贴板',
  101. // icon: '',
  102. // duration: 1000,
  103. // })
  104. // },
  105. })
  106. }
  107. },
  108. onRebuy() {
  109. this.setData({
  110. showConfirm: true,
  111. })
  112. },
  113. confirmDialog() {
  114. this.setData({
  115. showConfirm: false,
  116. wait: true,
  117. })
  118. GoodApi.OrderDeplicate({
  119. code: this.data.code,
  120. })
  121. .then((rsp) => {
  122. if (rsp.result === 'ok') {
  123. Navi.switchTab({
  124. url: '/pages/cart/index',
  125. })
  126. }
  127. this.setData({
  128. wait: false,
  129. })
  130. })
  131. .catch(() => {
  132. this.setData({
  133. wait: false,
  134. })
  135. })
  136. },
  137. closeDialog() {
  138. this.setData({
  139. showConfirm: false,
  140. })
  141. },
  142. })