<template>
  <basic-container>
    <avue-crud :option="option"
               :data="dataList"
               ref="crud"
               v-model="form"
               :page.sync="page"
               :search.sync="search"
               :table-loading="loading"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="flagSearch">
        <el-select   v-model="search.flag"  placeholder="" >
          <el-option
            v-for="item in flagOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
  import option from "./config/mainList.json";
  import clientOption from "./config/clientList.json";
  import { performanceAnalysis } from "@/api/workManagement/mainProject";
  import _ from "lodash";

  export default {
    data() {
      return {
        loading : false,
        form: {},
        search:{},
        detailData:{},
        option: option,
        parentId:0,
        dataList: [],
        flagOptions:[{
          value: '1',
          label: '制单人'
        }, {
          value: '2',
          label: '客户'
        }],
        page: {
          pageSize: 10,
          pagerCount: 5,
          total: 0,
        },
        query:{},
        configuration:{
          multipleChoices:false,
          multiple:false,
          disabled:false,
          searchShow:true,
          collapseTags:false,
          clearable:true,
          placeholder:'请点击右边按钮选择',
          dicData:[]
        },
        breakConfiguration:{
          multipleChoices:false,
          multiple:false,
          disabled:false,
          searchShow:true,
          collapseTags:false,
          clearable:true,
          placeholder:'请点击右边按钮选择',
          dicData:[]
        },
      }
    },
    created() {

    },
    mounted() {
      // option.height = window.innerHeight - 200 ;
    },
    methods: {
      //新单打开
      addReceipt(row){
        console.log(1)
      },
      //编辑打开
      editOpen(row){
        console.log(1)
      },
      searchReset() {
        console.log('1')
      },
      selectionChange() {
        console.log('1')
      },
      sizeChange() {
        console.log('1')
      },
      currentChange(val) {
        this.page.currentPage = val
      },
      refreshChange(params) {
        this.onLoad(this.page,params);
      },
      //点击搜索按钮触发
      searchChange(params) {
        this.onLoad(this.page, params);
      },
      paramsAdjustment(params) {
        params = Object.assign({}, this.search);
        if(!params.flag){
          params.flag = 1
        }
        if(!params.year){
          params.year = 2021
        }
        return params
      },

      onLoad(page, params) {
        this.loading = true;
        params = this.paramsAdjustment(params)
        performanceAnalysis(page.currentPage, page.pageSize,params).then(res=>{
          this.dataList = res.data.data.records
          this.page.total = res.data.data.total
        }).finally(()=>{
          this.loading = false;
        })
      },
    }
  }
</script>

<style scoped>

</style>
