<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="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="createPerson">
        <el-input
          v-model="queryParams.createPerson"
          placeholder="请输入创建人姓名"
          maxlength="20"
          show-word-limit
          clearable v-no-whitespace
          @keyup.enter.native="handleQuery"
        />
      </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>
        <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="proLeader" />
      <el-table-column label="工程状态" align="center" prop="proStatus" />
      <el-table-column label="创建人" align="center" prop="createPerson" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="工程设备数" align="center" prop="proEquipmentNum" />
      <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="openSupervisorInfoVue(scope.row)"
            v-hasPermi="['system:outsourcingPro:edit']"
          >基础信息</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} from "@/api/tool/select";
import {listEngineer} from "@/api/terminalEquipment/engineeringEquipmentBinding";
import { indexContinuous } from '@/utils/bonus'

export default {
  name: "Post",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工程表格数据
      proList: [],
      //工程状态下拉选
      proStatusDict: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      createTime: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proName: undefined,
        proLeader: undefined,
        proType: undefined,
        proStatus: undefined,
        createPerson: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList()
    this.getProStatus()
  },
  methods: {
    indexContinuous,
    /** 查询工程列表 */
    getList() {
      this.loading = true;
      listEngineer(this.queryParams).then(response => {
        this.proList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //获取工程状态下拉选
    getProStatus() {
      const params = {
        dictType: 'sys_pro_status',
        dictValue: ''
      }
      dictTableOption(params).then(response => {
        this.proStatusDict = response.data;
        this.proStatusDict.splice(0,1)
      });
    },
    // 取消按钮
    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.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.startDate = undefined;
      this.queryParams.endDate = undefined;
      this.createTime = undefined;
      this.handleQuery();
    },
    //打开监理页面
    openSupervisorInfoVue(row) {
      this.$router.push("/system/engineer-equipment-auth/bindingInformation/" + row.proId );
    },
    /** 导出按钮操作 */
    handleExport() {
      this.derive('project/engineeringEquipment/export', {
        ...this.queryParams
      }, `设备工程绑定.xlsx`)
    }
  }
};
</script>
