|
|
@@ -5,7 +5,6 @@
|
|
|
@click-overlay="clickOverlay"
|
|
|
@open="closeWay = 'self'"
|
|
|
v-model:visible="showPopup"
|
|
|
- :class="classes"
|
|
|
>
|
|
|
<view class="nut-address">
|
|
|
<view class="nut-address__header">
|
|
|
@@ -13,7 +12,7 @@
|
|
|
<nut-icon
|
|
|
:name="backBtnIcon"
|
|
|
color="#cccccc"
|
|
|
- v-if="privateType == 'custom' && type == 'exist' && backBtnIcon"
|
|
|
+ v-show="type == 'exist' && privateType == 'custom' && backBtnIcon"
|
|
|
></nut-icon>
|
|
|
</view>
|
|
|
|
|
|
@@ -28,16 +27,14 @@
|
|
|
|
|
|
<!-- 请选择 -->
|
|
|
<view class="custom-address" v-if="privateType == 'custom'">
|
|
|
- <view class="region-tab">
|
|
|
+ <view class="region-tab" ref="tabRegion">
|
|
|
<view
|
|
|
- class="tab-item"
|
|
|
- :class="[index == tabIndex ? 'active' : '', key]"
|
|
|
+ :class="{ 'tab-item': true, active: index == tabIndex, [tabName[index]]: true }"
|
|
|
v-for="(item, key, index) in selectedRegion"
|
|
|
:key="index"
|
|
|
- :ref="key"
|
|
|
@click="changeRegionTab(item, key, index)"
|
|
|
>
|
|
|
- <view>{{ getTabName(item, index) }}</view>
|
|
|
+ <view>{{ getTabName(item, index) }} </view>
|
|
|
</view>
|
|
|
|
|
|
<view class="region-tab-line" ref="regionLine" :style="{ left: lineDistance + 'px' }"></view>
|
|
|
@@ -48,8 +45,7 @@
|
|
|
<li
|
|
|
v-for="(item, index) in regionList[tabName[tabIndex]]"
|
|
|
:key="index"
|
|
|
- class="region-item"
|
|
|
- :class="[selectedRegion[tabName[tabIndex]].id == item.id ? 'active' : '']"
|
|
|
+ :class="['region-item', selectedRegion[tabName[tabIndex]].id == item.id ? 'active' : '']"
|
|
|
@click="nextAreaList(item)"
|
|
|
>
|
|
|
<nut-icon
|
|
|
@@ -65,21 +61,20 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <view class="custom-address" v-else-if="privateType === 'custom2'">
|
|
|
- <view class="region-tab">
|
|
|
+ <!-- 请选择 -->
|
|
|
+ <view class="custom-address" v-else-if="privateType == 'custom2'">
|
|
|
+ <view class="region-tab" ref="tabRegion">
|
|
|
<view
|
|
|
- class="tab-item"
|
|
|
- :class="[index == tabIndex ? 'active' : '']"
|
|
|
+ :class="{ 'tab-item': true, active: index == tabIndex, [tabName[index]]: true }"
|
|
|
v-for="(item, key, index) in selectedRegion"
|
|
|
:key="index"
|
|
|
- :ref="key"
|
|
|
@click="changeRegionTab(item, key, index)"
|
|
|
>
|
|
|
<view>{{ getTabName(item, index) }}</view>
|
|
|
</view>
|
|
|
<view class="region-tab-line" ref="regionLine" :style="{ left: lineDistance + 'px' }"></view>
|
|
|
</view>
|
|
|
- <view class="elevator-group" v-if="showPopup">
|
|
|
+ <view class="elevator-group">
|
|
|
<nut-elevator
|
|
|
:height="height"
|
|
|
:index-list="regionList[tabName[tabIndex]]"
|
|
|
@@ -119,7 +114,6 @@
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
-
|
|
|
<div class="choose-other" @click="switchModule" v-if="isShowCustomAddress">
|
|
|
<div class="btn">{{ customAndExistTitle }}</div>
|
|
|
</div>
|
|
|
@@ -128,7 +122,7 @@
|
|
|
</nut-popup>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
-import { reactive, ref, toRefs, watch, computed } from 'vue';
|
|
|
+import { reactive, ref, toRefs, watch, computed, onMounted } from 'vue';
|
|
|
import { createComponent } from '../../utils/create';
|
|
|
import Taro from '@tarojs/taro';
|
|
|
|
|
|
@@ -156,6 +150,10 @@ interface AddressList {
|
|
|
export default create({
|
|
|
inheritAttrs: false,
|
|
|
props: {
|
|
|
+ modelValue: {
|
|
|
+ type: Array,
|
|
|
+ default: () => []
|
|
|
+ },
|
|
|
visible: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
@@ -223,9 +221,13 @@ export default create({
|
|
|
height: {
|
|
|
type: [String, Number],
|
|
|
default: '200px'
|
|
|
+ },
|
|
|
+ columnsPlaceholder: {
|
|
|
+ type: [String, Array],
|
|
|
+ default: '请选择'
|
|
|
}
|
|
|
},
|
|
|
- emits: ['update:visible', 'type', 'change', 'selected', 'close', 'close-mask', 'switch-module'],
|
|
|
+ emits: ['update:visible', 'update:modelValue', 'type', 'change', 'selected', 'close', 'close-mask', 'switch-module'],
|
|
|
|
|
|
setup(props, { emit }) {
|
|
|
const classes = computed(() => {
|
|
|
@@ -247,6 +249,7 @@ export default create({
|
|
|
const privateType = ref(props.type);
|
|
|
const tabIndex = ref(0);
|
|
|
const tabName = ref(['province', 'city', 'country', 'town']);
|
|
|
+ const tabNameDefault = ref(['']);
|
|
|
|
|
|
const isCustom2 = computed(() => props.type === 'custom2');
|
|
|
|
|
|
@@ -306,6 +309,54 @@ export default create({
|
|
|
|
|
|
const lineDistance = ref(20);
|
|
|
|
|
|
+ onMounted(() => {
|
|
|
+ customPlaceholder();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 设置选中省市县
|
|
|
+ const initCustomSelected = () => {
|
|
|
+ console.log(props.modelValue);
|
|
|
+ if (props.modelValue.length > 0) {
|
|
|
+ tabIndex.value = props.modelValue.length - 1;
|
|
|
+ for (let index = 0; index < props.modelValue.length; index++) {
|
|
|
+ if ((regionList as any)[tabName.value[index]].length == 0) {
|
|
|
+ tabIndex.value = index - 1;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ const val = props.modelValue[index];
|
|
|
+ const arr: [] = (regionList as any)[tabName.value[index]];
|
|
|
+ if (privateType.value == 'custom') {
|
|
|
+ (selectedRegion as any)[tabName.value[index]] = arr.filter((item: RegionData) => item.id == val)[0];
|
|
|
+ } else if (privateType.value == 'custom2') {
|
|
|
+ let sumArr: any = [];
|
|
|
+ arr.map((item) => {
|
|
|
+ sumArr.push(...(item as any).list);
|
|
|
+ });
|
|
|
+ (selectedRegion as any)[tabName.value[index]] = sumArr.filter((item: RegionData) => item.id == val)[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lineAnimation();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 自定义‘请选择’文案
|
|
|
+ const customPlaceholder = () => {
|
|
|
+ let typeD = Object.prototype.toString.call(props.columnsPlaceholder);
|
|
|
+ if (typeD == '[object String]') {
|
|
|
+ tabNameDefault.value = new Array(4).fill(props.columnsPlaceholder);
|
|
|
+ } else if (typeD == '[object Array]') {
|
|
|
+ tabNameDefault.value = new Array(4).fill('');
|
|
|
+ tabNameDefault.value.forEach((val, index) => {
|
|
|
+ if (props.columnsPlaceholder[index]) {
|
|
|
+ tabNameDefault.value[index] = props.columnsPlaceholder[index];
|
|
|
+ } else {
|
|
|
+ tabNameDefault.value[index] = '请选择';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
//获取已选地区列表名称
|
|
|
const getTabName = (item: RegionData, index: number) => {
|
|
|
if (item.name) return item.name;
|
|
|
@@ -334,6 +385,7 @@ export default create({
|
|
|
Taro.createSelectorQuery()
|
|
|
.selectAll(`.${tabName.value[tabIndex.value]}`)
|
|
|
.boundingClientRect((rects) => {
|
|
|
+ console.log(rects);
|
|
|
(rects as any).forEach((rect) => {
|
|
|
if (rect.width > 0) lineDistance.value = rect.left;
|
|
|
});
|
|
|
@@ -352,7 +404,10 @@ export default create({
|
|
|
|
|
|
(selectedRegion as any)[tabName.value[tabIndex.value]] = item;
|
|
|
|
|
|
- for (let i = tabIndex.value; i < tabIndex.value - 1; i++) {
|
|
|
+ // for (let i = tabIndex.value; i < tabIndex.value - 1; i++) {
|
|
|
+ // (selectedRegion as any)[tabName.value[i + 1]] = {};
|
|
|
+ // }
|
|
|
+ for (let i = tabIndex.value; i < 4; i++) {
|
|
|
(selectedRegion as any)[tabName.value[i + 1]] = {};
|
|
|
}
|
|
|
|
|
|
@@ -367,6 +422,7 @@ export default create({
|
|
|
emit('change', calBack);
|
|
|
} else {
|
|
|
handClose();
|
|
|
+ emit('update:modelValue');
|
|
|
}
|
|
|
};
|
|
|
//切换地区Tab
|
|
|
@@ -480,6 +536,8 @@ export default create({
|
|
|
(value) => {
|
|
|
if (value == false) {
|
|
|
close();
|
|
|
+ } else {
|
|
|
+ initCustomSelected();
|
|
|
}
|
|
|
}
|
|
|
);
|