index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // pages/shopOrder/index.js
  2. let myPro = require("../../../utils/wxRequest.js");
  3. let util = require("../../../utils/util.js");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imgUrl: getApp().globalData.imgUrl,
  10. active: null, // null全部 0未支付 1待发货 2待自提 3已完成
  11. orderList: [],
  12. page: 1,
  13. size: 10,
  14. finished: false,
  15. loading: false // 全局loading
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. var that = this
  22. if(options.status != null){
  23. that.setData({
  24. active: parseInt(options.status),
  25. });
  26. };
  27. that.getOrderList();
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {
  38. let that = this;
  39. },
  40. /**
  41. * 生命周期函数--监听页面隐藏
  42. */
  43. onHide: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面卸载
  47. */
  48. onUnload: function () {
  49. },
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh: function () {
  54. },
  55. /**
  56. * 页面上拉触底事件的处理函数
  57. */
  58. onReachBottom: function () {
  59. // console.log('上拉触底事件')
  60. let that = this;
  61. if(!that.data.finished){
  62. that.getOrderList()
  63. };
  64. },
  65. // 获取商家订单列表
  66. getOrderList(){
  67. let that = this
  68. let params = {
  69. page: that.data.page,
  70. size: that.data.size
  71. };
  72. if(that.data.active != -1){
  73. params.status = that.data.active
  74. };
  75. myPro.wxRequest("store/order/list","GET",params).then(res=>{
  76. let tempList = res.result;
  77. let list = that.data.orderList;
  78. // 无数据
  79. if(tempList.length == 0){
  80. wx.showToast({
  81. title: "暂无更多数据",
  82. icon: "none"
  83. });
  84. that.setData({
  85. finished: true
  86. });
  87. }else{
  88. // 有数据
  89. for(let i in tempList){
  90. // 订单状态
  91. if(tempList[i].order_status == 0){
  92. tempList[i].statusTitle = '已关闭'
  93. }else if(tempList[i].order_status == 2){
  94. tempList[i].statusTitle = '已完成'
  95. }else if(tempList[i].order_status == 1){
  96. // 正常订单
  97. if(tempList[i].pay_status == 0){
  98. tempList[i].statusTitle = '待支付'
  99. }else if(tempList[i].pay_status == 1){
  100. if(tempList[i].ship_status == 0){
  101. // fare_type 0邮寄 1自提
  102. if(tempList[i].fare_type == 0){
  103. tempList[i].statusTitle = '待发货'
  104. }else if(tempList[i].fare_type == 1){
  105. tempList[i].statusTitle = '待自提'
  106. }
  107. }
  108. }else if(tempList[i].pay_status == 2){
  109. // fare_type 0邮寄 1自提
  110. if(tempList[i].fare_type == 0){
  111. tempList[i].statusTitle = '已发货'
  112. }else if(tempList[i].fare_type == 1){
  113. tempList[i].statusTitle = '已自提'
  114. }
  115. }
  116. }
  117. // 订单的商品总数
  118. let order_goods = tempList[i].order_good
  119. let nums = 0
  120. for(let j in order_goods){
  121. nums = nums + parseInt(order_goods[j].nums)
  122. }
  123. tempList[i].goods_total_nums = nums // 商品总数,也应该接口返回(现在没有,就先自己总)
  124. }
  125. list = list.concat(tempList);
  126. // 计算总价 (不计算了,直接拿pay_price,这里还有优惠券)
  127. // for(let i in list){
  128. // list[i].totalPrice = parseFloat(list[i].price) + parseFloat(list[i].delivery_fee);
  129. // list[i].totalMemberPrice = parseFloat(list[i].member_price) + parseFloat(list[i].delivery_fee)
  130. // };
  131. that.setData({
  132. orderList: list,
  133. page: that.data.page + 1
  134. });
  135. }
  136. }).catch(err=>{
  137. // that.setData({
  138. // loading: false
  139. // });
  140. console.log('报错信息',err);
  141. wx.showToast({
  142. title: err,
  143. icon: "none"
  144. })
  145. });
  146. },
  147. // 切换列表
  148. onClickTab(event){
  149. // console.log('event=====',event);
  150. let that = this;
  151. that.setData({
  152. active: event.detail.name,
  153. page: 1,
  154. orderList: []
  155. })
  156. that.getOrderList();
  157. },
  158. // 处理订单(发货)
  159. toHandle(event){
  160. let that = this;
  161. // console.log(event)
  162. let order = event.currentTarget.dataset.order;
  163. let params = {
  164. order_id: order.id
  165. };
  166. myPro.wxRequest("store/order/ship","POST",params).then(res=>{
  167. wx.showToast({
  168. title: res.msg,
  169. icon: "none"
  170. });
  171. that.setData({
  172. page: 1,
  173. orderList: [],
  174. finished: false
  175. });
  176. that.getOrderList();
  177. }).catch(err=>{
  178. console.log('报错信息',err);
  179. wx.showToast({
  180. title: err,
  181. icon: "none"
  182. })
  183. });
  184. },
  185. // 处理订单(取消)
  186. cancleOrder(event){
  187. let that = this;
  188. let order = event.currentTarget.dataset.order;
  189. let params = {
  190. order_id: order.id
  191. };
  192. myPro.wxRequest("store/tx/cancelOrder","POST",params).then(res=>{
  193. wx.showToast({
  194. title: res.msg,
  195. icon: "none"
  196. });
  197. that.setData({
  198. page: 1,
  199. orderList: [],
  200. finished: false
  201. });
  202. that.getOrderList();
  203. }).catch(err=>{
  204. console.log('报错信息',err);
  205. wx.showToast({
  206. title: err,
  207. icon: "none"
  208. })
  209. });
  210. }
  211. })