<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="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名称" v-no-whitespace
          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 proOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="承包商" prop="consName">
        <el-select v-model="queryParams.consName" placeholder="请选择承包商" clearable>
          <el-option
            v-for="dict in consOptions"
            :key="dict.dictValue"
            :label="dict.label"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <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 style="display: flex; justify-content: flex-end;">
        <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-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:proList:export']"
        >导出数据</el-button>

      </el-form-item>
    </el-form>
    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :style="{float:'right'}"></right-toolbar>

    <el-table v-loading="loading" :data="proList" >
      <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="fileName" />
      <el-table-column label="文件大小" align="center" prop="fileSize" />
      <el-table-column label="文件类型" align="center" prop="fileType" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <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="操作" width="300px" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            style="padding: 5px"
            @click="openSupervisorInfoVue(scope.row,1)"
            v-if="scope.row.status == '1'"
            v-hasPermi="['system:engineeringEquipment:listConstructionMaterial']"
          >审批</el-button>
          <el-button
            size="mini"
            type="text"
            style="padding: 5px"
            v-else
            @click="openSupervisorInfoVue(scope.row,2)"
            v-hasPermi="['system:engineeringEquipment:listConstructionMaterial']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            style="padding: 5px"
            @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, selectCons, selectPro} from "@/api/tool/select";
import {listConstructionMaterial} from "@/api/worksUnderConstruction/cMaterialsApproval";
import { encryptCBC } from '@/utils/aescbc'
import { indexContinuous } from '@/utils/bonus'

export default {
  name: "Post",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工程表格数据
      proList: [],
      //工程状态下拉选
      statusDict: [],
      proOptions: [],
      consOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      createTime: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proName: undefined,
        consName: undefined,
        fileName: undefined,
        status: '1'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      auditStatusDict: {
        '1': '待审批',
        '2': '审批中',
        '3': '已通过',
        '4': '已驳回',
        '5': '已撤销'
      }
    };
  },
  created() {
    this.getList()
    this.getStatus()
    this.selectPro()
    this.selectCons()
  },
  methods: {
    indexContinuous,
    updateStatus(status){
      return this.auditStatusDict[status]
    },
    /** 查询工程列表 */
    getList() {
      this.loading = true;
      this.queryParams.userType = this.$store.state.user.userType;
      this.queryParams.proId = this.$store.state.user.thisIds.proId;
      listConstructionMaterial(this.queryParams).then(response => {
        this.proList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    selectPro(){
      const params = {
        proId: ''
      }
      selectPro(params).then(response => {
        this.proOptions = response.data
      })
    },
    selectCons(){
      const params = {
        proId: '',
        consUuid: ''
      }
      selectCons(params).then(response => {
        console.log(response.data)
        this.consOptions = response.data
      })
    },
    //获取审批类型下拉选
    getStatus() {
      const params = {
        dictType: 'sys_approval_state',
        dictValue: ''
      }
      dictTableOption(params).then(response => {
        this.statusDict = response.data
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //打开监理页面
    openSupervisorInfoVue(row,type) {
      this.$router.push("/project/construction_materials_approval/approvalPage/" + encryptCBC(JSON.stringify({
        uuid: row.uuid,
        taskId: row.taskId,
        procInsId: row.procInsId,
        finalCheck: row.finalCheck,
        showType: type === 1 ? 2 : 1,
        btnShow: type === 1,
        isExamine: type === 1,
      })));
    },
    /** 审核记录按钮操作 */
    handleAuditRecord(row) {
      this.$router.push("/flow/auditRecord/" + encryptCBC(JSON.stringify({
        taskId: row.taskId,
        checkType:'2'
      })));
    },
    /** 导出按钮操作 */
    handleExport() {
      this.derive('project/outsourcingPro/export', {
        ...this.queryParams
      }, `设备工程绑定.xlsx`)
    }
  }
};
</script>
