riku
2023-05-19 c9571c465c756deedbfe424b5eab2d7591119f77
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
<template>
  <el-cascader
    v-model="selectedOptions"
    :options="locations"
    placeholder="placeholder"
    :props="props"
    style="width: 280px"
  />
</template>
 
<script>
import { enumLocation } from '@/enum/location';
 
export default {
  props: {
    // 是否在首选项处添加“全部”选项
    allOption: {
      type: Boolean,
      default: true,
    },
    // 查询的行政级别,取值1,2,3,4
    level: {
      type: Number,
      default: 4,
    },
    // 结果返回数组
    value: Array,
  },
  emits: ['update:value'],
  data() {
    return {
      locations: enumLocation(this.allOption, this.level),
      selectedOptions: [],
      props: {
        checkStrictly: true,
      },
    };
  },
  computed: {
    placeholder() {
      const list = '省/市/区/镇'.split('/');
      const p = [];
      for (let i = 0; i < this.level; i++) {
        p.push(list[i]);
      }
      return p;
    },
  },
  watch: {
    selectedOptions: {
      handler(val) {
        this.$emit('update:value', val);
      },
      deep: true,
    },
  },
  mounted() {
    this.selectedOptions = [this.locations[0].value];
  },
};
</script>