Browse Source

no message

kllay 1 day ago
parent
commit
8c81cef510

+ 143 - 25
src/views/system/borrow/component/ClassroomBorrow/index.vue

@@ -95,22 +95,63 @@
 			</el-table>
 			<el-button type="primary" @click="addItem">添加设备</el-button>
 
-			<div style="margin: 16px 0 8px 0; font-weight: bold">附件</div>
+			<!-- <div style="margin: 16px 0 8px 0; font-weight: bold">附件</div>
 			<el-upload
-			action="#"
 			drag
-			list-type="text"
-			accept=".bmp,.gif,.jpeg,.jpg,.png,‌.webp,.svg"
-			multiple
+			list-type="picture"
 			:show-file-list="true"
-			:on-success="handleUploadSuccess"
-			:on-error="handleUploadError"
+			:http-request="handleCustomUpload"
 			>
 			<i class="el-icon-upload"></i>
 			<div class="el-upload__text">将文件拖到此处,或 <em>点击上传</em></div>
+			</el-upload> -->
+			<div>
+			<el-upload
+			list-type="picture-card"
+			:show-file-list="true"
+			:http-request="handleCustomUpload"
+			:file-list="fileList"
+			style="margin-top: 10px;"
+			>
+			<el-icon><Plus /></el-icon>
 			</el-upload>
+		    </div>
+
 
 		</el-form>
+
+
+		<!-- 审批信息流程展示 -->
+		<div v-if="isView"  style="margin-top: 24px; padding: 0 12px">
+		<div style="font-weight: bold; margin-bottom: 12px">审批流程进度</div>
+		<el-steps :active="activeStep" align-center>
+			<el-step
+			title="创建申请"
+			:description="`创建时间:${ timeline.create }`"
+			icon="CircleCheck"
+			:status="activeStep >= 1 ? 'finish' : 'wait'"
+			/>
+			<el-step
+			title="待审批"
+			description="待超级管理员审批"
+			icon="CircleCheck"
+			:status="activeStep >= 2 ? 'finish' : 'wait'"
+			/>
+			<el-step
+			title="审批通过"
+			:description="`审批人:${timeline.approver},时间:${timeline.approve}`"
+			icon="CircleCheck"
+			:status="activeStep >= 3 ? 'finish' : 'wait'"
+			/>
+			<el-step
+			title="流程完成"
+			description="流程已结束"
+			icon="CircleCheck"
+			:status="activeStep >= 4 ? 'finish' : 'wait'"
+			/>
+		</el-steps>
+		</div>
+
 		<template #footer>
 			<el-button @click="onCancel">关闭</el-button>
 			<el-button v-if="!isViewMode" type="primary" @click="onSave">提交</el-button>
@@ -124,10 +165,60 @@ import { ref, watch, defineProps, defineEmits, onMounted, computed,inject,Ref, }
 import SelectDeviceDialog from '../SpecialBorrow/SelectDeviceDialog/index.vue';
 import timetablemanage from '../../../timetablemanage/index.vue';
 import * as apis from '../../../timetablemanage/api';
+import * as api from '../../api';
 import { provide } from 'vue';
 import dayjs from 'dayjs';
 import { ElMessage } from 'element-plus';
 import { cloneDeep } from 'lodash-es';
+import Cookies from 'js-cookie';
+import { request } from '/@/utils/service';
+import { Plus } from '@element-plus/icons-vue';
+
+
+
+const fileList = ref([]);
+
+// const fileList = ref([]);
+const handleCustomUpload = async ({ file, onProgress, onSuccess, onError }: any) => {
+  const token = Cookies.get('token'); 
+  const formData = new FormData();
+  formData.append('file', file);
+  console.log("token::::",token);
+
+  try {
+    const res = await request({
+		url: `/api/system/upload/`,
+		method: 'post',
+		headers: {
+			'Content-Type': 'multipart/form-data',
+			Authorization: 'JWT '+ token,
+		},
+		data: formData,
+		timeout: 60000,
+		onUploadProgress: (p: any) => {
+                            onProgress({percent: Math.round((p.loaded / p.total) * 100)});
+		}
+    });
+
+	// 构造 Element Plus 需要的 file 对象
+	const fileObj = {
+      name: res.data.name,
+      url: res.data.url,
+      status: 'success',
+      response: res.data
+    };
+
+    // 添加到附件列表
+	form.value.attachments = fileObj.url; 
+
+    ElMessage.success('上传成功');
+    onSuccess(fileObj); 
+  } catch (error) {
+    ElMessage.error('上传失败');
+    onError(error);
+  }
+};
+
 
 provide('isEmbedded', true);
 provide('onCourseSelected', handleCourseSelected);
@@ -137,18 +228,11 @@ const emit = defineEmits(['update:visible', 'update:modelValue', 'submit','updat
 const visible = ref(props.visible);
 const formRef = ref();
 
+const isEdit = computed(() => props.modelValue?.mode === 'edit');
+const isView = computed(() => props.modelValue?.mode === 'view');
+const isAdd = computed(() => props.modelValue?.mode === 'add');
 
 
-function handleUploadSuccess(response, file, fileList) {
-	// eslint-disable-next-line no-console
-  console.log('上传成功:', file.name);
-}
-
-function handleUploadError(err, file, fileList) {
-	// eslint-disable-next-line no-console
-  console.error('上传失败:', file.name);
-}
-
 
 function handleCourseSelected({ course_id, course_Name,expected_start_time }) {
 	// eslint-disable-next-line no-console
@@ -222,6 +306,7 @@ const form = ref({
 	items: [],
 	borrow_type:1,
 	course_input: '',
+	attachments:'',
 });
 const showSelectDeviceDialog = ref(false);
 const isViewMode = computed(() => props.modelValue?.mode === 'view');
@@ -302,7 +387,8 @@ function resetForm() {
     return_location: '',
     items: [],
     borrow_type: 1,
-    course_input: ''
+    course_input: '',
+	attachments:'',
   };
 }
 
@@ -313,8 +399,8 @@ watch(() => props.visible, (v) => {
 //   console.log("快照visible.value::",visible.value)
   if (v) {
     if (props.lastFormSnapshot) {
-	  console.log("快照lastFormSnapshot.value::",props.lastFormSnapshot )
-      form.value = { ...props.lastFormSnapshot };
+		console.log("快照lastFormSnapshot.value::",props.lastFormSnapshot )
+		form.value = { ...props.lastFormSnapshot };
     } else {
 		// console.log("没有快照lastFormSnapshot.value::",props.lastFormSnapshot )
       resetForm(); // 如果没有快照,初始化表单
@@ -323,12 +409,44 @@ watch(() => props.visible, (v) => {
 }, { immediate: true });
 
 
-watch(
-	() => props.modelValue,
-	(v) => {
-		if (v) Object.assign(form.value, v);
+const timeline = ref({
+  create: '',
+  approve: '',
+  approver: ''
+});
+const activeStep = ref(1);
+
+watch(() => props.modelValue, async (val) => {
+  if (val && val.id && isView.value) {
+			try {
+			const res = await api.GetApplicationDetail(val.id);
+			if (res.code === 2000 && res.data) {
+				const data = res.data;
+				Object.assign(form.value, data);
+				timeline.value.create = data.create_datetime || '';
+				timeline.value.approve = data.approve_time || '';
+				timeline.value.approver = data.approver_info?.name || '审批人';
+
+				activeStep.value = 1; // 创建
+				if (data.status >= 1) activeStep.value = 2; // 待审批
+				if (data.status >= 2) activeStep.value = 3; // 审批通过
+				if (data.status >= 3) activeStep.value = 4; // 完成
+			}
+			} catch (e) {
+			ElMessage.error('获取审批信息失败');
+			}
+	}else if(val&& isEdit.value){
+		try {
+			const res = await api.GetApplicationDetail(val.id);
+			if (res.code === 2000 && res.data) {
+				const data = res.data;
+				Object.assign(form.value, data);
+			}
+			} catch (e) {
+			ElMessage.error('获取审批信息失败');
+			}
 	}
-);
+}, { immediate: true });
 
 function addItem() {
 	showSelectDeviceDialog.value = true;

+ 57 - 20
src/views/system/borrow/component/SpecialBorrow/index.vue

@@ -89,20 +89,18 @@
 			<div style="margin: 16px 0 8px 0; font-weight: bold">配件信息</div>
 			<el-input v-model="form.accessory_info" placeholder="请输入配件信息"  :disabled="isView"/>
 
-			<div style="margin: 16px 0 8px 0; font-weight: bold">附件</div>
+			<div>
 			<el-upload
-			action="#"
-			drag
-			list-type="text"
-			accept=".bmp,.gif,.jpeg,.jpg,.png,‌.webp,.svg"
-			multiple
+			list-type="picture-card"
 			:show-file-list="true"
-			:on-success="handleUploadSuccess"
-			:on-error="handleUploadError"
+			:http-request="handleCustomUpload"
+			:file-list="fileList"
+			style="margin-top: 10px;"
 			>
-			<i class="el-icon-upload"></i>
-			<div class="el-upload__text">将文件拖到此处,或 <em>点击上传</em></div>
+			<el-icon><Plus /></el-icon>
 			</el-upload>
+		    </div>
+
 		</el-form>
 		<!-- 审批信息流程展示 -->
 		<div v-if="isView"  style="margin-top: 24px; padding: 0 12px">
@@ -149,6 +147,9 @@ import SelectDeviceDialog from './SelectDeviceDialog/index.vue';
 import dayjs from 'dayjs';
 import { ElMessage } from 'element-plus';
 import * as api from '../../api';
+import Cookies from 'js-cookie';
+import { request } from '/@/utils/service';
+import { Plus } from '@element-plus/icons-vue';
 
 const now = dayjs().format('YYYY-MM-DD HH:mm:ss');
 
@@ -165,6 +166,50 @@ const emit = defineEmits(['update:visible', 'update:modelValue', 'submit']);
 const visible = ref(props.visible);
 const formRef = ref();
 
+
+const fileList = ref([]);
+
+// const fileList = ref([]);
+const handleCustomUpload = async ({ file, onProgress, onSuccess, onError }: any) => {
+  const token = Cookies.get('token'); 
+  const formData = new FormData();
+  formData.append('file', file);
+  console.log("token::::",token);
+
+  try {
+    const res = await request({
+		url: `/api/system/upload/`,
+		method: 'post',
+		headers: {
+			'Content-Type': 'multipart/form-data',
+			Authorization: 'JWT '+ token,
+		},
+		data: formData,
+		timeout: 60000,
+		onUploadProgress: (p: any) => {
+                            onProgress({percent: Math.round((p.loaded / p.total) * 100)});
+		}
+    });
+
+	// 构造 Element Plus 需要的 file 对象
+	const fileObj = {
+      name: res.data.name,
+      url: res.data.url,
+      status: 'success',
+      response: res.data
+    };
+
+    // 添加到附件列表
+	form.value.attachments = fileObj.url; 
+
+    ElMessage.success('上传成功');
+    onSuccess(fileObj); 
+  } catch (error) {
+    ElMessage.error('上传失败');
+    onError(error);
+  }
+};
+
 // import { ElSteps } from 'element-plus';
 
 const timeline = ref({
@@ -174,15 +219,6 @@ const timeline = ref({
 });
 const activeStep = ref(1);
 
-function handleUploadSuccess(response, file, fileList) {
-	// eslint-disable-next-line no-console
-  console.log('上传成功:', file.name);
-}
-
-function handleUploadError(err, file, fileList) {
-	// eslint-disable-next-line no-console
-  console.error('上传失败:', file.name);
-}
 
 
 const form = ref({
@@ -202,7 +238,8 @@ const form = ref({
 	items: [],
 	accessory_info: '',
 	borrow_type: 2,
-	return_location:''
+	return_location:'',
+	attachments:'',
 });
 const showSelectDeviceDialog = ref(false);