<!-- 选择用户 -->
<template>
  <div class="page-container selectUser-addPage">
    <div class="page-form-title-box">
      <el-form :model="queryParams" class="form-box" ref="queryForm"
               :inline="true" style="width:100%;">
        <el-form-item label="" prop="gradeNumbers">
          <el-select v-model="queryParams.gradeNumbers" collapse-tags multiple placeholder="学年" style="width: 220px">
            <el-option
              v-for="dict in optionListD"
              :key="dict.gradeNumber"
              :label="dict.gradeNumber"
              :value="dict.gradeNumber"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="deptIds">
          <el-cascader
            collapse-tags
            style="width: 220px"
            v-model="queryParams.deptIds"
            :options="optionListB"
            :props="{
                    multiple:true,
                    emitPath:false,
                    checkStrictly: true,
                    value: 'deptId',
                    label: 'deptName',
                    children: 'child',
                  }"
            :show-all-levels="false"
            filterable
            placeholder="学院单位"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="" prop="userTypeIds">
          <el-select v-model="queryParams.userTypeIds" collapse-tags multiple placeholder="用户类别" style="width: 220px">
            <el-option
              v-for="dict in optionListC"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="majorId">
          <el-select v-model="queryParams.majorId" collapse-tags multiple placeholder="专业" style="width: 220px">
            <el-option
              v-for="dict in optionListE"
              :key="dict.id"
              :label="dict.disciplineName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="searchValue">
          <el-input
            maxLength="30"
            v-model="queryParams.searchValue"
            placeholder="姓名/学工号"
            style="width: 220px"
          />
        </el-form-item>
        <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
        <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        <p class="page-submit-common-style-button"
           style="float: right;"
           @click="checkButton()"
        >确定</p>
      </el-form>
    </div>
    <div class="page-content-box">
      <el-table class="table-box" border :data="dataList"
                ref="multipleTable" :row-key="getRowKey" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" :reserve-selection="true"></el-table-column>
        <el-table-column label="姓名" prop="userName"  show-overflow-tooltip/>
        <el-table-column label="学工号" prop="account" show-overflow-tooltip/>
        <el-table-column label="用户类别" prop="userTypeName" show-overflow-tooltip/>
        <el-table-column label="专业" prop="majorName" show-overflow-tooltip/>
        <el-table-column label="学年" prop="gradeNumber" show-overflow-tooltip/>
        <el-table-column label="学院单位" prop="deptName" show-overflow-tooltip/>
      </el-table>
      <pagination :page-sizes="[20, 30, 40, 50]"
                  v-show="total>0"
                  :total="total"
                  :page.sync="queryParams.page"
                  :limit.sync="queryParams.pageSize"
                  @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
  import {
    systemUserGetCategories,systemUserGetAcademicYear,
    systemUserGetUserDataByParam,examElDisciplineTypeList,systemDeptCurrentDept,
  } from "@/api/safetyEducationExaminationNew/index";
  export default {
    name: 'addPage',
    props: {
      propsData: {}
    },
    data() {
      return {
        //下拉列表数据
        optionListA:[],
        optionListB:[],
        optionListC:[],
        optionListD:[],
        optionListE:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          gradeNumbers:[],
          deptIds :[],
          userTypeIds :[],
          majorId :[],
          searchValue :'',
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //存储所有被勾选的数据
        multipleSelection: [],
      }
    },
    created() {

    },
    mounted() {
      this.getList();
      this.systemUserGetAcademicYear();
      this.systemUserGetCategories();
      this.examElDisciplineTypeList();
      this.systemDeptCurrentDept();
    },
    methods: {
      // 提交按钮
      checkButton() {
        let self = this;
        if(!this.multipleSelection[0]){
          this.msgError('请勾选用户')
          return
        }
        let list = [];
        for(let i=0;i<self.multipleSelection.length;i++){
          list.push({
            userId:self.multipleSelection[i].userId,
            userName:self.multipleSelection[i].userName,
            deptId:self.multipleSelection[i].deptId,
            deptName:self.multipleSelection[i].deptName,
            account:self.multipleSelection[i].account,
            disciplineId:self.multipleSelection[i].majorId,
            disciplineName:self.multipleSelection[i].majorName,
            academicYear:self.multipleSelection[i].gradeNumber,
          })
        }
        this.$parent.$parent.drawerOffButton(JSON.parse(JSON.stringify(list)))
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          gradeNumbers:[],
          deptIds :[],
          userTypeIds :[],
          majorId :[],
          searchValue :'',
        });
        this.getList();
      },
      //获取数据列表
      getList(){

        let obj = JSON.parse(JSON.stringify(this.queryParams))
        systemUserGetUserDataByParam(obj).then(response => {

          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //学年下拉列表
      systemUserGetAcademicYear(){
        systemUserGetAcademicYear({}).then(response => {
          this.$set(this,'optionListD',response.data);
        });
      },
      //用户类别下拉列表
      systemUserGetCategories(){
        systemUserGetCategories({}).then(response => {
          this.$set(this,'optionListC',response.data);
        });
      },
      //查询全部专业类别
      examElDisciplineTypeList(){
        examElDisciplineTypeList({}).then(response => {
          this.$set(this,'optionListE',response.data);
        });
      },
      //学院列表
      systemDeptCurrentDept(){
        systemDeptCurrentDept({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this,'optionListB',list);
        });
      },
      getRowKey(row) {
        return row.userId;
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
    }
  }
</script>

<style scoped lang="scss">
  .selectUser-addPage {
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
</style>
