<template>
  <div id="index" class="flex_direction_box">
    <el-cascader
      ref="myCascader"
      expand-trigger="click"
      v-model="areaDropValue1"
      :options="district"
      :props="areaProps1"
      clearable
      collapse-tags
      popper-class="disableFirstAndSecondLevel"
      @change="areaDropChange1"
    ></el-cascader>
  </div>
</template>
<script>
export default {
  data() {
    return {
      district: [
        {
          v: "1",
          n: "北京",
          c: [
            {
              v: "2816",
              n: "密云区",
              c: [
                { v: "6667", n: "城区" },
                { v: "2862", n: "城区以外" },
              ],
            },
            {
              v: "72",
              n: "朝阳区",
              c: [
                { v: "2819", n: "三环到四环之间" },
                { v: "2839", n: "四环到五环之间" },
                { v: "2840", n: "五环到六环之间" },
                { v: "4137", n: "管庄" },
                { v: "4139", n: "北苑" },
                { v: "4211", n: "定福庄" },
                { v: "2799", n: "三环以内" },
              ],
            },
          ],
        },
      ],
      areaProps1: {
        label: "n",
        value: "v",
        children: "c",
        multiple: true,
        checkStrictly: true,
      },
      shareScopeEnd: [],
    };
  },
  methods: {
    areaDropChange1(val) {
      console.log(
        val,
        this.areaDropValue1,
        this.$refs.myCascader.getCheckedNodes()
      );
      let changeFlag = false;
      let changeItem = null;
      if (this.shareScopeEnd.length == 0) {
        this.areaDropValue1 = val;
      } else {
        //与原数组比对
        this.areaDropValue1.forEach((item) => {
          if (item[0] !== this.shareScopeEnd[0][0]) {
            //一级标签不同
            changeFlag = true;
            changeItem = item;
          } else if (item[1] !== this.shareScopeEnd[0][1]) {
            //一级标题相同但二级标签不同
            changeFlag = true;
            changeItem = item;
          } else if (
            (!item[2] && this.shareScopeEnd[0][2]) ||
            (item[2] && !this.shareScopeEnd[0][2])
          ) {
            //一二极相同三级不同或从无到有
            changeFlag = true;
            changeItem = item;
          }
        });
      }
      if (changeFlag) {
        this.areaDropValue1 = [];
        this.areaDropValue1.push(changeItem);
      }
      this.shareScopeEnd = this.areaDropValue1;
    },
  },
};
</script>
<style lang="scss">
.disableFirstAndSecondLevel{
  .el-cascader-panel {
    .el-scrollbar:first-child {
      .el-checkbox {
        display: none !important;
      }
    }
    .el-scrollbar:nth-child(2) {
      .el-checkbox {
        display: none !important;
      }
    }
  }
}
</style>
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45 7 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐