<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="auto">
      <el-form-item label="审批状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审批状态" clearable>
          <el-option
            v-for="dict in statusDict"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </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-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="consList" @selection-change="handleSelectionChange">
      <el-table-column
        type="index"
        width="55"
        label="序号"
        align="center"
        :index="indexContinuous(queryParams.pageNum, queryParams.pageSize)"
      />
      <el-table-column label="工程名称" align="center" prop="proName" />
      <el-table-column label="承包商名称" align="center" prop="contName" />
      <el-table-column label="申请时间" align="center" prop="startDate" />
      <el-table-column label="审批状态" align="center" prop="intoStatus">
        <template slot-scope="scope">
          <!-- 检查是否存在身份证号 -->
          <span v-if="scope.row.intoStatus">{{ updateStatus(scope.row.intoStatus)
            }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleApprove(scope.row,1)"
            v-if="scope.row.status === '1'"
            v-hasPermi="['system:listCommencementApproval:list']"
          >审批
          </el-button>
          <el-button
            size="mini"
            type="text"
            v-else
            @click="handleApprove(scope.row,2)"
            v-hasPermi="['system:listCommencementApproval:list']"
          >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleAuditRecord(scope.row)"
            v-hasPermi="['system:audit:query']"
          >审核记录
          </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"
    />
  </div>
</template>

<script>
import { dictTableOption, getProName } from '@/api/tool/select'
import { listCommencementApproval } from '@/api/pro/cons/equip'
import { approvalHistory } from '@/api/terminalEquipment/deviceInformation'
import { indexContinuous, parseTime } from '@/utils/bonus'
import { encryptCBC } from '@/utils/aescbc'

export default {
  name: 'Post',
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      proNameDict: [],
      // 工程表格数据
      consList: [],
      //审批类型下拉选
      statusDict: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: ''
      },
      auditStatusDict: {
        '1': '待审批',
        '2': '审批中',
        '3': '已通过',
        '4': '已驳回',
        '5': '已撤销'
      }
    }
  },
  mounted() {
    this.loading = true
    setTimeout(() => {
      this.getStatus()
      this.queryParams.status = '1'
      this.getList()
    }, 500)

  },
  created() {


  },
  methods: {
    indexContinuous,
    updateStatus(status) {
      return this.auditStatusDict[status]
    },

    /** 查询开工审批列表 */
    getList() {
      this.loading = true
      this.queryParams.proId = this.$store.state.user.thisIds.proId
      this.queryParams.supUuid = this.$store.state.user.thisIds.supUuid
      this.queryParams.userType = this.$store.state.user.userType
      listCommencementApproval(this.queryParams).then(response => {
        this.consList = response.rows
        this.total = response.total
        this.loading = false
        console.log(this.consList)
      })
    },
    //获取审批类型下拉选
    getStatus() {
      const params = {
        dictType: 'sys_approval_state',
        dictValue: ''
      }
      dictTableOption(params).then(response => {
        this.statusDict = response.data

      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.subForm = {
        subName: undefined,
        address: undefined,
        corporateName: undefined,
        corporatePhone: undefined,
        socialUnifiedCreditCode: undefined,
        subPrincipal: undefined,
        subPrincipalPhone: undefined
      }
      this.resetForm('subForm')
      this.subOpen = false
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.proId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 审核按钮操作 */
    handleApprove(row, type) {
      this.$router.push("/pro/approval/consStartWorkApproval/" + encryptCBC(JSON.stringify({
        uuid: row.uuid,
        proId: row.proId,
        consUuid: row.consUuid,
        supUuid: row.supUuid,
        taskId: row.taskId,
        procInstId: row.procInsId,
        finalCheck: row.finalCheck,
        isExamine: type === 1,
        btnShow: type === 1,
        showType: type === 1 ? 2 : 1
      })));
    },
    /** 审核记录按钮操作 */
    handleAuditRecord(row) {
      this.$router.push("/flow/auditRecord/" + encryptCBC(JSON.stringify({
        taskId: row.taskId,
        checkType:'2'
      })));
    }
  }
}
</script>
