<!-- 使用记录 -->
<template>
  <div class="app-container usageRecord">
    <div class="page-container usageRecordPage" 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: 210px"
            />
          </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="usageAmount" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.usageAmount}}Mpa
            </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">
              <span>{{scope.row.subjectName}}{{scope.row.roomNum?'('+scope.row.roomNum+')':''}}</span>
            </template>
          </el-table-column>
          <el-table-column label="使用人" prop="operator" width="120" show-overflow-tooltip/>
          <el-table-column label="联系方式" prop="phone" width="150" show-overflow-tooltip/>
          <el-table-column label="使用时间" prop="startTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.usageStartTime,'{y}-{m}-{d} {h}:{i}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="归还时间" prop="endTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.usageEndTime,'{y}-{m}-{d} {h}:{i}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" 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:usageRecord: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 { airbottleUsageRecordList,airbottleUsageRecordFindById } 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:usageRecord:query',]),
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[],
        //查询条件
        queryParams:{
          pageNum:1,
          pageSize:20,
          searchValue:"",
          collegeId :null,
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.listDepartments();
      this.getList();
    },
    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 = "";
        }
        airbottleUsageRecordList(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){
          airbottleUsageRecordFindById({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();
        }
      },
    },
  }
</script>
<style scoped lang="scss">
  .usageRecord{
    display: flex;
    flex-direction: column;
    .usageRecordPage{

    }
  }
</style>
