<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="工程名称" prop="proName">
        <el-input
          v-model="queryParams.proName"
          placeholder="请输入工程名称"
          maxlength="60"
          show-word-limit
          clearable v-no-whitespace
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="工程负责人" prop="proLeader">
        <el-input
          v-model="queryParams.proLeader"
          placeholder="请输入工程负责人姓名"
          maxlength="20"
          show-word-limit
          clearable v-no-whitespace
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工程类型" prop="proType">
        <el-select v-model="queryParams.proType" placeholder="工程类型" clearable>
          <el-option
            v-for="dict in proTypeDict"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="工程状态" prop="proStatus">
        <el-select v-model="queryParams.proStatus" placeholder="工程状态" clearable>
          <el-option
            v-for="dict in proStatusDict"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label-width="100px" label="工程创建时间">
        <el-date-picker v-model="createTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                        :editable="false" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </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" @selection-change="handleSelectionChange">
      <el-table-column label="序号" type="index" width="55" align="center" :index="indexContinuous(queryParams.pageNum, queryParams.pageSize)" />
      <el-table-column label="工程名称" show-overflow-tooltip align="center" prop="proName" />
      <el-table-column label="工程负责人" show-overflow-tooltip align="center" prop="proLeader" />
      <el-table-column label="负责人联系方式" show-overflow-tooltip align="center" >
        <template slot-scope="scope">
          <!-- 检查是否存在身份证号 -->
          <span v-if="scope.row.proLeaderPhone">{{ hideSensitiveInfo(scope.row.proLeaderPhone) }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="工程类型" show-overflow-tooltip align="center" prop="proType" />
      <el-table-column label="计划开工日期" show-overflow-tooltip align="center" prop="startDate" />
      <el-table-column label="计划竣工日期" show-overflow-tooltip align="center" prop="endDate" />
      <el-table-column label="工程状态" show-overflow-tooltip align="center" prop="proStatus" />
      <el-table-column label="创建人" show-overflow-tooltip align="center" prop="createPerson" />
      <el-table-column label="创建时间" show-overflow-tooltip width="170px"  align="center" prop="createTime" />
      <el-table-column label="操作" width="300px" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            style="padding: 5px"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:outsourcingPro:edit']"
          >基础信息</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="primary"-->
<!--            style="padding: 5px;background: green;border: 1px solid green"-->
<!--            v-hasPermi="['system:outsourcingPro:supervisor']"-->
<!--            @click="openSupervisorInfoVue(scope.row)"-->
<!--          >监理信息</el-button>-->
          <el-button
            size="mini"
            type="primary"
            style="padding: 5px;background: orange;border: 1px solid orange"
            @click="openConsTab(scope.row)"
            v-hasPermi="['system:outsourcingPro:cons']"
          >承包商信息</el-button>
          <el-button
            size="mini"
            type="primary"
            style="padding: 5px;background: purple;border: 1px solid purple"
            @click="handleProProfileView(scope.row)"
            v-hasPermi="['system:outsourcingPro:profile']"
          >工程资料</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 { hideSensitiveInfo, indexContinuous } from '@/utils/bonus'
import { listPost } from "@/api/pro/outsourcingPro";
import { dictTableOption} from "@/api/tool/select";


export default {
  name: "Post",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工程表格数据
      proList: [],
      //工程类型下拉选
      proTypeDict: [],
      //工程状态下拉选
      proStatusDict: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      createTime: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proName: undefined,
        proLeader: undefined,
        proType: undefined,
        proStatus: undefined,
        startDate: undefined,
        endDate: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList()
    this.getProType()
    this.getProStatus()
  },
  methods: {
    indexContinuous,
    hideSensitiveInfo,
    //判断是否选择工程创建时间
    judgeTime(){
      if (this.createTime !== undefined){
        this.queryParams.startDate = this.createTime[0];
        this.queryParams.endDate = this.createTime[1];
      }
    },
    /** 查询工程列表 */
    getList() {
      this.loading = true;
      this.judgeTime();
      this.queryParams.isOutsourcing = '1'
      listPost(this.queryParams).then(response => {
        this.proList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //获取工程类型下拉选
    getProType() {
      const params = {
        dictType: 'sys_pro_type',
        dictValue: ''
      }
      dictTableOption(params).then(response => {
        this.proTypeDict = response.data;
      });
    },
    //获取工程状态下拉选
    getProStatus() {
      const params = {
        dictType: 'sys_pro_status',
        dictValue: ''
      }
      dictTableOption(params).then(response => {
        this.proStatusDict = response.data;
        this.proStatusDict.splice(0,1)
      });
    },
    //打开监理页面
    openSupervisorInfoVue(row) {
      this.$router.push("/project/outsourcing-supervisor-auth/supervisorInfo/" + row.proId );
    },
    //打开承包商页面
    openConsTab(row){
      this.$router.push("/project/outsourcing-consDetailsInfo-auth/consInfo/" + row.proId );
    },
    //打开工程资料页面
    handleProProfileView(row){
      this.$router.push("/project/outsourcing-pro-profile-auth/proProfile/" + row.proId );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        proId: undefined,
        proName: undefined,
        proLeader: undefined,
        proType: undefined,
        createPerson: undefined,
        createTime: undefined,
        postSort: 0,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    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
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push("/project/projectManagements/outsourcingPro/editOutsourcingPro/" + row.proId );
    },
    /** 导出按钮操作 */
    handleExport() {
      this.judgeTime()
      this.derive('project/outsourcingPro/export', {
        ...this.queryParams
      }, `外委外包工程.xlsx`)
    }
  }
};
</script>
