index.vue 6.74 KB
Newer Older
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-12-19 17:39:55
 * @LastEditors: 纪泽龙 jizelong@qq.com
5
 * @LastEditTime: 2023-01-13 15:37:54
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 * @FilePath: /danger-manage-web/src/views/educationPlanExam/textPaper/components/ChangePapel.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->

<template>
  <div class="changePeople-wrapper flex">
    <div class="changePeople-left">
      <div class="top-search flex">
        <el-select
          v-model="deptId"
          filterable
          placeholder="请选择"
          size="mini"
          style="width: 40%"
          clearable
        >
          <el-option
            v-for="item in searchList"
            :key="item.deptId"
            :label="item.deptName"
            :value="item.deptId"
          >
          </el-option>
        </el-select>
        <el-input
          v-model="staffName"
          size="mini"
纪泽龙's avatar
纪泽龙 committed
33
          placeholder="请输入姓名"
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
          suffix-icon="el-icon-date"
          style="width: 48%"
        >
        </el-input>
        <div>
          <el-button @click="searchTable" size="mini">搜索</el-button>
        </div>
      </div>
      <div class="left-middle-table">
        <ChangPapelTable
          ref="table"
          :selectNameList.sync="selectNameList"
          @selectOne="selectOne"
          @selectAll="selectAll"
        />
      </div>
      <!-- <div class="bottom-text">共有3n人</div> -->
    </div>
    <div class="middle flex">
      <div>>>></div>
    </div>
    <div class="changePeople-right flex">
      <div class="people-card flex zzz">
        <div
          class="item flex"
          v-for="item in selectNameList"
          :key="item.staffId"
        >
          <div>{{ item.staffName }}</div>
          <div class="close" @click="deleteName(item.staffId)">x</div>
        </div>
      </div>
纪泽龙's avatar
纪泽龙 committed
66
      <div class="bottom-text">已选择{{selectNameList.length}}</div>
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    </div>
  </div>
</template>

<script>
import ChangPapelTable from "./ChangPapelTable";
import { listDept } from "@/api/system/dept";

export default {
  name: "changepeopel",
  components: {
    ChangPapelTable,
  },
  props: {
    // 传进组件的已经被选择的人名
    jsonSelectNameList: {
      type: String,
      default: null,
    },
  },
  data() {
    return {
      selectNameList: [],
      searchList: [],
      deptId: null,
      staffName: null,
    };
  },
  created() {
    listDept().then((res) => {
      console.log(res);
      this.searchList = res.data;
    });
  },
  mounted() {},
  watch: {
    selectNameList() {
      let json;
      if (this.selectNameList.length == 0) {
        json = null;
      }
      if (Array.isArray(this.selectNameList)) {
        json = this.selectNameList.map((item) => {
          return {
纪泽龙's avatar
纪泽龙 committed
111 112
            peoPleId: item.staffId,
            peoPleName: item.staffName,
113 114 115 116 117 118 119 120 121 122 123 124
          };
        });
      } else {
        json = this.selectNameList;
      }

      this.$emit("getPeopleList", JSON.stringify(json));
    },
  },
  methods: {
    changeNameList(jsonSelectNameList) {
      if (jsonSelectNameList) {
纪泽龙's avatar
纪泽龙 committed
125 126 127 128 129 130
        this.selectNameList = JSON.parse(jsonSelectNameList).map((item) => {
          return {
            staffId: item.peoPleId,
            staffName: item.peoPleName,
          };
        });
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
      } else {
        this.selectNameList = [];
      }
      this.$refs.table.listStaff();
    },
    searchTable() {
      this.$refs.table.queryParams = {
        pageNum: 1,
        pageSize: 10,
        deptId: this.deptId,
        staffName: this.staffName,
      };
      this.$refs.table.listStaff();
    },
    deleteName(staffId) {
      const index = this.selectNameList.findIndex((item) => {
        return item.staffId == staffId;
      });
      if (index >= 0) {
        console.log(index);
        this.selectNameList.splice(index, 1);
        this.$refs.table.toggleSelection(staffId);
      }
    },
    addName(row) {
      const index = this.selectNameList.findIndex((item) => {
        // console.log(item.id)
        return item.staffId == row.staffId;
      });
      console.log(index);
      if (index >= 0) {
        this.selectNameList.splice(index, 1);
      } else {
        this.selectNameList.push(row);
      }
    },
    selectAll(all, allSelect) {
      // console.log(all);
      console.log(allSelect);
      if (allSelect) {
        all.forEach((item) => {
          const index = this.selectNameList.findIndex((iten) => {
            return iten.staffId == item.staffId;
          });
          if (index < 0) {
            this.selectNameList.push(item);
          }
        });
      } else {
        all.forEach((item) => {
          this.deleteName(item.staffId);
        });
      }
    },
    selectOne(all, row) {
      this.addName(row);
      // console.log(all,row)
    },
  },
};
</script>
<style lang="scss" scoped>
.changePeople-wrapper {
  width: 100%;
  height: 400px;
  // background-color: red;
  margin-top: 10px;
  justify-content: space-between;
  & > div {
    flex-direction: column;
  }
  .changePeople-left,
  .changePeople-right {
    width: 415px;
    height: 100%;
    border: 1px solid #e5e6eb;
  }
  .middle {
    align-items: center;
    justify-content: center;
纪泽龙's avatar
纪泽龙 committed
211 212
    div {
      color: #1890ff;
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
      font-weight: 2000;
    }
  }
  .changePeople-left {
    padding: 14px 20px 11px 16px;
    flex-direction: column;

    .top-search {
      margin-bottom: 12px;
      justify-content: space-between;
    }
    .left-middle-table {
      flex: 1;
      // background: red;
    }
    .bottom-text {
      padding-top: 10px;
      font-size: 12px;
      height: 20px;
      line-height: 20px;
      text-align: right;
      color: #1890ff;
    }
  }
  .changePeople-right {
    flex-direction: column;
    padding-top: 14px;
    height: 100%;

    .people-card {
      flex-wrap: wrap;
      align-content: flex-start;
      width: 100%;
      flex: 1;
      height: 0;
      padding-left: 11px;
      overflow-y: scroll;
      &::-webkit-scrollbar {
251
        // display: none; /* Chrome Safari */
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
      }
      .item {
        width: 70px;
        height: 30px;
        line-height: 30px;
        padding-left: 10px;
        padding-right: 5px;
        margin-right: 10px;
        color: #3d3d3d;
        box-sizing: border-box;
        margin-bottom: 10px;
        box-sizing: border-box;
        border: 1px solid #a3d3ff;
        border-radius: 3px;
        font-size: 12px;
        position: relative;
        justify-content: space-between;
      }
      .close {
        cursor: pointer;
      }
    }
    .bottom-text {
      // padding-top: 10px;
      padding-right: 10px;
      font-size: 12px;
      height: 20px;
      line-height: 20px;
      text-align: right;
      color: #1890ff;
    }
  }
}
</style>