<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>
    <ExcelUpload ref="uploadRef" @finished="uploadFinished" />
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import dictDataUtil from "@/common/configs/dictDataUtil";
import ButtonPermKeys from "@/common/configs/buttonPermission";
import { useCommonStoreHook, useDictionaryStoreHook } from "@/store";

// 数据字典相关
const { dicts } = useDictionaryStoreHook();

// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/op/base/check",
  });
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对象

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

/**
 * 上传excel相关
 */
const uploadRef = ref(null);
const uploadFinished = () => {
  // 上传完成后的刷新操作
  page.currentPage = 1;
  dataList();
};
const importExcelData = () => {
  if (uploadRef.value) {
    uploadRef.value.show("/api/v1/plan/order/import");
  }
};

// 设置表格列或者其他自定义的option
const switchOp = [
  {
    label: "",
    value: 0,
  },
  {
    label: "",
    value: 1,
  },
];
option.value = Object.assign(option.value, {
  selection: true,
  labelWidth: 110,
  searchLabelWidth: 110,
  column: [
    {
      label: "点检项名称",
      prop: "checkName",
      span: 12,
      search: true,
      editDisabled: true,
      rules: [
        {
          required: true,
          message: "点检项名称不能为空",
          trigger: "blur",
        },
      ],
    },
    {
      label: "点检项编码",
      prop: "checkCode",
      editDisabled: true,
      span: 12,
      search: true,
      rules: [
        {
          required: true,
          message: "点检项编码不能为空",
          trigger: "blur",
        },
      ],
    },
    {
      label: "内容",
      prop: "content",
      span: 12,
      search: false,
    },
    {
      label: "标准值",
      prop: "standard",
      span: 12,
      search: false,
    },
    {
      label: "上限值",
      prop: "upper",
      span: 12,
      search: false,
    },
    {
      label: "下限值",
      prop: "lower",
      span: 12,
      search: false,
    },
    {
      label: "单位",
      prop: "unit",
      span: 12,
      search: false,
    },
  ],
});
</script>
