index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. needAuth: false,
  9. has_slider: 0,
  10. slider_list: [],
  11. share_img: '',
  12. share_title: '',
  13. loadMore: true,
  14. loadText: "加载中...",
  15. loadOver: false,
  16. showEmpty: false,
  17. rushList: [],
  18. },
  19. pageNum: 1,
  20. onLoad: function (options) {
  21. this.getData();
  22. this.getList();
  23. },
  24. onShow: function () {
  25. let that = this;
  26. util.check_login_new().then((res) => {
  27. if(res) {
  28. that.setData({ needAuth: false })
  29. } else {
  30. this.setData({ needAuth: true });
  31. }
  32. })
  33. },
  34. authSuccess: function () {
  35. let that = this;
  36. this.pageNum = 1;
  37. this.setData({
  38. slider_list: [],
  39. loadMore: true,
  40. loadText: "加载中...",
  41. loadOver: false,
  42. showEmpty: false,
  43. rushList: []
  44. }, () => {
  45. that.getData();
  46. that.getList();
  47. })
  48. },
  49. authModal: function () {
  50. if (this.data.needAuth) {
  51. this.setData({ showAuthModal: !this.data.showAuthModal });
  52. return false;
  53. }
  54. return true;
  55. },
  56. getData: function () {
  57. app.util.ProReq('presalegoods.index', {}).then(res => {
  58. let { has_slider, slider_list, presale_share_img, presale_share_title, presale_layout } = res.data;
  59. this.setData({
  60. presale_layout,
  61. has_slider,
  62. slider_list,
  63. share_img: presale_share_img,
  64. share_title: presale_share_title
  65. })
  66. })
  67. },
  68. /**
  69. * 获取商品列表
  70. */
  71. getList: function () {
  72. let that = this;
  73. let token = wx.getStorageSync('token');
  74. let community = wx.getStorageSync('community');
  75. let head_id = community.communityId || 0;
  76. app.util.request({
  77. url: 'entry/wxapp/index',
  78. data: {
  79. controller: 'presalegoods.load_goods_list',
  80. pageNum: this.pageNum,
  81. token,
  82. head_id,
  83. pre_page: 10
  84. },
  85. dataType: 'json',
  86. success: function (res) {
  87. wx.hideLoading();
  88. wx.stopPullDownRefresh();
  89. if (res.data.code == 0) {
  90. let oldRushList = that.data.rushList;
  91. if (that.pageNum == 1) oldRushList = [];
  92. let h = {}, list = res.data.list;
  93. if (that.pageNum == 1 && list.length == 0) h.showEmpty = true;
  94. let rushList = oldRushList.concat(list);
  95. let rdata = res.data;
  96. let reduction = { full_money: rdata.full_money, full_reducemoney: rdata.full_reducemoney, is_open_fullreduction: rdata.is_open_fullreduction }
  97. h.rushList = rushList;
  98. h.reduction = reduction;
  99. h.loadOver = true;
  100. let loadMore = that.data.loadMore;
  101. if(res.data.list.length<10) { loadMore = false }
  102. h.loadMore = loadMore;
  103. h.loadText = loadMore ? "加载中..." : "没有更多商品了~";
  104. // h.pintuan_show_type = rdata.pintuan_show_type;
  105. that.setData(h, function () {
  106. that.pageNum += 1;
  107. })
  108. } else if (res.data.code == 1) {
  109. let s = { loadMore: false }
  110. if (that.pageNum == 1) s.showEmpty = true;
  111. that.setData(s);
  112. } else if (res.data.code == 2) {
  113. //no login
  114. that.setData({ needAuth: true })
  115. }
  116. }
  117. })
  118. },
  119. /**
  120. * 幻灯片跳转
  121. */
  122. goBannerUrl: function (t) {
  123. let idx = t.currentTarget.dataset.idx;
  124. let { slider_list, needAuth } = this.data;
  125. if (slider_list.length > 0) {
  126. let url = slider_list[idx].link;
  127. let type = slider_list[idx].linktype;
  128. if (util.checkRedirectTo(url, needAuth)) {
  129. this.authModal();
  130. return;
  131. }
  132. if (type == 0) {
  133. // 跳转webview
  134. url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) })
  135. } else if (type == 1) {
  136. if (url.indexOf('lionfish_comshop/pages/index/index') != -1 || url.indexOf('lionfish_comshop/pages/order/shopCart') != -1 || url.indexOf('lionfish_comshop/pages/user/me') != -1 || url.indexOf('lionfish_comshop/pages/type/index') != -1) {
  137. url && wx.switchTab({ url: url })
  138. } else {
  139. url && wx.navigateTo({ url: url })
  140. }
  141. } else if (type == 2) {
  142. // 跳转小程序
  143. let appid = slider_list[idx].appid;
  144. appid && wx.navigateToMiniProgram({
  145. appId: slider_list[idx].appid,
  146. path: url,
  147. extraData: {},
  148. envVersion: 'release',
  149. success(res) {
  150. // 打开成功
  151. },
  152. fail(error) {
  153. console.log(error)
  154. }
  155. })
  156. } else if (type == 6) {
  157. //领券
  158. wx.navigateTo({
  159. url: '/lionfish_comshop/moduleA/coupon/getCoupon?id='+url
  160. })
  161. }
  162. }
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. this.getData();
  169. let that = this;
  170. this.pageNum = 1;
  171. this.setData({
  172. loadMore: true,
  173. loadText: "加载中...",
  174. loadOver: false,
  175. showEmpty: false,
  176. rushList: []
  177. }, () => {
  178. that.getList();
  179. })
  180. },
  181. /**
  182. * 页面上拉触底事件的处理函数
  183. */
  184. onReachBottom: function () {
  185. console.log('这是我的底线');
  186. this.data.loadMore && (this.setData({ loadOver: false }), this.getList());
  187. },
  188. /**
  189. * 用户点击右上角分享
  190. */
  191. onShareAppMessage: function () {
  192. var member_id = wx.getStorageSync('member_id');
  193. let { share_title, share_img } = this.data;
  194. return {
  195. title: share_title,
  196. path: "lionfish_comshop/moduleB/presale/index?share_id=" + member_id,
  197. imageUrl: share_img,
  198. success: function () { },
  199. fail: function () { }
  200. };
  201. }
  202. })