<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="keyWord" label-width="120px">
        <el-input
          v-model="queryParams.keyWord" v-no-whitespace
          placeholder="请输入关键字"
          maxlength="60"
          show-word-limit
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工程" prop="proName">
        <el-select v-model="queryParams.proName" placeholder="请选择工程" clearable>
          <el-option
            v-for="dict in proNameDict"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审批状态" prop="proType">
        <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="consName" />
      <el-table-column label="社会统一征信代码" align="center" prop="socialUnifiedCreditCode" />
      <el-table-column label="法人姓名" align="center" prop="corporateName" />
      <el-table-column label="法人联系方式" width="120" align="center">
        <template slot-scope="scope">
          <!-- 检查是否存在身份证号 -->
          <span v-if="scope.row.corporatePhone">{{ hideSensitiveInfo(scope.row.corporatePhone) }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="承包商负责人" align="center" prop="subPrincipal" />
      <el-table-column label="承包商负责人联系方式" width="120" align="center">
        <template slot-scope="scope">
          <!-- 检查是否存在身份证号 -->
          <span v-if="scope.row.subPrincipalPhone">{{ hideSensitiveInfo(scope.row.subPrincipalPhone) }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="审批状态" align="center" prop="status" />
      <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)"
            v-hasPermi="['system:subList:edit']"
          >审批
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleAuditRecord(scope.row)"
            v-hasPermi="['system:subList:preparation']"
          >审核记录
          </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 { listPost, delPost, preparationPost } from '@/api/pro/proList'
import { dictTableOption,getProName } from '@/api/tool/select'
import { hideSensitiveInfo, indexContinuous } from '@/utils/bonus'

export default {
  name: 'Post',
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      proNameDict: [],
      // 工程表格数据
      consList: [
        {
          proName: '工程名称',
          consName: '承包商名称',
          socialUnifiedCreditCode: '社会统一征信代码',
          corporateName: '法人姓名',
          corporatePhone: '法人联系方式',
          subPrincipal: '承包商负责人',
          subPrincipalPhone: '承包商负责人联系方式',
          status: '审批状态'
        }
      ],
      //工程类型下拉选
      statusDict: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: undefined,
        status: undefined,
        proName: undefined,
        proId: undefined
      },
    }
  },
  created() {
    // this.getList();
    this.getStatus()
  },
  methods: {
    indexContinuous,
    hideSensitiveInfo,
    //判断是否选择工程创建时间
    /** 查询工程列表 */
    getList() {
      this.loading = true
      listPost(this.queryParams).then(response => {
        this.proList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    //获取工程类型下拉选
    getStatus() {
      const params = {
        dictType: 'sys_approval_state',
        dictValue: ''
      }
      dictTableOption(params).then(response => {
        this.statusDict = response.data
      })
    },
    getProName(){
      const params = {

      }
      getProName(params).then(response => {
        this.proNameDict = 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.judgeTime()
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryParams.startDate = undefined
      this.queryParams.endDate = undefined
      this.createTime = undefined
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.proId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 审核按钮操作 */
    handleApprove(row) {
      this.$router.push('/system/outsourcing-subDetailsInfo-auth/subDetailsInfo/' + JSON.stringify({
        proId: row.proId,
        consUuid: row.consUuid,
        supUuid: row.supUuid,
        subId: row.id,
        subUuid: row.subUuid,
        uuid: row.uuid
      }))
    },
    /** 审核记录按钮操作 */
    handleAuditRecord(row) {
      this.$router.push('/system/outsourcing-subDetailsInfo-auth/subDetailsInfo/' + JSON.stringify({
        proId: row.proId,
        consUuid: row.consUuid,
        supUuid: row.supUuid,
        subId: row.id,
        subUuid: row.subUuid,
        uuid: row.uuid
      }))
    },
  }
}
</script>
