<script setup lang="ts">
import {useCrud} from "@/hooks/userCrud";
import {getReworkItem} from "@/api/rework";
import ReworkShow from "@/views/pro-operation/remove/components/rework-show.vue";
const dialogVisible = ref(false);
const itemVisible = ref(false);
const dialogTitle = ref("返工记录卡");
const itemTitle = ref("返工记录卡详情");

const openDialog = () => {
  dialogVisible.value = true;
};

const closeDialog = () => {
  dialogVisible.value = false;
};
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/rework/record/machine",
  });
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils;
defineExpose({
  openDialog,
});
onMounted(
    () => {
        dataList();
    }
)
const reworkItem=ref({});
const tableData=ref({});
const showTable = (row) => {
    reworkItem.value.recordId = row.id;

    getReworkItem(reworkItem.value).then((data) => {
        if (data.code === "200") {
            tableData.value = row;
            tableData.value.itemList = data.data;
            itemVisible.value = true;
        } else {
            ElMessage({
                message: data.msg,
                type: "error",
            });
        }
    });

};
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  selection: false,
  addBtn: false,
  delBtn: false,
  editBtn: false,
  viewBtn: false,
  search: false,
  header: false,
  column: [
    {
      label: "生产批号",
      prop: "workOrderCode",
      editDisabled: true,
      overHidden: true,
      width: 120,

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

    },
    {
      label: "数量",
      editDisabled: true,
      prop: "num",
    },
    {
      label: "管号",
      prop: "seqNo",
      editDisabled: true,
      hide: true,
      display: false,
    },

    {
      label: "产品规格",
      prop: "materialModel",
      overHidden: true,
    },




  ],
});
</script>

<template>
  <el-dialog v-model="dialogVisible" append-to-body align-center :title="dialogTitle">
    <div class="content">
      <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"
        @selection-change="selectionChange"
      >
        <template #menu="{ row, index, type }">
          <el-button
            @click="showTable(row)"
            link
            type="primary"
            size="small"
          >查看</el-button
          >



        </template>

      </avue-crud>

    </div>
  </el-dialog>
  <el-dialog v-model="itemVisible" append-to-body align-center :title="itemTitle">
    <ReworkShow  :tableData="tableData" />
  </el-dialog>
</template>

<style scoped lang="scss">
.content {
  padding: 1px;
}
</style>
