<!--机柜管理/化学品详情-->
<template>
  <div class="listPage">
    <div class="title-box">
      <p>{{listPropsData.cabinetName}}-{{listPropsData.posi}}<span>(负责人：{{listPropsData.safeUserName}})</span></p>
      <p class="reset-button-one" @click="backPage"><i class="el-icon-arrow-left"></i>返回</p>
    </div>
    <el-form :model="queryParamsData" ref="queryForm" :inline="true" style="margin:20px 20px 0;">
      <el-form-item label="关键字" prop="searchValue">
        <el-input
          maxlength="20"
          v-model="queryParamsData.searchValue"
          placeholder="化学品名/CAS号/编号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="分类" prop="chemicalClassify">
        <el-select v-model="queryParamsData.chemicalClassify" clearable placeholder="请选择分类">
          <el-option
            v-for="item in optionsListOne"
            :key="item.id"
            :label="item.classifyName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="useStatus">
        <el-select v-model="queryParamsData.useStatus" clearable placeholder="请选择状态">
          <el-option
            v-for="item in optionsListTwo"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="柜锁" prop="lockId" v-if="$store.state.settings.smartAlarmType == 1">
        <el-select v-model="queryParamsData.lockId" clearable placeholder="请选择柜锁">
          <el-option
            v-for="item in optionsListThree"
            :key="item.id"
            :label="item.lockName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <p class="inquire-button-one" @click="handleQuery" style="margin-right:10px;">查询</p>
        <p class="reset-button-one" @click="resetQuery">重置</p>
      </el-form-item>
    </el-form>
    <div class="listPage-min scrollbar-box">
      <img style="width:300px;margin:100px auto 0;" src="@/assets/ZDimages/null-data-1.png" alt="" v-if="!tableList[0]">
      <div class="for-max-big-box" v-for="(item,index) in tableList" :key="index">
        <div class="for-title-box">
          <p class="for-title-name">{{item.chemicalName}} {{item.casNum}}<span v-for="(minText,index) in item.classifyAttribute">{{minText}}</span></p>
          <p class="for-title-num">总库存：{{item.totalStock}}</p>
          <p class="for-title-null">丨</p>
          <p class="for-title-num">使用中：{{item.useing}}</p>
          <p class="for-title-null">丨</p>
          <p class="for-title-num">作废：{{item.cancel}}</p>
          <p class="for-title-null">丨</p>
          <p class="for-title-num">用结：{{item.useUp}}</p>
          <!--<p class="for-title-null">丨</p>-->
          <!--<p class="for-title-num">未使用：{{item.noUse}}</p>-->
        </div>
        <el-table v-loading="loading" border :data="item.hxpCabinetInclusionChemicalSonList" style="margin:30px 0;">
          <el-table-column label="化学品编号" align="center" prop="joinNum" />
          <el-table-column label="柜锁名称" align="center" prop="lockName" v-if="$store.state.settings.smartAlarmType == 1"/>
          <el-table-column label="分类" align="center" prop="classifyName" />
          <el-table-column label="形态" align="center" prop="chemicalShape" />
          <el-table-column label="纯度" align="center" prop="purity" />
          <el-table-column label="容量规格" align="center" prop="chemicalAmountUnit" />
          <el-table-column label="过期时间" align="center" prop="expireTime" />
          <el-table-column label="状态" align="center" prop="useStatus" />
          <el-table-column label="库存净重" align="center" prop="outUsages" />
        </el-table>
      </div>
    </div>
    <pagination
      style="margin:20px;"
      v-show="total>0"
      :total="total"
      :page-sizes="[6]"
      layout="total, prev, pager, next, jumper"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { getCabinetByChemical,classifyList,getHardwareByLockList } from "@/api/medicUniversity-3_1/index";
  export default {
    name: "listPage",
    props:{
      listPropsData:{},
    },
    data() {
      return {
        loading:false,
        //实验室列表
        optionsListOne:[],
        //状态列表
        optionsListTwo:[{id:"1",name:"使用中"},{id:"2",name:"未使用"},{id:"3",name:"超时未归还"},{id:"4",name:"已过期"}],
        optionsListThree:[],
        // 搜索数据
        total:0,
        queryParamsData:{
          pageNum:1,
          pageSize:4,
        },
        // 搜索实际发送数据
        queryParams:{
          pageNum:1,
          pageSize:4,
        },
        tableList:[]
      };
    },
    created() {

    },
    mounted(){
      this.getHardwareByLockList();
      this.classifyList();
      this.getList();

    },
    methods: {
      //根据机柜id获取柜锁
      getHardwareByLockList(){
        getHardwareByLockList({joinCabinet:this.listPropsData.id}).then(response => {
          this.optionsListThree = response.data;
        });
      },
      //获取化学品分类列表
      classifyList(){
        classifyList().then(response => {
          this.optionsListOne = response.rows;
        });
      },
      //获取数据列表
      getList(){
        this.queryParamsData = JSON.parse(JSON.stringify(this.queryParams));
        this.queryParamsData.id = this.listPropsData.id;
        getCabinetByChemical(this.queryParamsData).then(response => {
          for(let i=0;i<response.rows.length;i++){
            if(response.rows[i].classifyAttribute){
              response.rows[i].classifyAttribute = response.rows[i].classifyAttribute.split(",");
            }
          }
          this.tableList = response.rows;
          this.total = response.total;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParamsData.pageNum = 1;
        this.queryParamsData.pageSize = 10;
        this.queryParams = JSON.parse(JSON.stringify(this.queryParamsData));
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$set(this,'queryParamsData',{});
        this.$set(this,'queryParams',{});
        this.handleQuery();
      },
      backPage(){
        this.$parent.pageToggle(1);
      },
    }
  }
</script>

<style scoped lang="scss">
  .listPage {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    p {
      margin: 0;
      padding: 0;
    }
    .title-box{
      display: flex;
      height:90px;
      border-bottom: 1px solid #D8D8D8;
      p:nth-child(1){
        flex:1;
        font-size:16px;
        line-height:90px;
        margin-left:18px;
        color:#0045AF;
        span{
          line-height:14px;
          color:#333333;
          font-weight:500;
          margin-left:20px;
        }
      }
      p:nth-child(2){
        margin:25px 25px 0 0;
      }
    }
    .listPage-min{
      flex:1;
      display: flex;
      flex-direction: column;
      padding:0 20px 20px;
      font-weight:500;
      color:#333333;
      .for-max-big-box{
        .for-title-box{
          display: flex;
          p{
            font-size:16px;
            line-height:20px;
          }
          .for-title-name{
            flex:1;
            span{
              margin-left:20px;
              font-size:14px;
              padding:0 14px;
              background: rgba(255, 132, 0, 0.2);
              color:#FF8400;
              border-radius:4px;
            }
          }
          .for-title-num{

          }
          .for-title-null{
            width:57px;
            text-align: center;
          }
        }
      }
    }
  }
</style>
<style lang="scss">
  .listPage{
    .listPage-min{
      .for-max-big-box{
        .el-table__empty-text{
          background: #fff!important;
          color:#999;
        }
      }
    }
  }
</style>
