<!--资质证照-->
<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="type" label-width="80px">
          <el-select v-model="queryParams.type" placeholder="请选择" clearable size="small">
            <el-option label="供应商资质" value="1"/>
            <el-option label="人员证照" value="2" />
            <el-option label="车辆证照" value="3" />
          </el-select>
        </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-col :span="1.5" style="margin-left: 10px;">
            <p class="add-button-one-90"
               @click="handleClick('','','add')"
               v-hasPermi="['airbottle:qualification:certificate:add']"
            ><i class="el-icon-plus"></i>新增</p>
          </el-col>
        </el-form-item>
      </el-form>
      <el-table border v-loading="loading" :data="tableData">
        <el-table-column label="名称" align="left" prop="name"/>
        <el-table-column label="类型" align="left" prop="type">
          <template slot-scope="scope">
            <span v-if="scope.row.type==1">供应商资质</span>
            <span v-if="scope.row.type==2">人员证照</span>
            <span v-if="scope.row.type==3">车辆证照</span>
          </template>
        </el-table-column>
        <el-table-column label="是否必填" align="left" prop="required">
          <template slot-scope="scope">
            <span v-if="scope.row.required==1">是</span>
            <span v-if="scope.row.required==0">否</span>
          </template>
        </el-table-column>
        <el-table-column label="需选择有效期" align="left" prop="validity">
          <template slot-scope="scope">
            <span v-if="scope.row.validity==1">是</span>
            <span v-if="scope.row.validity==0">否</span>
          </template>
        </el-table-column>
        <el-table-column label="添加时间" align="left" prop="createTime"></el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="260">
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 @click="handleClick('',scope.row,'edit')"
                 v-hasPermiAnd="['airbottle:qualification:certificate:edit']"
              >编辑</p>
              <p class="table-button-p"
                 @click="handleClick('',scope.row,'delete')"
                 v-hasPermi="['airbottle:qualification:certificate:remove']"
              >删除</p>
              <p class="table-button-null"></p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!--新增页面-->
    <add-page v-if="pageType==2" :pageData="pageData"></add-page>
  </div>
</template>

<script>
import {
  certificationDelete,
  certificationList,
  gasCategoryList,
  specificationDelete,
  specificationList
} from '@/api/gasManage3_0/gasManage'
import { getToken } from "@/utils/auth";
import addPage from "./certificationAdd.vue"

export default {
  name: "Approval",
  components: {
    addPage
  },
  data() {
    return {
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: "Bearer " + getToken()
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue:'',
        type:'',
      },
      total:0,
      tableData:[{}],
      dateRange:[],
      pageData:{},
    };


  },
  methods: {
    handleClick(index,row,doType){
      let _this=this;
      if(doType=='add'){//添加
        _this.pageData.status=0
        _this.pageType=2;
      }else if(doType=='edit'){//编辑
        _this.pageData.status=1
        _this.pageData.id=row.id
        _this.pageType=2;
      }else if(doType=='delete'){//删除

        this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          certificationDelete(row.id).then( response => {
            let res=response.rows;
            _this.getList();
            _this.msgSuccess("删除成功");
          });
        }).then(() => {

        }).catch(() => {});

      }else if(doType=='back'){//重新申请
        _this.pageType=1;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.searchValue = "";
      this.queryParams.type = "";

      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
      }
      certificationList(_this.queryParams).then( response => {
        let res=response.rows;
        _this.tableData=res;
        _this.total=response.total
      });
    },
  },
  mounted() {

    this.getList()
  }
};
</script>

<style scoped lang="scss">
  .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>
