|
@@ -4,19 +4,19 @@
|
|
<!--省份-->
|
|
<!--省份-->
|
|
<a-select v-model:value="province" @change="proChange" allowClear :disabled="disabled">
|
|
<a-select v-model:value="province" @change="proChange" allowClear :disabled="disabled">
|
|
<template v-for="item in provinceOptions" :key="`${item.value}`">
|
|
<template v-for="item in provinceOptions" :key="`${item.value}`">
|
|
- <a-select-option :value="item.value">{{ item.label }}</a-select-option>
|
|
|
|
|
|
+ <a-select-option :value="item.label">{{ item.label }}</a-select-option>
|
|
</template>
|
|
</template>
|
|
</a-select>
|
|
</a-select>
|
|
<!--城市-->
|
|
<!--城市-->
|
|
<a-select v-if="level >= 2" v-model:value="city" @change="cityChange" :disabled="disabled">
|
|
<a-select v-if="level >= 2" v-model:value="city" @change="cityChange" :disabled="disabled">
|
|
<template v-for="item in cityOptions" :key="`${item.value}`">
|
|
<template v-for="item in cityOptions" :key="`${item.value}`">
|
|
- <a-select-option :value="item.value">{{ item.label }}</a-select-option>
|
|
|
|
|
|
+ <a-select-option :value="item.label">{{ item.label }}</a-select-option>
|
|
</template>
|
|
</template>
|
|
</a-select>
|
|
</a-select>
|
|
<!--地区-->
|
|
<!--地区-->
|
|
<a-select v-if="level >= 3" v-model:value="area" @change="areaChange" :disabled="disabled">
|
|
<a-select v-if="level >= 3" v-model:value="area" @change="areaChange" :disabled="disabled">
|
|
<template v-for="item in areaOptions" :key="`${item.value}`">
|
|
<template v-for="item in areaOptions" :key="`${item.value}`">
|
|
- <a-select-option :value="item.value">{{ item.label }}</a-select-option>
|
|
|
|
|
|
+ <a-select-option :value="item.label">{{ item.label }}</a-select-option>
|
|
</template>
|
|
</template>
|
|
</a-select>
|
|
</a-select>
|
|
</div>
|
|
</div>
|
|
@@ -26,7 +26,7 @@
|
|
import { defineComponent, PropType, ref, reactive, watchEffect, computed, unref, watch, onMounted, onUnmounted, toRefs } from 'vue';
|
|
import { defineComponent, PropType, ref, reactive, watchEffect, computed, unref, watch, onMounted, onUnmounted, toRefs } from 'vue';
|
|
import { propTypes } from '/@/utils/propTypes';
|
|
import { propTypes } from '/@/utils/propTypes';
|
|
import { useRuleFormItem } from '/@/hooks/component/useFormItem';
|
|
import { useRuleFormItem } from '/@/hooks/component/useFormItem';
|
|
- import { provinceOptions, getDataByCode, getRealCode } from '../../utils/areaDataUtil';
|
|
|
|
|
|
+ import { provinceOptions, getDataByCode, getRealCode, getTextData } from '../../utils/areaDataUtil';
|
|
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
name: 'JAreaSelect',
|
|
name: 'JAreaSelect',
|
|
@@ -60,11 +60,19 @@
|
|
const [state] = useRuleFormItem(props, 'value', 'change', emitData);
|
|
const [state] = useRuleFormItem(props, 'value', 'change', emitData);
|
|
//城市下拉框的选项
|
|
//城市下拉框的选项
|
|
const cityOptions = computed(() => {
|
|
const cityOptions = computed(() => {
|
|
- return pca.province ? getDataByCode(pca.province) : [];
|
|
|
|
|
|
+ if (pca.province) {
|
|
|
|
+ const code = getTextData(pca.province);
|
|
|
|
+ return code ? getDataByCode(code) : [];
|
|
|
|
+ }
|
|
|
|
+ return [];
|
|
});
|
|
});
|
|
//地区下拉框的选项
|
|
//地区下拉框的选项
|
|
const areaOptions = computed(() => {
|
|
const areaOptions = computed(() => {
|
|
- return pca.city ? getDataByCode(pca.city) : [];
|
|
|
|
|
|
+ if (pca.city) {
|
|
|
|
+ const code = getTextData(pca.province, pca.city);
|
|
|
|
+ return code ? getDataByCode(code) : [];
|
|
|
|
+ }
|
|
|
|
+ return [];
|
|
});
|
|
});
|
|
/**
|
|
/**
|
|
* 监听props值
|
|
* 监听props值
|
|
@@ -114,10 +122,10 @@
|
|
* 省份change事件
|
|
* 省份change事件
|
|
*/
|
|
*/
|
|
function proChange(val) {
|
|
function proChange(val) {
|
|
- console.log(val, '设置');
|
|
|
|
-
|
|
|
|
- pca.city = val && getDataByCode(val)[0]?.value;
|
|
|
|
- pca.area = pca.city && getDataByCode(pca.city)[0]?.value;
|
|
|
|
|
|
+ const pro = getTextData(val);
|
|
|
|
+ pca.city = getDataByCode(pro)[0]?.value;
|
|
|
|
+ const cityCode = getTextData(val, pca.city);
|
|
|
|
+ pca.area = getDataByCode(cityCode)[0]?.value;
|
|
state.value = props.level <= 1 ? val : props.level <= 2 ? pca.city : pca.area;
|
|
state.value = props.level <= 1 ? val : props.level <= 2 ? pca.city : pca.area;
|
|
emit('update:value', unref(state));
|
|
emit('update:value', unref(state));
|
|
}
|
|
}
|
|
@@ -126,7 +134,8 @@
|
|
* 城市change事件
|
|
* 城市change事件
|
|
*/
|
|
*/
|
|
function cityChange(val) {
|
|
function cityChange(val) {
|
|
- pca.area = val && getDataByCode(val)[0]?.value;
|
|
|
|
|
|
+ const cityCode = getTextData(pca.province, val);
|
|
|
|
+ pca.area = val && getDataByCode(cityCode)[0]?.value;
|
|
state.value = props.level <= 2 ? val : pca.area;
|
|
state.value = props.level <= 2 ? val : pca.area;
|
|
emit('update:value', unref(state));
|
|
emit('update:value', unref(state));
|
|
}
|
|
}
|