admin-web/src/views/foundation/store/person.vue
@@ -7,7 +7,7 @@
          <el-tree ref="tree" :data="treeData" node-key="id" :props="defaultProps" default-expand-all>
            <template slot-scope="{ node, data }">
              <div v-if="data.type != 'user'">{{ data.name }}</div>
              <div v-else class="leaf-node" :class="data.checked ? 'checked' : ''" @click="handleCheckItem(node, data)">
              <div v-else class="leaf-node" :class="data.checked ? 'checked' : ''" @click="handleCheckItem(data)">
                {{ data.name }}
              </div>
            </template>
@@ -59,10 +59,15 @@
        children: 'children',
        label: 'name',
      },
      key: Math.random(),
    };
  },
  computed: {
    checkedKeys() {
      console.log(
        1111,
        this.selectdSections.map((v) => v.id),
      );
      return this.selectdSections.map((v) => v.id);
    },
  },
@@ -71,18 +76,38 @@
    if (this.setting.info) {
      this.formData = Object.assign({}, JSON.parse(this.setting.info));
    }
    this.initTree();
    this.init();
    warehouseManagerList({ warehouseId: this.formData.id }).then((res) => {
      console.log(res);
      this.selectdSections = res.map((item) => {
        item.name = item.managerName;
        item.id = item.managerId;
        return item;
      });
      this.key = Math.random();
    });
  },
  methods: {
    initTree() {
      userSelectDepartment({ agencyId: this.formData.agencyId }).then((res) => {
        this.treeData = [res];
    async init() {
      let managerRes = await warehouseManagerList({ warehouseId: this.formData.id });
      this.managerListStr = JSON.stringify(managerRes);
      const res = await userSelectDepartment({ agencyId: this.formData.agencyId });
      this.treeData = this.deepList([res]);
    },
    deepList(list) {
      return list.map((item) => {
        if (item.children && item.children.length) {
          this.deepList(item.children);
        } else {
          if (this.managerListStr.includes(item.id)) {
            item.checked = true;
          } else {
            item.checked = false;
          }
        }
        return item;
      });
    },
    handleCheckItem(node, data) {
    handleCheckItem(data) {
      this.selectdSections = [];
      this.treeData[0].children.forEach((item, index) => {
        if (item.children) {
@@ -96,14 +121,13 @@
          });
        }
      });
      console.log(this.treeData);
    },
    handleDel(item) {
      this.handleCheckItem({}, item);
      this.handleCheckItem(item);
    },
    handleClear() {
      this.selectdSections.forEach((item) => {
        this.handleCheckItem({}, item);
        this.handleCheckItem(item);
      });
      this.selectdSections = [];
    },
@@ -111,23 +135,21 @@
      this.$emit('close');
    },
    save() {
      let params = [];
      let params = {
        warehouseId: this.setting.id,
        warehouseManagerInfoList: [],
      };
      this.selectdSections.forEach((item) => {
        params.push({
        params.warehouseManagerInfoList.push({
          managerId: item.id,
          managerName: item.name,
          baseWarehouseId: this.setting.id,
        });
      });
      debugger;
      warehouseManagerAdd(params).then((res) => {
        if (res) {
          this.$message.success('保存成功!');
          this.close();
          this.$emit('search');
        } else {
          this.$message.error('保存失败');
        }
        this.$message.success('保存成功!');
        this.close();
        this.$emit('search');
      });
    },
  },