<!--库存统计列表-->
<template>
  <div class="page-container inventoryStatistics-listPage">
    <div class="inventoryStatistics-listPage-min" v-if="pageType == 1">
      <div class="page-top-title-box">
        <p class="page-top-title-name-p">{{newData. chemicalName}} 丨 {{newData.buildName}}-{{newData.floorName}}-{{newData.subName}}({{newData.subRoom?newData.subRoom:''}})</p>
        <p class="page-top-title-num-p">总数：{{newData.chemicalNumber}}</p>
        <p class="page-top-title-num-p">总量：{{newData.surplus}}{{newData.specUnit}}</p>
        <p class="page-top-title-out-p" @click="backPage">返回</p>
      </div>
      <div class="content-box">
        <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="queryParamsData5">
              <el-select
                style="width:145px;"
                @change="selectChange"
                v-model="queryParams.cabinetId"
                filterable
                remote
                placeholder="请搜索化学品柜"
                :remote-method="searchSelectList">
                <el-option
                  v-for="item in searchOptions"
                  :key="item.cabinetId"
                  :label="item.cabinetName"
                  :value="item.cabinetId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="useStatus">
              <el-select v-model="queryParams.useStatus"
                         placeholder="请选择状态" style="width: 140px">
                <el-option
                  v-for="item in statusOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="state">
              <el-date-picker
                :clearable="false"
                v-model="dateRange"
                size="small"
                style="width: 260px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="过期开始时间"
                end-placeholder="过期结束时间"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="" prop="searchValue">
              <el-input
                maxLength="30"
                v-model="queryParams.searchValue"
                placeholder="化学品名/CAS/编码/归属人/课题组"
                clearable
                style="width: 300px"
              />
            </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>
        </div>
        <p class="num-min-box"></p>
        <div class="page-content-box">
          <el-table  class="table-box" border :data="dataList">
            <el-table-column label="编码" prop="tagCode" show-overflow-tooltip/>
            <el-table-column label="规格" prop="specNum" width="130" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{scope.row.specNum}}{{scope.row.specUnit}}/{{scope.row.packUnit}}</span>
              </template>
            </el-table-column>
            <el-table-column label="储存位置" prop="position" width="300" show-overflow-tooltip/>
            <el-table-column label="归属人" prop="belongName" width="150" show-overflow-tooltip/>
            <el-table-column label="库存余量" prop="specNum" width="130" show-overflow-tooltip>
              <template slot-scope="scope">
                <span>{{scope.row.surplus}}{{scope.row.specUnit}}</span>
              </template>
            </el-table-column>
            <el-table-column label="过期时间" align="left" prop="expireTime">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.expireTime,"{y}-{m}-{d}") }}</span>
              </template>
            </el-table-column>
            <el-table-column label="状态" prop="statusStr" width="150" show-overflow-tooltip/>
            <el-table-column label="操作" width="150" show-overflow-tooltip>
              <template slot-scope="scope">
                <div class="table-button-box">
                  <p class="table-button-null"></p>
                  <p class="table-button-p"
                     @click="tableButton(2,scope.row)"
                     v-hasPermiRouter="['chemical:stock:detail']"
                  >详情</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"
                      :page.sync="queryParams.page"
                      :limit.sync="queryParams.pageSize"
                      @pagination="getList"
          />
        </div>
      </div>
    </div>
    <infoPage v-if="pageType == 2" :propsData="propsData2"></infoPage>
  </div>
</template>

<script>
  import infoPage from "./infoPage.vue"
  import {
    chemicalCabinetSelect,
    chemicalStockStockCollectDetailsList,
    chemicalStockStockDetails
  } from '@/api/chemicalManage'
  export default {
    name: 'listPage',
    components: {
      infoPage,
    },
    props:{
      propsData:{},
    },
    data(){
      return{
        pageType:1,
        //状态
        statusOptions:[
          {label:'未使用',value:'0'},
          {label:'使用中',value:'1'},
          {label:'超时未归还',value:'2'},
        ],
        propsData2:{},
        //类别
        categoryOptions:[],
        //级别
        levelOptions:[],
        dateRange:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          cabinetId:'',
          useStatus:'',
          startTime:'',
          endTime:'',
          searchValue:"",
        },
        //搜索化学品柜
        searchOptions:[],
        //列表数据
        dataList:[ ],
        //数据数量
        total:10,
        tableCheck:'1',
        newData:{
          name:"化学品柜名称",
          address:"所在位置地点",
          maxNum:9999,
        },
      }
    },
    created(){
      this.newData=this.propsData
      this.queryParams.stockId=this.propsData.id
    },
    mounted(){
      this.getList()
    },
    methods:{
      //化学品柜选中
      selectChange(data){

      },
      //搜索化学品柜
      searchSelectList(query) {
        if (query !== '' && query.length>1) {
          this.loading = true;
          let obj = {
            userName : query,
            userType: 2,
            pageSize: -1,
          };
          chemicalCabinetSelect({searchValue:query}).then(response => {
            this.searchOptions = response.data;
            this.loading = false;
          });
        } else {
          this.searchOptions = [];
        }
      },
      //操作按钮
      tableButton(type,row){
        if(type == 2){
          //详情
          chemicalStockStockDetails({id:row.id}).then(response => {
            this.$set(this,'propsData2',response.data);
            this.$set(this,'pageType',2);
          });
        }else if(type == 'out'){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      // 返回按钮
      backPage(){
        this.$parent.tableButton('out');
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[]);
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          cabinetId:'',
          useStatus:'',
          startTime:'',
          endTime:'',
          searchValue:"",
          stockId:this.propsData.id
        });
        this.getList();
      },
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0]+'T00:00:00'
          obj.endTime = this.dateRange[1]+'T23:59:59'
          obj.flg='gq'
        }else{
          obj.startTime = "";
          obj.endTime = "";
          obj.flg=''
        }
        chemicalStockStockCollectDetailsList(obj).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {

          }
        })
      }
    },
  }
</script>

<style scoped lang="scss">
  .inventoryStatistics-listPage{
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    .inventoryStatistics-listPage-min{
      flex:1;
      display: flex;
      flex-direction: column;
    }
    .page-top-title-num-p{
      line-height:40px;
      margin-right:40px;
    }
    .content-box{
      flex:1;
      display: flex;
      flex-direction: column;
      padding:0 20px 20px 20px;
      overflow: hidden;
      .table-max-box{
        p{
          cursor: pointer;
          display: inline-block;
          text-align: center;
          padding:0 20px;
          color:#333;
          border:1px solid #E0E0E0;
          border-radius:4px;
          line-height:40px;
          margin-right:10px;
        }
        .tableCheck{
          color:#fff;
          background-color: #0183FA;
          border:1px solid #0183FA;
        }
      }
      .page-form-title-box{
        border:none;
        padding-left:0;
      }
      .num-min-box{
        background-color:rgba(1,131,250,0.2);
        color:#0183FA;
        font-size:14px;
        line-height:40px;
        padding:0 20px;
      }
      .page-content-box{
        padding:0;
      }
    }
  }
</style>
