diff --git a/pages/index/index/index.js b/pages/index/index/index.js index ddf3450..bf7f321 100644 --- a/pages/index/index/index.js +++ b/pages/index/index/index.js @@ -1,17 +1,24 @@ -var e = function (e) { +var e = function(e) { return e && e.__esModule ? e : { - default: e + default: e }; - }(require("../../../utils/LoadMore.js")), t = getApp(), a = t.request, o = t.globalData.setting, os = o, - i = require("../../../utils/util.js"), ut = i, s = require("../../../utils/common.js"), n = new e.default(); + }(require("../../../utils/LoadMore.js")), + t = getApp(), + a = t.request, + o = t.globalData.setting, + os = o, + i = require("../../../utils/util.js"), + ut = i, + s = require("../../../utils/common.js"), + n = new e.default(); var regeneratorRuntime = require('../../../utils/runtime.js'); var api = require('../../../api/api.js'); var d = getApp().globalData; - + Page({ data: { url: o.imghost, - swiperimage: ["/miniapp/images/title.png"],//,"/miniapp/images/newpeople/newpeople.png" + swiperimage: ["/miniapp/images/title.png"], //,"/miniapp/images/newpeople/newpeople.png" resourceUrl: o.resourceUrl, logo: o.appLogo, homeData: null, @@ -32,69 +39,74 @@ Page({ banner: null, appdata: null, - saleGoods: null,//秒杀数据 - pindGoods: null,//拼单数据 - newGoods:null,//新商品 - hotGoods:null,//hot商品 + saleGoods: null, //秒杀数据 + pindGoods: null, //拼单数据 + newGoods: null, //新商品 + hotGoods: null, //hot商品 //----控制是是否显示计时器--- - is_timer:1, - ishow:0, + is_timer: 1, + ishow: 0, //是不是显示自定义模板 - isTemplate:0, - template_arr:null, - bgcolor_t:'', - - banner_index:0, - flash_index:0, - pt_index:0, - - pt_timer_item:null, - pt_timer_arr:null, - pt_timer:null, - pt_timer_active:0, + isTemplate: 0, + template_arr: null, + bgcolor_t: '', + + banner_index: 0, + flash_index: 0, + pt_index: 0, + + pt_timer_item: null, + pt_timer_arr: null, + pt_timer: null, + pt_timer_active: 0, //看下商家是否开通会员权益 - is_boot:0, - gd_category:null, - is_no_more:0, - max_sw_height:0, //banner的最大高度 - is_disgraceful:0,//是否显示新人广告 + is_boot: 0, + gd_category: null, + is_no_more: 0, + max_sw_height: 0, //banner的最大高度 + is_disgraceful: 0, //是否显示新人广告 + new_image: "", //新人有礼弹窗图片 + new_nav: "/pages/giftpack/newvipgift/newvipgift", //新人页面跳转地址 }, - onLoad: function () { + onLoad: function() { var th = this; // n.init(th, "", "recommend"); //看一下商家是否开通了权益 //--初始化是否有打勾-- getApp().request.promiseGet("/api/weshop/users/grade/vip/init/get", { - data: { storeId: os.stoid } + data: { + storeId: os.stoid + } }).then(res => { if (res.data.data) { var is_init = res.data.data.isBool; - th.setData({ is_boot: is_init }); + th.setData({ + is_boot: is_init + }); } }) th.is_new(); }, //关闭新用户领取广告 - close_disgraceful:function(){ + close_disgraceful: function() { var th = this; - th.setData({ - is_disgraceful:0 - }) + th.setData({ + is_disgraceful: 0 + }) }, async onShow() { var th = this; - if(getApp().globalData.user_id) getApp().requestCardNum(); + if (getApp().globalData.user_id) getApp().requestCardNum(); await this.init_load(); //显示的时候要开启计时器 this.data.is_timer = 1; //如果是自定义模板 if (this.data.isTemplate) { //---先获取会员--- - t.getUserFir(function () { - }); + t.getUserFir(function() {}); } else { await this.init_fir(); } @@ -109,7 +121,9 @@ Page({ if (th.data.pt_timer_arr && th.data.pt_timer_arr.length > 0) { for (var i in th.data.pt_timer_arr) { var p_item = th.data.pt_timer_arr[i]; - await getApp().request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + p_item.user_id, {1: 1}).then(res => { + await getApp().request.promiseGet("/api/weshop/users/get/" + os.stoid + "/" + p_item.user_id, { + 1: 1 + }).then(res => { th.data.pt_timer_arr[i].head_pic = res.data.data.head_pic; th.data.pt_timer_arr[i].nickname = res.data.data.nickname; }) @@ -119,51 +133,61 @@ Page({ //---处理正在6个分类---- await getApp().request.promiseGet("/api/weshop/goodscategory/page", { - data: {store_id: os.stoid, pageSize: 5,is_show:1} + data: { + store_id: os.stoid, + pageSize: 5, + is_show: 1 + } }).then(res => { - if(res.data.data) { - var gd_category = res.data.data.pageData; - - th.setData({gd_category: gd_category}); + if (res.data.data) { + var gd_category = res.data.data.pageData; + + th.setData({ + gd_category: gd_category + }); } }) }, - + //当隐藏的时候就关闭计时器 - onHide:function(){ - this.data.is_timer=0; + onHide: function() { + this.data.is_timer = 0; clearInterval(this.data.pt_timer) }, //同步初始加载 - async init_load(){ - var th=this; - await getApp().get_isbuy(); - this.setappdata(getApp().globalData.wxapp_buy_obj); - await getApp().getConfig_ays(); - - //因为营销版本的功能包含了自定义模板的功能,是同时的 - //读取全局是否有弄自定义模板 - await api.get_template_fir(o.stoid).then(res=>{ - var data=res.data.data; - if(data.length>0){ - var temp_data=data[0]; - var t_arr=JSON.parse(temp_data.json_str); - th.setData({ template_arr: t_arr, isTemplate: 1, bgcolor_t: temp_data.bkcolor}); - } - }) - - - //--首页的问题-- - if(getApp().globalData.config && getApp().globalData.config.store_name!=undefined && getApp().globalData.config.store_name!=null ){ - wx.setNavigationBarTitle({ - title: getApp().globalData.config.store_name, - }); - }else{ - wx.setNavigationBarTitle({ - title: getApp().globalData.setting.appName, - }); + async init_load() { + var th = this; + await getApp().get_isbuy(); + this.setappdata(getApp().globalData.wxapp_buy_obj); + await getApp().getConfig_ays(); + + //因为营销版本的功能包含了自定义模板的功能,是同时的 + //读取全局是否有弄自定义模板 + await api.get_template_fir(o.stoid).then(res => { + var data = res.data.data; + if (data.length > 0) { + var temp_data = data[0]; + var t_arr = JSON.parse(temp_data.json_str); + th.setData({ + template_arr: t_arr, + isTemplate: 1, + bgcolor_t: temp_data.bkcolor + }); } + }) + + + //--首页的问题-- + if (getApp().globalData.config && getApp().globalData.config.store_name != undefined && getApp().globalData.config.store_name != null) { + wx.setNavigationBarTitle({ + title: getApp().globalData.config.store_name, + }); + } else { + wx.setNavigationBarTitle({ + title: getApp().globalData.setting.appName, + }); + } }, //---读取数据内容--- @@ -172,16 +196,23 @@ Page({ //----广告---- var e = this; await getApp().request.promiseGet("/api/weshop/ad/list?pid=2&store_id=" + o.stoid, { - data:{enabled:1} - }).then(res=>{ + data: { + enabled: 1 + } + }).then(res => { var a = res.data.data; var arr = new Array(); for (var i = 0; i < a.length; i++) { - var tt = { 'ad_code': o.imghost + a[i].ad_code, 'media_link': '' }; + var tt = { + 'ad_code': o.imghost + a[i].ad_code, + 'media_link': '' + }; arr.push(tt); } - if (arr.length>0) e.setData({ banner: arr, }); - + if (arr.length > 0) e.setData({ + banner: arr, + }); + wx.stopPullDownRefresh(); }) @@ -202,20 +233,20 @@ Page({ flash_data = e.data.data.pageData; if (flash_data == null || flash_data.length <= 0) return false; - + //当前时间戳 var nt = ut.gettimestamp(); - flash_data.forEach(function (val,ind) { - if(val.start_time>nt) flash_data[ind].status=0; - else if(val.end_time>nt) flash_data[ind].status=1; - if(val.buy_num>=val.goods_num) flash_data[ind].status=2; + flash_data.forEach(function(val, ind) { + if (val.start_time > nt) flash_data[ind].status = 0; + else if (val.end_time > nt) flash_data[ind].status = 1; + if (val.buy_num >= val.goods_num) flash_data[ind].status = 2; }); var arr = new Array(); //--三个三个一组--- - for(var i=0;i< flash_data.length;i+=3){ - arr.push(flash_data.slice(i,i+3)); + for (var i = 0; i < flash_data.length; i += 3) { + arr.push(flash_data.slice(i, i + 3)); } th.setData({ saleGoods: arr @@ -236,35 +267,35 @@ Page({ var e = res; if (e.data.code == 0) { var pd_data = e.data.data.pageData; - + if (pd_data.length == 0) return; - + //获取当前 var nt = ut.gettimestamp(); - pd_data.forEach(function (val,ind) { - if(val.start_time>nt) pd_data[ind].status=0; - else if(val.end_time>nt) pd_data[ind].status=1; - if(val.buy_num>=val.goods_num) pd_data[ind].status=2; + pd_data.forEach(function(val, ind) { + if (val.start_time > nt) pd_data[ind].status = 0; + else if (val.end_time > nt) pd_data[ind].status = 1; + if (val.buy_num >= val.goods_num) pd_data[ind].status = 2; }); - - //获取当前时间,比较拼团中还在未开始 + + //获取当前时间,比较拼团中还在未开始 var timestamp = new Date().getTime(); var is_team_tepy; - for (var j = 0; j < pd_data.length;j++ ){ + for (var j = 0; j < pd_data.length; j++) { pd_data[j].is_team_tepy = 1; - if (timestamp { var e = res; @@ -283,8 +320,8 @@ Page({ var new_data = e.data.data.pageData; var arr = new Array(); //--三个三个一组--- - for(var i=0;i< new_data.length;i+=3){ - arr.push(new_data.slice(i,i+3)); + for (var i = 0; i < new_data.length; i += 3) { + arr.push(new_data.slice(i, i + 3)); } th.setData({ newGoods: arr, @@ -295,7 +332,13 @@ Page({ //------热卖------- await getApp().request.promiseGet("/api/weshop/goods/page?page=1", { data: { - is_mainshow: 1, isonsale: 1, is_on_sale: 1, store_id: o.stoid, pageSize: 9,is_hot:1,orderField:"sort" + is_mainshow: 1, + isonsale: 1, + is_on_sale: 1, + store_id: o.stoid, + pageSize: 9, + is_hot: 1, + orderField: "sort" } }).then(res => { var e = res; @@ -303,8 +346,8 @@ Page({ var new_data = e.data.data.pageData; var arr = new Array(); //--三个三个一组--- - for(var i=0;i< new_data.length;i+=3){ - arr.push(new_data.slice(i,i+3)); + for (var i = 0; i < new_data.length; i += 3) { + arr.push(new_data.slice(i, i + 3)); } th.setData({ hotGoods: arr, @@ -313,18 +356,22 @@ Page({ }) //---调用信息--- // this.requestRecommend(); - this.setData({ishow:1}); + this.setData({ + ishow: 1 + }); //---先获取会员--- - t.getUserFir(function () { + t.getUserFir(function() { }); var goods_list = this.selectComponent("#goods_list"); //组件的id goods_list.init(); - setTimeout(function () { goods_list.get_list();},300) + setTimeout(function() { + goods_list.get_list(); + }, 300) }, //--判断小程序是否过期-- - setappdata: function (t) { + setappdata: function(t) { if (t.isout == 1) wx.navigateTo({ url: "/pages/error/error?msg=小程序已经过期", @@ -335,40 +382,42 @@ Page({ }); }, //---加载更多是靠这个函数---- - onReachBottom: function () { + onReachBottom: function() { var goods_list = this.selectComponent("#goods_list"); //组件的id - if(goods_list) goods_list.get_list(); + if (goods_list) goods_list.get_list(); }, - onPullDownRefresh: function (e) { + onPullDownRefresh: function(e) { this.data.recommend = null, this.data.currentPage = 1, n.resetConfig(), this.requestHomePage(), this.requestRecommend(); }, - onUnload: function () { + onUnload: function() { this.destroyActivityTimer(); }, - setCountTime: function (e) { + setCountTime: function(e) { e.diffTime || (e.diffTime = new Date().getTime() - 1e3 * e.server_time), this.setData({ "sale.diffTime": e.diffTime }), this.setData({ "sale.good": e.flash_sale_goods[0] }), this.destroyActivityTimer(), this.createActivityTimer(); }, - createActivityTimer: function () { - var e = this.data.sale, t = this; - this.data.timer = setInterval(function () { - var a = 1e3 * e.good.end_time - new Date().getTime() + e.diffTime, o = i.transTime(a); + createActivityTimer: function() { + var e = this.data.sale, + t = this; + this.data.timer = setInterval(function() { + var a = 1e3 * e.good.end_time - new Date().getTime() + e.diffTime, + o = i.transTime(a); a <= 0 ? t.requestHomePage() : t.setData({ "sale.countTime": o }); }, 1e3); }, - destroyActivityTimer: function () { + destroyActivityTimer: function() { this.data.timer && (clearInterval(this.data.timer), this.data.timer = null); }, - onPageScroll: function (e) { + onPageScroll: function(e) { this.setData({ scrollTop: e.scrollTop }); @@ -384,34 +433,34 @@ Page({ }));--*/ }, - jumpSearch: function () { + jumpSearch: function() { wx.navigateTo({ url: "/pages/goods/search/search" }); }, - onShareAppMessage: function (e) { + onShareAppMessage: function(e) { return o.share; }, //图片失败,默认图片 - bind_bnerr: function (e) { + bind_bnerr: function(e) { var _errImg = e.target.dataset.errorimg; var _errObj = {}; - _errObj[_errImg] = this.data.url+ "/miniapp/images/del/logo.jpg"; + _errObj[_errImg] = this.data.url + "/miniapp/images/del/logo.jpg"; this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; }, //图片失败,默认图片 - bind_bnerr2: function (e) { + bind_bnerr2: function(e) { var _errImg = e.target.dataset.errorimg; var _errurl = e.target.dataset.url; - var _errObj = {}; - _errObj[_errImg] = "/miniapp/images/default_g_img.gif"; - this.setData(_errObj); //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; - + var _errObj = {}; + _errObj[_errImg] = "/miniapp/images/default_g_img.gif"; + this.setData(_errObj); //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; + }, -//图片失败,默认图片 - bind_bnerr3: function (e) { + //图片失败,默认图片 + bind_bnerr3: function(e) { var _errImg = e.target.dataset.errorimg; var _Img = e.target.dataset.img; if (_Img != undefined) { @@ -430,7 +479,7 @@ Page({ //----秒杀倒计时函数----- countDown() { - if(!this.data.is_timer) return false; + if (!this.data.is_timer) return false; var th = this; // 获取当前时间,同时得到活动结束时间数组 var newTime = ut.gettimestamp(); @@ -479,7 +528,7 @@ Page({ //----拼单倒计时函数----- countDown2() { - if(!this.data.is_timer) return false; + if (!this.data.is_timer) return false; var th = this; // 获取当前时间,同时得到活动结束时间数组 @@ -529,122 +578,146 @@ Page({ setTimeout(th.countDown2, 1000); }, - bannerSwiperChange:function (e) { - var index=e.detail.current; - this.setData({banner_index:index}); + bannerSwiperChange: function(e) { + var index = e.detail.current; + this.setData({ + banner_index: index + }); }, - flashSwiperChange:function (e) { - var index=e.detail.current; - this.setData({flash_index:index}); + flashSwiperChange: function(e) { + var index = e.detail.current; + this.setData({ + flash_index: index + }); }, - ptSwiperChange:function (e) { - var index=e.detail.current; - this.setData({pt_index:index}); + ptSwiperChange: function(e) { + var index = e.detail.current; + this.setData({ + pt_index: index + }); }, Interval_pt() { - var th=this; - this.data.pt_timer=setInterval(function () { - var item=ut.get_rand_item(th.data.pt_timer_arr); - th.setData({pt_timer_active:1,pt_timer_item:item}); - setTimeout(function () { - th.setData({pt_timer_active:0}); - },1500) - },4000); + var th = this; + this.data.pt_timer = setInterval(function() { + var item = ut.get_rand_item(th.data.pt_timer_arr); + th.setData({ + pt_timer_active: 1, + pt_timer_item: item + }); + setTimeout(function() { + th.setData({ + pt_timer_active: 0 + }); + }, 1500) + }, 4000); }, //---扫一扫的函数--- - getScancode: function () { + getScancode: function() { var _this = this; // 允许从相机和相册扫码 wx.scanCode({ success: (res) => { - var result = res.result; - wx.navigateTo({ - url: "/pages/goods/search/search?s_key="+result, - }); + var result = res.result; + wx.navigateTo({ + url: "/pages/goods/search/search?s_key=" + result, + }); } }) }, //跳转到分类 - go_cate:function(){ + go_cate: function() { getApp().goto("/pages/goods/categoryList/categoryList"); }, - go_url:function(e){ - var url=e.currentTarget.dataset.url; - getApp().goto(url); + go_url: function(e) { + var url = e.currentTarget.dataset.url; + getApp().goto(url); }, - bind_bnerr_icon:function (e) { + bind_bnerr_icon: function(e) { var def = "/miniapp/images/no_cate_def.png"; var _err = e.currentTarget.dataset.err; - var ob={}; - ob[_err]=def; + var ob = {}; + ob[_err] = def; this.setData(ob); }, //跳转到分类的商品列表 - go_cate2: function (t) { + go_cate2: function(t) { var cid = t.currentTarget.dataset.cid; var pid = t.currentTarget.dataset.pid; var lurl = "/pages/goods/goodsList/goodsList?cat_id=" + cid + "&pid=" + pid; - wx.navigateTo({ url: lurl }); - }, - - //跳转到权益 - go_quanyi:function(t){ - var user_info = getApp().globalData.userInfo; - if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { - wx.navigateTo({ url: '/pages/getphone/getphone', }) - return false; - } - getApp().goto("/pages/user/userqy/userqy"); - }, - - imageLoad:function (e) { - var imgwidth = e.detail.width; - var imgheight = e.detail.height; - //宽高比 - var ratio = imgwidth / imgheight; - //计算的高度值 - var viewHeight = 715 / ratio; - if(this.data.max_sw_height { - // var swiperimage = th.data.swiperimage; - // swiperimage.push("/api/weshop/marketing/newpeople/act/bound/judge"); - // if (res.data.code == 0) { - // th.setData({ - // is_disgraceful:1 - // }) - // } - // }) - - // getApp().request.promiseGet("/api/weshop/marketing/newpeople/act/judge", { - // data: { - // storeId: o.stoid, - // userId: d.user_id - // } - // }).then(res => { - // var swiperimage = th.data.swiperimage; - // swiperimage.push("/miniapp/images/newpeople/newpeople.png"); - // if (res.data.code == 0) { - // th.setData({ - // swiperimage: swiperimage - // }) - // } - // }) + is_new: function() { + var th = this; + + getApp().request.promiseGet("/api/weshop/marketing/newpeople/act/judge", { + data: { + storeId: o.stoid, + userId: d.user_id + } + }).then(res => { + var new_image = res.data.data.imageurl; + var swiperimage = th.data.swiperimage; + swiperimage.push("/miniapp/images/newpeople/newpeople.png"); + if (res.data.code == 0) { + th.setData({ + swiperimage: swiperimage, + new_image: new_image + }) + + getApp().request.promiseGet("/api/weshop/marketing/newpeople/act/bound/judge", { + data: { + storeId: o.stoid, + userId: d.user_id + } + }).then(res => { + if (res.data.code == 0) { + th.setData({ + is_disgraceful: 1 + }) + } + }) + } + }) } diff --git a/pages/index/index/index.wxml b/pages/index/index/index.wxml index 94e19af..f08e8c3 100644 --- a/pages/index/index/index.wxml +++ b/pages/index/index/index.wxml @@ -108,14 +108,13 @@ - - + @@ -349,7 +348,7 @@ - +