<template>
  <!-- 项目资料库 -->
  <div class="xmzlkContent">
    <div class="d-flex flex-between">
      <div>
        <el-button type="primary" size="medium" @click="handleDownload">导出</el-button>
      </div>
      <el-form label-width="100px" :inline="true">
        <el-form-item prop="xm_start_time">
          <el-date-picker v-model="searchForm.xm_start_time" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" @change="getListData"></el-date-picker>
        </el-form-item>
        <el-form-item prop="keyword">
          <el-input placeholder="请输入搜索关键字" v-model="searchForm.keyword" clearable @clear="getListData"></el-input>
        </el-form-item>
        <el-button type="primary" class="ml5" @click="getListData">搜索</el-button>
      </el-form>
    </div>

    <el-table :data="tableData" tooltip-effect="dark" v-loading="loading" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center" width="55"></el-table-column>
      <el-table-column label="序号" align="center" type="index" width="50">
      </el-table-column>
      <el-table-column v-for="(item, index) in columnData" :key="index" :label="item.name" show-overflow-tooltip :prop="item.key" width="auto"></el-table-column>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button type="text" @click="lookDetail(scope.row)">详情 </el-button>
        </template>
      </el-table-column>
    </el-table>
    <footer class="flex-item-none" style="display: flex; justify-content: flex-end; margin-top: 30px">
      <el-pagination background layout="total,prev, pager, next" :page-size="limit" :total="total" :current-page.sync="cur_page" @current-change="handleCurrentChange"></el-pagination>
    </footer>

    <el-dialog title="详情" :visible.sync="dialogFormVisible" width="80%">
      <detail :currentId="currentId" />
    </el-dialog>
  </div>
</template>

<script>
import { xmgl_xmzlkList } from "./api";
import Detail from "../xmgkt/components/Detail.vue";
import { download } from "@/utils/request";
export default {
  data() {
    return {
      searchForm: {
        xm_start_time: "",
        keyword: "",
      },
      loading: false,
      columnData: [
        {
          name: "项目名称",
          key: "xm_name"
        },
        {
          name: "项目类别",
          key: "xm_type"
        },
        {
          name: "项目预算(万元)",
          key: "xm_ys"
        },
        {
          name: "中标金额(万元)",
          key: "xm_zbje"
        },
        {
          name: "实际支付(万元)",
          key: "xm_sjzf"
        },
        {
          name: "经办科室",
          key: "department_name"
        },
        {
          name: "经办人",
          key: "xm_zrr"
        },
        {
          name: "项目开始时间",
          key: "xm_start_time"
        },
        {
          name: "项目进度",
          key: "per"
        }
      ],
      multipleSelection: [],
      tableData: [],
      limit: 10,
      total: 12,
      cur_page: 1,
      currentId: "",
      dialogFormVisible: false,
    }
  },
  components: { Detail },
  methods: {
    async getListData() {
      this.loading = true;
      let obj = {
        page: this.cur_page,
        limit: this.limit,
        xm_start_time: this.searchForm.xm_start_time,
        keyword: this.searchForm.keyword,
        xm_dqjd: "100"
      }
      let data = await xmgl_xmzlkList(obj);
      if (data) {
        data.page_data.map(item => {
          item.xm_start_time = item.xm_start_time.substring(0, 10);
          item.per = item.xm_dqjd != "" ? item.xm_dqjd + "%" : "0%";
        })
        this.tableData = data.page_data;
        this.cur_page = Number(data.page_now);
        this.total = Number(data.total_rows);
        this.loading = false;
      }
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    lookDetail(data) {
      this.dialogFormVisible = true;
      this.currentId = data.xm_id;
    },
    handleSelectionChange(val) {
      this.multipleSelection = [...val];
    },
    handleDownload() {
      let arr = [];
      this.multipleSelection.map((value) => {
        arr.push(value.xm_id);
      });
      let obj = {
        // page: this.cur_page,
        // limit: this.limit,
        xm_start_time: this.searchForm.xm_start_time,
        keyword: this.searchForm.keyword,
        ids: arr.join(","),
        xm_dqjd: "100"
      };
      download("/jdbg/xmgl_xmzlk/index", obj);
    }
  },
  created() {
    this.getListData();
  }
}
</script>

<style>
</style>