<template>
  <div class="<%=className>">
    <avue-crud
      :data="data"
      :option="option"
      :page.sync="page"
      ref="crud"
      @refresh-change="refreshChange"
      @row-save="rowSave"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @on-load="onLoad"
    >
      <!-- <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> -->
    </avue-crud>
  </div>
</template>

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

export default {
  data() {
    return {
      ...table
    };
  },
  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);
    },
  },
};
</script>

<style lang="scss" scoped>
.<%=className> {
  padding-top: 20px;
  width: 920px;
  margin: 0 auto;
}
</style>
