<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"
      @selection-change="selectionChange"
    >
      <template #menu="{ row, index, type }">
        <el-button
          type="primary"
          size="small"
          link
          @click="showSeq(row.seqNos)"
        >查看管号
        </el-button
        >
      </template>
    </avue-crud>
    <el-dialog
      v-model="dialog2.visible"
      :title="dialog2.title"
      width="950px"
      @close="dialog2.visible = false"
    >
      <el-card
        style="cursor: pointer; font-size: 20px"
        shadow="always"
        :key="item"
        v-for="item in showSeqList"
      >{{ item }}
      </el-card
      >
    </el-dialog>
  </div>
</template>
<script setup>
import {useCrud} from "@/hooks/userCrud";
import {useDictionaryStore} from "@/store";
import {ref} from "vue";
// 数据字典相关
const {dicts} = useDictionaryStore();
const showSeqList = ref([]);
// 传入一个url，后面不带/
const {form, data, option, search, page, toDeleteIds, Methords, Utils} =
  useCrud({
    // src: "/api/v1/processSeqDestruction",
    dataListUrl: "/api/v1/processSeqDestruction/checkPage",
  });
const {dataList, createRow, updateRow, deleteRow, searchChange, resetChange} =
  Methords; //增删改查
const {selectionChange} = Methords; //选中和批量删除事件
const {checkBtnPerm, downloadTemplate, exportData} = Utils; //按钮权限等工具
// const tableData = ref({});
const crudRef = ref(null); //crudRef.value 获取avue-crud对象

const dialog2 = reactive({
  title: "管号列表",
  visible: false,
});
const showSeq = async (seqs) => {
  showSeqList.value = []; // 清空
  await nextTick(); // 等待 DOM 更新
  showSeqList.value = [...seqs]; // 重新赋值
  dialog2.visible = true;
};
onMounted(() => {
  dataList();
});
// 设置表格列或者其他自定义的option
option.value = Object.assign(option.value, {
  searchEnter: true,
  selection: false,
  addBtn: false,
  delBtn: false,
  editBtn: false,
  viewBtn: false,
  column: [
    {
      label: "生产批号",
      prop: "workOrderCode",
      editDisabled: true,
      overHidden: true,
      width: 120,
      search: true,
    },
    {
      label: "产品名称",
      prop: "materialName",
      editDisabled: true,
      search: true,
    },
    {
      label: "管号",
      prop: "seqNo",
      search: true,
      editDisabled: true,
      hide: true,
      display: false,
    },
    {
      label: "破坏性检验",
      prop: "isDestruction",
      type: "select",
      display: false,
      dicData: [
        {
          label: "否",
          value: 0,
        },
        {
          label: "是",
          value: 1,
        }
      ],
      html: true,
      formatter: (val) => {
        if (val.isDestruction === 0) {
          return '<b class="el-tag el-tag--danger el-tag--light">否</b>';
        } else if (val.isDestruction === 1) {
          return '<b class="el-tag el-tag--success el-tag--light">是</b>';
        }
      },
    },
    {
      label: "检验类型",
      prop: "checkType",
      type: "select",
      display: false,
      dicData: [
        {
          label: "首件检验",
          value: "1",
        },
        {
          label: "过程检验",
          value: "2",
        }
      ],

      html: true,
      formatter: (val) => {
        if (val.checkType === "1") {
          return '<b class="el-tag el-tag--warning el-tag--light">首件检验</b>';
        } else if (val.checkType === "2") {
          return '<b class="el-tag el-tag--primary el-tag--light">过程检验</b>';
        }
      },
    },
    {
      label: "更新日期",
      prop: "updated",
      type: "date",
      width: 160,
      editDisplay: false,
      overHidden: true,
    },
    // {
    //   label: "日期",
    //   prop: "createdSearch",
    //   width: 160,
    //   type: "daterange",
    //   searchRange: true,
    //   display: false,
    //   hide: true,
    //   startPlaceholder: "开始范围",
    //   endPlaceholder: "结束范围",
    //   format: "YYYY-MM-DD",
    //   valueFormat: "YYYY-MM-DD",
    //   overHidden: true,
    //   search: true,
    // },
  ],
});
</script>
