orderList.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // pages/goods/orderList/orderList.js
  2. import { get, post } from '../../../utils/http'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. current: 4,
  9. list: [],
  10. total: 0,
  11. page: 1,
  12. statusTexts: {
  13. // 状态-1已取消,0待支付,1已支付待取货,2.已完成
  14. s_0: '待支付',
  15. s_1: '待取货',
  16. s_3: '已取消',
  17. s_2: '已取货'
  18. },
  19. time:900 * 1000,//秒杀剩余支付倒计时
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. if (options.current) {
  26. this.setData({ current: options.current })
  27. }
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {},
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. this.getOrder(1)
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {},
  43. /**
  44. * 生命周期函数--监听页面卸载
  45. */
  46. onUnload: function () {},
  47. /**
  48. * 页面相关事件处理函数--监听用户下拉动作
  49. */
  50. onPullDownRefresh: function () {},
  51. /**
  52. * 页面上拉触底事件的处理函数
  53. */
  54. onReachBottom: function () {
  55. if (this.data.page * 10 < this.data.total) {
  56. this.getOrder(++this.data.page)
  57. }
  58. },
  59. /**
  60. * 用户点击右上角分享
  61. */
  62. onShareAppMessage: function () {},
  63. /**
  64. * 切换tabs
  65. */
  66. onTabsChange(e) {
  67. let current = e.currentTarget.dataset.id
  68. if (current == this.data.current) {
  69. return
  70. }
  71. this.setData(
  72. {
  73. current,
  74. page: 1
  75. },
  76. () => {
  77. this.getOrder()
  78. }
  79. )
  80. },
  81. /**
  82. * 取消订单
  83. */
  84. onCancelOrder(e) {
  85. let that = this
  86. wx.showModal({
  87. title: '提示',
  88. content: '是否取消当前订单',
  89. success(res) {
  90. if (res.confirm) {
  91. console.log('用户点击确定')
  92. get(
  93. 'v2/api/goods_order/cancel',
  94. {
  95. order_id: e.currentTarget.dataset.id
  96. },
  97. (res) => {
  98. wx.showToast({
  99. title: res.msg,
  100. icon: 'success',
  101. duration: 2000
  102. })
  103. that.getOrder(1)
  104. }
  105. )
  106. } else if (res.cancel) {
  107. console.log('用户点击取消')
  108. }
  109. }
  110. })
  111. },
  112. onPay: function (e) {
  113. this.setData({
  114. order_id: e.currentTarget.dataset.id,
  115. payMoney: e.currentTarget.dataset.money,
  116. })
  117. wx.navigateTo({
  118. url: `/pages/goods/orderDetail/orderDetail?id=${ e.currentTarget.dataset.id}`,
  119. })
  120. },
  121. /**
  122. * 获取订单列表
  123. * api/order
  124. */
  125. getOrder(_page) {
  126. let { list, current, page, statusTexts } = this.data
  127. get(
  128. '/v2/api/goods_order/list',
  129. {
  130. type: Number(current),
  131. page: _page || page,
  132. limit: 10
  133. },
  134. (res) => {
  135. console.log(res);
  136. if (_page == 1 || page == 1) {
  137. list = []
  138. this.data.page = 1
  139. }
  140. res.data.list.map((item) => {
  141. // 状态,-3已退款,-2退款中,-1已取消,0待支付,1已支付,待取货,2已取货
  142. if(item.status==-1){
  143. item.status=3
  144. }
  145. item['status_text'] = statusTexts['s_' + item.status]
  146. let sum = 0
  147. item.good.map(item1=>{
  148. sum += item1.num
  149. })
  150. // 加上加购产品数量
  151. sum = item.plus.length+sum
  152. item.sum = sum
  153. item.seconds = Number(item.seconds)
  154. })
  155. list.push(...res.data.list)
  156. this.setData({ list, total: res.data.total })
  157. }
  158. )
  159. },
  160. /**
  161. * 用户允许消息通知
  162. * /api/message/agree
  163. */
  164. messageAgree(ids, order_id) {
  165. post(
  166. 'api/message/agree',
  167. {
  168. order_id,
  169. ids
  170. },
  171. () => {}
  172. )
  173. },
  174. // 计算倒计时结束
  175. finishTime(){
  176. // 时间结束重新刷新页面订单
  177. this.getOrder()
  178. }
  179. })