<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"
    >
    </avue-crud>
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import ButtonPermKeys from "@/common/configs/buttonPermission";

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/wmsOrder",
  });
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对象
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  delBtn: false,
  selection: false,
  viewBtn: false,
  editBtn: false,
  menu: false,
  addBtn: false,
  column: [
    {
      label: "类型",
      prop: "type",
      width: 60,
      overHidden: true,
      type: "select",
      search: true,
      dicData:[{label: "入库",value: "1"},{label: "出库",value: "2"},{label: "退料",value: "3"}],
    },
    {
      label: "载具编号",
      width: 110,
      overHidden: true,
      prop: "vehicleCode",
    },
    {
      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: "单位",
      width: 60,
      overHidden: true,
      prop: "unit",
    },
   /* {
      label: "任务单号",
      prop: "taskNo",
      search: true,
      overHidden: true
    },*/
    {
      label: "单号",
      prop: "planNo",
      search: true,
    },
    {
      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",
      width: 60,
      overHidden: true,
    },
    {
      label: "状态",
      prop: "state",
      type: "select",
      search: true,
      width: 70,
      overHidden: true,
      dicUrl:
          dictDataUtil.request_url +
          dictDataUtil.TYPE_CODE.warehouse_task_state,
      props: {
        label: "dictLabel",
        value: "dictValue",
      }
    },
    {
      label: "操作时间",
      prop: "created",
      width: 180,
      display: false
    },
    {
      label: "操作人",
      prop: "creator",
      display: false
    },
  ],
});

onMounted(() => {
  // console.log("crudRef", crudRef)
  //search.value.type = '2'
  dataList();
});
</script>
