index.vue 2.58 KB
<template>
  <div class="">
    <el-input placeholder="输入关键字进行过滤" v-model="filterText" size="small">
    </el-input>

    <div v-loading="loading">
      <el-tree style="max-height:50vh;overflow:auto" class="filter-tree" :data="filterTextData" :filter-node-method="filterNode" highlight-current ref="tree" node-key="id" check-on-click-node>
      </el-tree>
    </div>
    <p style="text-align: right; margin-top: 10px">
      <el-button @click="filterConfirm" type="primary">确定</el-button>
      <el-button @click="closeFilter">取消</el-button>
    </p>
  </div>
</template>
<script>
import { GET_ORGANIZATION_TREE } from "@/api/services/common";
import { showToast } from "@/utils/utils";
export default {
  name: "GlsxOrganization",
  data() {
    return {
      filterText: "",
      filterTextData: [],
      _timeout: "",
      loading: false,
    };
  },
  mounted() {
    this.getTree();
  },
  watch: {
    filterText(n) {
      let _this = this;
      _this.loading = true;
      setTimeout(function () {
        _this.$refs.tree.filter(n);
      }, 100);
    },
  },
  methods: {
    // 确认选择树
    filterConfirm() {
      let o = this.$refs.tree.getCurrentNode();

      if (!o) {
        showToast({
          message: "请选择所属组织",
          type: "error",
        });
        return false;
      }
      const { label, id, origin } = o;
      // if (origin && origin.type != "u") {
      //   showToast({
      //     message: "请选择下级所属组织",
      //     type: "error",
      //   });
      //   return false;
      // }
      console.log(o);
      this.$emit("change", o);
      //   this.searchForm.specialShopName = label.split("/")[1];
      //   this.searchForm.specialShopCode = label.split("/")[0];
      //this.$set(this, "form.specialShopName", label);
      //this.searchForm.specialShopId = id;
      //this.closeFilter();
    },

    // 获取组织机构树数据
    getTree() {
      GET_ORGANIZATION_TREE({ hasUserLeaf: true }).then((res) => {
        const { data } = res;
        this.filterTextData = data || [];
      });
    },

    // 搜索树
    filterNode(value, data) {
      let _this = this;
      if (!value) {
        _this.loading = false;
        return true;
      }
      setTimeout(function () {
        _this.loading = false;
      }, 1500);
      return data.label.indexOf(value) !== -1;
    },

    // 关闭树
    closeFilter() {
      this.$emit("change");
    },

    // 搜索树
    onChange(val) {
      this.loading = true;
      this.$refs.tree.filter(val);
    },
  },
};
</script>
<style lang="scss" scoped>
</style>