-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathlayer3.vue
107 lines (107 loc) · 3.46 KB
/
layer3.vue
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
<template>
<div class="flex-wrapper">
<wt-picker :dataSource="dataSource" @change="change"></wt-picker>
<wt-picker :dataSource="subDataSource" @change="subChange"></wt-picker>
<wt-picker :dataSource="ThreeDataSource" @change="threeChange"></wt-picker>
</div>
</template>
<script>
import layer from './layer1';
export default {
components: {
'wt-picker': layer
},
props: {
dataSource: {
type: Array,
default: () => {
return [];
}
},
filed: {
type: String,
default: () => {
return 'text';
}
},
children: {
type: String,
default: () => {
return 'children';
}
}
},
data () {
return {
lineHeight: '',
pickerIndex: 0, // 第一个选择器选择项的索引
pickerText: this.dataSource[0][this.filed],
picker2Index: 0, // 第二个选择器选择项的索引
picker2Text: this.dataSource[0][this.children][0][this.filed],
picker3Index: 0, // 第二个选择器选择项的索引
picker3Text: this.dataSource[0][this.children][0][this.children][0][this.filed],
subDataSource: [], // 第二个选择器的选项
ThreeDataSource: [] // 第三个选择器的选项
};
},
created () {
this.subDataSource = this.dataSource[0][this.children];
this.ThreeDataSource = this.dataSource[0][this.children][0][this.children];
},
mounted () {
},
methods: {
change (item, index) {
this.pickerText = item[this.filed];
this.picker2Text = item[this.children][0][this.filed];
this.picker3Text = item[this.children][0][this.children][0][this.filed];
// console.log('你选择了:' + this.pickerText + '____' + this.picker2Text + '____' + this.picker3Text);
this.pickerIndex = index;
this.picker2Index = 0;
this.picker3Index = 0;
this.subDataSource = item[this.children];
this.ThreeDataSource = item[this.children][0][this.children];
this.$children[1].rest(); // 重置第二级
this.$children[2].rest(); // 重置第三级
var code = {
one: item,
two: item[this.children][0],
three: item[this.children][0][this.children][0]
};
this.$emit('change', code, [index, 0, 0]);
},
subChange (item, index) {
this.picker2Text = item[this.filed];
this.picker3Text = item[this.children][0][this.filed];
this.picker3Index = 0;
this.ThreeDataSource = item[this.children];
// console.log('你选择了:' + this.pickerText + '____' + this.picker2Text + '____' + this.picker3Text);
this.picker2Index = index;
this.$children[2].rest(); // 重置第三级
var code = {
one: this.dataSource[this.pickerIndex],
two: item,
three: item[this.children][0]
};
this.$emit('change', code, [this.pickerIndex, index, 0]);
},
threeChange (item, index) {
this.picker3Text = item[this.filed];
this.picker3Index = index;
// console.log('你选择了:' + this.pickerText + '____' + this.picker2Text + '____' + this.picker3Text);
var code = {
one: this.dataSource[this.pickerIndex],
two: this.dataSource[this.pickerIndex][this.children][this.picker2Index],
three: item
};
this.$emit('change', code, [this.pickerIndex, this.picker2Index, index]);
}
}
};
</script>
<style lang='less' rel='stylesheet/less' scoped>
.flex-wrapper {
display: flex;
justify-content: space-around;
}
</style>