<template>
    <div class="app-container">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
      <el-form-item label="所属项目" prop="businessKey" v-if="showPro">
          <el-select
            v-model="queryParams.businessKey"
            placeholder="请选择所属项目"
            filterable
            clearable
          >
            <el-option
              v-for="(item, index) in projectOptions"
              :key="index"
              :label="item.projectName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单位名称" prop="deptName">
          <el-input
            v-model="queryParams.deptName"
            placeholder="请输入单位名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="审批类型" prop="category">
          <el-select v-model="queryParams.category" placeholder="请选择审批类型" clearable>
            <el-option
              v-for="dict in dict.type.project_approve_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="提交人" prop="createBy">
          <el-input
            v-model="queryParams.createBy"
            placeholder="请输入提交人/电话"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="提交时间">
          <el-date-picker
            v-model="daterangeTime"
            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>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane :label="tabs.all" name="all"></el-tab-pane>
        <el-tab-pane :label="tabs.await" name="await"></el-tab-pane>
        <el-tab-pane :label="tabs.finished" name="finished"></el-tab-pane
      ></el-tabs>
      <el-table
        v-loading="loading"
        :data="auditInfoList"
        border stripe
      >
        <el-table-column
          label="项目名称"
          align="center"
          prop="projectName"
          fixed="left"
          width="250"
          show-overflow-tooltip
        />
        <el-table-column
          label="审批类型"
          align="center"
          prop="typeName"
          width="250"
          show-overflow-tooltip
        />
        <el-table-column
          label="提交人"
          align="center"
          prop="nick_name"
          width="250"
          show-overflow-tooltip
        />
        <el-table-column
          label="提交单位"
          align="center"
          prop="dept_name"
          width="250"
          show-overflow-tooltip
        />
        <el-table-column label="提交时间" align="center" prop="create_time" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.create_time, "{y}-{m}-{d} {h}:{i}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审批状态" align="center" prop="approve_status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.project_check_status" :value="scope.row.approve_status" />
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          fixed="right"
          class-name="small-padding fixed-width"
          width="200"
        >
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.approve_status == 1"
              size="mini"
              type="text"
              icon="el-icon-edit-outline"
              @click="handleApprove(scope.row)"
              v-hasPermi="['project:projectAuditinfo:edit']"
              >处理</el-button
            >
            <el-button
              v-if="scope.row.approve_status != null"
              size="mini"
              type="text"
              icon="el-icon-tickets"
              @click="handleAuditinfo(scope.row)"
              >流程日志</el-button
            >
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
      <indexDrawer ref="indexDrawer"/>
      <approveMeasureDrawer ref="approveMeasureDrawer" :closeCallBack="getList"/>
      <approveCheckingDrawer ref="approveCheckingDrawer" :closeCallBack="getList"/>
      <approveMaterialSealDrawer ref="approveMaterialSealDrawer" :closeCallBack="getList"/>
      <approveCheckDetectionDrawer ref="approveCheckDetectionDrawer" :closeCallBack="getList"/>
    </div>
  </template>
  
  <script>
  import {
    listProjectAuditinfo,
    findAuditCount,
  } from "@/api/project/projectAuditinfo";
  import indexDrawer from "../projectAuditinfo/indexDrawer.vue";
  import approveMeasureDrawer from "./approveMeasureDrawer.vue";
  import approveCheckDetectionDrawer from "./approveCheckDetectionDrawer.vue";
  import approveCheckingDrawer from "./approveCheckingDrawer.vue";
  import approveMaterialSealDrawer from "./approveMaterialSealDrawer.vue";
  
  export default {
    name: "projectAuditinfo",
    components: {
      indexDrawer,
      approveMeasureDrawer,
      approveCheckingDrawer,
      approveMaterialSealDrawer,
      approveCheckDetectionDrawer
    },
    dicts: ["project_approve_type","project_check_status"],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 表格数据
        auditInfoList: [],
        // 时间范围
        daterangeTime: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          projectId: null,
          projectName: null,
          deptId: null,
          deptName: null,
          checkType: null,
          materialName: null,
          usePosition: null,
          sampleNum: null,
          sampleUserName: null,
          witnessUserName: null,
          laboratoryName: null,
          checkTime: null,
          checkState: null,
          detectionResult: null,
          activeName: "await"
        },
        activeName: "await",
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        showPro:false,
        projectOptions:[],
        tabs: {
          all: "全部数据（0）",
          await: "待审批（0）",
          finished: "已审批（0）",
        },
      };
    },
    created() {
      this.queryParams.activeName = this.activeName;
      this.getList();
      this.initMyProject();
    },
    methods: {
      // 页签点击
      handleClick() {
        this.queryParams.activeName = this.activeName;
        this.getList();
      },
      /** 查询材料取样复试列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};
        if (null != this.daterangeTime && "" != this.daterangeTime) {
          this.queryParams.params["beginDate"] = this.daterangeTime[0];
          this.queryParams.params["endDate"] = this.daterangeTime[1];
        }
        this.queryCount(this.queryParams);
        //重新刷新代办任务
        this.$store.dispatch('settingAwaitNum');
        listProjectAuditinfo(this.queryParams).then((response) => {
          this.auditInfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      queryCount(query) {
        findAuditCount(query).then((response) => {
          if (response && response.data) {
            this.tabs.await = "送检中（" + response.data.await + "）";
            this.tabs.finished = "已完成（" + response.data.finished + "）";
            this.tabs.all = "全部数据（" + (response.data.await + response.data.finished) + "）";
          }
        });
      },
      // 查询和我相关的项目信息
      initMyProject() {
        // 获取项目列表的接口
        this.$api.publics.getMyProjectList({}).then((response) => {
          this.projectOptions = response.rows;
          if (response.rows.length > 1) {
            this.showPro = true;
          }
        });
      },
      // 处理
      handleApprove(row){
        if(row.type=="1"){
          this.$refs.approveCheckDetectionDrawer.show(row);
        }else if(row.type=="2"){
          this.$refs.approveMeasureDrawer.show(row);
        }else if(row.type=="3"){
          this.$refs.approveCheckingDrawer.show(row);
        }else if(row.type=="4"){
          this.$refs.approveMaterialSealDrawer.show(row);
        }else{

        }
      },
      // 取消按钮
      cancel() {},
      // 表单重置
      reset() {},
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 新增按钮操作 */
      handleAdd() {},
      /** 修改按钮操作 */
      handleUpdate(row) {},
      /** 登记结果按钮操作 */
      handleUpdateResult(row) {},
      /** 提交按钮 */
      submitForm() {},
      /** 删除按钮操作 */
      handleDelete(row) {},
      /** 导出按钮操作 */
      handleExport() {},
      /** 流程日志 */
      handleAuditinfo(row) {
        row.title=row.typeName;
        row.logType=row.type;
        this.$refs.indexDrawer.show(row);
      }
    },
  };
  </script>
  