index.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import GoodApi from '../../../../services/good'
  2. import checkauth from '../../../../utils/checkauth'
  3. import Navi from '../../../../utils/navi'
  4. // pages/mine/myorder/list/index.ts
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. searchText: '',
  11. stickyProps: {
  12. zIndex: 2,
  13. },
  14. wait: false,
  15. loadMoreStatus: 0,
  16. orders: [],
  17. orderInput: {
  18. filterText: '',
  19. skipCount: 0,
  20. maxResultCount: 10,
  21. },
  22. total: 0,
  23. recode: '',
  24. showConfirm: false,
  25. },
  26. behaviors: [checkauth],
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad() {},
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady() {},
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow() {
  39. const self = this
  40. //@ts-ignore
  41. this.afterAuth(() => {
  42. self.load(true)
  43. })
  44. },
  45. /**
  46. * 生命周期函数--监听页面隐藏
  47. */
  48. onHide() {},
  49. /**
  50. * 生命周期函数--监听页面卸载
  51. */
  52. onUnload() {},
  53. /**
  54. * 页面相关事件处理函数--监听用户下拉动作
  55. */
  56. onPullDownRefresh() {
  57. if (!this.data.wait) {
  58. this.setData(
  59. {
  60. orderInput: {
  61. ...this.data.orderInput,
  62. skipCount: 0,
  63. },
  64. },
  65. () => {
  66. this.load(true)
  67. },
  68. )
  69. }
  70. },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom() {
  75. if (this.data.loadMoreStatus === 0 && this.data.orders.length < this.data.total) {
  76. this.setData(
  77. {
  78. orderInput: {
  79. ...this.data.orderInput,
  80. skipCount: this.data.orderInput.skipCount + 10,
  81. },
  82. },
  83. () => {
  84. this.load()
  85. },
  86. )
  87. }
  88. },
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage() {},
  93. load(rest = false) {
  94. this.setData({
  95. wait: true,
  96. loadMoreStatus: 1,
  97. })
  98. GoodApi.GetOrderList(this.data.orderInput)
  99. .then((rsp) => {
  100. if (rsp.result) {
  101. const { items = [], totalCount = 0 } = rsp.result
  102. const nowItems = rest ? items : this.data.orders.concat(items as any)
  103. this.setData({
  104. wait: false,
  105. total: totalCount,
  106. orders: nowItems as any,
  107. loadMoreStatus: nowItems.length === totalCount ? 2 : 0,
  108. })
  109. }
  110. })
  111. .catch(() => {
  112. this.setData({
  113. wait: false,
  114. loadMoreStatus: 0,
  115. })
  116. })
  117. .finally(() => {
  118. wx.stopPullDownRefresh()
  119. })
  120. },
  121. onSearchChange(e: WechatMiniprogram.CustomEvent<{ value: string }>) {
  122. const txt = e.detail.value
  123. this.setData({
  124. searchText: txt,
  125. })
  126. },
  127. onSearchSubmit(e: WechatMiniprogram.CustomEvent<{ value: string }>) {
  128. const txt = e.detail.value
  129. this.setData(
  130. {
  131. orderInput: {
  132. ...this.data.orderInput,
  133. filterText: txt,
  134. skipCount: 0,
  135. },
  136. },
  137. () => {
  138. this.load(true)
  139. },
  140. )
  141. },
  142. gotoDetail(e: WechatMiniprogram.CustomEvent<{}, {}, { code: string }>) {
  143. Navi.navigateTo({
  144. url: '/pages/mine/myorder/detail/index?code=' + e.currentTarget.dataset.code,
  145. })
  146. },
  147. onRebuy(e: WechatMiniprogram.CustomEvent<{}, {}, { code: string }>) {
  148. this.setData({
  149. showConfirm: true,
  150. recode: e.currentTarget.dataset.code,
  151. })
  152. },
  153. confirmDialog() {
  154. this.setData({
  155. showConfirm: false,
  156. wait: true,
  157. })
  158. GoodApi.OrderDeplicate({
  159. code: this.data.recode,
  160. })
  161. .then((rsp) => {
  162. if (rsp.result === 'ok') {
  163. Navi.switchTab({
  164. url: '/pages/cart/index',
  165. })
  166. }
  167. this.setData({
  168. wait: false,
  169. })
  170. })
  171. .catch(() => {
  172. this.setData({
  173. wait: false,
  174. })
  175. })
  176. },
  177. closeDialog() {
  178. this.setData({
  179. showConfirm: false,
  180. recode: '',
  181. })
  182. },
  183. })