<template>
  <div class="<%=className>">
    <avue-crud
      :data="data"
      :option="option"
      :page.sync="page"
      :search.sync="search"
      ref="crud"
      @refresh-change="refreshChange"
      @row-save="rowSave"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @on-load="onLoad"
      @search-change="searchChange"
      @search-reset="resetChange"
    >
      <!-- <template slot-scope="{ row, index }" slot="menu">
        <el-button type="danger" icon="el-icon-edit" size="small" @click="$refs.crud.rowEdit(row, index)">编辑</el-button>
        <el-button type="success" icon="el-icon-delete" size="small" @click="$refs.crud.rowDel(row, index)">删除</el-button>
      </template> -->
      <template slot="searchMenu" slot-scope="{ row, size }">
        <el-button :size="size" @click="output(row)">导出</el-button>
      </template>
    </avue-crud>
  </div>
</template>

<script>
import { tableSearch } from "./module";
// console.log("===table数据===", table);

export default {
  data() {
    return {
      ...tableSearch
    };
  },
  methods: {
    onLoad(page) {
      console.log("分页回调");
      console.log("onload");
      console.log("分页信息:" + JSON.stringify(page));
    },
    refreshChange() {
      console.log("刷新回调");
      this.$message.success("刷新回调");
    },
    rowSave(form, done, loading) {
      console.log("新增数据回调");
      form.id = new Date().getTime();
      this.$message.success("模拟网络请求");
      setTimeout(() => {
        this.$message.success("关闭按钮等待");
        loading();
      }, 1000);
      setTimeout(() => {
        this.$message.success("新增数据" + JSON.stringify(form));
        done(form);
      }, 2000);
    },
    rowDel(form, index, done) {
      console.log("删除条目回调");
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          done(form);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {});
    },
    rowUpdate(form, index, done, loading) {
      console.log("更新内容回调");
      this.$message.success("模拟网络请求");
      setTimeout(() => {
        this.$message.success("关闭按钮等待");
        loading();
      }, 1000);
      setTimeout(() => {
        this.$message.success(
          "编辑数据" + JSON.stringify(form) + "数据序号" + index
        );
        done(form);
      }, 2000);
    },
    resetChange(item) {
      console.log(item);
      this.$message.success("清空回调");
    },
    searchChange(params, done) {
      console.log(params);
      this.$message.success("2s后关闭锁定");
      setTimeout(() => {
        done();
        this.$message.success(JSON.stringify(params));
      }, 2000);
    },
    output(row) {
      console.log(row);
    },
  },
};
</script>

<style lang="scss" scoped>
.<%=className> {
  padding-top: 20px;
  width: 920px;
  margin: 0 auto;
  /deep/ .el-form-item__content {
    text-align: left;
  }
  /deep/ .el-col {
    padding: 0 !important;
  }
  /deep/ .el-button {
    margin: 0;
  }
}
</style>

