<!--实验室进出记录-->
<template>
  <div class="record">
    <div class="record-page" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
        <el-form-item label="关键字" prop="nickName" label-width="60px">
          <el-input
            style="width:200px;"
            v-model="queryParams.nickName"
            placeholder="请输入姓名"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="学院" prop="deptId" label-width="45px">
          <el-select v-model="queryParams.deptId" placeholder="请选择学院" @change="handleNodeClick" style="width:200px;">
            <el-option
              v-for="dict in deptOptions"
              :key="dict.deptId"
              :label="dict.deptName"
              :value="dict.deptId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="实验室" prop="subjectId" label-width="60px">
          <el-select v-model="queryParams.subjectId" placeholder="请选择学院再选择实验室" style="width:220px;">
            <el-option
              v-for="item in subjectOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="进入时间" prop="subjectId" label-width="75px">
          <el-date-picker
            :clearable="false"
            v-model="dateRange"
            style="width: 240px;height:40px;"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
        <el-form-item>
          <el-dropdown @command="exportButton" v-hasPermi="['chemical:hxpapply:export']">
            <div class="form-dropdown-box">
              <img src="@/assets/ZDimages/personnelManagement/icon_jzgxx_sc.png">
              <p>导出</p>
              <img src="@/assets/ZDimages/personnelManagement/icon_jzggl_xljt.png">
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;color:#333;" :command="{command:1}">导出全部数据</el-dropdown-item>
              <el-dropdown-item style="margin:0 10px;color:#666;" :command="{command:2}">导出选中数据</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-form-item>
        <el-form-item style="float: right;">
          <el-col :span="1.5">
            <p class="add-button-one-120"
               @click="clickPage(2)"
            >我的进出记录</p>
          </el-col>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" border :data="recordList" @selection-change="handleSelectionChange" ref="multipleTable" :row-key="getRowKeys">
        <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
        <el-table-column label="姓名" align="left" prop="nickName" show-overflow-tooltip width="170"/>
        <el-table-column label="学院" align="left" prop="deptName" show-overflow-tooltip width="250"/>
        <el-table-column label="实验室" align="left" prop="subjectName" show-overflow-tooltip/>
        <el-table-column label="进入时间" align="left" prop="inTime" show-overflow-tooltip width="220"/>
        <el-table-column label="离开时间" align="left" prop="outTime" show-overflow-tooltip width="220"/>
        <el-table-column label="停留时间" align="left" prop="intervalTime" show-overflow-tooltip width="220"/>
        <el-table-column label="操作" align="left" width="210">
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p" v-if="scope.row.outTime" @click="lookInfo(scope.row)">详情</p>
              <p class="table-button-null"></p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination :page-sizes="[20, 30, 40, 50]"
        v-show="total>0"
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <my-record v-if="pageType == 2"></my-record>

    <el-dialog class="record-el-dialog-max-box" :title="infoList[infoIndex].imgName" :visible.sync="infoShadeType" v-if="infoShadeType" width="1070px" height="700" append-to-body
               :close-on-click-modal="false">
      <div class="record-el-dialog-min-box scrollbar-box">
        <img style="width:1026px;" :src="infoList[infoIndex].imgUrl">
      </div>
      <p class="el-icon-arrow-left left-i-button" @click="infoLeftButton"></p>
      <p class="el-icon-arrow-right right-i-button" @click="infoRightButton"></p>
      <p class="record-el-dialog-bottom-text">{{infoIndex+1}}/{{infoList.length}}</p>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { listRecord, getRecord, delRecord, addRecord, updateRecord, subjectDictList,getDetial } from "@/api/laboratory/record";
import { listDepartments } from "@/api/system/dept";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import myRecord from "./myRecord.vue";

export default {
  name: "Record",
  components: {
    Treeselect,
    myRecord
  },
  data() {
    return {
      pageType:1,
      tableButtonType:this.hasPermiDom(['laboratory:record:query']),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 实验室进出记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 部门树选项
      deptOptions: [],
      //  进入或离开时间
      inOutTypeOptions: [{
        value: '1',
        label: '进入时间'
      }, {
        value: '2',
        label: '离开时间'
      }],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        nickName: null,
        subjectId: null,
        deptId: null,
        deptName: null,
        inTime: null,
        outTime: null,
        userId: null,
        inOutType: ''
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //实验室列表
      subjectOptions: [],
      //表格扩展选择器---需要在@selection-change绑定的方法内监控selection数组长度
      selectedNum:0,
      //进入时间
      dateRange:[],
      //详情遮罩开关
      infoShadeType:false,
      infoIndex:0,
      infoList:[],
    };
  },
  created() {
    this.getList();
    this.getDeptList();
    // this.getSubjectDictList();
  },
  methods: {
    //查看详情
    lookInfo(row){
      getDetial(row.id).then(response => {
        this.$set(this,'infoIndex',0);
        this.$set(this,'infoList',response.rows);
        this.$set(this,'infoShadeType',true);
      });
    },
    infoLeftButton(){
      if (this.infoIndex == 0){
        this.msgError('当前是第一张')
      }else{
        this.infoIndex--
      }
    },
    infoRightButton(){
      if (this.infoIndex == this.infoList.length-1){
        this.msgError('当前是最后一张')
      }else{
        this.infoIndex++
      }
    },
    clickPage(type){
      if(this.pageType != type){
        this.pageType = type;
      }
    },
    //导出按钮
    exportButton(data){
      if(data.command == 1){
        this.handleExport();
      } else if(data.command == 2){
        this.getSelected();
      }
    },
    //选中导出
    getSelected(){
      if(!this.ids[0]){
        Message({
          message: "请选择要导出的数据",
          type: 'error'
        });
        return
      }
      let obj = JSON.parse(JSON.stringify(this.queryParams));
      obj.accessIds = this.ids;
      this.download('laboratory/record/export', {
        ...obj
      }, `进出记录.xlsx`)
      this.$refs.multipleTable.clearSelection();
    },
    /* 全部导出按钮操作 */
    handleExport() {
      let obj = JSON.parse(JSON.stringify(this.queryParams));
      obj.accessIds = '';
      this.download('laboratory/record/export', {
        ...obj
      }, `进出记录.xlsx`)
      this.$refs.multipleTable.clearSelection();
    },
    /** 查询实验室字典列表 */
    getSubjectDictList (deptId) {
      this.subjectOptions = null;
      this.loading = true;
      // this.queryParams.deptId = deptId;
      let params = {};
      params.deptId = deptId;
      this.queryParams.subjectId = "";
      subjectDictList(params).then(response => {
        this.subjectOptions = response.data;
        this.loading = false;
      });
    },
    /*===记录勾选数据===
      需要再el-table 添加  :row-key="getRowKeys"
      需要在selection 添加 :reserve-selection="true"
    */
    getRowKeys(row) {
      return row.id
    },
    //=========表格扩展选择器方法---结束=========
    /** 查询实验室进出记录列表 */
    getList() {
      this.loading = true;
      if(this.dateRange&&this.dateRange.length>0) {
        this.queryParams.inTime = this.dateRange[0];
        this.queryParams.outTime = this.dateRange[1];
        this.queryParams.inOutType = 1
      } else {
        this.queryParams.inTime = null;
        this.queryParams.outTime = null;
        this.queryParams.inOutType = null
      }
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查询学院列表 */
    getDeptList() {
      listDepartments().then(response => {
        this.$set(this, 'deptOptions', response.data)
      });
    },
    // 学院选择事件
    handleNodeClick(data) {
      this.queryParams.deptId = data;
      // console.log("data",data);
      this.getSubjectDictList(data);
      // this.getList();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        joinUserId: null,
        subjectId: null,
        deptId: null,
        deptName: null,
        inTime: null,
        outTime: null,
        createTime: null,
        userId: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.$set(this,'subjectOptions',[]);
      this.$set(this,'queryParams',{
        pageNum: 1,
        pageSize:20,
        nickName:"",
        deptId:"",
        subjectId: '',
        inOutType: '',
        inTime: '',
        outTime: '',
      });
      this.dateRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedNum = selection.length;
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>

<style scoped lang="scss">
  .record {
    flex: 1;
    display: flex!important;
    flex-direction: column;
    overflow: hidden;
    .record-page{
      flex: 1;
      display: flex!important;
      flex-direction: column;
      box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
      margin:5px 20px 20px 10px;
      border-radius:10px;
      padding:20px!important;
      overflow: hidden;
      .form-dropdown-box{
        display: flex;
        margin:0;
        padding:0 10px;
        cursor: pointer;
        height:40px;
        img:nth-child(1){
          width:16px;
          height:16px;
          margin-top:12px;
        }
        p{
          width:47px;
          text-align: center;
          font-size:14px;
          margin:0;
          line-height:40px;
        }
        img:nth-child(3){
          width:10px;
          height:6px;
          margin-top:17px;
        }
      }
    }
    .el-row{
      margin-bottom:20px;
    }
    .sheet-expand-box{
      height:40px;
      display:flex;
      background:rgba(1,131,250,0.1);
      border-radius: 5px;
      margin-bottom:18px;
      font-size:14px;
      i{
        margin:10px 16px 0 14px;
        height:20px;
        width:20px;
        font-size:20px;
        display: block;
      }
      p{
        margin:0;
      }
      p:nth-child(2){
        width:132px;
        font-size:14px;
        height:40px;
        line-height:40px;
      }
      p:nth-child(3){
        width:60px;
        font-size:14px;
        height:40px;
        line-height:40px;
        margin-right:20px;
      }
      p:nth-child(4){
        width:60px;
        font-size:14px;
        height:40px;
        line-height:40px;
        margin-right:20px;
      }
      p:nth-child(5){
        font-size:14px;
        line-height:30px;
        width: 100px;
        height: 30px;
        border-radius: 6px;
        text-align: center;
        margin-top:5px;
        margin-right:20px;
      }
      p:nth-child(6){
        font-size:14px;
        line-height:30px;
        width: 100px;
        height: 30px;
        border-radius: 6px;
        text-align: center;
        margin-top:5px;
      }
    }
  }
</style>
<style lang="scss">
  .record-el-dialog-max-box{
    .left-i-button{
      cursor: pointer;
      text-align: center;
      line-height:28px;
      color:#fff;
      font-size:16px;
      top:350px;
      left:40px;
      position: absolute;
      width:30px;
      height:30px;
      border:1px solid #fff;
      border-radius:50%;
    }
    .right-i-button{
      cursor: pointer;
      text-align: center;
      line-height:28px;
      color:#fff;
      font-size:16px;
      position: absolute;
      top:350px;
      right:40px;
      width:30px;
      height:30px;
      border:1px solid #fff;
      border-radius:50%;
    }
    .record-el-dialog-bottom-text{
      text-align: center;
      line-height: 30px;
      font-size:16px;
    }
  }
  .record-el-dialog-min-box{
    height:560px;
  }
  .el-dialog__body{
    padding-bottom:0;
  }
</style>
