myorders.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // pages/myorders/myorders.js
  2. const app = getApp();
  3. const api = require('../../api/api');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. navbarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '我的订单', //导航栏 中间的标题
  12. capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
  13. },
  14. tabs: [
  15. "全部", "待支付", "待收货", "退款/售后"
  16. ],
  17. zhong: 0,
  18. orders: [], //我的订单
  19. share_order_id: 0, //分享订单ID
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. let that = this;
  26. // 获取我的订单列表
  27. wx.showLoading({
  28. title: '加载中',
  29. mask: true
  30. })
  31. wx.request({
  32. url: api.Member_order,
  33. header: {
  34. 'Authorization': wx.getStorageSync('token')
  35. },
  36. method: 'POST',
  37. success(res) {
  38. console.log(res);
  39. if (res.data.code === 1) {
  40. that.setData({
  41. orders: res.data.data
  42. })
  43. } else {
  44. wx.showToast({
  45. title: res.data.msg,
  46. mask: true,
  47. icon: 'none'
  48. })
  49. }
  50. },
  51. fail(err) {
  52. wx.showToast({
  53. title: '发起网络请求失败',
  54. icon: 'none',
  55. mask: true
  56. })
  57. },
  58. complete() {
  59. wx.hideLoading()
  60. }
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面显示
  70. */
  71. onShow: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面卸载
  80. */
  81. onUnload: function () {
  82. },
  83. /**
  84. * 页面相关事件处理函数--监听用户下拉动作
  85. */
  86. onPullDownRefresh: function () {
  87. },
  88. /**
  89. * 页面上拉触底事件的处理函数
  90. */
  91. onReachBottom: function () {
  92. },
  93. /**
  94. * 用户点击右上角分享
  95. */
  96. onShareAppMessage: function () {
  97. let order_id = this.data.share_order_id; //订单ID
  98. return {
  99. title: '订单分享',
  100. path: '/pages/orderdetail/orderdetail?id=' + order_id,
  101. imageUrl: 'https://s4.ax1x.com/2021/12/29/TccgfK.jpg'
  102. }
  103. },
  104. tabsbind(e) {
  105. let that = this;
  106. let oid = e.currentTarget.dataset.id; //用户选中的标签
  107. let order_status = 0; //对应的订单状态
  108. if (oid === 0) {
  109. // 全部
  110. order_status = '';
  111. } else if (oid === 1) {
  112. // 待支付
  113. order_status = 0;
  114. } else if (oid === 2) {
  115. // 待取货
  116. order_status = 1;
  117. } else if (oid === 3) {
  118. // 已完成
  119. order_status = 2;
  120. } else if (oid === 4) {
  121. // 退款/售后
  122. order_status = 4;
  123. }
  124. if (oid === 0) {
  125. // 获取我的订单列表
  126. wx.showLoading({
  127. title: '加载中',
  128. mask: true
  129. })
  130. wx.request({
  131. url: api.Member_order,
  132. header: {
  133. 'Authorization': wx.getStorageSync('token')
  134. },
  135. method: 'POST',
  136. success(res) {
  137. console.log(res);
  138. if (res.data.code === 1) {
  139. that.setData({
  140. orders: res.data.data,
  141. zhong: oid
  142. })
  143. } else {
  144. wx.showToast({
  145. title: res.data.msg,
  146. mask: true,
  147. icon: 'none'
  148. })
  149. }
  150. },
  151. fail(err) {
  152. wx.showToast({
  153. title: '发起网络请求失败',
  154. icon: 'none',
  155. mask: true
  156. })
  157. },
  158. complete() {
  159. wx.hideLoading()
  160. }
  161. })
  162. } else {
  163. // 获取我的订单列表
  164. wx.showLoading({
  165. title: '加载中',
  166. mask: true
  167. })
  168. wx.request({
  169. url: api.Member_order,
  170. header: {
  171. 'Authorization': wx.getStorageSync('token')
  172. },
  173. method: 'POST',
  174. data: {
  175. order_status: order_status
  176. },
  177. success(res) {
  178. console.log(res);
  179. if (res.data.code === 1) {
  180. that.setData({
  181. orders: res.data.data,
  182. zhong: oid
  183. })
  184. } else {
  185. wx.showToast({
  186. title: res.data.msg,
  187. mask: true,
  188. icon: 'none'
  189. })
  190. }
  191. },
  192. fail(err) {
  193. wx.showToast({
  194. title: '发起网络请求失败',
  195. icon: 'none',
  196. mask: true
  197. })
  198. },
  199. complete() {
  200. wx.hideLoading()
  201. }
  202. })
  203. }
  204. },
  205. // 订单跳转
  206. navToOrderDetail(e) {
  207. let id = e.currentTarget.dataset.id;
  208. let order_status = e.currentTarget.dataset.status;
  209. // console.log(order_status);
  210. if(order_status == 4) {
  211. wx.navigateTo({
  212. url: '/pages/confirmrefund/confirmrefund?id=' + id,
  213. })
  214. }else {
  215. wx.navigateTo({
  216. url: '/pages/orderdetail/orderdetail?id=' + id,
  217. })
  218. }
  219. },
  220. // 分享订单
  221. shareOrder(e) {
  222. this.setData({
  223. share_order_id: e.detail.value
  224. })
  225. }
  226. })