<template>
  <basic-container>
    <avue-crud :option="option"
               :data="dataList"
               ref="crud"
               v-model="form"
               :page.sync="page"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @cell-dblclick="cellDblclick"
               @on-load="onLoad">
    </avue-crud>
  </basic-container>
</template>

<script>
  import option from "./configuration/statisticalList.json";

  export default {
    name: "statisticalList",
    data() {
      return {
        form: {},
        option: option,
        parentId:0,
        dataList: [],
        page: {
          pageSize: 10,
          pagerCount: 5,
          total: 0,
        },
        query:{}
      }
    },
    created() {
      console.log(parseInt(this.option.column.length / 4),111111111)
      if (parseInt(this.option.column.length / 4) !== this.option.column.length / 4){
        console.log(123)
        this.option.searchMenuSpan = 6;
        this.option.searchMenuPosition = "center";
      }else {

        this.option.searchMenuPosition = "right";
      }
    },
    mounted() {
      option.height = window.innerHeight - 340 ;
    },
    methods: {
      //删除列表后面的删除按钮触发触发(row, index, done)
      rowDel(row, index, done) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          // 数据回调进行刷新
          done();
        });
      },
      //修改时的修改按钮点击触发
      rowUpdate(row, index, done, loading) {
        setTimeout(() => {
          this.$message.success("修改成功");
          loading();
          done();
        }, 1000);
        // typeSave(row).then(() => {
        //   this.$message({
        //     type: "success",
        //     message: "操作成功!"
        //   });
        //   // 数据回调进行刷新
        //   done(row);
        // }, error => {
        //   window.console.log(error);
        //   loading();
        // });
      },
      //新增修改时保存触发
      rowSave(row, done, loading) {
        setTimeout(() => {
          this.$message.success("保存成功");
          loading();
          done();
        }, 1000);
      },
      //点击搜索按钮触发
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        params.parentId = 0
        this.onLoad(this.page, params);
        done()
      },
      searchReset() {
        console.log('1')
      },
      selectionChange() {
        console.log('1')
      },
      currentChange() {
        console.log('1')
      },
      sizeChange() {
        console.log('1')
      },
      refreshChange() {
        console.log('1')
      },
      onLoad(page, params = {}) {
        const {createTimeA} = this.query;
        let values = {
          ...params,
          size:this.page.pageSize,
          current:this.page.currentPage
        };
        if (createTimeA) {
          values = {
            ...params,
            createTime: createTimeA[0] + ' 00:00:00',
            endTime: createTimeA[1] + ' 23:59:59',
            ...this.query,
            size:this.page.pageSize,
            current:this.page.currentPage
          };
          values.createTimeA = null;
        }
        values.parentId = 0;
        this.dataList = [
          {
            custmerName:"途宝",
            Ymoney:"2100",
            Smoney:"1500",
            qianfei:"600",
            kehuzt:"暂存",
            beizhu:"你好",
            zuixinxgr:"LOL",
            zuixinxgsj:"3030-10-10",
          },
          {
            custmerName:"途宝",
            Ymoney:"2100",
            Smoney:"1500",
            qianfei:"600",
            kehuzt:"暂存",
            beizhu:"你好",
            zuixinxgr:"LOL",
            zuixinxgsj:"3030-10-10",
          }
        ]
        this.page.total = 1
        // customerList(values).then(res => {
        //
        // })
      },
      cellDblclick(row, column, cell, event) {
        this.$refs.crud.rowEdit(row);
      }
    }
  }
</script>

<style scoped>

</style>
