<!-- 入库记录 -->
<template>
  <div class="app-container warehousingRecord">
    <div class="page-container warehousingRecordPage" 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="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="collegeName" width="200" show-overflow-tooltip/>
          <el-table-column label="实验地点" prop="subjectName" width="249" 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="operator" width="120" show-overflow-tooltip/>
          <el-table-column label="联系方式" prop="phone" width="220" show-overflow-tooltip/>
          <el-table-column label="入库时间" prop="createTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,'{y}-{m}-{d} {h}:{i}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="100" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(1,scope.row)"
                   v-hasPermi="['db:inOutRecord:query']"
                >详情</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.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <info-page :propsData="propsData" v-if="pageType === 2"></info-page>
  </div>
</template>
<script>
  import { airbottleInOutRecordList,airbottleInOutRecordFindById } 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 infoPage from "./infoPage.vue";
  export default {
    name: 'index',
    components: {
     infoPage
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['db:inOutRecord:query',]),
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[],
        //气瓶级别
        gasBottleLevel:[],
        gasBottleSpecification:[],
        //查询条件
        queryParams:{
          pageNum:1,
          pageSize:20,
          searchValue:"",
          collegeId :null,
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    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]
          obj.endTime = this.dateRange[1]
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        obj.type = 1;
        airbottleInOutRecordList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        if(type == 1){
          airbottleInOutRecordFindById({id:row.id}).then(response => {
            this.$set(this,'pageType',2);
            this.$set(this,'propsData',response.data);
          });
        }else if(type == 2){
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      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">
  .warehousingRecord{
    display: flex;
    flex-direction: column;
    .warehousingRecordPage{

    }
  }
</style>
