user_coupon.js
4.12 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
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:'',
},
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:async function () {
var th = this,q_list=null;
//--获取列表--
await 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}
}).then(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.setData({quan_list:q_list});
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
//获取券
get_quan:function (e) {
var th=this,index=e.currentTarget.dataset.ind;
var item = this.data.quan_list[index];
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);
}
}
})
},
//点击核销券
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');
var name= e.data.data.UseObjectName;
//--获取成功的时候--
if(e.data.code==0){
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 = this.selectComponent("#pop_txt"); //组件的id
var ob={title:"温馨提示",content:"您暂时还没有该券"};
qt_txt.open(ob);
}
}
})
}
})