<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"
      @selection-change="selectionChange1"
    >
    </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";
import { html2CanvasPrint } from "@/utils/common";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
const toPrintRef = ref(null);
const test = () => {
  isShowTable.value = true;
  tableType.value = tableType.value == 1 ? 2 : 1;
};
const info = ref({});
const props = defineProps({
  orderInfo: {
    type: Object,
    default: () => {
      return null;
    },
  },
});
const crudRef = ref(null); //crudRef.value 获取avue-crud对象

watch(
  () => props.workOrderInfo,
  () => {
    form.value.workOrderCode = props.workOrderInfo.workOrderCode;
    info.value = props.workOrderInfo;
    search.value.workOrderCode = props.workOrderInfo.workOrderCode;
    dataList();
  }
);
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/wmsOrder",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具

// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  searchEnter: true,
  delBtn: false,
  selection: false,
  search: false,
  filterBtn: false,
  columnBtn: false,
  editBtn: false,
  addBtn: false,
  viewBtn: false,
  menu: false,
  column: [
    {
      label: "物料编号",
      width: 130,
      search: true,
      overHidden: true,
      prop: "materialNo",
    },
    {
      label: "物料名称",
      width: 130,
      search: true,
      overHidden: true,
      prop: "materialName",
    },
    {
      label: "物料型号",
      width: 130,
      overHidden: true,
      prop: "spec",
    },
    {
      label: "单位",
      overHidden: true,
      prop: "unit",
    },
    {
      label: "库位",
      overHidden: true,
      prop: "locationNo",
    },
    {
      label: "二维码",
      prop: "batchCode",
      width: 150,
      overHidden: true,
      formatter: (val, value, label) => {
        if (val.seqNo) {
          return val.seqNo;
        } else {
          return val.batchCode;
        }
      },
    },
    {
      label: "数量",
      prop: "num",
    },
  ],
});

onMounted(() => {
  info.value = props.orderInfo;
  form.value.orderId = props.orderInfo.id;
  search.value.orderId = props.orderInfo.id;
  dataList();
});
</script>
