quan_list.js
6.07 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
var t = require("../../../utils/util.js"), ut = t,
e = require("../../../utils/common.js"),
oo = getApp().globalData,
os = getApp().globalData.setting;
var utils = require('../../../utils/util.js'), ut = utils;
Page({
data: {
stoid: os.stoid,
url: os.url,
resourceUrl: os.resourceUrl,
iurl: os.imghost,
defaultAvatar: os.resourceUrl + "/static/images/user68.jpg",
dataList: null,
config2: null,
curpage: 1,
loading: 0,
get_item: null,
show_success: 0,
getcurday: null,
},
//------初始化加载----------
onLoad: function (t) {
var th = this;
var first_leader=t.first_leader;
if(first_leader){
//-- user_id代过来免登录 --
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().globalData.guide_pick_id= res.data.data.pickup_id
}
})
}
getApp().getConfig2(function (conf) {
if (conf.couponset) conf.couponset = conf.couponset.replace(/\<img/g, '<img style="width:100%;height:auto;display:block"');
th.setData({ config2: conf });
})
},
//---展示---
onShow: function () {
//检查能不能分享
getApp().check_can_share();
console.log("onShow:1");
this.data.curpage = 1;
this.setData({ dataList: null });
console.log("onShow:2");
this.get_quan_list();
//券的模拟数据
//var data = [{ is_get:0,money:50,condition:500,id:1,name: "券名字", endtype: 0, use_start_time: 1579596090, use_end_time: 1611218490, everyone_num: 2,interval_time:1,color:"red"}];
//th.setData({dataList: data});
this.setData({ getcurday: ut.gettimestamp() });
},
onHide: function () {
},
//--券的列表页面的函数--
get_quan_list: function () {
console.log("onShow:3");
var th = this;
if (th.data.loading) return false;
th.data.loading = 1;
var user_id = getApp().globalData.user_id;
console.log("onShow:4");
var data = { store_id: os.stoid, type: 1, pageSize: 10, page: th.data.curpage, user_id: user_id, is_share: 0 };
console.log(data);
getApp().request.get("/api/weshop/prom/coupon/pageCouponList", {
data: data,
success: function (res) {
console.log("onShow:5");
console.log(res);
th.data.loading = 0;
if (res.data.code == 0) {
if (!th.data.dataList) th.data.dataList = new Array();
th.data.dataList = th.data.dataList.concat(res.data.data.pageData);
th.data.curpage++;
th.setData({ dataList: th.data.dataList });
}
},
fail: function (e) {
console.log("onShow:6");
console.log(e);
}
});
},
//---加载更多是靠这个函数----
onReachBottom: function () {
this.get_quan_list();
},
//--滚动到顶部--
doScrollTop: function () {
wx.pageScrollTo({ scrollTop: 0 });
},
//-----领取券-----
get_quan: function (e) {
var cid = e.currentTarget.dataset.cid;
var index = e.currentTarget.dataset.ind;
var item = this.data.dataList[index];
var good = new Array(); //单品且是免费领取专门使用
//--先判断会员状态--
var user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
wx.navigateTo({
url: '/packageE/pages/togoin/togoin',
})
return false;
}
//如果券还在领取中,不能再点
if (item.linging == 1) {
getApp().my_warnning('领取中..', 0, this);
return false;
}
//如果领取的次数到了
if (item.everyone_num > 0 && item.lqnum >= item.everyone_num) {
getApp().my_warnning('领取失败,您已领完该券', 0, this);
return false;
}
var lq_num = item.lqnum;
var pdata = {
'uid': oo.user_id,
'cid': cid,
'store_id': os.stoid,
'type': 5
};
if (item.useobjecttype == 20 && item.type == 1) {
getApp().request.get('/api/weshop/goods/list', {
data: {
store_id: os.stoid,
erpwareid: item.useobjectid,
},
success(res) {
if (ut.ajax_ok2(res)) {
good = res.data.data;
}
}
})
}
//-- 导购ID --
if (getApp().globalData.guide_id) {
pdata.guide_id = getApp().globalData.guide_id;
}
var app = getApp(),
th = this;
app.request.post("/api/weshop/couponList/saveCouponList", {
data: pdata,
success: function (res) {
if (res.data.code == 0) {
var text = "dataList[" + index + "].is_get";
var text2 = "dataList[" + index + "].linging";
var text3 = "get_item";
var obj = {}; obj[text] = 1; obj[text2] = 0; obj[text3] = item;
th.setData(obj);
if (good.length > 0) {
wx.showToast({
title: '领取成功',
success() {
let item = good[0];
let url = `/pages/goods/goodsInfo/goodsInfo?goods_id=${item.goods_id}&prom_type=${item.prom_type}&prom_id=${item.prom_id}`
setTimeout(()=>{
getApp().goto(url)
},500)
}
})
} else {
th.setData({
show_success: 1,
})
}
} else {
app.confirmBox(res.data.msg);
var text2 = "dataList[" + index + "].linging";
th.setData({ [text2]: 0 });
}
}
})
},
close_show: function () {
this.setData({ show_success: 0, get_item: null })
},
go_quan: function () {
getApp().goto("/packageD/pages/user/coupons/coupons");
},
go_detail: function (e) {
var index = e.currentTarget.dataset.ind;
var item = this.data.dataList[index];
getApp().goto("/packageA/pages/quan_pro/quan_pro?id=" + item.id);
},
//发送给好友
onShareAppMessage:async function(e) {
getApp().globalData.no_clear=1;
var url= `packageA/pages/quan_list/quan_list`;
var userInfo = getApp().globalData.userInfo;
//是分销商才带
if (userInfo) {
url += "?first_leader=" + userInfo.user_id;
}
var ob = {
title:"优惠券列表",
path: url,
//imageUrl:this.data.url+this.data.store_config.store_logo,
};
return ob;
},
//发送给朋友圈
onShareTimeline() {
getApp().globalData.no_clear=1;
var user_id= getApp().globalData.user_id
return {
title:"优惠券列表",
query: 'first_leader='+user_id
}
},
});