<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-update="updateRow"
      @row-del="deleteRow"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @selection-change="selectionChange"
    >


        <template #menu="{row,index,type}">
          <el-button @click="inStock(row)"
                     icon="el-icon-van"
                     text
                     type="primary"
          >入库</el-button>
          <el-button @click="viewStock(row)"
                     icon="el-icon-view"
                     text
                     type="primary"
          >查看</el-button>
        </template>

    </avue-crud>
    <el-dialog
      v-model="dialog.visible"
      :title="dialog.title"
      width="800px"
      :destroy-on-close="true"
      @close="dialog.visible = false"
    >
      <detailStock   :dialog="dialog" :workOrderCode="stockInfo.workOrderCode"/>
    </el-dialog>

    <el-dialog
      v-model="stockDialog.visible"
      :title="stockDialog.title"
      width="800px"
      :destroy-on-close="true"
      @close="stockClose"
    >
      <inStocks   :stockDialog="stockDialog" :workOrderCode="stockDetail.workOrderCode"/>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import ButtonPermKeys from "@/common/configs/buttonPermission";
import { useCommonStoreHook, useDictionaryStore } from "@/store";
import dictDataUtil from "@/common/configs/dictDataUtil";
import inStocks from "@/views/plan/finishProduct/components/in-stock.vue"
import detailStocks from "@/views/plan/finishProduct/components/detail-stock.vue"
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
// 数据字典相关
const { dicts } = useDictionaryStore();
const stockDetail=ref({});
const test = () => {
  isShowTable.value = true;
  tableType.value = tableType.value == 1 ? 2 : 1;
};
const dialog = reactive({
  title: "查看",
  visible: false,
});

const stockDialog = reactive({
  title: "入库",
  visible: false,
});
const stockClose=()=>{
  stockDialog.visible = false;
  dataList();
}
const stockInfo=ref({});
const viewStock=(row)=>{
  stockInfo.value=row;
  dialog.visible = true;
}
// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/plan/workOrder/finishProductIn",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
// checkBtnPerm(ButtonPermKeys.PLAN.BTNS.order_add) :permission="permission"
// const permission = reactive({
//   delBtn: checkPerm(buttonPermission.PLAN.BTNS.order_del),
//   addBtn: checkPerm(buttonPermission.PLAN.BTNS.order_add),
//   editBtn: checkPerm(buttonPermission.PLAN.BTNS.order_edit),
//   menu: true,
// });



onMounted(() => {
  // console.log("crudRef", crudRef)
  dataList();
});





const inStock=(row)=>{
  stockDialog.visible=true;
  stockDetail.value=row;

}
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  selection: false,
  addBtn:false,
  viewBtn:false,
  columnBtn: false,
  gridBtn: false,
  refreshBtn:false,
  editBtn:false,
  delBtn:false,
  column: [

    { label: "工单号", prop: "workOrderCode",
      search: true,
      overHidden: true

    },
    { label: "产品名称", prop: "materialName",
      search: true,
      overHidden: true,

    },
    { label: "物料编码", prop: "materialCode", width: 140,overHidden: true,search: true
    },
    {
      label: "订单编码",
      prop: "orderCode",
      search: true,
    },

    { label: "完工时间", prop: "updated", overHidden: true,
      disabled:true, hide:true},
    {
      label: "物料数量",
      prop: "completeNum",
    },
    {
      label: "入库数量",
      prop: "inventoryNum",
    },
  ],
});


</script>
