list.js
1.65 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
Component({
mixins: [],
data: {
comSelectListId: 0,
comSelectList: []
},
props: {
iconType: 'icon',
complete: false,
multiple: false,
},
didMount() {
this.setData({
comSelectListId: this.props.comSelectListId,
comSelectList: this.props.comSelectList
})
},
didUpdate() {
this.setData({
comSelectListId: this.props.comSelectListId
})
},
didUnmount() { },
methods: {
comSelectList(event) {
if (this.props.multiple && event.currentTarget.dataset.item.id != -1) {
if (this.data.comSelectList.includes(-1)) {
this.setData({
comSelectList: []
})
}
if (this.data.comSelectList.includes(event.target.dataset.item.id)) {
this.data.comSelectList.forEach((item, index) => {
if (item == event.target.dataset.item.id) {
this.data.comSelectList.splice(index, 1)
}
return
})
}
else {
this.data.comSelectList.push(event.target.dataset.item.id)
}
this.setData({
comSelectList: this.data.comSelectList
})
} else if (this.props.multiple && event.currentTarget.dataset.item.id == -1) {
this.setData({
comSelectList: [-1]
})
}
else if (!this.props.multiple) {
this.setData({
comSelectListId: event.currentTarget.dataset.item.id
})
this.props.onComSelectList(event)
}
},
complete(event) {
let comSelectList = this.data.comSelectList.sort((a, b) => {
return a - b
})
this.props.onCompelete(comSelectList)
}
},
});