<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @search-change="searchChange"
      @search-reset="resetChange"
      @size-change="dataList"
      @current-change="dataList"
      @selection-change="selectionChange"
    >
      <template #menu="{ row, index, type }">
        <el-button
          @click="checkApply(row)"
          v-if="row.state == '2'"
          text
          type="primary"
          >处理</el-button
        >
        <el-button
          @click="showApply(row)"
          v-if="row.state != '0'"
          text
          type="primary"
          >查看</el-button
        >
      </template>
    </avue-crud>
  </div>
  <el-dialog
    v-model="dialog.visible"
    :title="dialog.title"
    width="80%"
    @close="dialog.visible = false"
  >
    <Check
      :rowData="rowData"
      @close="dialog.visible = false"
      :showStatus
      @data-list="getList"
      :key="checkKey"
    />
  </el-dialog>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import { useCommonStoreHook, useDictionaryStore } from "@/store";
import dictDataUtil from "@/common/configs/dictDataUtil";
import Check from "./check.vue";
const checkKey = ref(false);
const getList = () => {
  dataList();
};
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
// 数据字典相关
const { dicts } = useDictionaryStore();
const rowData = ref({});
const showStatus = ref(false);
const checkApply = (row) => {
  checkKey.value = !checkKey.value;
  rowData.value = row;
  showStatus.value = false;
  dialog.value.visible = true;
};
const showApply = (row) => {
  checkKey.value = !checkKey.value;
  rowData.value = row;
  showStatus.value = true;
  dialog.value.visible = true;
};
const dialog = ref({
  visible: false,
  title: "归档审核",
});

// 传入一个url，后面不带/
const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  useCrud({
    src: "/api/v1/ProcessFormData/examine",
  });
const {
  dataEditList,
  createRow,
  updateRow,
  deleteRow,
  searchChange,
  dataList,
  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, {
  searchEnter: true,
  selection: false,
  viewBtn: false,
  editBtn: false,
  delBtn: false,
  addBtn: false,
  menu: true,
  column: [
    {
      label: "工单编码",
      prop: "workOrderCode",
      search: true,
      overHidden: true,
    },
    {
      label: "订单编号",
      prop: "orderCode",
      search: true,
      overHidden: true,
    },
    {
      label: "订单名称",
      prop: "orderName",
      overHidden: true,
      search: true,
    },
    {
      label: "物料编码",
      prop: "materialCode",
      overHidden: true,
      editDisplay: false,
      addDisplay: false,
    },

    {
      label: "物料型号",
      prop: "materialModel",
      overHidden: true,
      editDisplay: false,
      hide: true,
    },
    {
      label: "物料名称",
      prop: "materialName",
      search: true,
      overHidden: true,
      disabled: true,
    },
    {
      label: "表格类型",
      prop: "formType",
      search: true,
      filterable: true,
      type: "select",
      dicData: dicts.excel_type,
      props: { label: "dictLabel", value: "dictValue" },
    },
    {
      label: "状态",
      prop: "state",

      rules: [
        {
          required: true,
          message: "请选择文件",
          trigger: "blur",
        },
      ],
      dicData: [
        {
          label: "待发起",
          value: "0",
        },
        {
          label: "驳回",
          value: "1",
        },
        {
          label: "审核中",
          value: "2",
        },
        {
          label: "完成",
          value: "3",
        },
      ],
    },
    {
      label: "质量等级",
      prop: "hOrder",
      search: true,
      width: 100,
      overHidden: true,
      filterable: true,
      type: "select",
      dicData: dicts.quality_grade,
      props: { label: "dictLabel", value: "dictValue" },
      rules: [
        {
          required: true,
          message: "请选择质量等级",
          trigger: "blur",
        },
      ],
    },
  ],
});
onMounted(() => {
  search.value.isExamine = "1";
  dataList();
});
</script>
