<!--实验室进出记录-->
<template>
  <div class="record">
    <div class="record-page" v-if="pageType == 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
          <el-form-item label="" prop="searchValue">
            <el-input
              style="width:200px;"
              v-model="queryParams.searchValue"
              placeholder="请输入姓名"
              clearable
              size="small"
            />
          </el-form-item>
          <el-form-item label="" prop="deptId" >
            <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="subId">
            <el-select v-model="queryParams.subId" placeholder="请选择学院再选择实验室" style="width:220px;">
              <el-option
                v-for="item in subjectOptions"
                :key="item.subId"
                :label="item.subName"
                :value="item.subId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="">
            <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>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <el-form-item>
            <el-dropdown @command="exportButton" v-hasPermiRouter="['laboratory:passout:export']">
              <div class="form-dropdown-box">
                <img src="@/assets/ZDimages/basicsModules/icon_jzgxx_sc.png">
                <p>导出</p>
                <img src="@/assets/ZDimages/basicsModules/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="page-submit-common-style-button"
                 style="width:120px;"
                 @click="clickPage(2)"
              >我的进出记录</p>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" 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="userName" 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="subName" 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="hoursMinutes" 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.accessStatus == 2" @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.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <my-record v-if="pageType == 2"></my-record>
    <el-dialog class="record-el-dialog-max-box" title="详情" width="770px" append-to-body
               :visible.sync="infoShadeType" v-if="infoShadeType"
                @close="dialogOff()" :close-on-click-modal="false" :close-on-press-escape="false">
      <div class="record-el-dialog-big-box scrollbar-box">
        <div class="record-el-dialog-for-box" v-for="(item,index) in infoList" :key="index">
          <img v-if="item.subUrl" :src="item.subUrl">
          <p :class="item.subUrl?'borderA':'borderB'">{{item.checkOutName}}</p>
        </div>
      </div>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="dialogOff">取消</p>
        <p class="dialog-footer-button-primary" @click="dialogOff()">确定</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { examPointsRecordList, getRecord, delRecord, addRecord, updateRecord, subjectDictList,getDetial } from "@/apiDemo/laboratory/record";
import { treeselect } from "@/apiDemo/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import myRecord from "./myRecord.vue";
//                                    V3
import { getDeptDropList } from '@/api/commonality/permission'
import { laboratorySubRelInfoGetRelList } from '@/api/commonality/noPermission'
import { laboratorySubPassOutList,laboratorySubPassOutPhotoList } from '@/api/integratedManagement/index'


export default {
  name: "Record",
  components: {
    Treeselect,
    myRecord
  },
  data() {
    return {
      pageType:1,
      tableButtonType:this.hasPermiDom(['laboratory:record:detail']),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 部门树选项
      deptOptions: [],
      // 实验室进出记录表格数据
      recordList: [],
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        page: 1,
        pageSize:20,
        searchValue: null,
        subId: null,
        deptId: null,
      },
      //进入时间
      dateRange:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //实验室列表
      subjectOptions: [],
      //表格扩展选择器---需要在@selection-change绑定的方法内监控selection数组长度
      selectedNum:0,
      //详情遮罩开关
      infoShadeType:false,
      infoList:[],
    };
  },
  created() {
    this.getList();
    this.getDeptDropList();
  },
  methods: {
    //关闭弹层
    dialogOff() {
      this.$set(this, 'infoShadeType', false)
    },
    //查看详情
    lookInfo(row){
      laboratorySubPassOutPhotoList({passOutId:row.passOutId}).then(response => {
        this.$set(this,'infoList',response.data);
        this.$set(this,'infoShadeType',true);
      });
    },
    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]){
        this.msgError('请选择要导出的数据')
        return
      }
      let obj = JSON.parse(JSON.stringify(this.queryParams));
      obj.ids = this.ids;
      this.download('laboratory/subPassOut/export', {
        ...obj
      }, `进出记录.xlsx`)
      this.$refs.multipleTable.clearSelection();
    },
    /* 全部导出按钮操作 */
    handleExport() {
      let obj = JSON.parse(JSON.stringify(this.queryParams));
      this.download('laboratory/subPassOut/export', {
        ...obj
      }, `进出记录.xlsx`)
      this.$refs.multipleTable.clearSelection();
    },
    /*===记录勾选数据===
      需要再el-table 添加  :row-key="getRowKeys"
      需要在selection 添加 :reserve-selection="true"
    */
    getRowKeys(row) {
      return row.passOutId
    },
    //=========表格扩展选择器方法---结束=========
    getList() {
      this.loading = true;
      if(this.dateRange[0]) {
        this.queryParams.startTime = this.dateRange[0]+ 'T00:00:00';
        this.queryParams.endTime = this.dateRange[1]+ 'T23:59:59';
      } else {
        this.queryParams.startTime = null;
        this.queryParams.endTime = null;
      }
      laboratorySubPassOutList(this.queryParams).then(response => {
        this.recordList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 查询学院列表 */
    getDeptDropList() {
      getDeptDropList({deptName:"",level:2,deptType:1}).then(response => {
        this.$set(this, 'deptOptions', response.data)
      });
    },
    //根据楼栋id查询实验室列表
    laboratorySubRelInfoGetRelList(data,type){
      laboratorySubRelInfoGetRelList({deptId:data}).then(response => {
        this.subjectOptions = response.data;
      });
    },
    // 学院选择事件
    handleNodeClick(data) {
      this.$set(this.queryParams,'deptId',data);
      this.$set(this.queryParams,'subId','');
      this.laboratorySubRelInfoGetRelList(data);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.$set(this,'subjectOptions',[]);
      this.$set(this,'queryParams',{
        page: 1,
        pageSize:20,
        searchValue:"",
        deptId:"",
        subId: '',
      });
      this.dateRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedNum = selection.length;
      this.ids = selection.map(item => item.passOutId)
      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;
      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{
    .record-el-dialog-big-box{
      height:500px;
      .record-el-dialog-for-box{
        padding-bottom:20px;
        overflow: hidden;
        img{
          display: block;
          width:730px;
          height:400px;
          border-top-left-radius:6px;
          border-top-right-radius:6px;
          overflow: hidden;
        }
        p{
          font-size:16px;
          padding:0 20px;
          line-height:40px;
          overflow: hidden;
          background-color: #E0E0E0;
        }
        .borderA{
          border-bottom-left-radius:6px;
          border-bottom-right-radius:6px;
        }
        .borderB{
          border-radius:6px;
        }
      }
    }
  }
</style>
