<!-- 图片采集 -->
<template>
  <div class="mainContentBox">
    <img src="" />
    <avue-crud
      ref="crudRef2"
      v-model:search="search"
      v-model="form"
      :data="data"
      :option="option"
      v-model:page="page"
      @row-update="updateRow"
    >
      <template #menu="{ row, index, type }">
        <el-button
          @click="openDialog(row)"
          icon="el-icon-link"
          text
          type="primary"
          >查看</el-button
        >
      </template>
      <template #filePath-form="scope">
        <single-upload v-model="form.filePath" />
      </template>
    </avue-crud>
    <el-dialog
      v-model="dialog.visible"
      :title="dialog.title"
      width="60%"
      @close="dialog.visible = false"
      ><el-image :src="url" fit="none" />
    </el-dialog>
    <CommonTable
      ref="ctableRef"
      tableTitle="人员选择"
      tableType="USERS"
      @selected-sure="onSelectedFinish"
    />
  </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 SingleUpload from "@/components/Upload/SingleUpload.vue";
const ctableRef = ref(null);
// 数据字典相关
const { dicts } = useDictionaryStore();
const dialog = reactive({
  title: "图片预览",
  visible: false,
});
const url = ref(null);
// 传入一个url，后面不带/
const {
  form,
  data,
  option,
  search,
  page,
  toDeleteIds,
  Methords,
  Utils,
  commonConfig,
} = useCrud({
  src: "/api/v1/process/media",
});
const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  Methords; //增删改查
const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
const { checkBtnPerm, downloadTemplate, exportData } = Utils; //按钮权限等工具

const crudRef = ref(null); //crudRef.value 获取avue-crud对象
const openDialog = (row) => {
  dialog.visible = true;
  url.value = import.meta.env.VITE_APP_UPLOAD_URL + row.filePath;
};
const refreshTra = (row) => {
  commonConfig.value.params = { seqNo: row.seqNo,workOrderCode: row.workOrderCode};
  dataList();
};
const userStore = useUserStoreHook();
defineExpose({ refreshTra });
onMounted(() => {
  if (userStore.user.userId === 10000) {
    option.value.editBtn = true;
  }
});
const onSelectedFinish = (selectValue) => {
  form.value.creator = selectValue.userName;
};
option.value = Object.assign(option.value, {
  selection: false,
  border: true,
  index: false,
  expandLevel: 3,
  headerAlign: "center",
  align: "center",
  labelWidth: 100,
  addBtn: false,
  menu: true,
  editBtn: false,
  delBtn: false,
  viewBtn: false,
  header: false,
  column: [
    {
      label: "上传工序",
      prop: "operationName",
      search: false,
      display: false,
    },
    {
      label: "上传人员",
      prop: "creator",
      span: 16,
      search: false,
      click: ({ value, column }) => {
        ctableRef.value.startSelect();
      },
      change: ({ value, column }) => {
        if (value != form.value.creator) {
          ctableRef.value.startSelect();
        }
      },
      rules: [
        {
          required: true,
          message: "请选择上传人员",
          trigger: "blur",
        },
      ],
    },
    {
      label: "上传时间",
      prop: "created",
      search: false,
      span: 16,
      format: "YYYY-MM-DD HH:mm:ss",
      valueFormat: "YYYY-MM-DD HH:mm:ss",
      type: "datetime",
    },
    {
      label: "图片上传",
      prop: "filePath",
      span: 16,
      slot: true,
      hide: true,
      rules: [
        {
          required: true,
          message: "请上传图片",
          trigger: "blur",
        },
      ],
    },
  ],
});
</script>
