<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 '';
    }
  },
  materialVersion: {
    type: String,
    default: () => {
      return '';
    }
  },
  processRouteType: {
    type: String,
    default: () => {
      return '';
    }
  }
})
watch(
  () => props.materialCode,
  () => {
    search.value.prodtCode = props.materialCode
    dataList();
  }
);
watch(
    () => props.processRouteType,
    () => {
      search.value.processRouteType = props.processRouteType
      dataList();
    }
);
// 传入一个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: "usable",
      addDisplay: false,
      editDisplay: false,
      slot: true,
      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",
      precision: 1,
    },
    {
      label: "创建人",
      prop: "creator",
      overHidden: true,
    },
    {
      label: "创建时间",
      prop: "created",
      width: 150,
      overHidden: true,
    },
  ],
});

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