diy_pingd_buy.js
5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// var e = function(e) {
// return e && e.__esModule ? e : {
// default: e
// };
// }(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 regeneratorRuntime = require('../../utils/runtime.js');
Component({
properties: {
// 这里定义了innerText属性,属性值可以在组件使用时指定
object: {
type: Object,
value: null,
},
goods_array: {
type: Array,
value: []
},
newTime: {
type: Number,
value: 0
},
},
data: {
// 这里是一些组件内部数据
yc: false,
someData: null,
ylp_img: "https://mshopimg.yolipai.net/",
timer: null,
iurl:o.imghost,
},
pageLifetimes:{
//要处理一下,游客登录后的界面的变化,主要还该是改变会员
show: 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);
this.init(g_id);
},
detached() {
// 页面被被销毁的时候,清除定时器
clearInterval(this.data.timer);
},
methods: {
// 这里是一个自定义方法
customMethod: function() {},
init: function(g_id) {
var th = this,
app = getApp(), all_array = [],
index = 0,
goodsidlist="";
//-- 当是默认的调用的时候 --
if(!g_id || g_id.length<=0 ){
th.no_gid_set();
}else{
//--先把商品ID串起来--
g_id.forEach(function(val, ind) {
var item = {};
goodsidlist+=val.goodsid+",";
})
goodsidlist= goodsidlist.substr(0,goodsidlist.length-1);
//--调用接口,读取拼单--
app.request.promiseGet("/api/weshop/teamlist/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);
}
});
}
},
no_gid_set(){
var th=this;
var url= "/api/weshop/teamlist/pageteam/2?page=1&pageSize=9";
getApp().request.promiseGet(url, {
data: {
store_id: os.stoid,is_end: 0,is_show: 1,
}
}).then(res => {
if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0){
var goodslist=res.data.data.pageData;
th.set_goods_list(null,goodslist);
}
})
},
//设置商品列表
set_goods_list:function(g_id,goodslist){
var th=this,all_array=[];
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});
var newTime = ut.gettimestamp();
th.setData({ newTime: newTime });
th.data.timer = setInterval(function() {
th.countDown2(th);
}, 1000);
},
//---小于10的格式化函数----
timeFormat: function(param) {
return param < 10 ? '0' + param : param;
},
//----拼单倒计时函数-----
countDown2: function(ob) {
if (ob == undefined) return false;
var ee = ob;
// 获取当前时间,同时得到活动结束时间数组
var newTime = ut.gettimestamp();
this.setData({newTime:newTime});
var List = ee.data.goods_array;
if (List.length == 0) return false;
for (var j = 0; j < List.length; j++) {
// 对结束时间进行处理渲染到页面
var endTimeList = List[j];
for (var i = 0; i < endTimeList.length; i++) {
var o = endTimeList[i];
var endTime = o.end_time;
// if (o.status == 0) endTime = o.start_time;
let obj = null;
// 如果活动未结束,对时间进行处理
if (endTime - newTime > 0) {
let time = (endTime - newTime);
// 获取天、时、分、秒
let day = parseInt(time / (60 * 60 * 24));
let hou = parseInt(time % (60 * 60 * 24) / 3600);
let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
obj = {
day: this.timeFormat(day),
hou: this.timeFormat(hou),
min: this.timeFormat(min),
sec: this.timeFormat(sec)
}
} else {
//活动已结束,全部设置为'00'
obj = {
day: '00',
hou: '00',
min: '00',
sec: '00'
}
}
var txt = "goods_array[" + j + "][" + i + "].djs";
ee.setData({
[txt]: obj
});
}
}
},
//图片失败,默认图片
bind_bnerr3: function (e) {
var _errImg = e.target.dataset.errorimg;
var _Img = e.target.dataset.img;
if (_Img != undefined) {
var _errObj = {};
_errObj[_errImg] = "/public/images/default_goods_image_240.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
}
},
go_to_pindlist:function () {
wx.navigateTo({
url:"/pages/activity/pind_list/pind_list"
});
}
},
})