<!--用气审核-->
<template>
  <div class="app-container approval_handle">
    <div class="approval_handle-page" v-if="pageType==1">
      <template>
        <el-tabs v-model="activeName"  @tab-click="handleTabClick">
          <el-tab-pane :label="'待审核('+totalWait+')'" name="1"></el-tab-pane>
          <el-tab-pane :label="'已通过('+totalPass+')'" name="2"></el-tab-pane>
          <el-tab-pane :label="'未通过('+totalRefuse+')'" name="3"></el-tab-pane>
        </el-tabs>
      </template>
      <el-form :model="queryParams" ref="queryForm" style="margin-top:20px;" :inline="true">
        <el-form-item label="关键字" prop="safetyPrecautions" >
          <el-input v-model="queryParams.searchValue"  placeholder="申请人/联系电话" maxlength="50" />
        </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>
      <el-table border v-loading="loading" :data="tableData">
        <el-table-column label="申请人" align="left" prop="applyUserName"/>
        <el-table-column label="联系方式" align="left" prop="applyUserPhone"></el-table-column>
        <el-table-column label="使用气体" align="left" prop="useGasName"></el-table-column>
        <el-table-column label="申请时间" align="left" prop="applyTime"></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">
              <p class="table-min-button"
                 v-if="activeName==1"
                 v-hasPermi="['airbottle:taskManage:query']"
                 @click="handleClick('',scope.row,'check')"
              >审核</p>
              <p class="table-min-button"
                 v-if="activeName==2 || activeName==3"
                 v-hasPermi="['airbottle:taskManage:query']"
                 @click="handleClick('',scope.row,'detail')"
              >详情</p>
            </div>

          </template>
        </el-table-column>
      </el-table>
      <pagination :page-sizes="[20, 30, 40, 50]"
                  :total="total"
                  layout="total, prev, pager, next, sizes, jumper"
                  :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize"
                  @pagination="getList"
      />
    </div>
    <!--详情页面-->
    <detail-page v-if="pageType==2" :pageData2="pageData2"></detail-page>
  </div>
</template>

<script>
import { usegasPassApplyList, usegasRefuseApplyList,
  usegasTitle,
  usegasWaitApplyList
} from '@/api/gasManage3_0/gasManageSYD'
import { getToken } from "@/utils/auth";
import detailPage from '@/views/gasManage_syd/manage/useGasCheck/useGasCheckDetail'
export default {
  name: "Approval",
  components: {
    detailPage
  },
  data() {
    return {
      activeName:'1',
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: "Bearer " + getToken()
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue:'',
      },
      total:0,
      totalWait:0,
      totalPass:0,
      totalRefuse:0,

      tableData:[],
      dateRange:[],
      pageData2:{},
      form:{

      },
      rules:{
        txt:[
          {required: true, message: '请输入播放文字', trigger: 'blur'},
          { required: true, message: "请输入播放文字", validator: this.spaceJudgment, trigger: "blur" }
        ],
      },
    };


  },
  methods: {
      handleTabClick(tab, event) {
       // console.log(tab, event);
        console.log(this.activeName)
        this.getList()
      },
      handleClick(index,row,doType){
        let _this=this;
        if(doType=='check'){//审核
          this.pageType=2;
          _this.pageData2.status=0;
          _this.pageData2.item=row;
        }else if(doType=='detail'){//详情
          this.pageType=2;
          _this.pageData2.status=1;
          _this.pageData2.item=row;
        }else if(doType=='back'){//详情
          this.pageType=1;
          this.usegasTitle()
          this.getList()
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.searchValue = "";
        this.handleQuery();
      },
      // 取消按钮
      cancel() {
        this.form = {};
        this.dialogVisible = false;
      },
      /*提交*/
      submitForm(){
        this.$refs["form"].validate(valid => {
          if (valid) {
            let id = this.subId;

          }
        });
      },
      //tab头部数值
      usegasTitle(){
        usegasTitle().then( response => {
          let res=response.data;
           this.totalWait=res.waitApplyCount;
          this.totalPass=res.passApplyCount;
          this.totalRefuse=res.refuseApplyCount;

        });
      },
      getList(){
        let _this=this;
        if(this.activeName==1){
          usegasWaitApplyList(_this.queryParams).then( response => {
            let res=response.rows;
            _this.tableData=res;
            _this.total=response.total;
          });
        }else if(this.activeName==2){
          usegasPassApplyList(_this.queryParams).then( response => {
            let res=response.rows;
            _this.tableData=res;
            _this.total=response.total;
          });
        }else if(this.activeName==3){
          usegasRefuseApplyList(_this.queryParams).then( response => {
            let res=response.rows;
            _this.tableData=res;
            _this.total=response.total;
          });
        }


      },
  },
  mounted() {
    this.usegasTitle()
    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>
