-
Notifications
You must be signed in to change notification settings - Fork 1
/
picker.vue
183 lines (177 loc) · 5.93 KB
/
picker.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
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
<template>
<div>
<div class="group center">
<div class="panel"><text class="text">{{value}}</text></div>
</div>
<div class="group">
<mpwx-btn class="btn" label='Pick 一级' id="0" @onBtnClicked="pick"></mpwx-btn>
<mpwx-btn class="btn" label='Pick 二级' id="3" @onBtnClicked="pick2"></mpwx-btn>
<mpwx-btn class="btn" label='Pick 三级' id="4" @onBtnClicked="pick3"></mpwx-btn>
<mpwx-btn class="btn" label='Pick Date' id="1" @onBtnClicked="pickDate"></mpwx-btn>
<mpwx-btn class="btn" label='Pick Time' id="2" @onBtnClicked="pickTime"></mpwx-btn>
</div>
</div>
</template>
<script>
const picker = weex.requireModule('picker');
const items1 = ['广东', '湖南', '广西'];
const items2 = [
['广州', '佛山', '东莞', '珠海'],
['长沙', '岳阳', '株洲', '衡阳'],
['桂林', '玉林']
];
const items3 = [
[
['白云区', '从化区', '海珠区', '花都区', '黄埔区', '荔湾区', '番禺区'],
['高明区', '南海区', '三水区', '顺德区'],
['茶山镇', '长安镇', '常平镇'],
['香洲区', '斗门区', '金湾区', '其它区']
],
[
['芙蓉区', '开福区', '天心区', '雨花区', '岳麓区', '望城区', '长沙县'],
['君山区', '华容县', '岳阳楼区', '云溪区'],
['荷塘区', '芦淞区', '石峰区', '天元区', '株洲县'],
['石鼓区', '雁峰区', '蒸湘区', '珠晖区', '南岳区']
],
[
['叠彩区', '临桂区', '七星区', '象山区', '秀峰区'],
['福绵区', '玉州区', '容县']
],
];
function cValue(_this) {
var ret = "";
if (_this.index1 < items1.length && _this.index1 >= 0) {
ret = items1[_this.index1] + " ";
if (_this.index2 < items2[_this.index1].length && _this.index2 >= 0) {
ret += items2[_this.index1][_this.index2] + " ";
if (_this.index3 < items3[_this.index1][_this.index2].length && _this.index3 >= 0) {
ret += items3[_this.index1][_this.index2][_this.index3] + " ";
}
}
}
ret = ret.replace(/^\s+|\s+$/gm,'');
if(ret.length < 1) {
return '---';
}else {
return ret;
}
}
import MpwxBtn from "../mpwx-btn"
export default {
components : {MpwxBtn},
data () {
return {
value: '---',
index1: -1,
index2: -1,
index3: -1,
}
},
methods: {
pick () {
picker.pick({
index1: this.index1,
index2: -1,
index3: -1,
items1: items1,
title: "Picker Title"
}, event => {
if (event.result === 'success') {
this.index1 = event.data1;
this.index2 = -1;
this.index3 = -1;
this.value = cValue(this);
}
})
},
pick2 () {
picker.pick({
index1: this.index1,
index2: this.index2,
index3: -1,
items1: items1,
items2: items2,
title: "Picker Title"
}, event => {
if (event.result === 'success') {
this.index1 = event.data1;
this.index2 = event.data2;
this.index3 = -1;
this.value = cValue(this);
}
})
},
pick3 () {
picker.pick({
index1: this.index1,
index2: this.index2,
index3: this.index3,
items1: items1,
items2: items2,
items3: items3,
title: "Picker Title"
}, event => {
if (event.result === 'success') {
this.index1 = event.data1;
this.index2 = event.data2;
this.index3 = event.data3;
this.value = cValue(this);
}
})
},
pickTime () {
picker.pickTime({
value: "09:30:01",
title: "Picker Title"
}, event => {
if (event.result === 'success') {
this.value = event.data
}
})
},
pickDate () {
picker.pickDate({
value: "2017-01-22",
max: '2029-11-28',
min: '2005-11-28',
title: "Picker Title"
}, event => {
if (event.result === 'success') {
this.value = event.data
}
})
}
}
}
</script>
<style scoped>
.panel {
height: 100px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
.group {
flex-direction: column;
width: 650px;
margin-left: 50px;
margin-top: 50px;
}
.center {
justify-content: center;
}
.text {
font-size: 50px;
text-align: center;
padding-left: 25px;
padding-right: 25px;
color: #41B883;
}
.btn {
margin-bottom: 12px;
margin-top: 12px;
}
</style>