<!-- 库存信息 -->
<template>
  <div class="app-container inventoryInformation">
    <div class="page-container inventoryInformationPage" v-if="pageType === 1">
      <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="searchValue" label-width="60px">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="编号/气体名称/实验地点"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="学院" prop="collegeId">
            <el-select v-model="queryParams.collegeId"
                       clearable placeholder="请选择学院" style="width: 200px">
              <el-option
                v-for="dict in optionList"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="入库时间" prop="state">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              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>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <!--<el-table-column label="气瓶编号" prop="gasName"  show-overflow-tooltip/>-->
          <el-table-column label="气体名称" prop="gasName" show-overflow-tooltip/>
          <el-table-column label="气体级别/规格" prop="content" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              {{forData(1,scope.row.level)}}/ {{forData(2,scope.row.size)}}
            </template>
          </el-table-column>
          <el-table-column label="气体余量" prop="gasPressure" width="150" show-overflow-tooltip/>
          <el-table-column label="学院" prop="collegeName" width="249" show-overflow-tooltip/>
          <el-table-column label="实验地点" prop="subjectName" width="346" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.subjectName}}{{scope.row.roomNum?'('+scope.row.roomNum+')':''}}
            </template>
          </el-table-column>
          <el-table-column label="有效期" prop="validPeriod" width="249" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.validPeriod,'{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>
<script>
  import { airbottleStockList } from "@/api/gasBottleManage/index";
  import { listDepartments } from "@/api/system/dept";
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  //import { getInfo } from "@/api/basicsModules/index";
  //import addPage from "./addPage.vue";
  export default {
    name: 'index',
    data () {
      return {
        tableButtonType:this.hasPermiDom(['demo:demo:detail','demo:demo:edit','demo:demo:del',]),
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[],
        //气瓶级别
        gasBottleLevel:[],
        gasBottleSpecification:[],
        //查询条件
        queryParams:{
          pageNum:1,
          pageSize:20,
          searchValue:"",
          collegeId :null,
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //弹窗开关
        dialogType:false,
        dialogTitle:"",
        dialogForm:null,
      }
    },
    created () {

    },
    mounted () {
      this.listDepartments();
      this.getList();
      this.getDicts("gasBottleLevel").then((response) => {
        this.$set(this,'gasBottleLevel',response.data);
      });
      this.getDicts("gasBottleSpecification").then((response) => {
        this.$set(this,'gasBottleSpecification',response.data);
      });
    },
    methods: {
      listDepartments(){
        listDepartments().then(response => {
          this.$set(this,'optionList',response.data);
        });
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'pageNum',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          pageNum:1,
          pageSize:20,
          searchValue:"",
          collegeId :null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        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'
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        airbottleStockList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      forData(type,id){
        let self = this;
        let num = 0;
        if(type == 1){
          for(let i=0;i<self.gasBottleLevel.length;i++){
            if(id == self.gasBottleLevel[i].dictValue){
              num++
              return self.gasBottleLevel[i].dictLabel
            }
          }
        }else if (type){
          for(let i=0;i<self.gasBottleSpecification.length;i++){
            if(id == self.gasBottleSpecification[i].dictValue){
              num++
              return self.gasBottleSpecification[i].dictLabel
            }
          }
        }
        if(num == 0){
          return '其他'
        }
      },
    },
  }
</script>
<style scoped lang="scss">
  .inventoryInformation{
    display: flex;
    flex-direction: column;
    .inventoryInformationPage{

    }
  }
</style>
<style lang="scss">
  .inventoryInformation-dialog-box{
    .el-dialog__body{
      padding:10px 20px;
      .text-p{
        line-height:30px;
        font-size:16px;
        text-align: center;
      }
    }
    .dialog-footer{
      display: flex;
      .dialog-footer-null-p{
        flex:1;
      }
    }
  }
</style>
