create-wish.js
4.18 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
let app = getApp();
Page({
data: {
tipsRegisterVisible: false,
tipsGroupMemberVisible: false,
tipsNewMemberVisible: false,
tipsWishVisible: false,
tipsShakeVisible: false,
tipsCreateCompleteVisible: false,
curStatus: 1, // 当前场景
candidate: [], // 心愿候选列表
myWishList: [], // 我的心愿列表
},
onShareAppMessage() {},
onLoad(options) {
this.initData();
},
initData() {
app.queryIndex().then((result) => {
this.queryWishbillPrizeCandidate();
});
},
/**
* 点击提交心愿单按钮
* 首先要根据自身状态判断
*/
onSubmitHandler() {
this.checkSubmit().then((result) => {
}).catch((err) => {
});;
},
/**
* 提交前判断状态
* 判断顺序
* 1.crm登陆
* 2.黑名单 (团购会员)
* 3.新会员
*
*/
checkSubmit() {
return new Promise((resolve, reject) => {
let indexInfo = app.globalData.indexInfo;
console.log("indexInfo:", indexInfo);
let {
isCrmLogin,
isNewMember,
isBlackList,
hadAnswerQuestion,
isSelfAssist,
wishBillCode
} = indexInfo;
// 未登陆 出注册弹窗提示
// isCrmLogin = 1;
if (isCrmLogin == 0) {
this.setData({
tipsRegisterVisible: true
})
reject();
return;
}
// 黑名单
if (isBlackList == 1) {
this.setData({
tipsGroupMemberVisible: true
})
reject();
return;
}
// 新老会员
// isNewMember
// hadAnswerQuestion = 1; //硬编码答题
if (isNewMember == 1) {
// 新会员
if (hadAnswerQuestion) {
// 已经答题,提示创建心愿单
// todo 校验选择
// 校验完成后显示提示
this.setData({
tipsWishVisible: true
});
// this.queryWishbillCreate();
} else {
// 未答题,提示答题
this.setData({
tipsNewMemberVisible: true
})
}
} else {
// 老会员
}
resolve();
});
},
// billCode
// 创建心愿单
queryWishbillCreate() {
console.log("queryWishbillCreate");
// let myWishList = this.data.candidate;
// console.log("this.data.candidate:",this.data.candidate);
// console.log("myWishList:",myWishList);
// let myWishList = this.data.myWishList;
let myWishList = this.data.candidate[0].products;
let wishBillCodeList = [];
myWishList.forEach(element => {
wishBillCodeList.push(element.prizeDefineCode);
});
console.log("wishBillCodeList:", wishBillCodeList);
app.post({
url: app.api.wishbillCreate,
data: ["ee3e985407fd40abb22b5f75f0f489a1", "5e46119a5ad04649815b7c0171fd7e9a", "1301a7070b57433986a12ee982103b71"]
}).then((result) => {
console.log("创建成功")
console.log("result:", result);
}).catch((err) => {
console.log("err:", err);
});
},
// 换一批
onChangeStatusHandler() {
let curStatus = this.data.curStatus;
curStatus++;
if (curStatus > 3) {
curStatus = 1;
}
this.setData({
curStatus
})
},
// 心愿单产品候选列表
queryWishbillPrizeCandidate() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.wishbillPrizeCandidate,
data: {}
}).then((result) => {
this.setData({
candidate: result
})
resolve();
}).catch((err) => {
reject();
});
});
},
// 子组件事件
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
// 隐藏蒙层
case "_evt_hide_mask":
this.setData({
ruleTipsVisible: false,
tipsGroupMemberVisible: false,
tipsNewMemberVisible: false,
tipsWishVisible: false,
tipsWishVisible: false,
tipsCreateCompleteVisible: false,
})
break;
// 创建心愿单
case "_evt_create_wish":
this.setData({
tipsWishVisible: false
})
this.queryWishbillCreate();
break;
default:
break;
}
},
})