<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 dictDataUtil from "@/common/configs/dictDataUtil";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
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/op/route",
  });
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(["routeInfo"])
const rowClick = (row)=>{
  emit("routeInfo", 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: "processRouteCode",
      search: true,
      width: 150,
      addDisplay: false,
      editDisabled: true,
      overHidden: true,
    },
    {
      label: "工艺名称",
      prop: "processRouteName",
      width: 150,
      search: true,
      overHidden: true,
    },
    {
      label: "工艺类型",
      prop: "processRouteType",
      minWidth: 100,
      overHidden: true,
      type: "select",
      dicUrl: dictDataUtil.request_url + dictDataUtil.TYPE_CODE.routing_type,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
    {
      label: "产品名称",
      prop: "prodtName",
      overHidden: true,
      width: 150,
    },
    {
      label: "产品编号",
      prop: "prodtCode",
      overHidden: true,
      width: 150,
      disabled: true,
    },
    {
      label: "产品型号",
      prop: "prodtModel",
      overHidden: true,
      minWidth: 200,
    },
    // 在产品那边绑定了工艺路线才是已绑定
    {
      label: "路线状态",
      prop: "used",
      width: 100,
      type: "radio",
      dicData: [
        {
          label: "已绑定",
          value: 1,
        },
        {
          label: "未绑定",
          value: 0,
        },
      ],
    },
    {
      label: "启用状态",
      prop: "enabled",
      width: 100,
      type: "radio",
      dicData: [
        {
          label: "未启用",
          value: 1,
        },
        {
          label: "启用",
          value: 0,
        },
      ],
      value: 0,
    },
    {
      label: "版本",
      prop: "processRouteVersion",
      addDisplay: false,
      editDisplay: false,
    },
    {
      label: "创建人",
      prop: "createBy",
      addDisplay: false,
      editDisplay: false,
      overHidden: true,
    },
    {
      label: "创建时间",
      prop: "createWhen",
      addDisplay: false,
      editDisplay: false,
      width: 150,
      overHidden: true,
    },
  ],
});

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