zhengyiming
2025-02-10 958b79ed89b9e742540f714a80261d222c0fc09b
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
<template>
  <div class="area-select-wrapper">
    <el-select
      v-model="innerProvinceId"
      placeholder="请选择省份"
      filterable
      clearable
      :disabled="disabled"
    >
      <el-option
        v-for="(item, index) in provinceList"
        :key="index"
        :label="item.areaName"
        :value="item.areaCode"
      />
    </el-select>
    <el-select
      v-model="innerCityId"
      placeholder="请选择市"
      filterable
      clearable
      :disabled="disabled"
    >
      <el-option
        v-for="(item, index) in cityList"
        :key="index"
        :label="item.areaName"
        :value="item.areaCode"
      />
    </el-select>
    <el-select
      v-model="innerCountyId"
      placeholder="请选择区县"
      filterable
      clearable
      :disabled="disabled"
    >
      <el-option
        v-for="(item, index) in countyList"
        :key="index"
        :label="item.areaName"
        :value="item.areaCode"
      />
    </el-select>
  </div>
</template>
 
<script setup lang="ts">
import { useVModels, useAreaSelect } from '@/hooks';
 
defineOptions({
  name: 'AreaSelect',
});
 
type Props = {
  provinceId?: number | string;
  cityId?: number | string;
  countyId?: number | string;
  disabled?: boolean;
};
 
const props = withDefaults(defineProps<Props>(), {
  disabled: false,
});
 
const emit = defineEmits<{
  (e: 'update:provinceId', id: number): void;
  (e: 'update:cityId', id: number): void;
  (e: 'update:countyId', id: number): void;
}>();
 
const {
  provinceId: innerProvinceId,
  cityId: innerCityId,
  countyId: innerCountyId,
} = useVModels(props, emit);
 
const { provinceList, cityList, countyList } = useAreaSelect(
  innerProvinceId as Ref<number>,
  innerCityId as Ref<number>,
  innerCountyId as Ref<number>
);
</script>
 
<style lang="scss" scoped>
@use '@/style/common.scss' as *;
 
.area-select-wrapper {
  display: inline-flex;
  align-items: center;
 
  :deep() {
    .el-select {
      width: 140px;
 
      & + .el-select {
        margin-left: 10px;
      }
    }
  }
}
</style>