|
@@ -34,7 +34,7 @@
|
34
|
34
|
</view>
|
35
|
35
|
<view class="margin-top-sm">
|
36
|
36
|
<view v-for="(h, i) in params.hobbyOther" :key="i" class="hobby"
|
37
|
|
- >{{ h }}
|
|
37
|
+ >{{ i + 1 }}.{{ h }}
|
38
|
38
|
<text class="cuIcon-close del-hobby text-red" @tap="delHobby(h)"></text>
|
39
|
39
|
</view>
|
40
|
40
|
</view>
|
|
@@ -95,9 +95,9 @@
|
95
|
95
|
>
|
96
|
96
|
<view>
|
97
|
97
|
<checkbox
|
98
|
|
- :disabled="course.status == 0"
|
99
|
98
|
:value="course.class_attend_id"
|
100
|
|
- :checked="checked.includes(course.class_attend_id)"
|
|
99
|
+ :disabled="course.status == 0"
|
|
100
|
+ :checked="checked[i].includes(course.class_attend_id)"
|
101
|
101
|
class="round cyan"
|
102
|
102
|
style="transform: scale(0.7);"
|
103
|
103
|
/>
|
|
@@ -111,11 +111,13 @@
|
111
|
111
|
<label v-for="prop in course.prop" :key="prop.id">
|
112
|
112
|
<view>
|
113
|
113
|
<checkbox
|
|
114
|
+ :checked="
|
|
115
|
+ checked_props[i][c] ? checked_props[i][c].class_attend_id === course.class_attend_id && checked_props[i][c].prop.includes(prop.id) : false
|
|
116
|
+ "
|
114
|
117
|
:disabled="course.status == 0"
|
115
|
118
|
:value="prop.id"
|
116
|
119
|
class="cyan"
|
117
|
120
|
style="transform: scale(0.7);"
|
118
|
|
- :checked="checked_props[i].class_attend_id === course.class_attend_id && checked_props[i].prop.includes(prop.id)"
|
119
|
121
|
/>{{ prop.name }}<text>¥{{ prop.money }}</text>
|
120
|
122
|
</view>
|
121
|
123
|
</label>
|
|
@@ -135,7 +137,6 @@
|
135
|
137
|
</button>
|
136
|
138
|
</view>
|
137
|
139
|
<view class="static-order flex">
|
138
|
|
- <shop-cart :class_attend_id="attend_id" @changeDisableBtn="changeDisableBtn"></shop-cart>
|
139
|
140
|
<button class="cu-btn round bg-student text-white margin-left-xs" @tap="addCart">报课</button>
|
140
|
141
|
</view>
|
141
|
142
|
</view>
|
|
@@ -148,13 +149,10 @@
|
148
|
149
|
</template>
|
149
|
150
|
|
150
|
151
|
<script>
|
151
|
|
-import { _intelligentDates, _intelligentInterests, _intelligentCourses, _intelligentGetKeys, _joinShops } from '@/api/course'
|
152
|
|
-import shopCart from '@/components/shop-cart.vue'
|
|
152
|
+import { _intelligentDates, _intelligentInterests, _intelligentCourses, _intelligentGetKeys, _joinShops, _checkConflict } from '@/api/course'
|
153
|
153
|
import { mapGetters } from 'vuex'
|
|
154
|
+import socket from '@/common/webSocket'
|
154
|
155
|
export default {
|
155
|
|
- components: {
|
156
|
|
- shopCart
|
157
|
|
- },
|
158
|
156
|
data() {
|
159
|
157
|
return {
|
160
|
158
|
topHeader: this.globalCustomBarHeight,
|
|
@@ -189,13 +187,15 @@ export default {
|
189
|
187
|
colors: ['#0CAAF4', '#082FCC', '#FDC534', '#09E294'],
|
190
|
188
|
checked: [], // 选中
|
191
|
189
|
checked_props: [], // 选中工具
|
|
190
|
+ checkedIds: [], //已选中选项
|
|
191
|
+ conflictIds: [], //冲突选项
|
192
|
192
|
attend_id: 0, // 添加成功课程
|
193
|
193
|
disableBtn: false, // 避免多次重复点击
|
194
|
194
|
action: 'stopmove'
|
195
|
195
|
}
|
196
|
196
|
},
|
197
|
197
|
computed: {
|
198
|
|
- ...mapGetters(['kid'])
|
|
198
|
+ ...mapGetters(['kid', 'ifConnectOrder'])
|
199
|
199
|
},
|
200
|
200
|
onLoad(options) {
|
201
|
201
|
const id = decodeURIComponent(options.package_id)
|
|
@@ -209,19 +209,36 @@ export default {
|
209
|
209
|
methods: {
|
210
|
210
|
init() {
|
211
|
211
|
this.getDateConfig()
|
212
|
|
- this.getHobbyConfig()
|
|
212
|
+ socket.initSocket()
|
213
|
213
|
},
|
214
|
214
|
getDateConfig() {
|
215
|
215
|
_intelligentDates().then(res => {
|
216
|
216
|
this.days = res.data
|
217
|
217
|
})
|
218
|
218
|
},
|
|
219
|
+ checkConflict(id) {
|
|
220
|
+ return new Promise((resolve, reject) => {
|
|
221
|
+ if (this.checkedIds.length < 1) {
|
|
222
|
+ resolve(false)
|
|
223
|
+ return
|
|
224
|
+ }
|
|
225
|
+ const params = {
|
|
226
|
+ checked: id,
|
|
227
|
+ ids: this.checkedIds.join(',')
|
|
228
|
+ }
|
|
229
|
+ _checkConflict(params).then(res => {
|
|
230
|
+ this.checkedIds = res.data.checked_list.map(item => item.class_attend_id)
|
|
231
|
+ this.conflictIds = res.data.conflict_list.map(item => item.class_attend_id)
|
|
232
|
+ resolve(res.data.checked_res)
|
|
233
|
+ })
|
|
234
|
+ })
|
|
235
|
+ },
|
219
|
236
|
getHobbyConfig() {
|
220
|
|
- _intelligentInterests().then(res => {
|
221
|
|
- // this.interests = res.data
|
|
237
|
+ const params = { week: this.params.week.join(',') }
|
|
238
|
+ _intelligentInterests(params).then(res => {
|
222
|
239
|
const choose = res.data[res.data.length - 1]
|
223
|
240
|
this.params.hobby = [choose.id]
|
224
|
|
- this.keys = [...new Set(choose.names)].filter(e => e)
|
|
241
|
+ this.keys = [...new Set(Object.values(choose.names))].filter(e => e)
|
225
|
242
|
if (this.interests.length < 1) this.interests = this.keys.slice(0, 5)
|
226
|
243
|
})
|
227
|
244
|
},
|
|
@@ -239,6 +256,7 @@ export default {
|
239
|
256
|
const params = { week: this.params.week.join(','), student_id: this.kid, keywords: key }
|
240
|
257
|
_intelligentGetKeys(params).then(res => {
|
241
|
258
|
if (res.data.length < 1) {
|
|
259
|
+ this.params.hobbyOther = this.params.hobbyOther.filter(k => k != key)
|
242
|
260
|
uni.showToast({
|
243
|
261
|
title: '未找到相关课程',
|
244
|
262
|
icon: 'none',
|
|
@@ -257,17 +275,25 @@ export default {
|
257
|
275
|
this.checked = [] //初始化选项
|
258
|
276
|
if (this.attends.length > 0) {
|
259
|
277
|
this.attends.map((course, index) => {
|
260
|
|
- //过滤不能报课的
|
261
|
278
|
const list = course.list
|
262
|
279
|
const item = list[0]
|
263
|
280
|
const class_attend_id = item.status > 0 ? item.class_attend_id : null
|
264
|
|
- this.$set(this.checked, index, class_attend_id)
|
|
281
|
+ this.$set(this.checked, index, [class_attend_id])
|
265
|
282
|
const prop = item.prop.length > 0 ? [item.prop[0].id] : []
|
266
|
|
- this.$set(this.checked_props, index, { class_attend_id: class_attend_id, prop: prop })
|
|
283
|
+ this.$set(this.checked_props, index, [{ class_attend_id: class_attend_id, prop: prop }])
|
267
|
284
|
})
|
|
285
|
+ this.checkedIds = this.getCheckedIds()
|
268
|
286
|
}
|
269
|
287
|
})
|
270
|
288
|
},
|
|
289
|
+ getCheckedIds() {
|
|
290
|
+ //获取默认选择集合
|
|
291
|
+ let arr = []
|
|
292
|
+ this.checked.forEach(v => {
|
|
293
|
+ arr = arr.concat(v)
|
|
294
|
+ })
|
|
295
|
+ return arr.filter(e => e)
|
|
296
|
+ },
|
271
|
297
|
delHobby(key) {
|
272
|
298
|
this.params.hobbyOther = this.params.hobbyOther.filter(item => item != key)
|
273
|
299
|
},
|
|
@@ -307,6 +333,9 @@ export default {
|
307
|
333
|
uni.showToast({ title: '请先选择兴趣', icon: 'none' })
|
308
|
334
|
return false
|
309
|
335
|
}
|
|
336
|
+ if (index === 1) {
|
|
337
|
+ this.getHobbyConfig()
|
|
338
|
+ }
|
310
|
339
|
const step = Math.abs(index - this.cur)
|
311
|
340
|
if (step > 1) return false
|
312
|
341
|
this.cur = index
|
|
@@ -320,27 +349,61 @@ export default {
|
320
|
349
|
changeDisableBtn() {
|
321
|
350
|
this.disableBtn = true
|
322
|
351
|
},
|
323
|
|
- classChange(course, i) {
|
|
352
|
+ async classChange(course, i) {
|
|
353
|
+ //失效课程点击无效
|
324
|
354
|
if (course.status == 0) {
|
325
|
355
|
return false
|
326
|
356
|
}
|
327
|
357
|
const class_attend_id = course.class_attend_id
|
328
|
|
- if (this.checked.includes(class_attend_id)) {
|
329
|
|
- this.$set(this.checked, i, null)
|
330
|
|
- this.$set(this.checked_props, i, { class_attend_id: null, prop: [] })
|
|
358
|
+ if (this.checked[i].includes(class_attend_id)) {
|
|
359
|
+ this.batchCancel([class_attend_id])
|
331
|
360
|
} else {
|
332
|
|
- this.$set(this.checked, i, class_attend_id)
|
333
|
|
- this.$set(this.checked_props, i, { class_attend_id: class_attend_id, prop: [] })
|
|
361
|
+ //判断课程冲突
|
|
362
|
+ const pass = await this.checkConflict(course.class_attend_id)
|
|
363
|
+ if (pass) {
|
|
364
|
+ //冲突取消之前选择
|
|
365
|
+ uni.showToast({ title: '存在课程时间冲突,已取消冲突课程!', icon: 'none', duration: 2000 })
|
|
366
|
+ this.batchCancel(this.conflictIds)
|
|
367
|
+ }
|
|
368
|
+ this.batchChoose(class_attend_id, [])
|
334
|
369
|
}
|
335
|
370
|
},
|
336
|
|
- propChange(e, i) {
|
|
371
|
+ async propChange(e, i) {
|
337
|
372
|
const parentId = e.target.dataset.id
|
338
|
373
|
const values = e.detail.value.map(item => Number(item))
|
339
|
|
- if (values.length > 0 && !this.checked.includes(parentId)) {
|
340
|
|
- this.$set(this.checked, i, parentId)
|
|
374
|
+ if (values.length > 0 && !this.checked[i].includes(parentId)) {
|
|
375
|
+ //判断课程冲突
|
|
376
|
+ const pass = await this.checkConflict(parentId)
|
|
377
|
+ if (pass) {
|
|
378
|
+ //冲突取消之前选择
|
|
379
|
+ uni.showToast({ title: '存在课程时间冲突,已取消冲突课程!', icon: 'none', duration: 2000 })
|
|
380
|
+ this.batchCancel(this.conflictIds)
|
|
381
|
+ }
|
341
|
382
|
}
|
342
|
|
- const item = { class_attend_id: parentId, prop: values }
|
343
|
|
- this.$set(this.checked_props, i, item)
|
|
383
|
+ this.batchChoose(parentId, values)
|
|
384
|
+ },
|
|
385
|
+ batchCancel(ids) {
|
|
386
|
+ if (ids.length < 1) return false
|
|
387
|
+ this.checked.forEach((e, i) => {
|
|
388
|
+ const f = e.findIndex(c => ids.includes(c))
|
|
389
|
+ if (f >= 0) {
|
|
390
|
+ this.$set(this.checked[i], f, null)
|
|
391
|
+ this.$set(this.checked_props[i], f, { class_attend_id: null, prop: [] })
|
|
392
|
+ }
|
|
393
|
+ })
|
|
394
|
+ },
|
|
395
|
+ batchChoose(id, props) {
|
|
396
|
+ this.attends.map((course, i) => {
|
|
397
|
+ const list = course.list
|
|
398
|
+ const c = list.findIndex(e => e.class_attend_id == id)
|
|
399
|
+ if (c >= 0) {
|
|
400
|
+ const choose = list[c]
|
|
401
|
+ this.$set(this.checked[i], c, choose.class_attend_id)
|
|
402
|
+ //道具选择
|
|
403
|
+ const items = props.length > 0 ? props : choose.prop.length > 0 ? [choose.prop[0].id] : []
|
|
404
|
+ this.$set(this.checked_props[i], c, { class_attend_id: choose.class_attend_id, prop: items })
|
|
405
|
+ }
|
|
406
|
+ })
|
344
|
407
|
},
|
345
|
408
|
TabSelect(e) {
|
346
|
409
|
this.tabCur = e.currentTarget.dataset.id
|
|
@@ -348,10 +411,22 @@ export default {
|
348
|
411
|
this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50
|
349
|
412
|
},
|
350
|
413
|
addCart() {
|
351
|
|
- if (this.disableBtn) return false
|
|
414
|
+ uni.showLoading({
|
|
415
|
+ mask: true,
|
|
416
|
+ title: '加载中...'
|
|
417
|
+ })
|
|
418
|
+ //合并选中项
|
|
419
|
+ let arr = []
|
|
420
|
+ this.checked_props.forEach(v => {
|
|
421
|
+ arr = arr.concat(v)
|
|
422
|
+ })
|
|
423
|
+ if (this.disableBtn) {
|
|
424
|
+ uni.hideLoading()
|
|
425
|
+ return false
|
|
426
|
+ }
|
352
|
427
|
this.disableBtn = true
|
353
|
428
|
const _self = this
|
354
|
|
- const list = this.checked_props
|
|
429
|
+ const list = arr
|
355
|
430
|
.filter(item => item.class_attend_id)
|
356
|
431
|
.map(item => {
|
357
|
432
|
return {
|
|
@@ -361,13 +436,22 @@ export default {
|
361
|
436
|
}
|
362
|
437
|
})
|
363
|
438
|
if (list.length < 1) {
|
|
439
|
+ uni.hideLoading()
|
364
|
440
|
uni.showToast({ title: '请先选择课程', icon: 'none' })
|
365
|
441
|
this.disableBtn = false
|
366
|
442
|
return false
|
367
|
443
|
}
|
368
|
444
|
_joinShops({ list }).then(res => {
|
369
|
445
|
if (res.code === 1) {
|
370
|
|
- _self.globalNavigateTo('classCart')
|
|
446
|
+ setTimeout(() => {
|
|
447
|
+ if (!this.ifConnectOrder) {
|
|
448
|
+ // socket非正常状态
|
|
449
|
+ uni.hideLoading()
|
|
450
|
+ this.globalNavigateTo('order', { type: 1 })
|
|
451
|
+ }
|
|
452
|
+ this.disableBtn = false
|
|
453
|
+ this.$store.dispatch('setConnect', false)
|
|
454
|
+ }, 3000)
|
371
|
455
|
} else {
|
372
|
456
|
this.disableBtn = false
|
373
|
457
|
}
|
|
@@ -405,12 +489,7 @@ export default {
|
405
|
489
|
.hobby {
|
406
|
490
|
position: relative;
|
407
|
491
|
display: inline-block;
|
408
|
|
- margin-left: 20rpx;
|
409
|
|
- padding: 10rpx 40rpx;
|
410
|
|
- border-radius: 100rpx;
|
411
|
|
- border: 1px solid #eee;
|
412
|
|
- color: #fff;
|
413
|
|
- background-color: #09e294;
|
|
492
|
+ margin-left: 30rpx;
|
414
|
493
|
.del-hobby {
|
415
|
494
|
position: absolute;
|
416
|
495
|
top: -6rpx;
|