<!--
 * @Descripttion: 
 * @version: 
 * @Author: JC9527
 * @Date: 2023-09-27 14:01:34
 * @LastEditors: JC9527
 * @LastEditTime: 2023-09-28 17:03:02
-->
<template>
  <div>
    <el-cascader
      size="small"
      v-model="district"
      :options="compartment"
      :show-all-levels="false"
      :disabled="isNoneDivision"
      :props="props"
      @change="getData"
    ></el-cascader>
  </div>
</template>
<script>
import { xzTree } from "@/api/yingji/keyEnterprise.js";
import { mapState } from "vuex";
export default {
  data() {
    return {
      //区划的禁用
      district: "",
      compartment: [],
      isNoneDivision: false,
      props: {
        checkStrictly: true,
        value: "value",
        label: "label",
        children: "children",
      },
    };
  },
  created() {
    this.xzList();
  },
  computed: {
    ...mapState({
      //根据存储的dept.parentId判断是哪个等级
      dept: (state) => state.user.dept,
    }),
  },
  props: {
    none: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    xzList() {
      xzTree().then((res) => {
        if (this.dept.parentId == 0 || this.dept.leader == "admin") {
          res.data.forEach((value, index) => {
            this.compartment.push({
              value: value.county,
              label: value.institutionName,
              children: [],
            });
            if (value.children.length > 0) {
              value.children.forEach((value1, index1) => {
                this.compartment[index].children.push({
                  value: value1.subdistrict,
                  label: value1.institutionName,
                });
              });
            }
          });
        }
        this.$emit("quhuadizhi", this.compartment);
      });
    },
    getData(e) {
      if (!this.none) {
        if (e.length == 1) {
          this.$emit("quhua", e[0].slice(1, 8));
        } else if (e.length == 2 && e[0] == e[1]) {
          this.$emit("quhua", e[0].slice(1, 8));
        } else {
          this.$emit("quhua", e[1].slice(1, 11));
        }
      } else {
        if (e.length == 1) {
          this.$emit("quhua", e[0]);
        } else if (e.length == 2 && e[0] == e[1]) {
          this.$emit("quhua", e[0]);
        } else {
          this.$emit("quhua", e[1]);
        }
      }
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-cascader {
  background-color: transparent;
  width: 210px;
  .el-input__inner {
    height: 33px;
  }
  .el-input
    .el-input__suffix
    .el-input__suffix-inner
    .el-icon-arrow-down::before {
    content: "";
    background: url(../../../assets/images/down2.png) center center no-repeat;
    background-size: cover;
    position: absolute;
    width: 10px;
    height: 7px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}
</style>