<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-save="createRow"
      @row-update="updateRow"
      @row-del="deleteRow"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @selection-change="selectionChange"
    >
      <template #menu-left="{ size }">
        <el-button
          :disabled="toDeleteIds.length < 1"
          type="danger"
          icon="el-icon-delete"
          :size="size"
          @click="multipleDelete"
          >删除</el-button
        >
      </template>
    </avue-crud>
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import { useCommonStoreHook } from "@/store";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
const test = () => {
  isShowTable.value = true;
  tableType.value = tableType.value == 1 ? 2 : 1;
};
const loading = ref(false); //  加载状态
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/device/log",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
const crudRef = ref(null); //crudRef.value 获取avue-crud对象

// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  searchEnter: true,
  delBtn: false,
  editBtn: false,
  selection: true,
  addBtn: false,
  column: [
    {
      label: "日志来源",
      prop: "logFrom",
      search: true,
    },
    {
      label: "日志类型",
      prop: "logType",
      search: true,
      type: "select",
      dicData: [
        { label: "通知", value: "1" },
        { label: "预警", value: "2" },
        { label: "错误", value: "3" },
      ],
      html: true,
      formatter: (val) => {
        if (val.logType === "1") {
          return '<b class="el-tag el-tag--info el-tag--light">通知</b>';
        } else if (val.logType === "2") {
          return '<b class="el-tag el-tag--warning el-tag--light">预警</b>';
        } else if (val.logType === "3") {
          return '<b class="el-tag el-tag--danger el-tag--light">错误</b>';
        }
      },
    },
    {
      label: "日志内容",
      prop: "logContent",
      width: 550,
      overHidden: true,
    },
    {
      label: "创建时间",
      width: 160,
      display: false,
      prop: "created",
    },
  ],
});

onMounted(() => {
  // console.log("crudRef", crudRef)
  dataList();
});
</script>
