index.js 6.2 KB

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