<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :data="data"
      :option="option"
      :page.sync="page"
      :table-loading="loading"
      :before-open="beforeOpen"
      @row-del="rowDel"
      @size-change="sizeChange"
      @current-change="currentChange"
      @search-change="searchChange"
      @refresh-change="refreshChange"
      @cell-dblclick="cellDblclick"
      @on-load="getList"
      @saveColumn="saveColumn"
    >
      <template slot-scope="{row,index}" slot="menuLeft">
        <el-button
          icon="el-icon-printer"
          size="small"
          type="primary"
          @click.stop="openReport()"
        >报 表
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-check"
          size="small"
          @click.stop="settleAccounts(scope.row, scope.index)"
        >结 算
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
  import option from "./configuration/settleAccounts.json";
  import { getList } from "@/api/workManagement/mainProject";

  export default {
    data() {
      return {
        loading: false,
        data: [],
        option: option,
        page: {
          currentPage: 1,
          total: 0,
          pageSize: 10
        }
      };
    },
    mounted() {
      option.height = window.innerHeight - 340 ;
    },
    methods: {
      getList(page,params={flag:1}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize,params).then(res =>{
          this.data = res.data.data.records
          this.page.total = res.data.data.total
          this.loading = false
        })
      },
      //结算
      settleAccounts(row){
        this.$router.push({
          path: "/settleAccounts_detailsPage",
          query: {id: row.id},
        });
      },
      searchChange(params, done) {
        this.getList(this.page, params);
        done();
      },
      sizeChange(val) {
        this.page.pageSize = val;
        this.getList();
      },
      currentChange(val) {
        this.page.currentPage = val;
        this.getList();
      },
      refreshChange() {
        this.page.currentPage = 1;
        this.getList();
      },
      //删除列表后面的删除按钮触发触发(row, index, done)
      rowDel(row, index, done) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          // 数据回调进行刷新
          done(row);
        });
      },
      cellDblclick(row, column, cell, event) {
        console.log(row, column, cell, event);
        this.$refs.crud.rowEdit(row);
      },
      saveColumn(row, column) {
        console.log(row, column);
      },
    }
  };
</script>

<style></style>
