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
| Component({
| /**
| * 组件的属性列表
| * data: [{name:'标题',key:'字段key',data:[{ label:'', vlaue:'',children:[] }]}], 数据源
| * active: {'key':''}, 当前选中
| * menuTextAlign, 是否居中标题
| */
| properties: {
| data: {
| type: Array,
| value: [],
| },
| active: {
| type: Object,
| value: {},
| },
| menuTextAlign: {
| type: Boolean,
| value: false,
| },
| },
|
| /**
| * 组件的初始数据
| */
| data: {
| myActive: {}, // 当前选择的value,用于校验切换时重置
| dataIndex: null, // 当前选中的data数据的下标
| dataActive: { data: [] },
| activeName: {}, // 选中的标题
| },
|
| observers: {
| active: function (data) {
| let visible = false;
| for (let item in this.data.myActive) {
| if (this.data.myActive[item] !== data[item] && this.data.myActive[item]) {
| visible = true;
| }
| }
| if (visible) this.setData({ activeName: {} });
| },
| },
|
| /**
| * 组件的方法列表
| */
| methods: {
| // 选择item
| _handleClickItem(e) {
| let item = e.currentTarget.dataset.item;
| if (item.children) {
| // 存在子集则是标题不可选择
| return;
| }
| this.data.activeName[this.data.dataActive.key] = item.label;
| let activeCopy = { ...this.data.active };
| activeCopy[this.data.dataActive.key] = item.value;
| this.data.myActive[this.data.dataActive.key] = item.value;
| this.triggerEvent('ongetvalue', activeCopy);
| this.setData({ activeName: this.data.activeName, dataIndex: null, dataActive: { data: [] }, myActive: this.data.myActive });
| },
| // 选择
| _handleSelectData(e) {
| let index = e.currentTarget.dataset.index;
| this.setData({ dataIndex: index, dataActive: this.data.data[index] });
| },
| // 取消
| _handleClose() {
| this.setData({ dataIndex: null, dataActive: { data: [] } });
| },
| },
| });
|
|