list.js
4.99 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
var e = getApp(), i = e.request, os = e.globalData.setting, ut = require("../../../../utils/util.js");
var regeneratorRuntime = require('../../../../utils/runtime.js');
Page({
data: {
url: os.imghost,
goodlist:[],
page: 1,
timer: null,
ismore: 1, //是否可以加载更多
isshow: 0,
ad_data: null,
max_sw_height: 200,
},
//------初始化加载----------
onLoad: function (t) {
var first_leader = t.first_leader;
var th = this;
getApp().getConfig();
this.data.act_id=t.act_id;
if (first_leader) {
getApp().globalData.first_leader = first_leader;
//调用接口判断是不是会员
getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
if (res.data.code == 0) {
getApp().globalData.guide_id = res.data.data.id;
}
})
}
getApp().request.promiseGet("/api/weshop/ad/page?pid=1202&store_id=" + os.stoid, {
data: {
enabled: 1
}
}).then(res => {
if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length > 0) {
var a = res.data.data.pageData;
var narr = [];
for (var i in a) {
var tt = {
'ad_code': os.imghost + a[i].ad_code,
'media_link': '',
'ad_weapplink': a[i].ad_weapplink
};
narr.push(tt);
}
th.setData({ad_data: narr});
}
})
var userInfo=getApp().globalData.userInfo;
if(userInfo && goodlist.length==0){
//调用列表
this.get_list();
}else{
getApp().goto("/pages/togoin/togoin");
}
},
onShow: function (t) {
var userInfo=getApp().globalData.userInfo;
if(userInfo && this.data.goodlist.length==0){
//调用列表
this.get_list();
}else{
if(getApp().globalData.pre_back==1){
getApp().globalData.pre_back=0;
getApp().goto("/pages/index/index/index");
}
}
},
//---小于10的格式化函数----
timeFormat(param) {
return param < 10 ? '0' + param : param;
},
onReachBottom: function () {
this.get_list();
},
//图片失败,默认图片
bind_bnerr2: function (e) {
var _errImg = e.target.dataset.errorimg;
var val = e.target.dataset.val;
if (val != undefined && val != null && val != 'null') {
var _errObj = {};
_errObj[_errImg] = "/public/images/default_goods_image_240.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
}
},
imageLoad: function (e) {
var imgwidth = e.detail.width;
var imgheight = e.detail.height;
//宽高比
var ratio = imgwidth / imgheight;
//计算的高度值
var viewHeight = 750 / ratio;
var hei = this.data.max_sw_height;
if (hei < viewHeight) {
this.setData({max_sw_height: viewHeight});
}
},
//获取数据
get_list(){
var self = this;
if (this.data.loading) return false;
if (this.data.no_more) return false;
this.data.loading = 1;
var req = {
is_end: 0,
store_id: os.stoid,
page: this.data.page,
pageSize: 10,
timetype: 1
}
if(getApp().globalData.userInfo){
req.user_id=getApp().globalData.userInfo.user_id;
}
if(this.data.act_id){
req.prom_type=8;
req.prom_id=this.data.act_id;
}
//调用接口获取数据
getApp().request.get("/api/weshop/marketing/marketingPresellList/page", {
data: req,
success: function (res) {
console.log(res);
self.data.loading = 0;
if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length > 0) {
var list = self.data.goodlist ? self.data.goodlist : [];
var arr = res.data.data.pageData;
//数组合起来
for (var i in arr) {
list.push(arr[i]);
}
self.data.page++;
self.setData({goodlist: list});
if (arr.length < 10) {
self.setData({no_more: 1})
}
} else {
self.setData({no_more: 1})
}
self.setData({is_get: 1})
}
})
},
go_index:function () {
getApp().goto("/pages/index/index/index");
}
});