index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import { getOrderList, orderData, orderCancel, orderDel, orderPay } from '../../api/order.js';
  2. import { getUserInfo } from '../../api/user.js';
  3. import { openOrderSubscribe } from '../../utils/SubscribeMessage.js';
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. parameter: {
  11. 'navbar': '1',
  12. 'return': '1',
  13. 'title': '我的订单',
  14. 'color': true,
  15. 'class': '0'
  16. },
  17. loading:false,//是否加载中
  18. loadend:false,//是否加载完毕
  19. loadTitle:'加载更多',//提示语
  20. orderList:[],//订单数组
  21. orderData:{},//订单详细统计
  22. orderStatus:0,//订单状态
  23. page:1,
  24. limit:10,
  25. isClose:false,
  26. payMode:[
  27. { name: "微信支付", icon: "icon-weixinzhifu", value: 'weixin', title: '微信快捷支付' },
  28. { name: "余额支付", icon: "icon-yuezhifu", value: 'yue', title: '可用余额:',number:0},
  29. ],
  30. pay_close:false,
  31. pay_order_id:'',
  32. totalPrice:'0',
  33. },
  34. /**
  35. * 登录回调
  36. *
  37. */
  38. onLoadFun:function(){
  39. this.getOrderData();
  40. this.getOrderList();
  41. this.getUserInfo();
  42. },
  43. /**
  44. * 事件回调
  45. *
  46. */
  47. onChangeFun:function(e){
  48. let opt = e.detail;
  49. let action = opt.action || null;
  50. let value = opt.value != undefined ? opt.value : null;
  51. (action && this[action]) && this[action](value);
  52. },
  53. /**
  54. * 获取用户信息
  55. *
  56. */
  57. getUserInfo:function(){
  58. let that = this;
  59. getUserInfo().then(res=>{
  60. that.data.payMode[1].number = res.data.now_money;
  61. that.setData({ payMode: that.data.payMode});
  62. });
  63. },
  64. /**
  65. * 关闭支付组件
  66. *
  67. */
  68. pay_close:function(){
  69. this.setData({ pay_close:false});
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. onLoad: function (options) {
  75. if (options.status) this.setData({ orderStatus:options.status});
  76. this.setData({ 'parameter.return': options.is_return ? '0' : '1'});
  77. },
  78. /**
  79. * 获取订单统计数据
  80. *
  81. */
  82. getOrderData:function(){
  83. var that=this;
  84. orderData().then(res=>{
  85. that.setData({ orderData: res.data });
  86. })
  87. },
  88. /**
  89. * 取消订单
  90. *
  91. */
  92. cancelOrder:function(e){
  93. var order_id = e.currentTarget.dataset.order_id;
  94. var index = e.currentTarget.dataset.index,that=this;
  95. if (!order_id) return app.Tips({title:'缺少订单号无法取消订单'});
  96. orderCancel(order_id).then(res=>{
  97. return app.Tips({ title: res.msg, icon: 'success' }, function () {
  98. that.data.orderList.splice(index, 1);
  99. that.setData({ orderList: that.data.orderList, 'orderData.unpaid_count': that.data.orderData.unpaid_count - 1 });
  100. that.getOrderData();
  101. });
  102. }).catch(err=>{
  103. return app.Tips({title:err});
  104. });
  105. },
  106. /**
  107. * 打开支付组件
  108. *
  109. */
  110. goPay:function(e){
  111. let order_id = e.currentTarget.dataset.order_id, pay_price = e.currentTarget.dataset.pay_price;
  112. this.setData({ pay_close: true, pay_order_id: order_id, totalPrice: pay_price});
  113. },
  114. /**
  115. * 支付成功回调
  116. *
  117. */
  118. pay_complete:function(){
  119. this.setData({ loadend: false, page: 1, orderList: [], pay_close: false, pay_order_id:''});
  120. this.getOrderData();
  121. this.getOrderList();
  122. },
  123. /**
  124. * 支付失败回调
  125. *
  126. */
  127. pay_fail:function(){
  128. this.setData({ pay_close: false, pay_order_id:''});
  129. },
  130. /**
  131. * 去订单详情
  132. */
  133. goOrderDetails:function(e){
  134. var order_id = e.currentTarget.dataset.order_id;
  135. if (!order_id) return app.Tips({ title: '缺少订单号无法查看订单详情' });
  136. wx.showLoading({
  137. title: '正在加载',
  138. })
  139. openOrderSubscribe().then(()=>{
  140. wx.hideLoading();
  141. wx.navigateTo({ url: '/pages/order_details/index?order_id=' + order_id })
  142. }).catch(()=>{
  143. wx.hideLoading();
  144. })
  145. },
  146. /**
  147. * 切换类型
  148. */
  149. statusClick:function(e){
  150. var status = e.currentTarget.dataset.status;
  151. if (status == this.data.orderStatus) return;
  152. this.setData({ orderStatus: status, loadend: false, page: 1, orderList:[]});
  153. this.getOrderList();
  154. },
  155. /**
  156. * 获取订单列表
  157. */
  158. getOrderList:function(){
  159. var that=this;
  160. if(that.data.loadend) return;
  161. if(that.data.loading) return;
  162. that.setData({ loading: true, loadTitle:""});
  163. getOrderList({
  164. type: that.data.orderStatus,
  165. page: that.data.page,
  166. limit: that.data.limit,
  167. }).then(res=>{
  168. var list = res.data || [];
  169. var loadend = list.length < that.data.limit;
  170. that.data.orderList = app.SplitArray(list, that.data.orderList);
  171. that.setData({
  172. orderList: that.data.orderList,
  173. loadend: loadend,
  174. loading: false,
  175. loadTitle: loadend ? "我也是有底线的" : '加载更多',
  176. page: that.data.page + 1,
  177. });
  178. }).catch(err=>{
  179. that.setData({ loading: false, loadTitle: "加载更多" });
  180. })
  181. },
  182. /**
  183. * 删除订单
  184. */
  185. delOrder:function(e){
  186. var order_id = e.currentTarget.dataset.order_id;
  187. var index = e.currentTarget.dataset.index, that = this;
  188. orderDel(order_id).then(res=>{
  189. that.data.orderList.splice(index, 1);
  190. that.setData({ orderList: that.data.orderList, 'orderData.unpaid_count': that.data.orderData.unpaid_count - 1 });
  191. that.getOrderData();
  192. return app.Tips({ title: '删除成功', icon: 'success' });
  193. }).catch(err=>{
  194. return app.Tips({title:err});
  195. })
  196. },
  197. /**
  198. * 生命周期函数--监听页面初次渲染完成
  199. */
  200. onReady: function () {
  201. },
  202. /**
  203. * 生命周期函数--监听页面显示
  204. */
  205. onShow: function () {
  206. if (app.globalData.isLog && this.data.isClose){
  207. this.getOrderData();
  208. this.setData({ loadend: false, page: 1, orderList:[]});
  209. this.getOrderList();
  210. }
  211. },
  212. /**
  213. * 生命周期函数--监听页面隐藏
  214. */
  215. onHide: function () {
  216. this.setData({ isClose:true});
  217. },
  218. /**
  219. * 生命周期函数--监听页面卸载
  220. */
  221. onUnload: function () {
  222. },
  223. /**
  224. * 页面相关事件处理函数--监听用户下拉动作
  225. */
  226. onPullDownRefresh: function () {
  227. },
  228. /**
  229. * 页面上拉触底事件的处理函数
  230. */
  231. onReachBottom: function () {
  232. this.getOrderList();
  233. },
  234. })