xiangpei
2025-01-07 8779375b26e23113ebfa5940e4e5dbe696980f53
src/components/flow/User/MultUser.vue
@@ -6,6 +6,7 @@
      width="65%"
      :destroy-on-close="true"
      :close-on-click-modal="false"
      :modal-append-to-body="false"
      :modal="false"
      :before-close="close">
      <el-row :gutter="20">
@@ -53,7 +54,7 @@
            </el-form-item>
          </el-form>
          <el-table ref="dataTable" v-loading="loading" :row-key="getRowKey" :data="userList" @selection-change="handleUserSelect">
            <el-table-column type="selection" align="center" />
            <el-table-column type="selection" align="center" :reserve-selection="true"/>
            <el-table-column label="用户编号" align="center" key="userId" prop="userId" v-if="columns[0].visible" />
            <el-table-column label="登录账号" align="center" key="userName" prop="userName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
            <el-table-column label="用户姓名" align="center" key="nickName" prop="nickName" v-if="columns[2].visible" :show-overflow-tooltip="true" />
@@ -96,7 +97,7 @@
    },
    // 回显数据传值
    selectUserList: {
      type: Number,
      type: Array,
      default: null,
      required: false
    },
@@ -104,9 +105,9 @@
  },
  data() {
    return {
      innerSelected: [],
      innerSelected: [], // 选中
      // 遮罩层
      loading: true,
      loading: false,
      // 选中数组
      ids: [],
      // 显示搜索条件
@@ -148,7 +149,6 @@
        { key: 5, label: `状态`, visible: true },
        { key: 6, label: `创建时间`, visible: true }
      ],
      radioSelected: 0, // 单选框传值
    };
  },
  watch: {
@@ -156,46 +156,23 @@
    deptName(val) {
      this.$refs.tree.filter(val);
    },
    selectUserList: {
      deep: true,
      handler(newVal) {
        console.log(this.selectValues, "传入的值是")
        this.setChecked(newVal)
      },
    },
    userList: {
      deep: true,
      handler(newVal) {
        this.$nextTick(() => {
          this.$refs.dataTable.clearSelection();
          this.innerSelected.forEach(check => {
            newVal.forEach(item => {
              if (check.userId === item.userId) {
                this.$refs.dataTable.toggleRowSelection(item)
              }
            })
          })
        });
      },
    },
  },
  mounted() {
    this.getList();
    this.getDeptTree();
    this.getList();
  },
  methods: {
    getRowKeys(row) {
      return row.userId
    },
    setChecked(val) {
      this.innerSelected = val
      this.$nextTick(() => {
        this.$refs.dataTable.clearSelection();
        this.innerSelected = val
        val.forEach(check => {
          this.userList.forEach(item => {
            if (check.userId === item.userId) {
              this.$refs.dataTable.toggleRowSelection(item)
            }
          })
          this.$refs.dataTable.toggleRowSelection(check, true)
        })
      });
    },
    /** 查询用户列表 */
    getList() {
@@ -215,7 +192,7 @@
    },
    // 保存选中的数据id,row-key就是要指定一个key标识这一行的数据
    getRowKey (row) {
      return row.id
      return row.userId
    },
    // 筛选节点
    filterNode(value, data) {
@@ -229,11 +206,17 @@
    },
    // 传递选中值
    handleUserSelect(selectionList) {
      console.log("选中值", selectionList)
      this.innerSelected = selectionList
      console.log("原先值", this.innerSelected)
      this.innerSelected = [...new Set(selectionList)]
      console.log("选中值", this.innerSelected)
    },
    getSelected() {
      this.$emit('submit', this.innerSelected);
    },
    close() {
      this.$emit("close")
    },
    /** 搜索按钮操作 */
    handleQuery() {
@@ -248,9 +231,7 @@
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    close() {
      this.$emit("close")
    },
  }
};
</script>