user_coupon.js
6.19 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
var e = getApp(),os = e.globalData.setting;
var utils = require('../../../../utils/util.js');
var regeneratorRuntime = require('../../../../utils/runtime.js');
Page({
/**
* 页面的初始数据
*/
data: {
judge:0,
quan_list:null,
iurl:os.imghost,
h_pic:null,
GradeId:null,
FormId:null,
now:'',
ismore: 0, //数据是否全部加载完成
is_read: 0, //是否查询过我的礼包接口
curpage: 1, //当前分页数
pageSize: 10, //页大小
total: 0, //总数量
},
clik_coupon:function(){
this.setData({
judge:1
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log("onLoad");
console.log(options);
var h_pic=options.img;
if(h_pic.indexOf("http")==-1){
h_pic= os.imghost+h_pic;
}
var FormId=options.FormId;
var GradeId=options.gradeId;
var now=utils.gettimestamp();
this.setData({h_pic:h_pic,GradeId:GradeId,FormId:FormId,now:now});
},
/**
* 生命周期函数--监听页面显示
*/
onShow:function () {
this.getList();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
var th = this;
if (th.data.total <= th.data.pageSize) return;
if (th.data.ismore) return;
th.getList();
},
getList: function () {
if(this.data.ismore) return false;
if(this.data.searching) return false;
this.data.searching=1;
wx.showLoading({
title: '加载中.',
})
var th = this,q_list=null;
//--获取列表--
getApp().request.promiseGet("/api/weshop/users/grade/wechat/cash/page", {
data:{ storeId:os.stoid,
FormId:th.data.FormId,
GradeId:th.data.GradeId,
userId:getApp().globalData.user_id,
page: th.data.curpage,
pageSize: th.data.pageSize}
}).then(res => {
th.data.searching=0;
if (utils.ajax_ok(res)){
q_list = res.data.data.pageData;
//取分类最后一级
for(var i in q_list){
var name=q_list[i].UseObjectName;
var arr=name.split("\\")
q_list[i].UseObjectName=arr[arr.length-1];
q_list[i].Remark = q_list[i].Remark.replace(/\n/g, "\n")
}
th.data.curpage++;
var quan_list=th.data.quan_list||[];
quan_list=quan_list.concat(q_list);
if (quan_list.length>=res.data.data.total) {
th.setData({
is_read: 1,
ismore: 1,
is_get:1,
})
}
th.setData({
quan_list:quan_list,
total: res.data.data.total
});
}
else {
th.setData({
is_read: 1,
ismore: 1,
is_get:1,
})
}
wx.hideLoading();
})
},
//获取券
get_quan:function (e) {
console.log("get_quan_ing:"+this.data.get_quan_ing);
if(this.data.get_quan_ing) return false;
this.data.get_quan_ing=1;
var th=this,index=e.currentTarget.dataset.ind;
var item = this.data.quan_list[index];
var txt_get="quan_list["+index+"].get_quan_ing";
this.setData({
[txt_get]:1
})
var can_get = item.ObtainTimes;
var Obtain = item.Obtain;
var Id = item.Id;
if (!Obtain || Obtain == undefined) Obtain = 0;
getApp().request.post("/api/weshop/users/grade/cash/insert",{
data:{
privilegeId:Id,
storeId:os.stoid,
userId:getApp().globalData.user_id,
},
success:function (e) {
if(e.data.code==0){
var txt="quan_list["+index+"].ObtainTimes"
var obj={};obj[txt]=can_get-1;
var text = "quan_list[" + index + "].Obtain"; Obtain++;
obj[text] = Obtain;
th.setData(obj);
getApp().my_warnning("您已成功领取该券",1,th);
setTimeout(()=>{
th.data.get_quan_ing=0;
th.setData({
[txt_get]:0
})
},1000)
}else{
getApp().my_warnning(e.data.msg,0,th);
setTimeout(()=>{
th.data.get_quan_ing=0;
th.setData({
[txt_get]:0
})
})
}
}
})
},
//点击核销券
get_out:function (e) {
var qt_txt = this.selectComponent("#pop_txt"); //组件的id
var ob={title:"温馨提示",content:"当前优惠券已领取,点击二维码可立即使用"};
qt_txt.open(ob);
},
clik_coupon:function (e) {
var ind=e.currentTarget.dataset.ind;
var is_open=this.data.quan_list[ind].is_open;
if(is_open==1) is_open=0;
else is_open=1;
var txt="quan_list["+ind+"].is_open"
var obj={};obj[txt]=is_open;
this.setData(obj);
},
//--显示核销券--
show_quan:function (e) {
var ind=e.currentTarget.dataset.ind;
var item=this.data.quan_list[ind];
var pId=this.data.quan_list[ind].Id;
var th=this;
var validay = item.Validay;
var now = e.currentTarget.dataset.now;
getApp().request.get("/api/weshop/users/grade/cash/code/get",{
data:{
storeId:os.stoid,
privilegeId:pId,
userId:getApp().globalData.user_id,
},
success:function (e) {
console.log(e);
console.log('/code/get');
//--获取成功的时候--
if(e.data.code==0 && e.data.data){
var name= e.data.data.UseObjectName;
var no=e.data.data.CashRepNo;
var qc_com = th.selectComponent("#qc_com"); //组件的id
var obj={val:no,content:"请将二维码展示给核销员,抵券更快捷",now: now, validay: validay, name: name,is_quan:1};
qc_com.open(obj)
}else{
var qt_txt = th.selectComponent("#pop_txt"); //组件的id
var ob={title:"温馨提示",content:e.data.msg};
qt_txt.open(ob);
}
}
})
}
})