<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-click="rowClick"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
    >
    </avue-crud>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { useCrud } from "@/hooks/userCrud";

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;
};
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/device",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate } = Utils; //按钮权限等工具
const props = defineProps({
  deviceType: {
    type: String,
    default: () => {
      return 0;
    },
  },
  operate: {
    type: String,
    default: () => {
      return "";
    },
  },
});
const crudRef = ref(null); //crudRef.value 获取avue-crud对象
const emit = defineEmits(["deviceInfo"]);
const rowClick = (row) => {
  emit("deviceInfo", row);
};

// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  delBtn: false,
  selection: false,
  search: false,
  editBtn: false,
  addBtn: false,
  viewBtn: false,
  menu: false,
  column: [
    {
      label: "资产编号",
      prop: "deviceNo",
      search: true,
      width: "120",
      rules: [
        {
          required: true,
          message: "设备编号不能为空",
          trigger: "trigger",
        },
      ],
    },
    {
      label: "设备名称",
      prop: "deviceName",
      search: true,
      width: "120",
      rules: [
        {
          required: true,
          message: "设备名称不能为空",
          trigger: "trigger",
        },
      ],
    },

    {
      label: "负责人",
      width: "100",
      prop: "head",
    },
    {
      label: "存放位置",
      width: "150",
      prop: "devicePosition",
    },
    {
      label: "型号",
      width: "150",
      prop: "specifications",
    },
    {
      label: "制造厂",
      width: "150",
      prop: "brand",
    },
    {
      label: "原值",
      prop: "originalValue",
      width: 100,
      overHidden: true,
    },
    {
      label: "出厂编号",
      prop: "serialNumber",
      width: 100,
      overHidden: true,
    },
    {
      label: "设备类型",
      prop: "deviceType",
      type: "select",
      search: true,
      width: "100",
      dicUrl: dictDataUtil.request_url + dictDataUtil.TYPE_CODE.device_type,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
  ],
});

onMounted(() => {
  console.log("aaa", props.operate);
  if (props.deviceType != null) {
    search.value.deviceType = props.deviceType;
  }
  if (props.operate != null) {
    search.value.operate = props.operate;
  }
  dataList();
});
</script>
