<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;
};
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/plan/workOrder",
  });
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(["orderInfo"])
const rowClick = (row)=>{
  emit("orderInfo", row)
}
const props = defineProps({
  queryType: {
    type: String,
    default: () => {
      return "0";
    }
  }
})
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  delBtn: false,
  selection: false,
  search: false,
  editBtn: false,
  addBtn: false,
  viewBtn: false,
  menu: false,
  column: [
    {
      label: "工单编号",
      prop: "workOrderCode",
      search: true,
      display: false,
      width: 125,
      overHidden: true,
    },
    {
      label: "订单编号",
      prop: "orderCode",
      search: true,
      width: 125,
      overHidden: true,
    },
    {
      label: "订单名称",
      prop: "orderName",
      search: true,
      disabled: true,
      width: 125,
      overHidden: true,
    },
    {
      label: "产品编号",
      width: 125,
      overHidden: true,
      search: true,
      disabled: true,
      prop: "materialCode",
    },
    {
      label: "产品名称",
      width: 125,
      overHidden: true,
      search: true,
      disabled: true,
      prop: "materialName",
    },
    {
      label: "产品规格",
      width: 125,
      search: true,
      overHidden: true,
      disabled: true,
      prop: "materialModel",
    },
    {
      label: "优先级",
      prop: "priority",
      display: false,
      width: "80",
      type: "select", //类型为下拉选择框
      dicUrl:
          dictDataUtil.request_url + dictDataUtil.TYPE_CODE.plan_order_priority,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
    {
      label: "状态",
      prop: "workOrderState",
      width: "80",
      display: false,
      type: "select", //类型为下拉选择框
      dicUrl:
          dictDataUtil.request_url + dictDataUtil.TYPE_CODE.plan_work_order_state,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
    {
      label: "工艺路线",
      prop: "processRouteName",
      width: 125,
      overHidden: true,
    },
    {
      label: "生产车间",
      prop: "workshopName",
      width: 120,
      overHidden: true,
    },
    {
      label: "产线名称",
      prop: "productLineName",
      width: 120,
      overHidden: true,
    },
    {
      label: "开始时间",
      prop: "planStartWhen",
      width: 180,
      overHidden: true,
      display: false,
    },
    {
      label: "结束时间",
      prop: "planStartEnd",
      width: 180,
      display: false,
      overHidden: true,
    },
    {
      label: "工单数量",
      prop: "planNum",
      width: 85,
      type: "number",
      min: 1,
      max: 99999,
    },
    {
      label: "完成数量",
      width: 85,
      display: false,
      prop: "completeNum",

    },
    {
      label: "下线数量",
      width: 85,
      display: false,
      prop: "beforeNum",
    },
    {
      label: "报废数量",
      width: 85,
      display: false,
      prop: "scrapNum",
    },
    {
      label: "创建时间",
      width: 180,
      display: false,
      prop: "created",
    },
    {
      label: "创建人",
      width: 90,
      display: false,
      prop: "creator",
    },
  ],
});

onMounted(() => {
  search.value.queryType = props.queryType
  dataList();
});
</script>
