<template>
  <div class="mainContentBox">
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane label="未完成" name="no" />
      <el-tab-pane label="已完成" name="ok" />
    </el-tabs>
    <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="addApply(row)"
          v-if="row.state == '0' || row.state == '1'"
          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"
  >
    <Apply
      :rowData="rowData"
      @close="dialog.visible = false"
      :showStatus
      @data-list="getList"
      :key="applyKey"
    />
  </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 Apply from "./apply.vue";
const { isShowTable, tableType } = toRefs(useCommonStoreHook());
const activeName = ref("no");
// 数据字典相关
const { dicts } = useDictionaryStore();
const getList = () => {
  dataList();
};
const rowData = ref({});
const showStatus = ref(false);
const applyKey = ref(false);
const addApply = (row) => {
  applyKey.value = !applyKey.value;
  rowData.value = row;
  showStatus.value = false;
  dialog.value.visible = true;
};
const showApply = (row) => {
  applyKey.value = !applyKey.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",
              },
          ],
      },
  ],
});
watch(
  () => activeName.value,
  (val) => {
    if (val == "ok") {
      search.value.isComplete = "1";
    } else {
      search.value.isComplete = "0";
    }
    dataList();
  }
);
onMounted(() => {
  search.value.isExamine = "0";
  dataList();
});
</script>
