Commit cff760d3dc64fb85a5146005f9b523dc36592a84

Authored by 前端研发-钱巧玲
1 parent 23d99549

首页礼包信息判断

Showing 1 changed file with 226 additions and 161 deletions
pages/index/index/index.js
1 1 var e = function (e) {
2   - return e && e.__esModule ? e : {
3   - default: e
4   - };
5   - }(require("../../../utils/LoadMore.js")), t = getApp(), a = t.request, o = t.globalData.setting, os = o,
  2 + return e && e.__esModule ? e : {
  3 + default: e
  4 + };
  5 +}(require("../../../utils/LoadMore.js")), t = getApp(), a = t.request, o = t.globalData.setting, os = o,
6 6 i = require("../../../utils/util.js"), ut = i, s = require("../../../utils/common.js"), n = new e.default();
7 7 var regeneratorRuntime = require('../../../utils/runtime.js');
8 8 var api = require('../../../api/api.js');
9   -
  9 +var d = getApp().globalData;
  10 +
10 11 Page({
11 12 data: {
12 13 url: o.imghost,
13   - swiperimage: ["/miniapp/images/title.png","/miniapp/images/newpeople/newpeople.png"],
  14 + swiperimage: ["/miniapp/images/title.png"],//,"/miniapp/images/newpeople/newpeople.png"
14 15 resourceUrl: o.resourceUrl,
15 16 logo: o.appLogo,
16 17 homeData: null,
... ... @@ -33,30 +34,30 @@ Page({
33 34 appdata: null,
34 35 saleGoods: null,//秒杀数据
35 36 pindGoods: null,//拼单数据
36   - newGoods:null,//新商品
37   - hotGoods:null,//hot商品
  37 + newGoods: null,//新商品
  38 + hotGoods: null,//hot商品
38 39 //----控制是是否显示计时器---
39   - is_timer:1,
40   - ishow:0,
  40 + is_timer: 1,
  41 + ishow: 0,
41 42 //是不是显示自定义模板
42   - isTemplate:0,
43   - template_arr:null,
44   - bgcolor_t:'',
45   -
46   - banner_index:0,
47   - flash_index:0,
48   - pt_index:0,
49   -
50   - pt_timer_item:null,
51   - pt_timer_arr:null,
52   - pt_timer:null,
53   - pt_timer_active:0,
  43 + isTemplate: 0,
  44 + template_arr: null,
  45 + bgcolor_t: '',
  46 +
  47 + banner_index: 0,
  48 + flash_index: 0,
  49 + pt_index: 0,
  50 +
  51 + pt_timer_item: null,
  52 + pt_timer_arr: null,
  53 + pt_timer: null,
  54 + pt_timer_active: 0,
54 55 //看下商家是否开通会员权益
55   - is_boot:0,
56   - gd_category:null,
57   - is_no_more:0,
58   - max_sw_height:0, //banner的最大高度
59   - is_disgraceful:1,//是否显示新人广告
  56 + is_boot: 0,
  57 + gd_category: null,
  58 + is_no_more: 0,
  59 + max_sw_height: 0, //banner的最大高度
  60 + is_disgraceful: 0,//是否显示新人广告
60 61 },
61 62  
62 63 onLoad: function () {
... ... @@ -73,18 +74,19 @@ Page({
73 74 th.setData({ is_boot: is_init });
74 75 }
75 76 })
  77 + th.is_new();
76 78  
77 79 },
78 80 //关闭新用户领取广告
79   - close_disgraceful:function(){
  81 + close_disgraceful: function () {
80 82 var th = this;
81   - th.setData({
82   - is_disgraceful:0
83   - })
  83 + th.setData({
  84 + is_disgraceful: 0
  85 + })
84 86 },
85 87 async onShow() {
86 88 var th = this;
87   - if(getApp().globalData.user_id) getApp().requestCardNum();
  89 + if (getApp().globalData.user_id) getApp().requestCardNum();
88 90 await this.init_load();
89 91 //显示的时候要开启计时器
90 92 this.data.is_timer = 1;
... ... @@ -107,7 +109,7 @@ Page({
107 109 if (th.data.pt_timer_arr && th.data.pt_timer_arr.length > 0) {
108 110 for (var i in th.data.pt_timer_arr) {
109 111 var p_item = th.data.pt_timer_arr[i];
110   - await getApp().request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + p_item.user_id, {1: 1}).then(res => {
  112 + await getApp().request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + p_item.user_id, { 1: 1 }).then(res => {
111 113 th.data.pt_timer_arr[i].head_pic = res.data.data.head_pic;
112 114 th.data.pt_timer_arr[i].nickname = res.data.data.nickname;
113 115 })
... ... @@ -117,51 +119,51 @@ Page({
117 119  
118 120 //---处理正在6个分类----
119 121 await getApp().request.promiseGet("/api/weshop/goodscategory/page", {
120   - data: {store_id: os.stoid, pageSize: 5,is_show:1}
  122 + data: { store_id: os.stoid, pageSize: 5, is_show: 1 }
121 123 }).then(res => {
122   - if(res.data.data) {
123   - var gd_category = res.data.data.pageData;
124   -
125   - th.setData({gd_category: gd_category});
  124 + if (res.data.data) {
  125 + var gd_category = res.data.data.pageData;
  126 +
  127 + th.setData({ gd_category: gd_category });
126 128 }
127 129 })
128 130 },
129   -
  131 +
130 132 //当隐藏的时候就关闭计时器
131   - onHide:function(){
132   - this.data.is_timer=0;
  133 + onHide: function () {
  134 + this.data.is_timer = 0;
133 135 clearInterval(this.data.pt_timer)
134 136 },
135 137  
136 138 //同步初始加载
137   - async init_load(){
138   - var th=this;
139   - await getApp().get_isbuy();
140   - this.setappdata(getApp().globalData.wxapp_buy_obj);
141   - await getApp().getConfig_ays();
142   -
143   - //因为营销版本的功能包含了自定义模板的功能,是同时的
144   - //读取全局是否有弄自定义模板
145   - await api.get_template_fir(o.stoid).then(res=>{
146   - var data=res.data.data;
147   - if(data.length>0){
148   - var temp_data=data[0];
149   - var t_arr=JSON.parse(temp_data.json_str);
150   - th.setData({ template_arr: t_arr, isTemplate: 1, bgcolor_t: temp_data.bkcolor});
151   - }
152   - })
153   -
154   -
155   - //--首页的问题--
156   - if(getApp().globalData.config && getApp().globalData.config.store_name!=undefined && getApp().globalData.config.store_name!=null ){
157   - wx.setNavigationBarTitle({
158   - title: getApp().globalData.config.store_name,
159   - });
160   - }else{
161   - wx.setNavigationBarTitle({
162   - title: getApp().globalData.setting.appName,
163   - });
  139 + async init_load() {
  140 + var th = this;
  141 + await getApp().get_isbuy();
  142 + this.setappdata(getApp().globalData.wxapp_buy_obj);
  143 + await getApp().getConfig_ays();
  144 +
  145 + //因为营销版本的功能包含了自定义模板的功能,是同时的
  146 + //读取全局是否有弄自定义模板
  147 + await api.get_template_fir(o.stoid).then(res => {
  148 + var data = res.data.data;
  149 + if (data.length > 0) {
  150 + var temp_data = data[0];
  151 + var t_arr = JSON.parse(temp_data.json_str);
  152 + th.setData({ template_arr: t_arr, isTemplate: 1, bgcolor_t: temp_data.bkcolor });
164 153 }
  154 + })
  155 +
  156 +
  157 + //--首页的问题--
  158 + if (getApp().globalData.config && getApp().globalData.config.store_name != undefined && getApp().globalData.config.store_name != null) {
  159 + wx.setNavigationBarTitle({
  160 + title: getApp().globalData.config.store_name,
  161 + });
  162 + } else {
  163 + wx.setNavigationBarTitle({
  164 + title: getApp().globalData.setting.appName,
  165 + });
  166 + }
165 167 },
166 168  
167 169 //---读取数据内容---
... ... @@ -170,16 +172,16 @@ Page({
170 172 //----广告----
171 173 var e = this;
172 174 await getApp().request.promiseGet("/api/weshop/ad/list?pid=2&store_id=" + o.stoid, {
173   - data:{enabled:1}
174   - }).then(res=>{
  175 + data: { enabled: 1 }
  176 + }).then(res => {
175 177 var a = res.data.data;
176 178 var arr = new Array();
177 179 for (var i = 0; i < a.length; i++) {
178 180 var tt = { 'ad_code': o.imghost + a[i].ad_code, 'media_link': '' };
179 181 arr.push(tt);
180 182 }
181   - if (arr.length>0) e.setData({ banner: arr, });
182   -
  183 + if (arr.length > 0) e.setData({ banner: arr, });
  184 +
183 185 wx.stopPullDownRefresh();
184 186 })
185 187  
... ... @@ -200,20 +202,20 @@ Page({
200 202 flash_data = e.data.data.pageData;
201 203 if (flash_data == null || flash_data.length <= 0) return false;
202 204  
203   -
  205 +
204 206 //当前时间戳
205 207 var nt = ut.gettimestamp();
206 208  
207   - flash_data.forEach(function (val,ind) {
208   - if(val.start_time>nt) flash_data[ind].status=0;
209   - else if(val.end_time>nt) flash_data[ind].status=1;
210   - if(val.buy_num>=val.goods_num) flash_data[ind].status=2;
  209 + flash_data.forEach(function (val, ind) {
  210 + if (val.start_time > nt) flash_data[ind].status = 0;
  211 + else if (val.end_time > nt) flash_data[ind].status = 1;
  212 + if (val.buy_num >= val.goods_num) flash_data[ind].status = 2;
211 213 });
212 214  
213 215 var arr = new Array();
214 216 //--三个三个一组---
215   - for(var i=0;i< flash_data.length;i+=3){
216   - arr.push(flash_data.slice(i,i+3));
  217 + for (var i = 0; i < flash_data.length; i += 3) {
  218 + arr.push(flash_data.slice(i, i + 3));
217 219 }
218 220 th.setData({
219 221 saleGoods: arr
... ... @@ -234,35 +236,35 @@ Page({
234 236 var e = res;
235 237 if (e.data.code == 0) {
236 238 var pd_data = e.data.data.pageData;
237   -
  239 +
238 240 if (pd_data.length == 0) return;
239   -
  241 +
240 242 //获取当前
241 243 var nt = ut.gettimestamp();
242   - pd_data.forEach(function (val,ind) {
243   - if(val.start_time>nt) pd_data[ind].status=0;
244   - else if(val.end_time>nt) pd_data[ind].status=1;
245   - if(val.buy_num>=val.goods_num) pd_data[ind].status=2;
  244 + pd_data.forEach(function (val, ind) {
  245 + if (val.start_time > nt) pd_data[ind].status = 0;
  246 + else if (val.end_time > nt) pd_data[ind].status = 1;
  247 + if (val.buy_num >= val.goods_num) pd_data[ind].status = 2;
246 248 });
247   -
248   - //获取当前时间,比较拼团中还在未开始
  249 +
  250 + //获取当前时间,比较拼团中还在未开始
249 251 var timestamp = new Date().getTime();
250 252 var is_team_tepy;
251   - for (var j = 0; j < pd_data.length;j++ ){
  253 + for (var j = 0; j < pd_data.length; j++) {
252 254 pd_data[j].is_team_tepy = 1;
253   - if (timestamp<pd_data[j].start_time*1000){
  255 + if (timestamp < pd_data[j].start_time * 1000) {
254 256 var is_team_tepy;
255 257 pd_data[j].is_team_tepy = 0;
256   - }
  258 + }
257 259 }
258   -
  260 +
259 261 var arr = new Array();
260 262 //--2个2个一组---
261   - for(var i=0;i< pd_data.length;i+=2){
262   -
263   - arr.push(pd_data.slice(i,i+2));
  263 + for (var i = 0; i < pd_data.length; i += 2) {
  264 +
  265 + arr.push(pd_data.slice(i, i + 2));
264 266 }
265   -
  267 +
266 268 th.setData({
267 269 pindGoods: arr
268 270 });
... ... @@ -273,7 +275,7 @@ Page({
273 275 //------新品-------
274 276 await getApp().request.promiseGet("/api/weshop/goods/page?page=1", {
275 277 data: {
276   - is_mainshow: 1, isonsale: 1, is_on_sale: 1, store_id: o.stoid, pageSize: 9,is_new:1,orderField:"sort"
  278 + is_mainshow: 1, isonsale: 1, is_on_sale: 1, store_id: o.stoid, pageSize: 9, is_new: 1, orderField: "sort"
277 279 }
278 280 }).then(res => {
279 281 var e = res;
... ... @@ -281,8 +283,8 @@ Page({
281 283 var new_data = e.data.data.pageData;
282 284 var arr = new Array();
283 285 //--三个三个一组---
284   - for(var i=0;i< new_data.length;i+=3){
285   - arr.push(new_data.slice(i,i+3));
  286 + for (var i = 0; i < new_data.length; i += 3) {
  287 + arr.push(new_data.slice(i, i + 3));
286 288 }
287 289 th.setData({
288 290 newGoods: arr,
... ... @@ -293,7 +295,7 @@ Page({
293 295 //------热卖-------
294 296 await getApp().request.promiseGet("/api/weshop/goods/page?page=1", {
295 297 data: {
296   - is_mainshow: 1, isonsale: 1, is_on_sale: 1, store_id: o.stoid, pageSize: 9,is_hot:1,orderField:"sort"
  298 + is_mainshow: 1, isonsale: 1, is_on_sale: 1, store_id: o.stoid, pageSize: 9, is_hot: 1, orderField: "sort"
297 299 }
298 300 }).then(res => {
299 301 var e = res;
... ... @@ -301,8 +303,8 @@ Page({
301 303 var new_data = e.data.data.pageData;
302 304 var arr = new Array();
303 305 //--三个三个一组---
304   - for(var i=0;i< new_data.length;i+=3){
305   - arr.push(new_data.slice(i,i+3));
  306 + for (var i = 0; i < new_data.length; i += 3) {
  307 + arr.push(new_data.slice(i, i + 3));
306 308 }
307 309 th.setData({
308 310 hotGoods: arr,
... ... @@ -311,14 +313,14 @@ Page({
311 313 })
312 314 //---调用信息---
313 315 // this.requestRecommend();
314   - this.setData({ishow:1});
  316 + this.setData({ ishow: 1 });
315 317 //---先获取会员---
316 318 t.getUserFir(function () {
317 319  
318 320 });
319 321 var goods_list = this.selectComponent("#goods_list"); //组件的id
320 322 goods_list.init();
321   - setTimeout(function () { goods_list.get_list();},300)
  323 + setTimeout(function () { goods_list.get_list(); }, 300)
322 324 },
323 325  
324 326 //--判断小程序是否过期--
... ... @@ -335,7 +337,7 @@ Page({
335 337 //---加载更多是靠这个函数----
336 338 onReachBottom: function () {
337 339 var goods_list = this.selectComponent("#goods_list"); //组件的id
338   - if(goods_list) goods_list.get_list();
  340 + if (goods_list) goods_list.get_list();
339 341 },
340 342  
341 343  
... ... @@ -395,7 +397,7 @@ Page({
395 397 bind_bnerr: function (e) {
396 398 var _errImg = e.target.dataset.errorimg;
397 399 var _errObj = {};
398   - _errObj[_errImg] = this.data.url+ "/miniapp/images/del/logo.jpg";
  400 + _errObj[_errImg] = this.data.url + "/miniapp/images/del/logo.jpg";
399 401 this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
400 402 },
401 403  
... ... @@ -403,12 +405,12 @@ Page({
403 405 bind_bnerr2: function (e) {
404 406 var _errImg = e.target.dataset.errorimg;
405 407 var _errurl = e.target.dataset.url;
406   - var _errObj = {};
407   - _errObj[_errImg] = "/miniapp/images/default_g_img.gif";
408   - this.setData(_errObj); //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
409   -
  408 + var _errObj = {};
  409 + _errObj[_errImg] = "/miniapp/images/default_g_img.gif";
  410 + this.setData(_errObj); //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
  411 +
410 412 },
411   -//图片失败,默认图片
  413 + //图片失败,默认图片
412 414 bind_bnerr3: function (e) {
413 415 var _errImg = e.target.dataset.errorimg;
414 416 var _Img = e.target.dataset.img;
... ... @@ -428,7 +430,7 @@ Page({
428 430  
429 431 //----秒杀倒计时函数-----
430 432 countDown() {
431   - if(!this.data.is_timer) return false;
  433 + if (!this.data.is_timer) return false;
432 434 var th = this;
433 435 // 获取当前时间,同时得到活动结束时间数组
434 436 var newTime = ut.gettimestamp();
... ... @@ -477,9 +479,7 @@ Page({
477 479  
478 480 //----拼单倒计时函数-----
479 481 countDown2() {
480   - if(!this.data.is_timer) return false;
481   -
482   -
  482 + if (!this.data.is_timer) return false;
483 483  
484 484 var th = this;
485 485 // 获取当前时间,同时得到活动结束时间数组
... ... @@ -529,28 +529,28 @@ Page({
529 529 setTimeout(th.countDown2, 1000);
530 530 },
531 531  
532   - bannerSwiperChange:function (e) {
533   - var index=e.detail.current;
534   - this.setData({banner_index:index});
  532 + bannerSwiperChange: function (e) {
  533 + var index = e.detail.current;
  534 + this.setData({ banner_index: index });
535 535 },
536   - flashSwiperChange:function (e) {
537   - var index=e.detail.current;
538   - this.setData({flash_index:index});
  536 + flashSwiperChange: function (e) {
  537 + var index = e.detail.current;
  538 + this.setData({ flash_index: index });
539 539 },
540   - ptSwiperChange:function (e) {
541   - var index=e.detail.current;
542   - this.setData({pt_index:index});
  540 + ptSwiperChange: function (e) {
  541 + var index = e.detail.current;
  542 + this.setData({ pt_index: index });
543 543 },
544 544  
545 545 Interval_pt() {
546   - var th=this;
547   - this.data.pt_timer=setInterval(function () {
548   - var item=ut.get_rand_item(th.data.pt_timer_arr);
549   - th.setData({pt_timer_active:1,pt_timer_item:item});
550   - setTimeout(function () {
551   - th.setData({pt_timer_active:0});
552   - },1500)
553   - },4000);
  546 + var th = this;
  547 + this.data.pt_timer = setInterval(function () {
  548 + var item = ut.get_rand_item(th.data.pt_timer_arr);
  549 + th.setData({ pt_timer_active: 1, pt_timer_item: item });
  550 + setTimeout(function () {
  551 + th.setData({ pt_timer_active: 0 });
  552 + }, 1500)
  553 + }, 4000);
554 554 },
555 555  
556 556  
... ... @@ -560,29 +560,29 @@ Page({
560 560 // 允许从相机和相册扫码
561 561 wx.scanCode({
562 562 success: (res) => {
563   - var result = res.result;
564   - wx.navigateTo({
565   - url: "/pages/goods/search/search?s_key="+result,
566   - });
  563 + var result = res.result;
  564 + wx.navigateTo({
  565 + url: "/pages/goods/search/search?s_key=" + result,
  566 + });
567 567 }
568 568 })
569 569 },
570 570  
571 571 //跳转到分类
572   - go_cate:function(){
  572 + go_cate: function () {
573 573 getApp().goto("/pages/goods/categoryList/categoryList");
574 574 },
575 575  
576   - go_url:function(e){
577   - var url=e.currentTarget.dataset.url;
578   - getApp().goto(url);
  576 + go_url: function (e) {
  577 + var url = e.currentTarget.dataset.url;
  578 + getApp().goto(url);
579 579 },
580 580  
581   - bind_bnerr_icon:function (e) {
  581 + bind_bnerr_icon: function (e) {
582 582 var def = "/miniapp/images/no_cate_def.png";
583 583 var _err = e.currentTarget.dataset.err;
584   - var ob={};
585   - ob[_err]=def;
  584 + var ob = {};
  585 + ob[_err] = def;
586 586 this.setData(ob);
587 587 },
588 588  
... ... @@ -594,24 +594,89 @@ Page({
594 594 wx.navigateTo({ url: lurl });
595 595 },
596 596  
597   - //跳转到权益
598   - go_quanyi:function(t){
599   - var user_info = getApp().globalData.userInfo;
600   - if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
601   - wx.navigateTo({ url: '/pages/getphone/getphone', })
602   - return false;
603   - }
604   - getApp().goto("/pages/user/userqy/userqy");
605   - },
606   -
607   - imageLoad:function (e) {
608   - var imgwidth = e.detail.width;
609   - var imgheight = e.detail.height;
610   - //宽高比
611   - var ratio = imgwidth / imgheight;
612   - //计算的高度值
613   - var viewHeight = 715 / ratio;
614   - if(this.data.max_sw_height<viewHeight) this.setData({ max_sw_height:viewHeight });
615   - }
  597 + //跳转到权益
  598 + go_quanyi: function (t) {
  599 + var user_info = getApp().globalData.userInfo;
  600 + if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
  601 + wx.navigateTo({ url: '/pages/getphone/getphone', })
  602 + return false;
  603 + }
  604 + getApp().goto("/pages/user/userqy/userqy");
  605 + },
  606 +
  607 + imageLoad: function (e) {
  608 + var imgwidth = e.detail.width;
  609 + var imgheight = e.detail.height;
  610 + //宽高比
  611 + var ratio = imgwidth / imgheight;
  612 + //计算的高度值
  613 + var viewHeight = 715 / ratio;
  614 + if (this.data.max_sw_height < viewHeight) this.setData({ max_sw_height: viewHeight });
  615 + },
  616 + //判断该用户是否是新会员
  617 + is_new: function () {
  618 + var th = this;
  619 + var user_id = 56820683;//d.user_id;//用户id
  620 + getApp().request.promiseGet("/api/weshop/marketing/newpeople/act/bound/judge", {
  621 + data: {
  622 + storeId: o.stoid,
  623 + userId: user_id
  624 + }
  625 + }).then(res => {
  626 + var data = res.data.data;
  627 + if (res.data.code == 0) {
  628 + th.setData({
  629 + is_disgraceful:1
  630 + })
  631 + //礼包信息接口
  632 + getApp().request.promiseGet("/api/weshop/marketing/giftbag/bound/get",{
  633 + data:{
  634 + actId:data.id,
  635 + actType:1,
  636 + giftBagId: data.giftBagId,
  637 + storeId:o.stoid,
  638 + userId: user_id
  639 + }
  640 + }).then(res=>{
  641 + var data = res.data.data;
  642 + if(res.data.code==0){
  643 +
  644 + }
  645 + })
  646 + }
  647 + })
  648 +
  649 + getApp().request.promiseGet("/api/weshop/marketing/newpeople/act/judge", {
  650 + data: {
  651 + storeId: o.stoid,
  652 + userId: user_id
  653 + }
  654 + }).then(res => {
  655 + var data = res.data.data;
  656 + var swiperimage = th.data.swiperimage;
  657 + swiperimage.push("/miniapp/images/newpeople/newpeople.png");
  658 + if (res.data.code == 0) {
  659 + th.setData({
  660 + swiperimage: swiperimage
  661 + })
  662 + //礼包信息接口
  663 + getApp().request.promiseGet("/api/weshop/marketing/giftbag/bound/get", {
  664 + data: {
  665 + actId: data.id,
  666 + actType: 1,
  667 + giftBagId: data.giftBagId,
  668 + storeId: o.stoid,
  669 + userId: user_id
  670 + }
  671 + }).then(res => {
  672 + var data = res.data.data;
  673 + if (res.data.code == 0) {
  674 +
  675 + }
  676 + })
  677 + }
  678 + })
  679 +
  680 + }
616 681  
617 682 });
618 683 \ No newline at end of file
... ...