order-detail.js
13.7 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// pages/index/confirm-appointment-info/confirm-appointment-info.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
show: false,
modal_data: {
is_showModal: false,
currentBtn: null,
title: '当前学员还没有购买/兑换畅玩卡,暂不能预约实验活动,是否马上购买/兑换?',
tab_left: '否',
tab_right: '是',
},
state_data: {
is_showSuccessModal: false,
icon: '../../../images/success.png',
title:'恭喜您!',
content: '您已经预约成功!'
},
student_list: [],
is_choose: false,
num_arr: [],
session_info: {},
student_num: 0,
is_choose_student: false,
is_buy: false,
choose_student_id:0,
// checked_student: [],
page_number: 1,
has_more: true,
},
//获取学员列表
getStudentList() {
if(!this.data.has_more) return;
this.setData({has_more: false});
let url = '/user/Student/student_list';
let header = {
"XX-token": wx.getStorageSync('token')
};
let params = {
page: this.data.page_number,
};
app.post(url,params,header).then((res) => {
console.log('学员列表',res);
if(res.this_page < res.total_page) {
this.setData({has_more: true});
}
// console.log('list', list);
var new_arr = [];
res.list.forEach((item) => {
new_arr.push({ ...item, checked: false })
});//给每一项添加checked属性
console.log(new_arr);
this.setData({student_list:this.data.student_list.concat(new_arr)})
})
},
//选择学员(待确认可选)
chooseChildren(e) {
console.log('29------e', e);
// const current = e.currentTarget.dataset.index;
const that = this;
if(that.data.detail.status === 1) {//待确认可选择学员
console.log(e.detail);
var index_arr = e.detail.value;
console.log(index_arr);
//新建数组全部设置为没被选中
var new_arr = [];
that.data.student_list.forEach((item) => {
new_arr.push({ ...item, checked: false })
});//给每一项添加checked属性
console.log('new_arr',new_arr);
var new_itmes = new_arr;
console.log('new_itmes', new_itmes);
if(that.data.detail.num >=2) { //两个学员预约时
console.log('两个学员');
if (index_arr.length > 2) {
//取出倒数两个值
var key1 = index_arr[index_arr.length - 1];
var key2 = index_arr[index_arr.length - 2];
// var key3 = skin[skin.length - 3];
// console.log(key1, key2, key3);
console.log(key1, key2);
console.log(new_itmes[key1]['checked'],new_itmes[key1].id,new_itmes[key2].id);
//设置最后两个值为选中状态
new_itmes[key1]['checked'] = true
new_itmes[key2]['checked'] = true
// new_itmes[key3 - 1]['checked'] = 'true'
//删除被选中的第一个值
index_arr.splice(0, 1);
console.log('skin',index_arr);
const id_arr = [];
id_arr.push(new_itmes[key1].id,new_itmes[key2].id);
that.setData({student_id: id_arr.join(','),is_choose_student:true});
console.log('student_id', that.data.student_id);
} else {
const checked_student = [];
//被选中少于两个,直接设置被选中
for (var i = 0; i < index_arr.length; i++) {
var key = index_arr[i]
console.log('key', key);
new_itmes[key]['checked'] = true
}
console.log('选一个时候new_itmes', new_itmes);
new_itmes.forEach((item) => {
if(item.checked) {
checked_student.push(item)
}
});
console.log('选择学员length', checked_student,checked_student.length);
if(checked_student.length>=2) {
const arr = [];
new_itmes.forEach((item) => {
if(item.checked) {
arr.push(item.id)
}
});
that.setData({student_id: arr.join(','),is_choose_student:true});
}else if(checked_student.length<2){
wx.showToast({title:'请选择两个学员!',icon:'none'});
that.setData({student_id: new_itmes[key].id,is_choose_student:true});
}
console.log('student_id', that.data.student_id);
}
}else if(that.data.detail.num <2){//一个学员预约时
console.log('一个学员');
if (index_arr.length > 1) {
//取出倒数一个值
var key1 = index_arr[index_arr.length - 1];
// var key2 = skin[skin.length - 2];
// var key3 = skin[skin.length - 3];
// console.log(key1, key2, key3);
console.log(key1);
console.log(new_itmes[key1]['checked'],new_itmes[key1].id);
//设置最后一个值为选中状态
new_itmes[key1]['checked'] = true
// new_itmes[key2]['checked'] = true
// new_itmes[key3 - 1]['checked'] = 'true'
//删除被选中的第一个值
index_arr.splice(0, 1);
console.log('skin',index_arr);
that.setData({student_id: new_itmes[key1].id,is_choose_student:true});
console.log('student_id', that.data.student_id);
} else {
//被选中少于1个,直接设置被选中
for (var i = 0; i < index_arr.length; i++) {
var key = index_arr[i]
console.log('key', key);
new_itmes[key]['checked'] = true
}
that.setData({student_id: new_itmes[key].id,is_choose_student:true});
console.log('student_id', that.data.student_id);
}
}
//存入
that.setData({
index_arr: index_arr,
// text: text,
student_list: new_itmes,
})
}
},
chooseNo(e) {
this.setData({
'modal_data.currentBtn': e.currentTarget.dataset.index,
'modal_data.is_showModal': false
});
// wx.switchTab({url: '/pages/index/index'})
wx.navigateBack({delta: 1})
},
chooseYes(e) {
this.setData({
'modal_data.currentBtn': e.currentTarget.dataset.index,
'modal_data.is_showModal': false,
});
wx.navigateTo({url: '/pages/my/buyCard/buyCard?from_appointment=' + true})
},
modalConfirm() {
this.setData({'state_data.is_showSuccessModal': false})
wx.redirectTo({url: '/pages/my/all-appointment/all-appointment?currentTab=' + 2})
},
disableScroll() {},
addStudent() {
wx.navigateTo({url: '../../index/confirm-appointment-info/add-student/add-student?is_back=' + true})
},
//获取预约详情
getAppointmentInfo() {
console.log('this.data.student_list', this.data.student_list);
let url = '/user/Reservation/reservation_detail';
let header = {
"XX-token": wx.getStorageSync('token')
};
let params = {
reservation_id: this.data.reservation_id,
};
app.post(url,params,header).then((res) => {
console.log('预约详情',res.info.status === 1);
this.setData({
detail: res.info,
});
if(this.data.detail.status === 1 && !this.data.is_buy) {
console.log('111111111111111');
this.getStudentList();
}
});
},
//更新购买状态
refreshBuyState() {
console.log('更新购买状态---学生id--人数',this.data.detail.num,this.data.is_buy,this.data.choose_student_id);
if(this.data.is_buy) {
if(this.data.detail.num<2) {
this.data.student_list.forEach((item) => {
item.checked = false;
if (item.id === this.data.choose_student_id) {
console.log('item.id', item.id);
item.checked = true;
}
});
this.setData({student_list:this.data.student_list,is_choose_student:true})
console.log('student_list',this.data.student_list);
}else if(this.data.detail.num>=2) {
console.log('购买完进入两个学员student_list',this.data.student_list);
this.data.student_list.forEach((item) => {
item.checked = false;
if (item.id === this.data.choose_student_id) {
console.log('item.id', item.id);
item.checked = true;
// total_student_num.push(item)
}
});
this.setData({student_list:this.data.student_list,is_choose_student:true,});
console.log('student_list',this.data.student_list);
}
}
},
//取消
clickCancel(e) {
console.log('取消',e);
let url = '/user/Reservation/reservation_cancel';
let header = {
"XX-token": wx.getStorageSync('token')
};
let params = {
reservation_id: this.data.reservation_id,
formId: e.detail.formId,
};
app.post(url, params,header).then((res) => {
console.log('取消',res);
// this.setData({orderList: res.list})
})
},
//确认
clickConfirm(e) {
console.log(e.detail);
if(this.data.student_list.length === 0) {
wx.showToast({title: '请添加学员!',icon:'none'})
}else if(!this.data.is_choose_student) {
wx.showToast({title: '请选择学员!',icon:'none'})
}else if(this.data.detail.num>=2 && ('' + this.data.student_id).indexOf(',') === -1) {
console.log('检验student_id',('' + this.data.student_id).indexOf(','));
wx.showToast({title:'请选择两个学员!',icon:'none'})
}else {
// this.setData({'modal_data.is_showModal': true})
let url = '/portal/Experiment/confirm_session_submit';
let header = {
"XX-token": wx.getStorageSync('token')
};
let params = {
_type: 2,//2,活动预约成功
formId: e.detail.formId,
experiment_id: this.data.detail.experiment_id,
session_id: this.data.detail.session_id,
reservation_id: this.data.reservation_id,
students: this.data.student_id,
};
app.post(url,params,header).then((res) => {
console.log('提交预约信息',res);
if(res.data.card_modal === 1) {
this.setData({'modal_data.is_showModal': true});
}else if(res.data.reservation_modal === 1) {
this.setData({'state_data.is_showSuccessModal': true});
}
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
const self =this;
console.log('load');
console.log(options);
self.setData({
currentTab: +options.currentTab?+options.currentTab:'',
reservation_id: +options.reservation_id?options.reservation_id:'',
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
console.log('show-buy',this.data.has_more,this.data.is_buy);
const self = this;
self.setData({is_choose_student: false});
self.getAppointmentInfo();
if(!self.data.is_buy) {
self.setData({has_more:true,page_number:1,student_list:[]});
self.getStudentList();
}else {
self.setData({is_choose_student: true});
}
setTimeout(function() {
self.setData({
show: true
})
}, 500)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
if (this.data.has_more) {
this.data.page_number++;
this.getStudentList();
} else {
wx.showToast({
title: '没有更多数据了~',
icon: 'none'
});
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})