<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="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>
        <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
        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="jdMaterialNum" />
      <el-table-column label="日常资料数量" align="center" prop="rcMaterialNum" />
      <el-table-column label="其它资料数量" align="center" prop="otherMaterialNum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            style="padding: 5px"
            @click="openUploadPage(scope.row)"
            v-hasPermi="['system:statistic:jump']"
          >编辑资料</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 { proMaterialStatistic } from '@/api/proMaterialStatistics/proMaterialManagement'
import { indexContinuous } from '@/utils/bonus'

export default {
  name: "Post",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工程表格数据
      proList: [],
      //工程类型下拉选
      proTypeDict: [],
      //工程状态下拉选
      proStatusDict: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      createTime: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,

        proName: undefined,
        proLeader: undefined,
        proType: 2,
        proStatus: undefined,
        startDate: undefined,
        endDate: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
    this.getProType();
    this.getProStatus()
  },
  methods: {
    indexContinuous,
    //判断是否选择工程创建时间
    judgeTime(){
      if (this.createTime !== undefined){
        this.queryParams.startDate = this.createTime[0];
        this.queryParams.endDate = this.createTime[1];
      }
    },
    /** 查询工程列表 */
    getList() {
      this.loading = true;
      this.judgeTime();
      proMaterialStatistic(this.queryParams).then(response => {
        console.log(response.rows);
        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;
        //this.loading = false;
      });
    },
    //获取工程状态下拉选
    getProStatus() {
      const params = {
        dictType: 'sys_pro_status',
        dictValue: ''
      }
      dictTableOption(params).then(response => {
        this.proStatusDict = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        proId: undefined,
        proName: undefined,
        proLeader: undefined,
        proType: undefined,
        proStatus: undefined,
        startDate: undefined,
        endDate: undefined,
        postSort: 0,
      };
      this.resetForm("form");
    },

    //打开工程资料上传页面
    openUploadPage(row){
      this.$router.push("/project/proMaterialManagement-auth/uploadMaterialPage/" + row.proId );
    },

    /** 搜索按钮操作 */
    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
    },
    /** 导出按钮操作 */
    handleExport() {
      this.derive('project/proMaterialManagement/export', {
        ...this.queryParams
      }, `工程资料统计.xlsx`)
    }
  }
};
</script>
