index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. app.updateUnread(res.data.notice.toString());
  63. });
  64. },
  65. /**
  66. * 关闭支付组件
  67. *
  68. */
  69. pay_close:function(){
  70. this.setData({ pay_close:false});
  71. },
  72. /**
  73. * 生命周期函数--监听页面加载
  74. */
  75. onLoad: function (options) {
  76. if (options.status) this.setData({ orderStatus:options.status});
  77. this.setData({ 'parameter.return': options.is_return ? '0' : '1'});
  78. },
  79. /**
  80. * 获取订单统计数据
  81. *
  82. */
  83. getOrderData:function(){
  84. var that=this;
  85. orderData().then(res=>{
  86. that.setData({ orderData: res.data });
  87. })
  88. },
  89. /**
  90. * 取消订单
  91. *
  92. */
  93. cancelOrder:function(e){
  94. var order_id = e.currentTarget.dataset.order_id;
  95. var index = e.currentTarget.dataset.index,that=this;
  96. if (!order_id) return app.Tips({title:'缺少订单号无法取消订单'});
  97. orderCancel(order_id).then(res=>{
  98. return app.Tips({ title: res.msg, icon: 'success' }, function () {
  99. that.data.orderList.splice(index, 1);
  100. that.setData({ orderList: that.data.orderList, 'orderData.unpaid_count': that.data.orderData.unpaid_count - 1 });
  101. that.getOrderData();
  102. });
  103. }).catch(err=>{
  104. return app.Tips({title:err});
  105. });
  106. },
  107. /**
  108. * 打开支付组件
  109. *
  110. */
  111. goPay:function(e){
  112. let order_id = e.currentTarget.dataset.order_id, pay_price = e.currentTarget.dataset.pay_price;
  113. this.setData({ pay_close: true, pay_order_id: order_id, totalPrice: pay_price});
  114. },
  115. /**
  116. * 支付成功回调
  117. *
  118. */
  119. pay_complete:function(){
  120. this.setData({ loadend: false, page: 1, orderList: [], pay_close: false, pay_order_id:''});
  121. this.getOrderData();
  122. this.getOrderList();
  123. },
  124. /**
  125. * 支付失败回调
  126. *
  127. */
  128. pay_fail:function(){
  129. this.setData({ pay_close: false, pay_order_id:''});
  130. },
  131. /**
  132. * 去订单详情
  133. */
  134. goOrderDetails:function(e){
  135. var order_id = e.currentTarget.dataset.order_id;
  136. if (!order_id) return app.Tips({ title: '缺少订单号无法查看订单详情' });
  137. wx.showLoading({
  138. title: '正在加载',
  139. })
  140. openOrderSubscribe().then(()=>{
  141. wx.hideLoading();
  142. wx.navigateTo({ url: '/pages/order_details/index?order_id=' + order_id })
  143. }).catch(()=>{
  144. wx.hideLoading();
  145. })
  146. },
  147. /**
  148. * 切换类型
  149. */
  150. statusClick:function(e){
  151. var status = e.currentTarget.dataset.status;
  152. if (status == this.data.orderStatus) return;
  153. this.setData({ orderStatus: status, loadend: false, page: 1, orderList:[]});
  154. this.getOrderList();
  155. },
  156. /**
  157. * 获取订单列表
  158. */
  159. getOrderList:function(){
  160. var that=this;
  161. if(that.data.loadend) return;
  162. if(that.data.loading) return;
  163. that.setData({ loading: true, loadTitle:""});
  164. getOrderList({
  165. type: that.data.orderStatus,
  166. page: that.data.page,
  167. limit: that.data.limit,
  168. }).then(res=>{
  169. var list = res.data || [];
  170. var loadend = list.length < that.data.limit;
  171. that.data.orderList = app.SplitArray(list, that.data.orderList);
  172. that.setData({
  173. orderList: that.data.orderList,
  174. loadend: loadend,
  175. loading: false,
  176. loadTitle: loadend ? "我也是有底线的" : '加载更多',
  177. page: that.data.page + 1,
  178. });
  179. }).catch(err=>{
  180. that.setData({ loading: false, loadTitle: "加载更多" });
  181. })
  182. },
  183. /**
  184. * 删除订单
  185. */
  186. delOrder:function(e){
  187. var order_id = e.currentTarget.dataset.order_id;
  188. var index = e.currentTarget.dataset.index, that = this;
  189. orderDel(order_id).then(res=>{
  190. that.data.orderList.splice(index, 1);
  191. that.setData({ orderList: that.data.orderList, 'orderData.unpaid_count': that.data.orderData.unpaid_count - 1 });
  192. that.getOrderData();
  193. return app.Tips({ title: '删除成功', icon: 'success' });
  194. }).catch(err=>{
  195. return app.Tips({title:err});
  196. })
  197. },
  198. /**
  199. * 生命周期函数--监听页面初次渲染完成
  200. */
  201. onReady: function () {
  202. },
  203. /**
  204. * 生命周期函数--监听页面显示
  205. */
  206. onShow: function () {
  207. if (app.globalData.isLog && this.data.isClose){
  208. this.getOrderData();
  209. this.setData({ loadend: false, page: 1, orderList:[]});
  210. this.getOrderList();
  211. }
  212. },
  213. /**
  214. * 生命周期函数--监听页面隐藏
  215. */
  216. onHide: function () {
  217. this.setData({ isClose:true});
  218. },
  219. /**
  220. * 生命周期函数--监听页面卸载
  221. */
  222. onUnload: function () {
  223. },
  224. /**
  225. * 页面相关事件处理函数--监听用户下拉动作
  226. */
  227. onPullDownRefresh: function () {
  228. },
  229. /**
  230. * 页面上拉触底事件的处理函数
  231. */
  232. onReachBottom: function () {
  233. this.getOrderList();
  234. },
  235. })