diff --git a/components/diy_seckill/diy_seckill.js b/components/diy_seckill/diy_seckill.js index d218285..13526c1 100644 --- a/components/diy_seckill/diy_seckill.js +++ b/components/diy_seckill/diy_seckill.js @@ -4,13 +4,13 @@ // }; // }(require("../../utils/LoadMore3.js")), // n = new e.default(), -var t = getApp(), - a = t.request, - o = t.globalData.setting, - os = o, - i = require("../../utils/util.js"), - ut = i, - s = require("../../utils/common.js"); +var t = getApp(), + a = t.request, + o = t.globalData.setting, + os = o, + i = require("../../utils/util.js"), + ut = i, + s = require("../../utils/common.js"); var regeneratorRuntime = require('../../utils/runtime.js'); Component({ properties: { @@ -36,23 +36,25 @@ Component({ imghost: os.imghost, timer: null, }, - - pageLifetimes:{ + + pageLifetimes: { //要处理一下,游客登录后的界面的变化,主要还该是改变会员 show: function () { - var th=this; - if(this.data.goods_array.length>0){ - th.data.timer = setInterval(function() { - th.countDown2(th); - }, 1000); - } - } - }, - - ready: function() { + + var th = this; + if (this.data.goods_array.length > 0) { + th.data.timer = setInterval(function () { + th.countDown2(th); + }, 1000); + } + } + }, + + ready: function () { console.log("ready"); - var g_id = this.data.object.data; - console.log(g_id); + // var g_id = this.data.object.data; + var g_id = this.data.object; + // console.log(g_id); this.init(g_id); }, detached() { @@ -61,96 +63,100 @@ Component({ }, methods: { // 这里是一个自定义方法 - customMethod: function() {}, - init: function(g_id) { - var th = this, app = getApp(), goodsidlist=""; - if(g_id && g_id.length>0){ - //--先把商品ID串起来-- - g_id.forEach(function(val, ind) { - var item = {}; - goodsidlist+=val.goodsid+","; - }) - goodsidlist=ut.sub_last(goodsidlist); - - //--调用接口,读取秒杀-- - app.request.promiseGet("/api/ms/flash_sale/getGoodsList?store_id=" - +os.stoid+"&goodsidlist="+goodsidlist, {}).then(res => { - //如果秒杀的数组为空的时候 - var goodslist=res.data.data; - //就算是添加的活动已经过期,就要用最新的进行中活动 - if(goodslist && goodslist.length>0) { - th.set_goods_list(g_id,goodslist); - } - }); - }else{ - th.no_gid_set(); - } + customMethod: function () { }, + init: function (g_id) { + var th = this, app = getApp(), goodsidlist = ""; + if (g_id.data_type == 2) { + if (g_id.data && g_id.data.length > 0) { + //--先把商品ID串起来-- + g_id.data.forEach(function (val, ind) { + var item = {}; + goodsidlist += val.goodsid + ","; + }) + goodsidlist = ut.sub_last(goodsidlist); + + //--调用接口,读取秒杀-- + app.request.promiseGet("/api/ms/flash_sale/getGoodsList?store_id=" + + os.stoid + "&goodsidlist=" + goodsidlist, {}).then(res => { + console.log(res); + //如果秒杀的数组为空的时候 + var goodslist = res.data.data; + //就算是添加的活动已经过期,就要用最新的进行中活动 + if (goodslist && goodslist.length > 0) { + th.set_goods_list(g_id.data, goodslist); + } + }); + } + } else { + th.no_gid_set(); + } + }, + + //当是默认的情况 + no_gid_set() { + console.log(5623); + getApp().request.promiseGet("/api/ms/flash_sale/spikepage?page=1&pageSize=9", + { isShowLoading: 1, data: { store_id: os.stoid, is_end: 0, is_show: 1, timetype: 2 } } + ).then(res => { + if (res.data.code == 0 && res.data.data.pageData && res.data.data.pageData.length > 0) { + var goodsidlist = res.data.data.pageData; + this.set_goods_list(null, goodsidlist); + } + }); + }, + + //就算是添加的活动已经过期,就要用最新的活动 + set_goods_list(g_id, goodslist) { + // 判断火热,预热 + var newTime = ut.gettimestamp(), all_array = [], th = this; + th.setData({ newTime: newTime }); + if (g_id) { + /*--商品队列按照添加的顺序排列--*/ + g_id.forEach(function (val, ind) { + goodslist.forEach(function (vy, indy) { + if (val.goodsid == vy.goods_id) { + all_array.push(vy); + //th.setData({goods_array:arr}); + } + }) + }) + } else { + all_array = goodslist; + } + + + if (all_array.length == 0) { + all_array = goodslist; + } + + var arr = new Array(); + //--三个三个一组--- + for (var i = 0; i < all_array.length; i += 3) { + arr.push(all_array.slice(i, i + 3)); + } + /*--熏染到前台--*/ + + th.setData({ goods_array: arr }); + + th.data.timer = setInterval(function () { + th.countDown2(th); + }, 1000); }, - - //当是默认的情况 - no_gid_set(){ - getApp().request.promiseGet("/api/ms/flash_sale/spikepage?page=1&pageSize=9", - {isShowLoading:1,data:{store_id:os.stoid,is_end:0,is_show:1,timetype:2 }} - ).then(res=>{ - if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0) { - var goodsidlist=res.data.data.pageData; - this.set_goods_list(null,goodsidlist); - } - }); - }, - - //就算是添加的活动已经过期,就要用最新的活动 - set_goods_list(g_id,goodslist){ - // 判断火热,预热 - var newTime = ut.gettimestamp(),all_array = [],th=this; - th.setData({newTime:newTime}); - if(g_id){ - /*--商品队列按照添加的顺序排列--*/ - g_id.forEach(function(val, ind) { - goodslist.forEach(function (vy,indy) { - if(val.goodsid==vy.goods_id){ - all_array.push(vy); - //th.setData({goods_array:arr}); - } - }) - }) - }else{ - all_array=goodslist; - } - - - if(all_array.length==0){ - all_array=goodslist; - } - - var arr = new Array(); - //--三个三个一组--- - for(var i=0;i< all_array.length;i+=3){ - arr.push(all_array.slice(i,i+3)); - } - /*--熏染到前台--*/ - - th.setData({goods_array:arr}); - - th.data.timer = setInterval(function() { - th.countDown2(th); - }, 1000); - }, - - - + + + //---小于10的格式化函数---- - timeFormat: function(param) { + timeFormat: function (param) { return param < 10 ? '0' + param : param; }, //----秒杀倒计时函数----- - countDown2: function(ob) { + countDown2: function (ob) { if (ob == undefined) return false; var ee = ob; // 获取当前时间,同时得到活动结束时间数组 var newTime = ut.gettimestamp(); - this.setData({newTime:newTime}); - + this.setData({ newTime: newTime }); + var List = ee.data.goods_array; if (List.length == 0) return false; for (var j = 0; j < List.length; j++) { @@ -159,7 +165,7 @@ Component({ for (var i = 0; i < endTimeList.length; i++) { var o = endTimeList[i]; var endTime = o.end_time; - if (newTime< o.start_time) endTime = o.start_time; + if (newTime < o.start_time) endTime = o.start_time; let obj = null; // 如果活动未结束,对时间进行处理 if (endTime - newTime > 0) { @@ -199,9 +205,9 @@ Component({ this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; }, - go_to_skill:function () { + go_to_skill: function () { wx.navigateTo({ - url:"/pages/activity/seckill_list/seckill_list" + url: "/pages/activity/seckill_list/seckill_list" }); } },