34
34
</view >
35
35
36
36
<!-- 请选择 -->
37
- <view class =" custom-address" v-if =" privateType == 'custom'" >
38
- <view class =" region-tab" ref =" tabRegion" >
37
+ <view class =" custom-address" v-if =" [ 'custom', 'custom2'].includes(privateType) " >
38
+ <view class =" nut-address- region-tab" ref =" tabRegion" >
39
39
<view
40
- class =" tab-item"
41
- :class =" [index == tabIndex ? 'active' : '']"
40
+ :class =" ['tab-item', index == tabIndex ? 'active' : '']"
42
41
v-for =" (item, key, index) in selectedRegion"
43
42
:key =" index"
44
43
@click =" changeRegionTab(item, key, index)"
49
48
<view class =" region-tab-line" ref =" regionLine" :style =" { left: lineDistance + 'px' }" ></view >
50
49
</view >
51
50
52
- <view class =" region-con" >
51
+ <view class =" region-con" v-if = " privateType == 'custom' " >
53
52
<ul class =" region-group" >
54
53
<li
55
54
v-for =" (item, index) in regionList[tabName[tabIndex]]"
72
71
</li >
73
72
</ul >
74
73
</view >
75
- </view >
76
74
77
- <!-- 请选择 -->
78
- <view class =" custom-address" v-else-if =" privateType == 'custom2'" >
79
- <view class =" region-tab" ref =" tabRegion" >
80
- <view
81
- class =" tab-item"
82
- :class =" [index == tabIndex ? 'active' : '']"
83
- v-for =" (item, key, index) in selectedRegion"
84
- :key =" index"
85
- @click =" changeRegionTab(item, key, index)"
86
- >
87
- <view >{{ getTabName(item, index) }}</view >
88
- </view >
89
- <view class =" region-tab-line" ref =" regionLine" :style =" { left: lineDistance + 'px' }" ></view >
90
- </view >
91
- <view class =" elevator-group" >
75
+ <view class =" elevator-group" v-else >
92
76
<nut-elevator
93
77
:height =" height"
94
78
:index-list =" regionList[tabName[tabIndex]]"
142
126
<script lang="ts">
143
127
import { reactive , ref , toRefs , watch , nextTick , computed , Ref , onMounted } from ' vue' ;
144
128
import { createComponent } from ' @/packages/utils/create' ;
129
+ import { isArray , isString , TypeOfFun } from ' @/packages/utils/util' ;
145
130
import { popupProps } from ' ../popup/props' ;
146
131
const { componentName, create, translate } = createComponent (' address' );
147
132
interface RegionData {
@@ -250,12 +235,12 @@ export default create({
250
235
const privateType = ref (props .type );
251
236
const tabIndex = ref (0 );
252
237
const tabName = ref ([' province' , ' city' , ' country' , ' town' ]);
253
- const tabNameDefault = ref ([ ' ' ] );
238
+ const tabNameDefault = ref (new Array ( 4 ). fill ( translate ( ' select ' )) );
254
239
255
240
const isCustom2 = computed (() => props .type === ' custom2' );
256
241
257
242
const transformData = (data : RegionData []) => {
258
- if (! Array . isArray (data )) throw new TypeError (' params muse be array.' );
243
+ if (! isArray (data )) throw new TypeError (' params muse be array.' );
259
244
260
245
if (! data .length ) return [];
261
246
@@ -310,10 +295,6 @@ export default create({
310
295
311
296
const lineDistance = ref (20 );
312
297
313
- onMounted (() => {
314
- customPlaceholder ();
315
- });
316
-
317
298
// 设置选中省市县
318
299
const initCustomSelected = () => {
319
300
if (props .modelValue .length > 0 ) {
@@ -341,18 +322,13 @@ export default create({
341
322
};
342
323
// 自定义‘请选择’文案
343
324
const customPlaceholder = () => {
344
- let selectStr = translate (' select' );
345
- let typeD = Object .prototype .toString .call (props .columnsPlaceholder || selectStr );
346
- if (typeD == ' [object String]' ) {
347
- tabNameDefault .value = new Array (4 ).fill (props .columnsPlaceholder || selectStr );
348
- } else if (typeD == ' [object Array]' ) {
349
- tabNameDefault .value = new Array (4 ).fill (' ' );
350
- tabNameDefault .value .forEach ((val , index ) => {
351
- if (props .columnsPlaceholder [index ]) {
352
- tabNameDefault .value [index ] = props .columnsPlaceholder [index ];
353
- } else {
354
- tabNameDefault .value [index ] = selectStr ;
355
- }
325
+ const { columnsPlaceholder } = props ;
326
+ if (! columnsPlaceholder ) return ;
327
+ if (isString (columnsPlaceholder )) {
328
+ tabNameDefault .value = new Array (4 ).fill (columnsPlaceholder );
329
+ } else if (isArray (columnsPlaceholder ) && columnsPlaceholder .length < 5 ) {
330
+ columnsPlaceholder .forEach ((val , index ) => {
331
+ tabNameDefault .value [index ] = val ;
356
332
});
357
333
}
358
334
};
@@ -401,9 +377,6 @@ export default create({
401
377
};
402
378
403
379
(selectedRegion as any )[tabName .value [tabIndex .value ]] = item ;
404
- // for (let i = tabIndex.value; i < tabIndex.value - 1; i++) {
405
- // (selectedRegion as any)[tabName.value[i + 1]] = {};
406
- // }
407
380
408
381
for (let i = tabIndex .value ; i < 4 ; i ++ ) {
409
382
(selectedRegion as any )[tabName .value [i + 1 ]] = {};
@@ -462,7 +435,6 @@ export default create({
462
435
463
436
// 关闭
464
437
const close = () => {
465
- console .log (' 关闭' , closeWay .value , showPopup .value );
466
438
const resCopy = Object .assign (
467
439
{
468
440
addressIdStr: ' ' ,
@@ -523,6 +495,10 @@ export default create({
523
495
nextAreaList (item );
524
496
};
525
497
498
+ const updateRegion = (type : string , value : any ) => {
499
+ regionList [type ] = isCustom2 .value ? transformData (value ) : value ;
500
+ };
501
+
526
502
watch (
527
503
() => props .visible ,
528
504
(value ) => {
@@ -533,10 +509,8 @@ export default create({
533
509
watch (
534
510
() => showPopup .value ,
535
511
(value ) => {
536
- console .log (' 监听 showpopup' , showPopup .value );
537
- if (value == false ) {
538
- // close();
539
- } else {
512
+ if (value ) {
513
+ customPlaceholder ();
540
514
initCustomSelected ();
541
515
}
542
516
}
@@ -545,33 +519,32 @@ export default create({
545
519
watch (
546
520
() => props .province ,
547
521
(value ) => {
548
- regionList . province = isCustom2 . value ? transformData ( value ) : value ;
522
+ updateRegion ( ' province' , value ) ;
549
523
}
550
524
);
551
525
watch (
552
526
() => props .city ,
553
527
(value ) => {
554
- regionList . city = isCustom2 . value ? transformData ( value ) : value ;
528
+ updateRegion ( ' city' , value ) ;
555
529
}
556
530
);
557
531
watch (
558
532
() => props .country ,
559
533
(value ) => {
560
- regionList . country = isCustom2 . value ? transformData ( value ) : value ;
534
+ updateRegion ( ' country' , value ) ;
561
535
}
562
536
);
563
537
watch (
564
538
() => props .town ,
565
539
(value ) => {
566
- regionList . town = isCustom2 . value ? transformData ( value ) : value ;
540
+ updateRegion ( ' town' , value ) ;
567
541
}
568
542
);
569
543
570
544
watch (
571
545
() => props .existAddress ,
572
546
(value ) => {
573
- // existAddress.value = value;
574
- value .forEach ((item , index ) => {
547
+ value .forEach ((item ) => {
575
548
if ((item as AddressList ).selectedAddress ) {
576
549
selectedExistAddress = item as {};
577
550
}
0 commit comments