<template>
  <div>
  <basic-container  v-show="show">
    <avue-crud
      ref="crud"
      :data="data"
      :option="option"
      :page.sync="page"
      :search.sync="search"
      :table-loading="loading"
      @row-del="rowDel"
      @size-change="sizeChange"
      @current-change="currentChange"
      @search-change="searchChange"
      @refresh-change="refreshChange"
      @on-load="getList"
      @saveColumn="saveColumn"
    >
      <template slot="corpIdSearch">
        <select-component
          v-model="search.corpId"
          :configuration="configuration"
        ></select-component>
      </template>
      <template slot="userNameSearch">
        <el-select
          v-model="search.userName"
          multiple
          filterable
          remote
          reserve-keyword
          :remote-method="remoteMethod">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="{row,index}" slot="menuLeft">
        <el-button
          icon="el-icon-printer"
          size="small"
          type="primary"
          @click.stop=""
        >报 表
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-edit"
          size="small"
          @click.stop="settleAccounts(scope.row, scope.index)"
        >编 辑
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
  <detail-page
    v-if="!show"
    ref="detail"
    @goBack="goBack"
    :detailData="detailData"
  ></detail-page>
  </div>
</template>

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

  export default {
    data() {
      return {
        loading: false,
        show:true,
        detailData:{},
        data: [],
        option: option,
        search:{},
        configuration:{
          multipleChoices:false,
          multiple:false,
          disabled:false,
          searchShow:true,
          collapseTags:false,
          clearable:true,
          placeholder:'请点击右边按钮选择',
          dicData:[]
        },
        page: {
          currentPage: 1,
          total: 0,
          pageSize: 10
        }
      };
    },
    components:{
      detailPage
    },
    mounted() {
      // option.height = window.innerHeight - 340 ;
    },
    methods: {
      getList(page,params={}) {
        this.loading = true;
        params.flag = 1;
        if(params){
          if (params.createTime != undefined && params.createTime.length !=0) {  //发货
            params.createStartDate = params.createTime[0]+ " " + "00:00:00";
            params.createEndDate = params.createTime[1] + " " + "23:59:59";
            this.$delete(params,'createTime')
          }
        }
        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.detailData = {
          id: row.id
        };
        this.show = false;
      },
      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);
        });
      },
      saveColumn(row, column) {
        console.log(row, column);
      },
      goBack() {
        this.detailData=this.$options.data().detailData
        this.show = true;

        this.search.createTime[0] =  this.search.createStartDate
        this.search.createTime[1] =  this.search.createEndDate
        console.log(this.search)

        this.getList(this.page,this.search)
      },
    }
  };
</script>

<style></style>
