<!--资格管理-->
<template>
  <div class="app-container approval_handle">
    <div class="approval_handle-page" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" style="margin-top:20px;" :inline="true">
        <el-form-item label="关键字" prop="name">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="姓名/联系方式/实验地点"
            clearable
            maxLength="30"
            size="small"
          />
        </el-form-item>
        <el-form-item label="使用期限" prop="dateRange">
          <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>
        <el-form-item>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
        <el-form-item label="" prop="title" style="float: right">
          <el-dropdown @command="exportButton" style="float: left"   v-hasPermi="['airbottle:taskManage:export']">
            <div class="form-dropdown-box">
              <img src="@/assets/ZDimages/personnelManagement/icon_jzgxx_sc.png">
              <p>导出</p>
              <img src="@/assets/ZDimages/personnelManagement/icon_jzggl_xljt.png">
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;color:#333;" :command="{command:1}">导出全部数据</el-dropdown-item>
              <el-dropdown-item style="margin:0 10px;color:#666;" :command="{command:2}">导出选中数据</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <p v-hasPermi="['airbottle:useAgsAuditManage:list']" class="inquire-button-one" style="width: 120px;margin-left: 10px;"   @click="handleClick('','','audit')">审核资格</p>
        </el-form-item>
      </el-form>
      <el-table border v-loading="loading" :data="tableData" @selection-change="handleSelectionChange" ref="multipleTable" :row-key="getRowKeys">
        <el-table-column type="selection" width="50" align="center"/>
        <el-table-column label="姓名" align="left" prop="applyUser"/>
        <el-table-column label="联系方式" align="left" prop="phone"></el-table-column>
        <el-table-column label="实验地点" align="left" prop="location"></el-table-column>
        <el-table-column label="使用气体" align="left" prop="useGasName"></el-table-column>
        <el-table-column label="使用期限" align="left" prop="creatTime">
          <template slot-scope="scope">
            <span>{{scope.row.startTime}}-{{scope.row.endTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120">
          <template slot-scope="scope">
            <div class="button-box" v-hasPermi="['airbottle:useAgsApplyManage:query']" >

              <p class="table-min-button"
                 @click="handleClick('',scope.row,'detail')"
              >查看</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div style="display: flex;height:32px;margin-top:15px;">
        <!--<p style="flex:4;"></p>-->
        <p style="text-align: left;margin:0;line-height:32px;margin-right:20px;font-size:14px;color:#999;">
          <i class="el-icon-warning" style="color:#0183FA;"></i>
          已选择 {{selectedNum}} 项
        </p>
        <div style="flex:5;">
          <pagination :page-sizes="[20, 30, 40, 50]"
            v-show="total>0"
            :total="total"
            style="margin:0;"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>
      </div>
    </div>
    <!--审核页面-->
    <check-page v-if="pageType==2"></check-page>
    <!--详情页面-->
    <detail-page v-if="pageType==3" :pageData2="pageData2"></detail-page>
  </div>
</template>
<script>
import { useGasManageList } from '@/api/gasManage3_0/gasManage'
import { getToken } from "@/utils/auth";
import detailPage from "./useGasManageDetail.vue"
import checkPage from "./useGasManageCheckList.vue"
export default {
  name: "Approval",
  components: {
    detailPage,
    checkPage
  },
  data() {
    return {
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: "Bearer " + getToken()
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue:'',
      },
      total:0,
      tableData:[{}],
      dateRange:[],
      pageData2:{},
      //导出
      //表格扩展选择器---需要在@selection-change绑定的方法内监控selection数组长度
      selectedNum:0,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    };


  },
  methods: {
    handleClick(index,row,doType){
      let _this=this;
      if(doType=='detail'){//查看
        _this.pageData2.id=row.id;
        _this.pageType=3;
      }else if(doType=='audit'){//审核
        _this.pageType=2;
      }else if(doType=='back'){//返回
        _this.pageType=1;
      }else if(doType=='export'){//导出
        this.download('airbottle/useAgsApplyManage/export', {
          ...this.queryParams
        }, `用气信息数据导出.xlsx`)
      }

    },
    /** 当前时间 */
    getCurrentTime () {
      const yy = new Date().getFullYear()
      const mm = new Date().getMonth() + 1
      const dd = new Date().getDate()
      const hh = new Date().getHours()
      const mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
      const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
      return yy + '-' + mm + '-' + dd
    },
    /** 导出按钮操作 */
    exportButton(item) {
      let self = this;
      let currentDate = this.getCurrentTime()
      if(item.command == 1){
        self.$confirm(`确认导出全部数据?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(async () => {
          self.download('/airbottle/useAgsApplyManage/export/', {...self.queryParamsData}, '用气信息数据导出-'+currentDate+'.xlsx')
        }).catch(() => {})
      }else if(item.command == 2){
        if(self.ids.length>0) {
          self.$confirm(`确认导出选中数据?`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(async () => {
            let ids = self.ids.join(',');
            let obj = {
              ids :ids
            }
            console.log("obj",obj)
            self.download(`/airbottle/useAgsApplyManage/export/`,obj, '用气信息数据导出-'+currentDate+'.xlsx')
          }).catch(() => {})
        }else {
          this.msgError('请选择要导出的数据')
        }
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedNum = selection.length;
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /*===记录勾选数据===
      需要再el-table 添加  :row-key="getRowKeys"
      需要在selection 添加 :reserve-selection="true"
    */
    getRowKeys(row) {
      return row.id
    },
    //返回
    backPage(){
      this.$parent.handleClick('','','back');
      this.$parent.outStatistics()
      this.$parent.gasApplyStatistics()
      this.$parent.useGasStatistics()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.searchValue = "";
      this.dateRange=[];
      this.queryParams.startTime=null;
      this.queryParams.endTime=null
      this.handleQuery();
    },
    getList(){
      let _this=this;
      if(this.dateRange&&this.dateRange.length>0) {
        this.queryParams.startTime=this.dateRange[0]
        this.queryParams.endTime=this.dateRange[1]
      } else {
        this.queryParams.startTime=null;
        this.queryParams.endTime=null
      }
      useGasManageList(_this.queryParams).then( response => {
        let res=response.rows;
        _this.tableData=res;
        _this.total=response.total
      });
    },
  },
  mounted() {
    this.getList();
  }
};
</script>

<style scoped lang="scss">
/*导出按钮样式*/
.form-dropdown-box{
  display: flex;
  margin:0;
  padding:0 10px;
  cursor: pointer;
  height:40px;
  img:nth-child(1){
    width:16px;
    height:16px;
    margin-top:12px;
  }
  p{
    width:47px;
    text-align: center;
    font-size:14px;
    margin:0;
    line-height:40px;
  }
  img:nth-child(3){
    width:10px;
    height:6px;
    margin-top:17px;
  }
}
.approval_handle {
  display: flex!important;
  flex-direction: column;
  .approval_handle-page{
    flex:1;
    display: flex!important;
    flex-direction: column;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    padding:20px 20px 20px!important;
    border-radius:10px;

    .button-box{
      width:200px;
      display: flex;
    }
  }

}
</style>
