<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 { 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/base/workShop",
  });
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(["workShopInfo"])
const rowClick = (row)=>{
  emit("workShopInfo", 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: "orderCode",
      search: true,
      width: "125",
      display: false,
    },
    {
      label: "订单名称",
      prop: "orderName",
      search: true,
      width: "100",
    },
    {
      label: "ERP号",
      prop: "erpCode",
      search: true,
      width: "100",
    },
    {
      label: "产品编码",
      prop: "materialCode",
      search: true,
      width: "100",
    },
    {
      label: "产品名称",
      prop: "materialName",
      search: true,
      width: "100",
    },
    {
      label: "产品规格",
      width: "100",
      prop: "materialModel",
    },
    {
      label: "订单状态",
      prop: "orderState",
      display: false,
      width: "100",
      type: "select", //类型为下拉选择框
      dicUrl:
          dictDataUtil.request_url + dictDataUtil.TYPE_CODE.plan_order_state,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
      searchClearable: false, //可清空的输入框,默认为true
      filterable: true, //添加filterable属性即可启用搜索功能
    },
    {
      label: "订单类型",
      prop: "orderType",
      type: "select", //类型为下拉选择框
      width: "100",
      dicUrl: dictDataUtil.request_url + dictDataUtil.TYPE_CODE.plan_order_type,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
      searchClearable: false, //可清空的输入框,默认为true
      filterable: true, //添加filterable属性即可启用搜索功能
    },
    {
      label: "订单数量",
      prop: "orderNum",
      type: "number",
      width: "100",
      min: 1,
      max: 99999,
    },
    {
      label: "排产数量",
      prop: "scheduledNum",
      width: "100",
      display: false,
    },
    {
      label: "优先级",
      prop: "priority",
      width: "100",
      type: "select", //类型为下拉选择框
      dicUrl:
          dictDataUtil.request_url + dictDataUtil.TYPE_CODE.plan_order_priority,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
      searchClearable: false, //可清空的输入框,默认为true
      filterable: true, //添加filterable属性即可启用搜索功能
    },
    {
      label: "交付日期",
      prop: "deliverTime",
      type: "date",
      width: "100",
      format: "YYYY-MM-DD", //前端展示格式
      valueFormat: "YYYY-MM-DD", //设置后端接收的日期格式
    },
    {
      label: "所属公司",
      prop: "companyId",
      width: "100",
      type: "select", //类型为下拉选择框
      dicUrl: import.meta.env.VITE_APP_BASE_API + "/api/v1/sys/dept/orgList",
      props: {
        label: "deptName",
        value: "id",
      },
    },
    {
      label: "项目号",
      width: "100",
      prop: "projectCode",
    },
    {
      label: "绑定铭牌",
      prop: "nameplated",
      width: "100",
      type: "radio", //类型为单选框
      dicData: [
        {
          label: "否",
          value: 0,
        },
        {
          label: "是",
          value: 1,
        },
      ],
      value: 0,
    },
    {
      label: "备注",
      prop: "remark",
      width: "100",
      minRows: 2, //最小行/最小值
      type: "textarea", //类型为多行文本域框
      maxlength: 512, //最大输入长度
    },
    {
      label: "创建时间",
      prop: "created",
      width: "140",
      overHidden: true,
      type: "datetime",
      valueFormat: "yyyy-MM-dd HH:mm:ss",
    },
    {
      label: "创建人",
      prop: "creator",
      width: 80,
      overHidden: true,
    },
  ],
});

onMounted(() => {
  dataList();
});
</script>
