<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"
    >

      <template #menu-left="{ size }">
        <el-button
            :size="size"
            icon="el-icon-plus"
            type="primary"
            @click="addRow"
        >新增
        </el-button>
      </template>
      <template #menu="{ size, row, index }">
        <el-button text @click="showSeqPage(row)" type="primary" :size="size"
        >明细
          <template #icon>
            <svg-icon icon-class="luozhuankahao" />
          </template>
        </el-button>
      </template>
    </avue-crud>
    <el-dialog
        v-model="dialog4.visible"
        :title="dialog4.title"
        width="950px"
        @close="dialog4.visible = false"
    >
      <wms_order_details :orderId="form.id" />
    </el-dialog>
    <el-dialog
        v-model="dialog.visible"
        :destroy-on-close="true"
        :title="dialog.title"
        width="1200px"
        @close="dialog.visible = false"
    >
      <add_order_details @closeDialog="closeDialog"/>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } 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/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对象
const dialog4 = reactive({
  title: "任务明细",
  visible: false,
});

const dialog = reactive({
  title: "添加出入库",
  visible: false,
});
const addRow = () => {
  dialog.visible = true;
}

const closeDialog =(val) =>{
  dialog.visible = false
  dataList()
}

const showSeqPage = (workOrderCode) => {
  form.value = workOrderCode;
  dialog4.visible = true;
};
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  delBtn: false,
  selection: false,
  viewBtn: false,
  editBtn: false,
  menu: true,
  addBtn: false,
  column: [
    {
      label: "仓库编码",
      prop: "houseNo",
      type: "select",
      search: true,
      width: 90,
      overHidden: true,
      editDisabled: true,
      dicUrl:
          dictDataUtil.request_url +
          dictDataUtil.TYPE_CODE.warehouse_type,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
      rules: [
        {
          required: true,
          message: "仓库编码不能为空",
          trigger: "trigger",
        },
      ],
    },
    {
      label: "类型",
      prop: "type",
      overHidden: true,
      type: "select",
      search: true,
      dicData:[{label: "原材料入库",value: "1"},{label: "工装入库",value: "2"},{label: "退料",value: "3"},{label: "出库",value: "4"}],
    },
    {
      label: "货区",
      width: 110,
      overHidden: true,
      prop: "coordinate",
    },
    {
      label: "任务单号",
      width: 130,
      search: true,
      overHidden: true,
      prop: "taskNo",
    },
    {
      label: "开始时间",
      width: 130,
      search: true,
      overHidden: true,
      prop: "startTime",
      type:"datetime",
    },
    {
      label: "结束时间",
      width: 130,
      search: true,
      overHidden: true,
      prop: "endTime",
      type:"datetime",
    },
    {
      label: "库位",
      overHidden: true,
      prop: "locationNo",
    },
    {
      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: "message",
      width: 180,
      overHidden: true,
      display: false
    },*/
    {
      label: "操作时间",
      prop: "created",
      width: 180,
      display: false
    },
    {
      label: "操作人",
      prop: "creator",
      search: true,
      display: false
    },
  ],
});

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