Commit 821785d35ef3243fdbd44c19b8edf667cfdff1e5

Authored by antploy
1 parent ff61af95

秒杀新增data_type字段判断

components/diy_seckill/diy_seckill.js
@@ -4,13 +4,13 @@ @@ -4,13 +4,13 @@
4 // }; 4 // };
5 // }(require("../../utils/LoadMore3.js")), 5 // }(require("../../utils/LoadMore3.js")),
6 // n = new e.default(), 6 // n = new e.default(),
7 -var t = getApp(),  
8 - a = t.request,  
9 - o = t.globalData.setting,  
10 - os = o,  
11 - i = require("../../utils/util.js"),  
12 - ut = i,  
13 - s = require("../../utils/common.js"); 7 +var t = getApp(),
  8 + a = t.request,
  9 + o = t.globalData.setting,
  10 + os = o,
  11 + i = require("../../utils/util.js"),
  12 + ut = i,
  13 + s = require("../../utils/common.js");
14 var regeneratorRuntime = require('../../utils/runtime.js'); 14 var regeneratorRuntime = require('../../utils/runtime.js');
15 Component({ 15 Component({
16 properties: { 16 properties: {
@@ -36,23 +36,25 @@ Component({ @@ -36,23 +36,25 @@ Component({
36 imghost: os.imghost, 36 imghost: os.imghost,
37 timer: null, 37 timer: null,
38 }, 38 },
39 -  
40 - pageLifetimes:{ 39 +
  40 + pageLifetimes: {
41 //要处理一下,游客登录后的界面的变化,主要还该是改变会员 41 //要处理一下,游客登录后的界面的变化,主要还该是改变会员
42 show: function () { 42 show: function () {
43 - var th=this;  
44 - if(this.data.goods_array.length>0){  
45 - th.data.timer = setInterval(function() {  
46 - th.countDown2(th);  
47 - }, 1000);  
48 - }  
49 - }  
50 - },  
51 -  
52 - ready: function() { 43 +
  44 + var th = this;
  45 + if (this.data.goods_array.length > 0) {
  46 + th.data.timer = setInterval(function () {
  47 + th.countDown2(th);
  48 + }, 1000);
  49 + }
  50 + }
  51 + },
  52 +
  53 + ready: function () {
53 console.log("ready"); 54 console.log("ready");
54 - var g_id = this.data.object.data;  
55 - console.log(g_id); 55 + // var g_id = this.data.object.data;
  56 + var g_id = this.data.object;
  57 + // console.log(g_id);
56 this.init(g_id); 58 this.init(g_id);
57 }, 59 },
58 detached() { 60 detached() {
@@ -61,96 +63,100 @@ Component({ @@ -61,96 +63,100 @@ Component({
61 }, 63 },
62 methods: { 64 methods: {
63 // 这里是一个自定义方法 65 // 这里是一个自定义方法
64 - customMethod: function() {},  
65 - init: function(g_id) {  
66 - var th = this, app = getApp(), goodsidlist="";  
67 - if(g_id && g_id.length>0){  
68 - //--先把商品ID串起来--  
69 - g_id.forEach(function(val, ind) {  
70 - var item = {};  
71 - goodsidlist+=val.goodsid+",";  
72 - })  
73 - goodsidlist=ut.sub_last(goodsidlist);  
74 -  
75 - //--调用接口,读取秒杀--  
76 - app.request.promiseGet("/api/ms/flash_sale/getGoodsList?store_id="  
77 - +os.stoid+"&goodsidlist="+goodsidlist, {}).then(res => {  
78 - //如果秒杀的数组为空的时候  
79 - var goodslist=res.data.data;  
80 - //就算是添加的活动已经过期,就要用最新的进行中活动  
81 - if(goodslist && goodslist.length>0) {  
82 - th.set_goods_list(g_id,goodslist);  
83 - }  
84 - });  
85 - }else{  
86 - th.no_gid_set();  
87 - } 66 + customMethod: function () { },
  67 + init: function (g_id) {
  68 + var th = this, app = getApp(), goodsidlist = "";
  69 + if (g_id.data_type == 2) {
  70 + if (g_id.data && g_id.data.length > 0) {
  71 + //--先把商品ID串起来--
  72 + g_id.data.forEach(function (val, ind) {
  73 + var item = {};
  74 + goodsidlist += val.goodsid + ",";
  75 + })
  76 + goodsidlist = ut.sub_last(goodsidlist);
  77 +
  78 + //--调用接口,读取秒杀--
  79 + app.request.promiseGet("/api/ms/flash_sale/getGoodsList?store_id="
  80 + + os.stoid + "&goodsidlist=" + goodsidlist, {}).then(res => {
  81 + console.log(res);
  82 + //如果秒杀的数组为空的时候
  83 + var goodslist = res.data.data;
  84 + //就算是添加的活动已经过期,就要用最新的进行中活动
  85 + if (goodslist && goodslist.length > 0) {
  86 + th.set_goods_list(g_id.data, goodslist);
  87 + }
  88 + });
  89 + }
  90 + } else {
  91 + th.no_gid_set();
  92 + }
  93 + },
  94 +
  95 + //当是默认的情况
  96 + no_gid_set() {
  97 + console.log(5623);
  98 + getApp().request.promiseGet("/api/ms/flash_sale/spikepage?page=1&pageSize=9",
  99 + { isShowLoading: 1, data: { store_id: os.stoid, is_end: 0, is_show: 1, timetype: 2 } }
  100 + ).then(res => {
  101 + if (res.data.code == 0 && res.data.data.pageData && res.data.data.pageData.length > 0) {
  102 + var goodsidlist = res.data.data.pageData;
  103 + this.set_goods_list(null, goodsidlist);
  104 + }
  105 + });
  106 + },
  107 +
  108 + //就算是添加的活动已经过期,就要用最新的活动
  109 + set_goods_list(g_id, goodslist) {
  110 + // 判断火热,预热
  111 + var newTime = ut.gettimestamp(), all_array = [], th = this;
  112 + th.setData({ newTime: newTime });
  113 + if (g_id) {
  114 + /*--商品队列按照添加的顺序排列--*/
  115 + g_id.forEach(function (val, ind) {
  116 + goodslist.forEach(function (vy, indy) {
  117 + if (val.goodsid == vy.goods_id) {
  118 + all_array.push(vy);
  119 + //th.setData({goods_array:arr});
  120 + }
  121 + })
  122 + })
  123 + } else {
  124 + all_array = goodslist;
  125 + }
  126 +
  127 +
  128 + if (all_array.length == 0) {
  129 + all_array = goodslist;
  130 + }
  131 +
  132 + var arr = new Array();
  133 + //--三个三个一组---
  134 + for (var i = 0; i < all_array.length; i += 3) {
  135 + arr.push(all_array.slice(i, i + 3));
  136 + }
  137 + /*--熏染到前台--*/
  138 +
  139 + th.setData({ goods_array: arr });
  140 +
  141 + th.data.timer = setInterval(function () {
  142 + th.countDown2(th);
  143 + }, 1000);
88 }, 144 },
89 -  
90 - //当是默认的情况  
91 - no_gid_set(){  
92 - getApp().request.promiseGet("/api/ms/flash_sale/spikepage?page=1&pageSize=9",  
93 - {isShowLoading:1,data:{store_id:os.stoid,is_end:0,is_show:1,timetype:2 }}  
94 - ).then(res=>{  
95 - if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0) {  
96 - var goodsidlist=res.data.data.pageData;  
97 - this.set_goods_list(null,goodsidlist);  
98 - }  
99 - });  
100 - },  
101 -  
102 - //就算是添加的活动已经过期,就要用最新的活动  
103 - set_goods_list(g_id,goodslist){  
104 - // 判断火热,预热  
105 - var newTime = ut.gettimestamp(),all_array = [],th=this;  
106 - th.setData({newTime:newTime});  
107 - if(g_id){  
108 - /*--商品队列按照添加的顺序排列--*/  
109 - g_id.forEach(function(val, ind) {  
110 - goodslist.forEach(function (vy,indy) {  
111 - if(val.goodsid==vy.goods_id){  
112 - all_array.push(vy);  
113 - //th.setData({goods_array:arr});  
114 - }  
115 - })  
116 - })  
117 - }else{  
118 - all_array=goodslist;  
119 - }  
120 -  
121 -  
122 - if(all_array.length==0){  
123 - all_array=goodslist;  
124 - }  
125 -  
126 - var arr = new Array();  
127 - //--三个三个一组---  
128 - for(var i=0;i< all_array.length;i+=3){  
129 - arr.push(all_array.slice(i,i+3));  
130 - }  
131 - /*--熏染到前台--*/  
132 -  
133 - th.setData({goods_array:arr});  
134 -  
135 - th.data.timer = setInterval(function() {  
136 - th.countDown2(th);  
137 - }, 1000);  
138 - },  
139 -  
140 -  
141 - 145 +
  146 +
  147 +
142 //---小于10的格式化函数---- 148 //---小于10的格式化函数----
143 - timeFormat: function(param) { 149 + timeFormat: function (param) {
144 return param < 10 ? '0' + param : param; 150 return param < 10 ? '0' + param : param;
145 }, 151 },
146 //----秒杀倒计时函数----- 152 //----秒杀倒计时函数-----
147 - countDown2: function(ob) { 153 + countDown2: function (ob) {
148 if (ob == undefined) return false; 154 if (ob == undefined) return false;
149 var ee = ob; 155 var ee = ob;
150 // 获取当前时间,同时得到活动结束时间数组 156 // 获取当前时间,同时得到活动结束时间数组
151 var newTime = ut.gettimestamp(); 157 var newTime = ut.gettimestamp();
152 - this.setData({newTime:newTime});  
153 - 158 + this.setData({ newTime: newTime });
  159 +
154 var List = ee.data.goods_array; 160 var List = ee.data.goods_array;
155 if (List.length == 0) return false; 161 if (List.length == 0) return false;
156 for (var j = 0; j < List.length; j++) { 162 for (var j = 0; j < List.length; j++) {
@@ -159,7 +165,7 @@ Component({ @@ -159,7 +165,7 @@ Component({
159 for (var i = 0; i < endTimeList.length; i++) { 165 for (var i = 0; i < endTimeList.length; i++) {
160 var o = endTimeList[i]; 166 var o = endTimeList[i];
161 var endTime = o.end_time; 167 var endTime = o.end_time;
162 - if (newTime< o.start_time) endTime = o.start_time; 168 + if (newTime < o.start_time) endTime = o.start_time;
163 let obj = null; 169 let obj = null;
164 // 如果活动未结束,对时间进行处理 170 // 如果活动未结束,对时间进行处理
165 if (endTime - newTime > 0) { 171 if (endTime - newTime > 0) {
@@ -199,9 +205,9 @@ Component({ @@ -199,9 +205,9 @@ Component({
199 this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; 205 this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
200 }, 206 },
201 207
202 - go_to_skill:function () { 208 + go_to_skill: function () {
203 wx.navigateTo({ 209 wx.navigateTo({
204 - url:"/pages/activity/seckill_list/seckill_list" 210 + url: "/pages/activity/seckill_list/seckill_list"
205 }); 211 });
206 } 212 }
207 }, 213 },