<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"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        @selection-change="selectionChange"
    />
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import ButtonPermKeys from "@/common/configs/buttonPermission";
import { useCommonStoreHook } from "@/store";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
    useCrud({
      src: "/api/v1/semiFinishedStock/detail",
    });
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对象
import { getSemi, oprerate } from "@/api/storage/index";
import { useDictionaryStore } from "@/store";
const { dicts } = useDictionaryStore();
const emits = defineEmits(["close"]);
const ruleFormRef = ref(null);
const dialog1 = reactive({
  title: "工单号选择",
  visible: false,
});
const materialInfo1 = (value) => {
  formData.value.outWorkOrderCode = value.workOrderCode;
  dialog1.visible = false;
};
const formData = ref({
  stockId: "",
  stockType: "2",
  inWorkOrderCode: "",
  workOrderSeqNos: [],
});
const props = defineProps({
  id: {
    type: String,
  },
});
const detailsData = ref();
const tableData = ref([]);
const getData = async () => {
  const { data } = await getSemi(props.id);
  detailsData.value = data;
  formData.value.inWorkOrderCode = data.inWorkOrderCode;
  tableData.value = detailsData.value.detailsList;
};
const submit = async () => {
  await ruleFormRef.value.validate(async (valid, fields) => {
    if (valid) {
      const { code } = await oprerate({ ...formData.value, stockId: props.id });
      if (code == "200") {
        ElMessage.success("出库成功！");
        ruleFormRef.value.resetFields();
        getData();
        emits("close");
      }
    } else {
    }
  });
};
onMounted(() => {
  search.value.inStockId=props.id;
  dataList();
});

// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  searchEnter: true,
  delBtn: false,
  selection: true,
  labelWidth: 100,
  editBtn: false,
  viewBtn: false,
  menu: false,
  addBtn: false,
  column: [
    {
      label: "生产批号",
      prop: "workOrderCode",
      editDisabled: true,
      addDisplay: false,
      search: true,
      rules: [
        {
          required: true,
          trigger: "trigger",
        },
      ],
    },
    {
      label: "管号",
      prop: "workOrderSeqNo",
      editDisabled: true,
      addDisplay: false,
      search: true,
    },

  ]
});
watch(
  () => props.id,
  () => {
    search.value.inStockId=props.id;
    dataList();
  }
);
</script>
