<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"
               @on-load="onLoad"
               @tree-load="treeLoad">
      <template slot="menuLeft">
        <el-button type="primary"
                   size="small"
                   icon="el-icon-upload2"
                   plain
                   @click="handleDelete">导 入
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-view"
          size="small"
          @click.stop="beforeOpenPage(scope.row,scope.index)"
        >发送
        </el-button>
        <el-button
          type="text"
          icon="el-icon-edit"
          size="small"
          @click.stop="editOpen(scope.row,scope.index)"
        >完工
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
  import option from "./configuration/mainList.json";
  import {customerList, typeSave,detail,deleteDetails} from "@/api/basicData/customerCategory"

  export default {
    name: "customerInformation",
    data() {
      return {
        form: {},
        option: option,
        parentId:0,
        dataList: [],
        page: {
          pageSize: 10,
          pagerCount: 5,
          total: 0,
        },
        query:{}
      }
    },
    created() {

    },
    methods: {
      //删除列表后面的删除按钮触发触发(row, index, done)
      rowDel(row, index, done) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          // 数据回调进行刷新
          done(row);
        });
      },
      //修改时的修改按钮点击触发
      rowUpdate(row, index, done, loading) {
        setTimeout(() => {
          this.$message.success("修改成功");
          loading();
          done();
        }, 1000);
      },
      //新增修改时保存触发
      rowSave(row, done, loading) {
        setTimeout(() => {
          this.$message.success("保存成功");
          loading();
          done();
        }, 1000);
      },
      //查询全部
      initData(){
        customerList().then(res => {
          console.log(this.form);
          const column = this.findObject(this.option.column, "parentId");
          column.dicData = res.data.data.records;
        });
      },
      //点击搜索按钮触发
      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 = [{
          aname:"tuobao",
          bname:"途宝注册",
          cname:"途宝",
          dname:"ABC",
          ename:"2020-10-10",
          fname:"2020-10-10",
          gname:"2020-10-10",
          hname:"技术部",
          iname:"123",
          jname:"2100",
          kname:"李",
        }];
      },
      //树桩列点击展开触发
      treeLoad(tree, treeNode, resolve) {
        const parentId = tree.id;
        customerList({parentId:parentId}).then(res => {
          resolve(res.data.data.records);
        });
      },
    }
  }
</script>

<style scoped>

</style>
