|
|
@@ -1,77 +1,114 @@
|
|
1
|
1
|
<template name="cascade-picker">
|
|
2
|
|
- <view class="aui-picker" v-if="SHOW" :class="{'aui-picker-in': FADE==1,'aui-picker-out': FADE==0}">
|
|
|
2
|
+ <view
|
|
|
3
|
+ class="aui-picker"
|
|
|
4
|
+ v-if="SHOW"
|
|
|
5
|
+ :class="{ 'aui-picker-in': FADE == 1, 'aui-picker-out': FADE == 0 }"
|
|
|
6
|
+ >
|
|
3
|
7
|
<view class="aui-mask" @click.stop="close"></view>
|
|
4
|
8
|
<view class="aui-picker-main">
|
|
5
|
9
|
<view class="aui-picker-header">
|
|
6
|
10
|
<view class="aui-picker-header-icon" @click.stop="close">取消</view>
|
|
7
|
11
|
<view class="aui-picker-title" v-if="title">{{ title }}</view>
|
|
8
|
|
- <view class="aui-picker-header-icon aui-picker-confirm" @click.stop="_confirm">确认</view>
|
|
|
12
|
+ <view
|
|
|
13
|
+ class="aui-picker-header-icon aui-picker-confirm"
|
|
|
14
|
+ @click.stop="_confirm"
|
|
|
15
|
+ >确认</view
|
|
|
16
|
+ >
|
|
9
|
17
|
</view>
|
|
10
|
18
|
<view class="aui-picker-nav">
|
|
11
|
|
- <view class="aui-picker-navitem"
|
|
12
|
|
- v-if="nav.length>0"
|
|
13
|
|
- v-for="(item, index) in nav"
|
|
14
|
|
- :key="index"
|
|
15
|
|
- :data-index="index"
|
|
16
|
|
- :class="[index==navCurrentIndex ? 'active' : '', 'aui-picker-navitem-'+index]"
|
|
17
|
|
- :style="{margin: nav.length>2 ? '0 25rpx 0 0' : '0 45rpx 0 0'}"
|
|
18
|
|
- @click.stop="_changeNav($event)"
|
|
19
|
|
- >{{ item.name }}
|
|
|
19
|
+ <view
|
|
|
20
|
+ class="aui-picker-navitem"
|
|
|
21
|
+ v-if="nav.length > 0"
|
|
|
22
|
+ v-for="(item, index) in nav"
|
|
|
23
|
+ :key="index"
|
|
|
24
|
+ :data-index="index"
|
|
|
25
|
+ :class="[
|
|
|
26
|
+ index == navCurrentIndex ? 'active' : '',
|
|
|
27
|
+ 'aui-picker-navitem-' + index,
|
|
|
28
|
+ ]"
|
|
|
29
|
+ :style="{ margin: nav.length > 2 ? '0 25rpx 0 0' : '0 45rpx 0 0' }"
|
|
|
30
|
+ @click.stop="_changeNav($event)"
|
|
|
31
|
+ >{{ item.name }}
|
|
20
|
32
|
</view>
|
|
21
|
|
- <view class="aui-picker-navitem"
|
|
22
|
|
- :key="nav.length"
|
|
23
|
|
- :data-index="nav.length"
|
|
24
|
|
- :class="[nav.length==navCurrentIndex ? 'active' : '', 'aui-picker-navitem-'+nav.length]"
|
|
25
|
|
- :style="{margin: nav.length>2 ? '0 25rpx 0 0' : '0 45rpx 0 0'}"
|
|
26
|
|
- @click.stop="_changeNav($event)">请选择
|
|
|
33
|
+ <view
|
|
|
34
|
+ class="aui-picker-navitem"
|
|
|
35
|
+ :key="nav.length"
|
|
|
36
|
+ :data-index="nav.length"
|
|
|
37
|
+ :class="[
|
|
|
38
|
+ nav.length == navCurrentIndex ? 'active' : '',
|
|
|
39
|
+ 'aui-picker-navitem-' + nav.length,
|
|
|
40
|
+ ]"
|
|
|
41
|
+ :style="{ margin: nav.length > 2 ? '0 25rpx 0 0' : '0 45rpx 0 0' }"
|
|
|
42
|
+ @click.stop="_changeNav($event)"
|
|
|
43
|
+ >请选择
|
|
27
|
44
|
</view>
|
|
28
|
|
- <view class="aui-picker-navborder" :style="{left: navBorderLeft+'px'}"></view>
|
|
|
45
|
+ <view
|
|
|
46
|
+ class="aui-picker-navborder"
|
|
|
47
|
+ :style="{ left: navBorderLeft + 'px' }"
|
|
|
48
|
+ ></view>
|
|
29
|
49
|
</view>
|
|
30
|
50
|
<view class="aui-picker-content">
|
|
31
|
51
|
<view class="aui-picker-lists">
|
|
32
|
|
- <view class="aui-picker-list"
|
|
33
|
|
- v-for="(list, index) in queryItems.length + 1"
|
|
34
|
|
- :key="index"
|
|
35
|
|
- :data-index="index"
|
|
36
|
|
- :class="[index==navCurrentIndex ? 'active' : '']"
|
|
|
52
|
+ <view
|
|
|
53
|
+ class="aui-picker-list"
|
|
|
54
|
+ v-for="(list, index) in queryItems.length + 1"
|
|
|
55
|
+ :key="index"
|
|
|
56
|
+ :data-index="index"
|
|
|
57
|
+ :class="[index == navCurrentIndex ? 'active' : '']"
|
|
37
|
58
|
>
|
|
38
|
59
|
<view class="aui-picker-list-warp" v-if="index == 0">
|
|
39
|
|
- <view class="aui-picker-item"
|
|
40
|
|
- v-for="(item, key) in items"
|
|
41
|
|
- v-if="item.pid=='0'"
|
|
42
|
|
- :key="key"
|
|
43
|
|
- :data-pindex="index"
|
|
44
|
|
- :data-index="key"
|
|
45
|
|
- :data-id="item.id"
|
|
46
|
|
- :data-pid="item.pid"
|
|
47
|
|
- :data-name="item.name"
|
|
48
|
|
- :data-type="item.type"
|
|
49
|
|
- :class="{'active': result.length>index && result[index].id==item.id}"
|
|
50
|
|
- :style="{'background': touchConfig.index==key && touchConfig.pindex==index ? touchConfig.style.background : ''}"
|
|
51
|
|
- @click.stop="_chooseItem($event)"
|
|
52
|
|
- @touchstart="_btnTouchStart($event)"
|
|
53
|
|
- @touchmove="_btnTouchEnd($event)"
|
|
54
|
|
- @touchend="_btnTouchEnd($event)"
|
|
55
|
|
- >{{ item.name }}
|
|
|
60
|
+ <view
|
|
|
61
|
+ class="aui-picker-item"
|
|
|
62
|
+ v-for="(item, key) in items"
|
|
|
63
|
+ v-if="item.pid == '0'"
|
|
|
64
|
+ :key="key"
|
|
|
65
|
+ :data-pindex="index"
|
|
|
66
|
+ :data-index="key"
|
|
|
67
|
+ :data-id="item.id"
|
|
|
68
|
+ :data-pid="item.pid"
|
|
|
69
|
+ :data-name="item.name"
|
|
|
70
|
+ :data-type="item.type"
|
|
|
71
|
+ :class="{
|
|
|
72
|
+ active: result.length > index && result[index].id == item.id,
|
|
|
73
|
+ }"
|
|
|
74
|
+ :style="{
|
|
|
75
|
+ background:
|
|
|
76
|
+ touchConfig.index == key && touchConfig.pindex == index
|
|
|
77
|
+ ? touchConfig.style.background
|
|
|
78
|
+ : '',
|
|
|
79
|
+ }"
|
|
|
80
|
+ @click.stop="_chooseItem($event)"
|
|
|
81
|
+ @touchstart="_btnTouchStart($event)"
|
|
|
82
|
+ @touchmove="_btnTouchEnd($event)"
|
|
|
83
|
+ @touchend="_btnTouchEnd($event)"
|
|
|
84
|
+ >{{ item.name }}
|
|
56
|
85
|
</view>
|
|
57
|
86
|
</view>
|
|
58
|
87
|
<view class="aui-picker-list-warp" v-else>
|
|
59
|
|
- <view class="aui-picker-item"
|
|
60
|
|
- v-for="(item, key) in queryItems[index-1]"
|
|
61
|
|
- :key="key"
|
|
62
|
|
- :data-pindex="index"
|
|
63
|
|
- :data-index="key"
|
|
64
|
|
- :data-id="item.id"
|
|
65
|
|
- :data-pid="item.pid"
|
|
66
|
|
- :data-name="item.name"
|
|
67
|
|
- :data-type="item.type"
|
|
68
|
|
- :class="{'active': result.length>index && result[index].id==item.id}"
|
|
69
|
|
- :style="{'background': touchConfig.index==key && touchConfig.pindex==index ? touchConfig.style.background : ''}"
|
|
70
|
|
- @click.stop="_chooseItem($event)"
|
|
71
|
|
- @touchstart="_btnTouchStart($event)"
|
|
72
|
|
- @touchmove="_btnTouchEnd($event)"
|
|
73
|
|
- @touchend="_btnTouchEnd($event)"
|
|
74
|
|
- >{{ item.name }}
|
|
|
88
|
+ <view
|
|
|
89
|
+ class="aui-picker-item"
|
|
|
90
|
+ v-for="(item, key) in queryItems[index - 1]"
|
|
|
91
|
+ :key="key"
|
|
|
92
|
+ :data-pindex="index"
|
|
|
93
|
+ :data-index="key"
|
|
|
94
|
+ :data-id="item.id"
|
|
|
95
|
+ :data-pid="item.pid"
|
|
|
96
|
+ :data-name="item.name"
|
|
|
97
|
+ :data-type="item.type"
|
|
|
98
|
+ :class="{
|
|
|
99
|
+ active: result.length > index && result[index].id == item.id,
|
|
|
100
|
+ }"
|
|
|
101
|
+ :style="{
|
|
|
102
|
+ background:
|
|
|
103
|
+ touchConfig.index == key && touchConfig.pindex == index
|
|
|
104
|
+ ? touchConfig.style.background
|
|
|
105
|
+ : '',
|
|
|
106
|
+ }"
|
|
|
107
|
+ @click.stop="_chooseItem($event)"
|
|
|
108
|
+ @touchstart="_btnTouchStart($event)"
|
|
|
109
|
+ @touchmove="_btnTouchEnd($event)"
|
|
|
110
|
+ @touchend="_btnTouchEnd($event)"
|
|
|
111
|
+ >{{ item.name }}
|
|
75
|
112
|
</view>
|
|
76
|
113
|
</view>
|
|
77
|
114
|
</view>
|
|
|
@@ -83,24 +120,32 @@
|
|
83
|
120
|
|
|
84
|
121
|
<script>
|
|
85
|
122
|
export default {
|
|
86
|
|
- name: 'cascade-picker',
|
|
|
123
|
+ name: "cascade-picker",
|
|
87
|
124
|
props: {
|
|
88
|
|
- title: { //标题
|
|
|
125
|
+ title: {
|
|
|
126
|
+ //标题
|
|
89
|
127
|
type: String,
|
|
90
|
|
- default: ''
|
|
|
128
|
+ default: "",
|
|
91
|
129
|
},
|
|
92
|
|
- layer: { //控制几级联动,默认无限级(跟随数据有无下级)
|
|
|
130
|
+ layer: {
|
|
|
131
|
+ //控制几级联动,默认无限级(跟随数据有无下级)
|
|
93
|
132
|
type: Number,
|
|
94
|
|
- default: null
|
|
|
133
|
+ default: null,
|
|
95
|
134
|
},
|
|
96
|
|
- data: { //数据 如:[{id: '', name: '', children: [{id: '', name: ''}]}]
|
|
|
135
|
+ data: {
|
|
|
136
|
+ //数据 如:[{id: '', name: '', children: [{id: '', name: ''}]}]
|
|
97
|
137
|
type: Array,
|
|
98
|
138
|
default() {
|
|
99
|
139
|
return [
|
|
100
|
140
|
// [{id: '', name: '', children: [{id: '', name: ''}]}]
|
|
101
|
|
- ]
|
|
102
|
|
- }
|
|
103
|
|
- }
|
|
|
141
|
+ ];
|
|
|
142
|
+ },
|
|
|
143
|
+ },
|
|
|
144
|
+ value: {
|
|
|
145
|
+ // 新增初始选中值
|
|
|
146
|
+ type: Array,
|
|
|
147
|
+ default: () => [],
|
|
|
148
|
+ },
|
|
104
|
149
|
},
|
|
105
|
150
|
data() {
|
|
106
|
151
|
return {
|
|
|
@@ -116,27 +161,27 @@ export default {
|
|
116
|
161
|
index: -1,
|
|
117
|
162
|
pindex: -1,
|
|
118
|
163
|
style: {
|
|
119
|
|
- color: '#214579',
|
|
120
|
|
- background: '#EFEFEF'
|
|
121
|
|
- }
|
|
|
164
|
+ color: "#214579",
|
|
|
165
|
+ background: "#EFEFEF",
|
|
|
166
|
+ },
|
|
122
|
167
|
},
|
|
123
|
|
- selectedData: [] // 用于回显数据的属性
|
|
124
|
|
- }
|
|
|
168
|
+ selectedData: [], // 用于回显数据的属性
|
|
|
169
|
+ };
|
|
125
|
170
|
},
|
|
126
|
171
|
watch: {
|
|
127
|
172
|
data() {
|
|
128
|
173
|
const _this = this;
|
|
129
|
174
|
const data = _this.data;
|
|
130
|
|
- _this.items = _this._flatten(data, '0')
|
|
131
|
|
- console.log(_this.items,"_this.items")
|
|
132
|
|
- }
|
|
|
175
|
+ _this.items = _this._flatten(data, "0");
|
|
|
176
|
+ console.log(_this.items, "_this.items");
|
|
|
177
|
+ },
|
|
133
|
178
|
},
|
|
134
|
179
|
methods: {
|
|
135
|
180
|
// 打开
|
|
136
|
181
|
open() {
|
|
137
|
182
|
const _this = this;
|
|
138
|
183
|
_this.reset(); //打开时重置picker
|
|
139
|
|
- // _this._restoreSelectedData()
|
|
|
184
|
+ // _this._restoreSelectedData()
|
|
140
|
185
|
return new Promise(function (resolve, reject) {
|
|
141
|
186
|
_this.SHOW = true;
|
|
142
|
187
|
_this.FADE = 1;
|
|
|
@@ -153,7 +198,7 @@ export default {
|
|
153
|
198
|
_this.FADE = -1;
|
|
154
|
199
|
clearTimeout(_hidetimer);
|
|
155
|
200
|
resolve();
|
|
156
|
|
- }, 100)
|
|
|
201
|
+ }, 100);
|
|
157
|
202
|
});
|
|
158
|
203
|
},
|
|
159
|
204
|
//重置
|
|
|
@@ -170,10 +215,15 @@ export default {
|
|
170
|
215
|
const _this = this;
|
|
171
|
216
|
const index = Number(e.currentTarget.dataset.index);
|
|
172
|
217
|
_this.navCurrentIndex = index;
|
|
173
|
|
- const _el = uni.createSelectorQuery().in(this).select(".aui-picker-navitem-" + index);
|
|
174
|
|
- _el.boundingClientRect(data => {
|
|
175
|
|
- _this.navBorderLeft = data.left + 10;
|
|
176
|
|
- }).exec();
|
|
|
218
|
+ const _el = uni
|
|
|
219
|
+ .createSelectorQuery()
|
|
|
220
|
+ .in(this)
|
|
|
221
|
+ .select(".aui-picker-navitem-" + index);
|
|
|
222
|
+ _el
|
|
|
223
|
+ .boundingClientRect((data) => {
|
|
|
224
|
+ _this.navBorderLeft = data.left + 10;
|
|
|
225
|
+ })
|
|
|
226
|
+ .exec();
|
|
177
|
227
|
},
|
|
178
|
228
|
//数据选择
|
|
179
|
229
|
_chooseItem(e) {
|
|
|
@@ -183,54 +233,93 @@ export default {
|
|
183
|
233
|
const pid = e.currentTarget.dataset.pid;
|
|
184
|
234
|
const type = e.currentTarget.dataset.type;
|
|
185
|
235
|
const _arr = [];
|
|
186
|
|
- _this.result[_this.navCurrentIndex] = {id: id, name: name, pid: pid, type: type};
|
|
|
236
|
+ // _this.result[_this.navCurrentIndex] = {
|
|
|
237
|
+ // id: id,
|
|
|
238
|
+ // name: name,
|
|
|
239
|
+ // pid: pid,
|
|
|
240
|
+ // type: type,
|
|
|
241
|
+ // };
|
|
|
242
|
+ const item = {
|
|
|
243
|
+ id: e.currentTarget.dataset.id,
|
|
|
244
|
+ name: e.currentTarget.dataset.name,
|
|
|
245
|
+ pid: e.currentTarget.dataset.pid,
|
|
|
246
|
+ type: e.currentTarget.dataset.type,
|
|
|
247
|
+ };
|
|
|
248
|
+ // 清除后续层级数据
|
|
|
249
|
+ _this.result = _this.result.slice(0, _this.navCurrentIndex + 1);
|
|
|
250
|
+ _this.result[_this.navCurrentIndex] = item;
|
|
|
251
|
+ _this.queryItems = _this.queryItems.slice(0, _this.navCurrentIndex);
|
|
|
252
|
+ _this.nav = _this.nav.slice(0, _this.navCurrentIndex);
|
|
187
|
253
|
if (
|
|
188
|
|
- (!_this._isDefine(_this.layer) && _this._isDefine(_this._deepQuery(_this.data, id).children))
|
|
189
|
|
- ||
|
|
190
|
|
- (_this.navCurrentIndex < (Number(_this.layer) - 1) && _this._isDefine(_this._deepQuery(_this.data, id).children))
|
|
191
|
|
- ) { //有下级数据
|
|
192
|
|
- _this._deepQuery(_this.data, id).children.forEach(function (item, index) {
|
|
193
|
|
- _arr.push({id: item.id, name: item.name, pid: id, type: item.type});
|
|
194
|
|
- });
|
|
195
|
|
- if (_this.navCurrentIndex == _this.queryItems.length) { //选择数据
|
|
|
254
|
+ (!_this._isDefine(_this.layer) &&
|
|
|
255
|
+ _this._isDefine(_this._deepQuery(_this.data, id).children)) ||
|
|
|
256
|
+ (_this.navCurrentIndex < Number(_this.layer) - 1 &&
|
|
|
257
|
+ _this._isDefine(_this._deepQuery(_this.data, id).children))
|
|
|
258
|
+ ) {
|
|
|
259
|
+ //有下级数据
|
|
|
260
|
+ _this
|
|
|
261
|
+ ._deepQuery(_this.data, id)
|
|
|
262
|
+ .children.forEach(function (item, index) {
|
|
|
263
|
+ _arr.push({
|
|
|
264
|
+ id: item.id,
|
|
|
265
|
+ name: item.name,
|
|
|
266
|
+ pid: id,
|
|
|
267
|
+ type: item.type,
|
|
|
268
|
+ });
|
|
|
269
|
+ });
|
|
|
270
|
+ if (_this.navCurrentIndex == _this.queryItems.length) {
|
|
|
271
|
+ //选择数据
|
|
196
|
272
|
_this.queryItems.push(_arr);
|
|
197
|
|
- _this.nav.push({name: name});
|
|
198
|
|
- } else { //重新选择数据
|
|
|
273
|
+ _this.nav.push({ name: name });
|
|
|
274
|
+ } else {
|
|
|
275
|
+ //重新选择数据
|
|
199
|
276
|
_this.queryItems.splice(_this.navCurrentIndex + 1, 1);
|
|
200
|
277
|
_this.nav.splice(_this.navCurrentIndex + 1, 1);
|
|
201
|
278
|
_this.queryItems.splice(_this.navCurrentIndex, 1, _arr);
|
|
202
|
|
- _this.nav.splice(_this.navCurrentIndex, 1, {name: name});
|
|
|
279
|
+ _this.nav.splice(_this.navCurrentIndex, 1, { name: name });
|
|
203
|
280
|
}
|
|
204
|
281
|
_this.navCurrentIndex = _this.navCurrentIndex + 1;
|
|
205
|
|
- const _el = uni.createSelectorQuery().in(this).select(".aui-picker-navitem-" + _this.navCurrentIndex);
|
|
|
282
|
+ const _el = uni
|
|
|
283
|
+ .createSelectorQuery()
|
|
|
284
|
+ .in(this)
|
|
|
285
|
+ .select(".aui-picker-navitem-" + _this.navCurrentIndex);
|
|
206
|
286
|
setTimeout(() => {
|
|
207
|
|
- _el.boundingClientRect(data => {
|
|
208
|
|
- _this.navBorderLeft = data.left + 10;
|
|
209
|
|
- }).exec();
|
|
210
|
|
- }, 100)
|
|
211
|
|
- } else { //无下级数据且最后一级数据的type为1时,则可以确认关闭
|
|
212
|
|
- // console.log(_this.result,type,"typetypetypetypetype",e.currentTarget.dataset)
|
|
|
287
|
+ _el
|
|
|
288
|
+ .boundingClientRect((data) => {
|
|
|
289
|
+ _this.navBorderLeft = data.left + 10;
|
|
|
290
|
+ })
|
|
|
291
|
+ .exec();
|
|
|
292
|
+ }, 100);
|
|
|
293
|
+ } else {
|
|
|
294
|
+ //无下级数据且最后一级数据的type为1时,则可以确认关闭
|
|
|
295
|
+ // console.log(_this.result,type,"typetypetypetypetype",e.currentTarget.dataset)
|
|
213
|
296
|
_this._confirm();
|
|
214
|
297
|
}
|
|
215
|
298
|
},
|
|
|
299
|
+ _hasChildren(id) {
|
|
|
300
|
+ return this._deepQuery(this.data, id)?.children?.length > 0;
|
|
|
301
|
+ },
|
|
216
|
302
|
_confirm() {
|
|
217
|
303
|
const _this = this;
|
|
218
|
304
|
const lastItem = _this.result[_this.result.length - 1];
|
|
219
|
|
- console.log(lastItem)
|
|
220
|
|
- console.log(_this.result)
|
|
|
305
|
+ console.log(lastItem);
|
|
|
306
|
+ console.log(_this.result);
|
|
221
|
307
|
if (lastItem && lastItem.type === 1) {
|
|
222
|
308
|
_this.close().then(() => {
|
|
223
|
|
- _this.selectedData = [..._this.result]; // 保存选择的数据
|
|
224
|
|
- _this.$emit("callback", {status: 0, data: _this.result});
|
|
|
309
|
+ _this.selectedData = [..._this.result]; // 保存选择的数据
|
|
|
310
|
+ _this.$emit("callback", { status: 0, data: _this.result });
|
|
225
|
311
|
});
|
|
226
|
312
|
} else {
|
|
227
|
|
- uni.$u.toast('请选择最后一级分类')
|
|
|
313
|
+ uni.$u.toast("请选择最后一级分类");
|
|
228
|
314
|
}
|
|
229
|
315
|
},
|
|
230
|
316
|
//递归遍历——将树形结构数据转化为数组格式
|
|
231
|
317
|
_flatten(tree, pid) {
|
|
232
|
|
- return tree.reduce((arr, {id, name, type, children = []}) =>
|
|
233
|
|
- arr.concat([{id, name, pid, type}], this._flatten(children, id)), [])
|
|
|
318
|
+ return tree.reduce(
|
|
|
319
|
+ (arr, { id, name, type, children = [] }) =>
|
|
|
320
|
+ arr.concat([{ id, name, pid, type }], this._flatten(children, id)),
|
|
|
321
|
+ []
|
|
|
322
|
+ );
|
|
234
|
323
|
},
|
|
235
|
324
|
//根据id查询对应的数据(如查询id=10100对应的对象)
|
|
236
|
325
|
_deepQuery(tree, id) {
|
|
|
@@ -258,7 +347,16 @@ export default {
|
|
258
|
347
|
@example: aui.isDefine("变量");
|
|
259
|
348
|
*/
|
|
260
|
349
|
_isDefine(str) {
|
|
261
|
|
- if (str == null || str == "" || str == "undefined" || str == undefined || str == "null" || str == "(null)" || str == 'NULL' || typeof (str) == 'undefined') {
|
|
|
350
|
+ if (
|
|
|
351
|
+ str == null ||
|
|
|
352
|
+ str == "" ||
|
|
|
353
|
+ str == "undefined" ||
|
|
|
354
|
+ str == undefined ||
|
|
|
355
|
+ str == "null" ||
|
|
|
356
|
+ str == "(null)" ||
|
|
|
357
|
+ str == "NULL" ||
|
|
|
358
|
+ typeof str == "undefined"
|
|
|
359
|
+ ) {
|
|
262
|
360
|
return false;
|
|
263
|
361
|
} else {
|
|
264
|
362
|
str = str + "";
|
|
|
@@ -283,47 +381,72 @@ export default {
|
|
283
|
381
|
_this.touchConfig.index = -1;
|
|
284
|
382
|
_this.touchConfig.pindex = -1;
|
|
285
|
383
|
},
|
|
286
|
|
- // 恢复选择的数据
|
|
|
384
|
+ // 恢复选择的数据
|
|
287
|
385
|
_restoreSelectedData() {
|
|
288
|
386
|
const _this = this;
|
|
289
|
|
- console.log(_this.selectedData, "selectedData")
|
|
290
|
|
- if (_this.selectedData.length > 0) {
|
|
291
|
|
- _this.result = [..._this.selectedData];
|
|
292
|
|
- _this.queryItems = [];
|
|
293
|
|
- _this.nav = [];
|
|
294
|
|
- _this.navCurrentIndex = 0;
|
|
295
|
|
- _this.selectedData.forEach((item, index) => {
|
|
296
|
|
- _this.result[index] = item;
|
|
297
|
|
- if (index > 0) {
|
|
298
|
|
- const parent = _this._deepQuery(_this.data, item.pid);
|
|
299
|
|
- if (parent && parent.children) {
|
|
300
|
|
- _this.queryItems[index - 1] = parent.children.map(child => ({
|
|
301
|
|
- id: child.id,
|
|
302
|
|
- name: child.name,
|
|
303
|
|
- pid: child.pid,
|
|
304
|
|
- type: child.type
|
|
305
|
|
- }));
|
|
306
|
|
- _this.nav[index - 1] = {name: parent.name};
|
|
307
|
|
- }
|
|
308
|
|
- }
|
|
309
|
|
- });
|
|
310
|
|
- _this.navCurrentIndex = _this.selectedData.length - 1;
|
|
311
|
|
- const lastItem = _this.selectedData[_this.selectedData.length - 1];
|
|
312
|
|
- if (lastItem) {
|
|
313
|
|
- const _el = uni.createSelectorQuery().in(_this).select(".aui-picker-navitem-" + _this.navCurrentIndex);
|
|
314
|
|
- setTimeout(() => {
|
|
315
|
|
- _el.boundingClientRect(data => {
|
|
316
|
|
- // _this.navBorderLeft = data?.left + 10;
|
|
317
|
|
- console.log(data, "data")
|
|
318
|
|
- }).exec();
|
|
319
|
|
- },50)
|
|
320
|
|
- _this.$emit("callback", {status: 1, data: _this.result});
|
|
321
|
|
- }
|
|
|
387
|
+ if (_this.selectedData.length === 0) return;
|
|
|
388
|
+
|
|
|
389
|
+ // 验证数据有效性
|
|
|
390
|
+ const isValid = _this.selectedData.every((item) =>
|
|
|
391
|
+ _this._deepQuery(_this.data, item.id)
|
|
|
392
|
+ );
|
|
|
393
|
+ if (!isValid) {
|
|
|
394
|
+ uni.showToast({ title: "无效的初始数据", icon: "none" });
|
|
|
395
|
+ return;
|
|
322
|
396
|
}
|
|
323
|
|
-
|
|
|
397
|
+
|
|
|
398
|
+ _this.reset();
|
|
|
399
|
+ _this.result = [..._this.selectedData];
|
|
|
400
|
+
|
|
|
401
|
+ // 构建各级数据
|
|
|
402
|
+ _this.selectedData.forEach((item, index) => {
|
|
|
403
|
+ if (index === 0) return;
|
|
|
404
|
+
|
|
|
405
|
+ const parent = _this._deepQuery(_this.data, item.pid);
|
|
|
406
|
+ if (parent && parent.children) {
|
|
|
407
|
+ _this.queryItems[index - 1] = parent.children.map((child) => ({
|
|
|
408
|
+ id: child.id,
|
|
|
409
|
+ name: child.name,
|
|
|
410
|
+ pid: child.pid,
|
|
|
411
|
+ type: child.type,
|
|
|
412
|
+ }));
|
|
|
413
|
+ _this.nav[index - 1] = { name: parent.name };
|
|
|
414
|
+ }
|
|
|
415
|
+ });
|
|
|
416
|
+
|
|
|
417
|
+ _this.navCurrentIndex = _this.selectedData.length - 1;
|
|
|
418
|
+
|
|
|
419
|
+ // 计算导航栏位置
|
|
|
420
|
+ setTimeout(() => {
|
|
|
421
|
+ const _el = uni
|
|
|
422
|
+ .createSelectorQuery()
|
|
|
423
|
+ .in(_this)
|
|
|
424
|
+ .select(`.aui-picker-navitem-${_this.navCurrentIndex}`);
|
|
|
425
|
+ _el
|
|
|
426
|
+ .boundingClientRect((data) => {
|
|
|
427
|
+ _this.navBorderLeft = data.left + 10;
|
|
|
428
|
+ })
|
|
|
429
|
+ .exec();
|
|
|
430
|
+ }, 100);
|
|
|
431
|
+
|
|
|
432
|
+ // 更新选中状态
|
|
|
433
|
+ _this.$nextTick(() => {
|
|
|
434
|
+ _this._updateSelectedStyle();
|
|
|
435
|
+ });
|
|
324
|
436
|
},
|
|
325
|
|
- }
|
|
326
|
|
-}
|
|
|
437
|
+ // 更新选中样式
|
|
|
438
|
+ _updateSelectedStyle() {
|
|
|
439
|
+ const _this = this;
|
|
|
440
|
+ _this.result.forEach((item, index) => {
|
|
|
441
|
+ const list = index === 0 ? _this.items : _this.queryItems[index - 1];
|
|
|
442
|
+ const targetItem = list.find((i) => i.id === item.id);
|
|
|
443
|
+ if (targetItem) {
|
|
|
444
|
+ targetItem.active = true;
|
|
|
445
|
+ }
|
|
|
446
|
+ });
|
|
|
447
|
+ },
|
|
|
448
|
+ },
|
|
|
449
|
+};
|
|
327
|
450
|
</script>
|
|
328
|
451
|
|
|
329
|
452
|
<style lang="scss" scoped>
|
|
|
@@ -346,7 +469,7 @@ $custom-content-color: #1f7cff;
|
|
346
|
469
|
.aui-mask {
|
|
347
|
470
|
width: 100%;
|
|
348
|
471
|
height: 100%;
|
|
349
|
|
- background: rgba(0, 0, 0, .3);
|
|
|
472
|
+ background: rgba(0, 0, 0, 0.3);
|
|
350
|
473
|
position: absolute;
|
|
351
|
474
|
left: 0;
|
|
352
|
475
|
top: 0;
|
|
|
@@ -354,23 +477,23 @@ $custom-content-color: #1f7cff;
|
|
354
|
477
|
}
|
|
355
|
478
|
|
|
356
|
479
|
.aui-picker.aui-picker-in {
|
|
357
|
|
- -moz-animation: aui-fade-in .1s ease-out forwards;
|
|
358
|
|
- -ms-animation: aui-fade-in .1s ease-out forwards;
|
|
359
|
|
- -webkit-animation: aui-fade-in .1s ease-out forwards;
|
|
360
|
|
- animation: aui-fade-in .1s ease-out forwards;
|
|
|
480
|
+ -moz-animation: aui-fade-in 0.1s ease-out forwards;
|
|
|
481
|
+ -ms-animation: aui-fade-in 0.1s ease-out forwards;
|
|
|
482
|
+ -webkit-animation: aui-fade-in 0.1s ease-out forwards;
|
|
|
483
|
+ animation: aui-fade-in 0.1s ease-out forwards;
|
|
361
|
484
|
}
|
|
362
|
485
|
|
|
363
|
486
|
.aui-picker.aui-picker-out {
|
|
364
|
|
- -moz-animation: aui-fade-out .1s ease-out forwards;
|
|
365
|
|
- -ms-animation: aui-fade-out .1s ease-out forwards;
|
|
366
|
|
- -webkit-animation: aui-fade-out .1s ease-out forwards;
|
|
367
|
|
- animation: aui-fade-out .1s ease-out forwards;
|
|
|
487
|
+ -moz-animation: aui-fade-out 0.1s ease-out forwards;
|
|
|
488
|
+ -ms-animation: aui-fade-out 0.1s ease-out forwards;
|
|
|
489
|
+ -webkit-animation: aui-fade-out 0.1s ease-out forwards;
|
|
|
490
|
+ animation: aui-fade-out 0.1s ease-out forwards;
|
|
368
|
491
|
}
|
|
369
|
492
|
|
|
370
|
493
|
.aui-picker-main {
|
|
371
|
494
|
width: 100vw;
|
|
372
|
495
|
height: 50vh;
|
|
373
|
|
- background: #FFF;
|
|
|
496
|
+ background: #fff;
|
|
374
|
497
|
position: absolute;
|
|
375
|
498
|
left: 0rpx;
|
|
376
|
499
|
bottom: 0;
|
|
|
@@ -378,17 +501,17 @@ $custom-content-color: #1f7cff;
|
|
378
|
501
|
}
|
|
379
|
502
|
|
|
380
|
503
|
.aui-picker.aui-picker-in .aui-picker-main {
|
|
381
|
|
- -moz-animation: aui-slide-up-screen .2s ease-out forwards;
|
|
382
|
|
- -ms-animation: aui-slide-up-screen .2s ease-out forwards;
|
|
383
|
|
- -webkit-animation: aui-slide-up-screen .2s ease-out forwards;
|
|
384
|
|
- animation: aui-slide-up-screen .2s ease-out forwards;
|
|
|
504
|
+ -moz-animation: aui-slide-up-screen 0.2s ease-out forwards;
|
|
|
505
|
+ -ms-animation: aui-slide-up-screen 0.2s ease-out forwards;
|
|
|
506
|
+ -webkit-animation: aui-slide-up-screen 0.2s ease-out forwards;
|
|
|
507
|
+ animation: aui-slide-up-screen 0.2s ease-out forwards;
|
|
385
|
508
|
}
|
|
386
|
509
|
|
|
387
|
510
|
.aui-picker.aui-picker-out .aui-picker-main {
|
|
388
|
|
- -moz-animation: aui-slide-down-screen .2s ease-out forwards;
|
|
389
|
|
- -ms-animation: aui-slide-down-screen .2s ease-out forwards;
|
|
390
|
|
- -webkit-animation: aui-slide-down-screen .2s ease-out forwards;
|
|
391
|
|
- animation: aui-slide-down-screen .2s ease-out forwards;
|
|
|
511
|
+ -moz-animation: aui-slide-down-screen 0.2s ease-out forwards;
|
|
|
512
|
+ -ms-animation: aui-slide-down-screen 0.2s ease-out forwards;
|
|
|
513
|
+ -webkit-animation: aui-slide-down-screen 0.2s ease-out forwards;
|
|
|
514
|
+ animation: aui-slide-down-screen 0.2s ease-out forwards;
|
|
392
|
515
|
}
|
|
393
|
516
|
|
|
394
|
517
|
.aui-picker-header {
|
|
|
@@ -417,14 +540,14 @@ $custom-content-color: #1f7cff;
|
|
417
|
540
|
}
|
|
418
|
541
|
|
|
419
|
542
|
.aui-picker-header::after {
|
|
420
|
|
- content: '';
|
|
|
543
|
+ content: "";
|
|
421
|
544
|
width: 100%;
|
|
422
|
|
- height:2rpx;
|
|
423
|
|
- background: rgba(100, 100, 100, .3);
|
|
424
|
|
- -moz-transform: scaleY(.3);
|
|
425
|
|
- -ms-transform: scaleY(.3);
|
|
426
|
|
- -webkit-transform: scaleY(.3);
|
|
427
|
|
- transform: scaleY(.3);
|
|
|
545
|
+ height: 2rpx;
|
|
|
546
|
+ background: rgba(100, 100, 100, 0.3);
|
|
|
547
|
+ -moz-transform: scaleY(0.3);
|
|
|
548
|
+ -ms-transform: scaleY(0.3);
|
|
|
549
|
+ -webkit-transform: scaleY(0.3);
|
|
|
550
|
+ transform: scaleY(0.3);
|
|
428
|
551
|
position: absolute;
|
|
429
|
552
|
left: 0;
|
|
430
|
553
|
bottom: 0;
|
|
|
@@ -466,14 +589,14 @@ $custom-content-color: #1f7cff;
|
|
466
|
589
|
}
|
|
467
|
590
|
|
|
468
|
591
|
.aui-picker-nav::after {
|
|
469
|
|
- content: '';
|
|
|
592
|
+ content: "";
|
|
470
|
593
|
width: 100%;
|
|
471
|
594
|
height: 2rpx;
|
|
472
|
|
- background: rgba(100, 100, 100, .3);
|
|
473
|
|
- -moz-transform: scaleY(.3);
|
|
474
|
|
- -ms-transform: scaleY(.3);
|
|
475
|
|
- -webkit-transform: scaleY(.3);
|
|
476
|
|
- transform: scaleY(.3);
|
|
|
595
|
+ background: rgba(100, 100, 100, 0.3);
|
|
|
596
|
+ -moz-transform: scaleY(0.3);
|
|
|
597
|
+ -ms-transform: scaleY(0.3);
|
|
|
598
|
+ -webkit-transform: scaleY(0.3);
|
|
|
599
|
+ transform: scaleY(0.3);
|
|
477
|
600
|
position: absolute;
|
|
478
|
601
|
left: 0;
|
|
479
|
602
|
bottom: 0;
|
|
|
@@ -501,7 +624,7 @@ $custom-content-color: #1f7cff;
|
|
501
|
624
|
height: 6rpx;
|
|
502
|
625
|
background: $custom-content-color;
|
|
503
|
626
|
border-radius: 10rpx;
|
|
504
|
|
- transition: left .15s;
|
|
|
627
|
+ transition: left 0.15s;
|
|
505
|
628
|
position: absolute;
|
|
506
|
629
|
left: 60rpx;
|
|
507
|
630
|
bottom: 0;
|
|
|
@@ -551,12 +674,11 @@ $custom-content-color: #1f7cff;
|
|
551
|
674
|
}
|
|
552
|
675
|
|
|
553
|
676
|
.aui-picker-item.active::after {
|
|
554
|
|
- content: '✔';
|
|
|
677
|
+ content: "✔";
|
|
555
|
678
|
font-size: 25rpx;
|
|
556
|
679
|
color: $custom-content-color;
|
|
557
|
680
|
position: absolute;
|
|
558
|
681
|
top: 0rpx;
|
|
559
|
682
|
right: 20rpx;
|
|
560
|
683
|
}
|
|
561
|
|
-
|
|
562
|
684
|
</style>
|