index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. var util = require('../../utils/util.js');
  2. var status = require('../../utils/index.js');
  3. var app = getApp();
  4. Page({
  5. mixins: [require('../../mixin/globalMixin.js')],
  6. data: {
  7. classification: {
  8. tabs: [],
  9. activeIndex: 0
  10. },
  11. slider_list: [],
  12. pintuan_show_type: 0,
  13. loadMore: true,
  14. loadText: "加载中...",
  15. loadOver: false,
  16. showEmpty: false,
  17. rushList: [],
  18. isIpx: app.globalData.isIpx
  19. },
  20. pageNum: 1,
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. app.setShareConfig();
  26. status.setNavBgColor();
  27. this.initFn();
  28. },
  29. initFn: function(){
  30. wx.showLoading();
  31. this.getTabs();
  32. this.getData();
  33. },
  34. authSuccess: function () {
  35. let that = this;
  36. this.pageNum = 1;
  37. this.setData({
  38. classification: {
  39. tabs: [],
  40. activeIndex: 0
  41. },
  42. slider_list: [],
  43. pintuan_show_type: 0,
  44. loadMore: true,
  45. loadText: "加载中...",
  46. loadOver: false,
  47. showEmpty: false,
  48. rushList: []
  49. }, () => {
  50. that.initFn();
  51. })
  52. },
  53. authModal: function () {
  54. if (this.data.needAuth) {
  55. this.setData({ showAuthModal: !this.data.showAuthModal });
  56. return false;
  57. }
  58. return true;
  59. },
  60. /**
  61. * 获取分类
  62. */
  63. getTabs: function () {
  64. let that = this;
  65. app.util.request({
  66. url: 'entry/wxapp/index',
  67. data: {
  68. controller: 'group.pintuan_slides'
  69. },
  70. dataType: 'json',
  71. success: function (res) {
  72. if(res.data.code==0) {
  73. let {
  74. category_list,
  75. pintuan_show_type,
  76. slider_list,
  77. pintuan_index_share_title,
  78. pintuan_index_share_img
  79. } = res.data;
  80. let params = {
  81. classification: {}
  82. };
  83. params.slider_list = slider_list || [];
  84. params.pintuan_show_type = pintuan_show_type;
  85. params.pintuan_index_share_title = pintuan_index_share_title || '';
  86. params.pintuan_index_share_img = pintuan_index_share_img || '';
  87. category_list = category_list || [];
  88. let index_type_first_name = '推荐';
  89. if (category_list.length > 0) {
  90. category_list.unshift({
  91. name: index_type_first_name,
  92. id: 0
  93. })
  94. params.isShowClassification = true;
  95. params.classification.tabs = category_list;
  96. } else {
  97. params.isShowClassification = false;
  98. }
  99. that.setData(params)
  100. }
  101. }
  102. })
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow: function () {
  108. let that = this;
  109. (0, status.cartNum)('', true).then((res) => {
  110. res.code == 0 && that.setData({
  111. cartNum: res.data
  112. })
  113. });
  114. },
  115. /**
  116. * 监控分类导航
  117. */
  118. classificationChange: function (t) {
  119. console.log(t.detail.e)
  120. wx.showLoading();
  121. var that = this;
  122. this.pageNum = 1;
  123. this.setData({
  124. rushList: [],
  125. showEmpty: false,
  126. "classification.activeIndex": t.detail.e,
  127. classificationId: t.detail.a
  128. }, function () {
  129. that.getData();
  130. });
  131. },
  132. /**
  133. * 获取商品列表
  134. */
  135. getData: function () {
  136. let that = this;
  137. let token = wx.getStorageSync('token');
  138. let gid = that.data.classificationId;
  139. let community = wx.getStorageSync('community');
  140. let head_id = community.communityId || 0;
  141. app.util.request({
  142. url: 'entry/wxapp/index',
  143. data: {
  144. controller: 'group.get_pintuan_list',
  145. pageNum: this.pageNum,
  146. gid,
  147. token,
  148. head_id,
  149. is_index: 1
  150. },
  151. dataType: 'json',
  152. success: function (res) {
  153. wx.hideLoading();
  154. wx.stopPullDownRefresh();
  155. if (res.data.code == 0) {
  156. let oldRushList = that.data.rushList;
  157. if (that.pageNum == 1) oldRushList = [];
  158. let h = {}, list = res.data.list;
  159. if (that.pageNum == 1 && list.length == 0) h.showEmpty = true;
  160. let rushList = oldRushList.concat(list);
  161. let rdata = res.data;
  162. let reduction = { full_money: rdata.full_money, full_reducemoney: rdata.full_reducemoney, is_open_fullreduction: rdata.is_open_fullreduction }
  163. let pintuan_model_buy = rdata.pintuan_model_buy || 0;
  164. h.rushList = rushList;
  165. h.reduction = reduction;
  166. h.loadOver = true;
  167. let loadMore = that.data.loadMore;
  168. if(res.data.list.length<20) { loadMore = false }
  169. h.loadMore = loadMore;
  170. h.loadText = loadMore ? "加载中..." : "没有更多商品了~";
  171. h.pintuan_model_buy = pintuan_model_buy;
  172. h.pintuan_show_type = rdata.pintuan_show_type;
  173. if (pintuan_model_buy == 1) h.needPosition=true,(!head_id&&that.needCommunity());
  174. that.setData(h, function () {
  175. that.pageNum += 1;
  176. })
  177. } else if (res.data.code == 1) {
  178. let s = { loadMore: false }
  179. if (that.pageNum == 1) s.showEmpty = true;
  180. that.setData(s);
  181. } else if (res.data.code == 2) {
  182. //no login
  183. that.setData({ needAuth: true })
  184. }
  185. }
  186. })
  187. },
  188. /**
  189. * 需要社区
  190. * 判断是否已绑定
  191. */
  192. needCommunity: function(){
  193. let token = wx.getStorageSync('token');
  194. let that = this;
  195. console.log('需要社区')
  196. if (token) {
  197. util.getCommunityInfo().then(res=>{
  198. if(res) {
  199. that.pageNum = 1;
  200. that.setData({
  201. loadMore: true,
  202. loadText: "加载中...",
  203. loadOver: false,
  204. showEmpty: false,
  205. rushList: []
  206. }, () => {
  207. that.getData();
  208. })
  209. }
  210. })
  211. }
  212. },
  213. /**
  214. * 幻灯片跳转
  215. */
  216. goBannerUrl: function (t) {
  217. let idx = t.currentTarget.dataset.idx;
  218. let { slider_list, needAuth } = this.data;
  219. if (slider_list.length > 0) {
  220. let url = slider_list[idx].link;
  221. let type = slider_list[idx].linktype;
  222. if (util.checkRedirectTo(url, needAuth)) {
  223. this.authModal();
  224. return;
  225. }
  226. if (type == 0) {
  227. // 跳转webview
  228. url && wx.navigateTo({ url: '/lionfish_comshop/pages/web-view?url=' + encodeURIComponent(url) })
  229. } else if (type == 1) {
  230. 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) {
  231. url && wx.switchTab({ url: url })
  232. } else {
  233. url && wx.navigateTo({ url: url })
  234. }
  235. } else if (type == 2) {
  236. // 跳转小程序
  237. let appid = slider_list[idx].appid;
  238. appid && wx.navigateToMiniProgram({
  239. appId: slider_list[idx].appid,
  240. path: url,
  241. extraData: {},
  242. envVersion: 'release',
  243. success(res) {
  244. // 打开成功
  245. },
  246. fail(error) {
  247. console.log(error)
  248. }
  249. })
  250. }
  251. }
  252. },
  253. /**
  254. * 页面相关事件处理函数--监听用户下拉动作
  255. */
  256. onPullDownRefresh: function () {
  257. let that = this;
  258. this.pageNum = 1;
  259. this.setData({
  260. loadMore: true,
  261. loadText: "加载中...",
  262. loadOver: false,
  263. showEmpty: false,
  264. rushList: []
  265. }, () => {
  266. that.getData();
  267. })
  268. },
  269. /**
  270. * 页面上拉触底事件的处理函数
  271. */
  272. onReachBottom: function () {
  273. console.log('这是我的底线');
  274. this.data.loadMore && (this.setData({ loadOver: false }), this.getData());
  275. },
  276. /**
  277. * 用户点击右上角分享
  278. */
  279. onShareAppMessage: function () {
  280. var member_id = wx.getStorageSync('member_id');
  281. let { pintuan_index_share_title, pintuan_index_share_img } = this.data;
  282. return {
  283. title: pintuan_index_share_title,
  284. path: "lionfish_comshop/moduleA/pin/index?share_id=" + member_id,
  285. imageUrl: pintuan_index_share_img,
  286. success: function () { },
  287. fail: function () { }
  288. };
  289. },
  290. onShareTimeline: function() {
  291. var member_id = wx.getStorageSync('member_id');
  292. let { pintuan_index_share_title, pintuan_index_share_img } = this.data;
  293. var query= `share_id=${member_id}`;
  294. return {
  295. title: pintuan_index_share_title,
  296. imageUrl: pintuan_index_share_img,
  297. query,
  298. success: function() {},
  299. fail: function() {}
  300. };
  301. }
  302. })