<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 { defineProps, ref } from "vue";
import { useCrud } from "@/hooks/userCrud";
import { useCommonStoreHook } from "@/store";
import { useDictionaryStore } from "@/store";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
const { dicts } = useDictionaryStore();
const test = () => {
  isShowTable.value = true;
  tableType.value = tableType.value == 1 ? 2 : 1;
};
const props = defineProps({
  materialCode: {
    type: String,
    default: () => {
      return "";
    },
  },
});
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/base/material",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate } = Utils; //按钮权限等工具
const crudRef = ref(null); //crudRef.value 获取avue-crud对象
const emit = defineEmits(["materialInfo"]);
const rowClick = (row) => {
  emit("materialInfo", row);
};

// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  searchEnter: true,
  delBtn: false,
  selection: false,
  search: false,
  editBtn: false,
  addBtn: false,
  viewBtn: false,
  menu: false,
  column: [
    {
      label: "物料编码",
      width: 150,
      overHidden: true,
      prop: "materialCode",
      search: true,
    },
    {
      label: "物料名称",
      width: 150,
      overHidden: true,
      prop: "materialName",
      search: true,
    },
    {
      label: "物料属性",
      prop: "attributeDictValue",
      search: true,
      width: 120,
      overHidden: true,
      type: "select",
      dicData: dicts.material_properties,
      props: { label: "dictLabel", value: "dictValue" },
    },
    { label: "物料规格", width: 120, prop: "spec", search: true },
    {
      label: "单位",
      prop: "unitDictValue",
      type: "select",
      dicData: dicts.danwei_type,
      props: { label: "dictLabel", value: "dictValue" },
    },
    {
      label: "物料级别",
      prop: "levelDictValue",
      width: 100,
      overHidden: true,
      type: "select",
      dicData: dicts.material_level,
      props: { label: "dictLabel", value: "dictValue" },
    },
    { label: "维修厂家", width: 120, overHidden: true, prop: "manufacturer" },
    {
      label: "质检方案",
      prop: "inspectDictValue",
      width: 120,
      overHidden: true,
      type: "select",
      dicData: dicts.quality_testing_plan,
      props: { label: "dictLabel", value: "dictValue" },
    },
    {
      label: "适用平台",
      prop: "applicablePlatformsDictValue",
      width: 120,
      type: "select",
      overHidden: true,
      dicData: dicts.applicable_platforms,
      props: { label: "dictLabel", value: "dictValue" },
    },
    {
      label: "质量等级",
      prop: "qualityLevelDictValue",
      width: 120,
      type: "select",
      overHidden: true,
      dicData: dicts.quality_grade,
      props: { label: "dictLabel", value: "dictValue" },
    },
    {
      label: "选用类型",
      prop: "selectionDictValue",
      width: 100,
      overHidden: true,
      type: "select",
      dicData: dicts.selection_type,
      props: { label: "dictLabel", value: "dictValue" },
    },
    {
      label: "产品阶段",
      prop: "stageDictValue",
      search: true,
      overHidden: true,
      width: 100,
      filterable: true,
      type: "select",
      dicData: dicts.stage,
      props: { label: "dictLabel", value: "dictValue" },
    },
    { label: "客户型号", width: 100, overHidden: true, prop: "customerModel" },
    {
      label: "保质期(天)",
      width: 100,
      overHidden: true,
      prop: "qualityGuaranteePeriod",
    },
    {
      label: "封装方法",
      prop: "packageDictValue",
      width: 100,
      overHidden: true,
      type: "select",
      dicData: dicts.packaging_method,
      props: { label: "dictLabel", value: "dictLabel" },
    },
    {
      label: "是否工装",
      prop: "frock",
      width: 100,
      type: "radio", //类型为单选框
      dicData: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 0,
        },
      ],
      value: 1,
      rules: [
        {
          required: true,
          message: "是否工装",
          trigger: "blur",
        },
      ],
    },
    {
      label: "筛选规范",
      width: 100,
      overHidden: true,
      prop: "selectionSpec",
      type: "textarea",
      span: 18,
    },
    {
      label: "备注",
      width: 100,
      overHidden: true,
      prop: "remark",
      type: "textarea",
      span: 18,
    },
  ],
});

onMounted(() => {
  search.value.prodtCode = props.materialCode;
  search.value.enabled = "0";
  dataList();
});
</script>
