zhaoxiaoqiang1
2026-01-04 f1d30d03186c79ca2cbcfe60d6d2ce7d73fba97b
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template>
<div>
  <el-col :md="12" :lg="8" v-if="province.visible">
    <el-form-item :label="province.filedDescription" :prop="province.name+'.value'" :rules="rules.province">
      <el-select v-model="provinceVal" filterable clearable placeholder="请选择" :disabled="!province.writeAble">
        <el-option v-for="(item, index) in options.province" :key="index" :label="item.itemname" :value="item.itemno">
        </el-option>
      </el-select>
    </el-form-item>
  </el-col>
  <el-col :md="12" :lg="8" v-if="citys.visible">
    <el-form-item :label="citys.filedDescription" :prop="citys.name+'.value'" :rules="rules.citys">
      <el-select v-model="citysVal" filterable clearable placeholder="请选择" :disabled="!citys.writeAble">
        <el-option v-for="(item, index) in options.citys" :key="index" :label="item.itemname" :value="item.itemno">
        </el-option>
      </el-select>
    </el-form-item>
  </el-col>
  <el-col :md="12" :lg="8" v-if="county.visible">
    <el-form-item :label="county.filedDescription" :prop="county.name+'.value'" :rules="rules.county">
      <el-select v-model="countyVal" filterable clearable placeholder="请选择" :disabled="!county.writeAble">
        <el-option v-for="(item, index) in options.county" :key="index" :label="item.itemname" :value="item.itemno">
        </el-option>
      </el-select>
    </el-form-item>
  </el-col>
</div>
</template>
 
<script>
import { getProvinceCodeList, getCityCodeList, getAreaCodeList } from '@/api/area'
export default {
  props: ['province', 'citys', 'county'],
  data: function() {
    return {
      options: {
        citys: '',
        province: '',
        county: ''
      }
    }
  },
  created() {
    this.initSelect()
  },
  watch: {
    'province.value': {
      immediate: true,
      handler(newVal) {
        if (!this._.isEmpty(newVal)) {
          let params = {
            codeNo: 'AreaCode',
            itmeNo: newVal
          }
          getCityCodeList(params).then(res => {
            this.options.citys = res.result
          })
        }
      }
    },
    'citys.value': {
      immediate: true,
      handler(newVal) {
        if (!this._.isEmpty(newVal)) {
          let params = {
            codeNo: 'AreaCode',
            itmeNo: newVal
          }
          getAreaCodeList(params).then(res => {
            this.options.county = res.result
          })
        }
      }
    }
  },
  computed: {
    provinceVal: {
      get() {
        return this.province.value
      },
      set(newVal) {
        this.citysVal = ''
        this.province.value = newVal
        this.$emit('update:province', this.province)
      }
    },
    citysVal: {
      get() {
        return this.citys.value
      },
      set(newVal) {
        this.countyVal = ''
        this.citys.value = newVal
        this.$emit('update:citys', this.citys)
      }
    },
    countyVal: {
      get() {
        return this.county.value
      },
      set(newVal) {
        this.county.value = newVal
        this.$emit('update:county', this.county)
      }
    },
    rules() {
      return {
        citys: {
          required: this.citys.required,
          message: '请输入' + this.citys.filedDescription,
          trigger: 'blur'
        },
        province: {
          required: this.province.required,
          message: '请输入' + this.province.filedDescription,
          trigger: 'blur'
        },
        county: {
          required: this.county.required,
          message: '请输入' + this.county.filedDescription,
          trigger: 'blur'
        }
      }
    },
  },
  methods: {
    initSelect () {
      // 查询省
      getProvinceCodeList({}).then(res => {
        this.options.province = res.result
      })
    }
  }
}
</script>
 
<style scoped>
 
</style>