<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({
  workOrderInfo: {
    type: Object,
    default: () => {
      return null;
    }
  }
})
const clickObjs = ref([])
const selectionChange1 =(row)=>{
  toDeleteIds.value = [];
  row?.forEach((element) => {
    toDeleteIds.value.push(element.id);
  });
  clickObjs.value = row
}
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/deviceTask",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } = Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具

const printCode = () =>{
  dialog.visible = true
}


// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  delBtn: false,
  selection: false,
  search: false,
  filterBtn: false,
  columnBtn: false,
  editBtn: true,
  addBtn: false,
  viewBtn: false,
  menu: true,
  column: [
    {
      label: "流转卡号",
      prop: "seqNo",
      width: 120,
      editDisabled: true,
      overHidden: true,
    },
    {
      label: "工序名称",
      prop: "operationName",
      editDisabled: true,
    },
    {
      label: "分配设备",
      prop: "allocationDeviceName",
      width: 100,
      overHidden: true,
      editDisabled: true,
      type: "select",
      //dicData: userList,
      props: { label: "userName", value: "userName" },
    },
    {
      label: "开始时间",
      prop: "planStartWhen",
      type: "datetime",
      valueFormat: "YYYY-MM-DD HH:mm:ss",
      rules: [
        {
          required: true,
          message: "开始时间不能大于结束时间",
          trigger: "blur",
        },
      ],
    },
    {
      label: "结束时间",
      prop: "planStartEnd",
      type: "datetime",
      valueFormat: "YYYY-MM-DD HH:mm:ss",
    },
  ],
});
onMounted(() => {
  info.value = props.workOrderInfo
  form.value.workOrderCode = props.workOrderInfo.workOrderCode
  search.value.workOrderCode = props.workOrderInfo.workOrderCode
  dataList();
});
</script>
