authorization.vue 4.3 KB
<template>
  <div class="select_info_page">
    <h2 class="title">注:按车辆所属组织层级直接授权数据,包括后续增加的车辆</h2>
    <div class="device_box">
      <div class="card_box">
        <div class="head">请选择组织层级(支持多选)</div>
        <div class="info_box">
          <div class="search_box">
            <el-input v-model="term" placeholder="请输入两位以上组织层级名称" suffix-icon="el-icon-search" @input="onSearch" @keyup.enter.native="onSearch"></el-input>
          </div>
          <div class="tree_box" v-loading="treeLoading">
            <el-scrollbar class="el_scroll">
              <el-tree ref="elTree" :data="organizationList" default-expand-all :props="treeProps" :default-checked-keys="checkKeys" show-checkbox node-key="id" :filter-node-method="filterNode">
              </el-tree>
            </el-scrollbar>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { GET_ORGZ_ASSIGN_INFO, SAVE_ORGZ_ASSIGN_INFO } from "@/services/user";
import { GET_ORIGINIZATION_LIST } from "@/services/orginizaManage";
import { deepClone, showToast, broadcast, received } from "@/utils/util";
export default {
  name: "AuthorizationInfo",
  props: {
    id: {
      type: [String, Number],
      default: "",
    },
  },
  data() {
    return {
      term: "",
      organizationList: this.$store.state.organizationUserTree,
      treeLoading: false,
      treeProps: {
        label: "label",
        children: "children",
        isLeaf: "leaf",
        ["node-key"]: "id",
      },
      checkKeys: [],
    };
  },
  created() {
  },
  mounted() {
    let list = this.$store.state.organizationUserTree;
    if (!list || list.length <= 0) {
      this.getList();
    }
    this.getInfo();
  },
  methods: {
    // 获取组织树列表
    getList() {
      this.treeLoading = true;
      GET_ORIGINIZATION_LIST().then((res) => {
        this.treeLoading = false;
        this.organizationList = res.data || [];
        this.$store.commit("updateTreeByOrganization", res.data || []);
      });
    },

    // 搜索树
    onSearch() {
      let term = this.term;
      if (term && term.length < 2) {
        return false;
      }
      this.$refs.elTree.filter(term);
    },

    // 筛选树
    filterNode(value, data) {
      return data.label.indexOf(value) !== -1;
    },

    // 保存数据
    async saveInfo() {
      let _keys = this.$refs.elTree.getCheckedKeys();
      let oParams = {};
      oParams.receiverId = this.id;
      oParams.orgzIds = _keys;
      console.log(_keys);
      let res = await SAVE_ORGZ_ASSIGN_INFO(oParams);
      console.log(res);
      broadcast("cancel-loading");
      if (res.code == 200) {
        showToast({
          message: "保存成功",
          type: "success",
        });
        broadcast("assign-success");
      }
    },

    // 获取详情
    getInfo() {
      let oParams = {};
      oParams.receiverId = this.id;
      GET_ORGZ_ASSIGN_INFO(oParams).then((res) => {
        this.checkKeys = res.data || [];
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.select_info_page {
  .title {
    font-family: PingFangSC-Regular;
    font-size: 14px;
    color: #666666;
    font-weight: 400;
  }
  .device_box {
    display: flex;
    justify-content: space-between;
    .card_box {
      flex: 1;
      //width: 380px;
      flex-shrink: 0;
      box-sizing: border-box;
      .head {
        height: 54px;
        line-height: 54px;
        background: #f5f7fa;
        padding: 0 16px;
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: #333333;
        font-weight: 400;
      }
      .info_box {
        border: 1px solid #eee;
        .search_box {
          padding: 10px;
          .input_select {
            width: 100%;
            ::v-deep .el-input-group__prepend {
              background: #fff !important;
              //padding: 0 10px;
              padding-left: 10px;
              .el-select {
                width: 90px;
                box-sizing: border-box;
              }
            }
          }
        }
        .tree_box {
          border-top: 1px solid #eee;
          .el_scroll {
            padding: 10px 0;
            height: 340px;
            box-sizing: border-box;
            overflow-y: auto;
          }
        }
      }
    }
  }
}
</style>