<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
            type="primary"
            icon="el-icon-plus"
            :size="size"
            @click="addItem"
        >新增</el-button
        >
        <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, defineProps} from "vue";
import { useCrud } from "@/hooks/userCrud";
import buttonPermission from "@/common/configs/buttonPermission";
import {configList} from "@/api/device";
import { useCommonStoreHook } from "@/store";
import dictDataUtil from "@/common/configs/dictDataUtil";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
const test = () => {
  isShowTable.value = true;
  tableType.value = tableType.value == 1 ? 2 : 1;
};
const pageData = ref([]);
const loading = ref(false); //  加载状态
const dialog = reactive({
  title: "参数设置",
  visible: false,
});
const props = defineProps({
  deviceType: {
    type: String,
    default: () => {
      return '';
    }
  },
})
watch(
    () => props.deviceType,
    () => {
      search.value.deviceType = props.deviceType
      form.value.deviceType = props.deviceType
      dataList();
    },
);
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/device/model",
  });
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对象

const addItem =()=>{
  form.value.deviceType = props.deviceType
  crudRef.value && crudRef.value.rowAdd();
}
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  delBtn: false,
  selection: true,
  addBtn: false,
  searchBtn: false,
  column: [
    {
      label: "设备类型",
      prop: "deviceType",
      type: "select",
      width: 130,
      disabled: true,
      overHidden: true,
      dicUrl:
        dictDataUtil.request_url +
        dictDataUtil.TYPE_CODE.device_type,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
      rules: [
        {
          required: true,
          message: "设备类型不能为空",
          trigger: "trigger",
        },
      ],
    },
    {
      label: "参数",
      prop: "paramField",
      rules: [
        {
          required: true,
          message: "参数不能为空",
          trigger: "trigger",
        },
      ],
    },
    {
      label: "参数名",
      prop: "paramLabel",
      rules: [
        {
          required: true,
          message: "参数名不能为空",
          trigger: "trigger",
        },
      ],
    },
    {
      label: "参数类型",
      prop: "paramType",
      type: "select",
      dicUrl:
          dictDataUtil.request_url +
          dictDataUtil.EXPAND_FIELD_TABLE.expand_field_type,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
      rules: [
        {
          required: true,
          message: "参数类型不能为空",
          trigger: "trigger",
        },
      ],
    },
    {
      label: "创建人",
      prop: "creator",
      width: 160,
      display: false
    },
    {
      label: "创建时间",
      width: 160,
      display: false,
      prop: "created",
    },
  ],
});

onMounted(() => {
  form.value.deviceType = props.deviceType
  search.value.deviceType = props.deviceType
  dataList();
});
</script>
