index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. const app = getApp();
  2. import { getRollList } from '../../api/order.js';
  3. import { getIndexData, getCoupons } from '../../api/api.js';
  4. import Util from '../../utils/util.js';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. loading:false,//是否加载中
  11. loadend:false,//是否加载完毕
  12. loadTitle:'加载更多',//提示语
  13. imgUrls: [],
  14. bastBanner: [],
  15. bastInfo: '',
  16. bastList: [],
  17. fastInfo: '',
  18. firstInfo: '',
  19. salesInfo: '',
  20. indicatorDots: false,
  21. circular: true,
  22. autoplay: true,
  23. interval: 3000,
  24. duration: 500,
  25. orderStatus:1,//订单状态
  26. orderList:[],//订单数组
  27. page:1,
  28. limit:5,
  29. loading:false,//是否加载中
  30. loadend:false,//是否加载完毕
  31. parameter:{
  32. 'navbar': '1',
  33. 'return': '0',
  34. 'title': '首页',
  35. 'color': true,
  36. 'class': '5'
  37. },
  38. window: false,
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad: function (options) {
  44. if (options.spid) app.globalData.spid = options.spid;
  45. if (options.scene) app.globalData.code = decodeURIComponent(options.scene);
  46. // this.getOrderList();
  47. console.log(wx.getStorageSync('token'));
  48. },
  49. /**
  50. * 事件回调
  51. *
  52. */
  53. onChangeFun:function(e){
  54. let opt = e.detail;
  55. let action = opt.action || null;
  56. let value = opt.value != undefined ? opt.value : null;
  57. (action && this[action]) && this[action](value);
  58. },
  59. getIndexConfig:function(){
  60. var that = this;
  61. getIndexData().then(res=>{
  62. that.setData({
  63. imgUrls: res.data.banner,
  64. bastBanner: res.data.info.bastBanner,
  65. bastInfo: res.data.info.bastInfo,
  66. bastList: res.data.info.bastList,
  67. fastInfo: res.data.info.fastInfo,
  68. firstInfo: res.data.info.firstInfo,
  69. salesInfo: res.data.info.salesInfo,
  70. logoUrl: res.data.logoUrl,
  71. couponList: res.data.couponList,
  72. });
  73. wx.getSetting({
  74. success(res) {
  75. if (!res.authSetting['scope.userInfo']) {
  76. that.setData({ window: that.data.couponList.length ? true : false });
  77. } else {
  78. that.setData({ window: false });
  79. }
  80. }
  81. });
  82. })
  83. },
  84. /**
  85. * 获取开团列表
  86. */
  87. getOrderList:function(){
  88. var that=this;
  89. if(that.data.loadend) return;
  90. if(that.data.loading) return;
  91. that.setData({ loading: true, loadTitle:""});
  92. getRollList({
  93. status: that.data.orderStatus
  94. }).then(res=>{
  95. var list = res.data, loadend = list.length < that.data.limit;
  96. that.data.orderList = app.SplitArray(list, that.data.orderList);
  97. that.setData({
  98. orderList: that.data.orderList,
  99. loadend: loadend,
  100. loading: false,
  101. loadTitle: loadend ? "我也是有底线的" : '加载更多',
  102. page: that.data.page + 1,
  103. });
  104. }).catch(err=>{
  105. that.setData({ loading: false, loadTitle: "加载更多" });
  106. })
  107. },
  108. /**
  109. * 切换类型
  110. */
  111. statusClick:function(e){
  112. var status = e.currentTarget.dataset.status;
  113. if (status == this.data.orderStatus) return;
  114. this.setData({ orderStatus: status, loadend: false, page: 1, orderList:[]});
  115. this.getOrderList();
  116. },
  117. catchTouchMove: function (res) {
  118. return false
  119. },
  120. onColse:function(){
  121. this.setData({ window: false});
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面显示
  130. */
  131. onShow: function () {
  132. this.getIndexConfig();
  133. this.getOrderList();
  134. if(app.globalData.isLog && app.globalData.token) this.get_issue_coupon_list();
  135. if (app.globalData.isLog && this.data.isClose){
  136. this.setData({ loadend: false, page: 1, orderList:[]});
  137. }
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide: function () {
  143. this.setData({ window:false});
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. this.getIndexConfig();
  155. this.getOrderList();
  156. if (app.globalData.isLog && app.globalData.token) this.get_issue_coupon_list();
  157. wx.stopPullDownRefresh();
  158. },
  159. setGoodsSearch:function(){
  160. wx.navigateTo({
  161. url: '/pages/goods_search/index',
  162. })
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function () {
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function () {
  173. },
  174. /**
  175. * 页面上拉触底事件的处理函数
  176. */
  177. // onReachBottom: function () {
  178. // this.getOrderList();
  179. // },
  180. })