<!-- 表格数据 -->
<template>
  <div class="mainContentBox">
    <avue-crud
      ref="crudRef2"
      v-model:search="search"
      v-model="form"
      @row-update="createRow"
      :data="data"
      :option="option"
      v-model:page="page"
    >
      <template #menu="{ size, row, index }">
        <el-button
          v-if="row.excelData != '' && row.excelData != null"
          link
          size="small"
          type="primary"
          @click="opView(row)"
          style="margin: 0"
          ><i-ep-view />查看
        </el-button>
        <el-button
          v-if="row.excelData != '' && row.excelData != null"
          type="warning"
          link
          size="small"
          @click="opUpdate(row)"
          style="margin: 0"
          ><i-ep-edit />修改表格数据
        </el-button>
      </template>
    </avue-crud>
    <el-dialog
      v-model="updataShow"
      :title="updateTitle"
      @close="updataShow = false"
      width="1600"
    >
      <updateExcel
        @refresh="refreshDatalist"
        :data="ExData"
        @close="closeShow"
      />
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, getCurrentInstance } from "vue";
import { useCrud } from "@/hooks/userCrud";
import dictDataUtil from "@/common/configs/dictDataUtil";
import ButtonPermKeys from "@/common/configs/buttonPermission";
import {
  useCommonStoreHook,
  useDictionaryStore,
  useUserStoreHook,
} from "@/store";
import updateExcel from "./updateExcel.vue";
// 数据字典相关
const { dicts } = useDictionaryStore();
const updataShow = ref(false);
const updateTitle = ref("修改表格数据");
const crudRef2 = ref({});
const lookStatus = ref(false);
const opUpdate = (row) => {
  ExData.value = row;
  ExData.value.lookStatus = false;
  updataShow.value = true;
};
const opView = (row) => {
  ExData.value = row;
  ExData.value.lookStatus = true;
  updataShow.value = true;
};
const closeShow = () => {
  updataShow.value = false;
};
const ExData = ref("");
// 传入一个url，后面不带/
const {
  form,
  data,
  option,
  search,
  page,
  toDeleteIds,
  Methords,
  Utils,
  commonConfig,
} = useCrud({
  src: "/api/v1/ProcessFormData",
});
const ctableRef = ref(null);
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具
const userStore = useUserStoreHook();
const crudRef = ref(null); //crudRef.value 获取avue-crud对象
const doEdit = (row, index) => {
  crudRef2.value && crudRef2.value.rowEdit(row, index);
};
const refreshTra = (row) => {
  commonConfig.value.params = { seqNo: row.seqNo };
  dataList();
};
const refreshDatalist = () => {
  dataList();
};
defineExpose({ refreshTra });
onMounted(() => {
  if (userStore.user.userId === 10000) {
    option.value.menu = true;
  }
});

option.value = Object.assign(option.value, {
  selection: false,
  border: true,
  index: false,
  expandLevel: 3,
  headerAlign: "center",
  align: "center",
  labelWidth: 100,
  addBtn: false,
  delBtn: false,
  viewBtn: false,
  menu: false,
  header: false,
  editBtn: false,
  rowKey: "operationId",
  column: [
    {
      label: "工序Id",
      prop: "operationId",
      display: false,
      hide: true,
    },
    {
      label: "工序名称",
      prop: "operationName",
      disabled: true,
      search: false,
      display: false,
    },

    {
      label: "表格名称",
      disabled: true,
      prop: "formName",
      search: false,
    },
    {
      label: "表格类型",
      prop: "formType",
      type: "select",
      disabled: true,
      search: false,
      dicData: dicts.excel_type,
      props: {
        label: "dictLabel",
        value: "dictValue",
      },
    },
  ],
});
</script>
