From 1229f3ec76bffe282d85b48daf0b32bc17022810 Mon Sep 17 00:00:00 2001
From: Admin <978517621@qq.com>
Date: 星期五, 26 八月 2022 12:29:18 +0800
Subject: [PATCH] Default Changelist

---
 src/views/specialWorkSystem/workTicket/workApply/components/plate.vue |  170 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 139 insertions(+), 31 deletions(-)

diff --git a/src/views/specialWorkSystem/workTicket/workApply/components/plate.vue b/src/views/specialWorkSystem/workTicket/workApply/components/plate.vue
index c5833fd..16b94cc 100644
--- a/src/views/specialWorkSystem/workTicket/workApply/components/plate.vue
+++ b/src/views/specialWorkSystem/workTicket/workApply/components/plate.vue
@@ -9,9 +9,9 @@
 						<el-select v-model="form.operatorUids" multiple>
 							<el-option
 									v-for="item in workerList"
-									:key="item.value"
-									:label="item.label"
-									:value="item.value"
+									:key="item.uid"
+									:label="item.username"
+									:value="item.uid"
 							/>
 						</el-select>
 					</el-form-item>
@@ -97,7 +97,9 @@
 								v-model="form.workDetail.temperature"
 								type="number"
 								placeholder="请输入"
-						/>
+						>
+							<template #append>摄氏度(℃)</template>
+						</el-input>
 					</el-form-item>
 				</el-col>
 				<el-col :span="12">
@@ -106,7 +108,9 @@
 								v-model="form.workDetail.pressure"
 								type="number"
 								placeholder="请输入"
-						/>
+						>
+							<template #append>千帕(kPa)</template>
+						</el-input>
 					</el-form-item>
 				</el-col>
 			</el-row>
@@ -171,12 +175,27 @@
 					</el-form-item>
 				</el-col>
 			</el-row>
+			<el-row>
+				<el-col :span="24">
+					<el-form-item label="盲板位置图" prop="workDetail.bpLocationMapPath">
+						<el-upload accept="image/*" :on-exceed="showTip" :on-preview="handlePictureCardPreview" :limit='imgLimit' v-model:file-list="fileList" :http-request="upload" :action="uploadUrl" list-type="picture-card" :on-remove="handleRemove" :before-remove="beforeRemove" :before-upload="getUploadUrl">
+							<el-icon><Plus /></el-icon>
+							<template #tip>
+								<div class="el-upload__tip">上传jpg/png图片尺寸小于500KB,最多可上传5张</div>
+							</template>
+						</el-upload>
+					</el-form-item>
+				</el-col>
+			</el-row>
 			</div>
 		</el-form>
 		<div class="applyBtn">
 			<el-button type="primary" size="large" plain @click="submitForm(ruleFormRef)">发起申请</el-button>
 		</div>
 	</div>
+	<el-dialog v-model="dialogVisible">
+		<img w-full :src="dialogImageUrl" alt="Preview Image" />
+	</el-dialog>
 	</div>
 </template>
 
@@ -187,21 +206,29 @@
 	import {useUserInfo} from "/@/stores/userInfo";
 	import { Session } from '/@/utils/storage';
 	import { Search } from '@element-plus/icons-vue'
-	import { ElMessage } from 'element-plus'
-	import type { FormInstance, FormRules } from 'element-plus'
+	import { ElMessage, ElMessageBox } from 'element-plus'
+	import type { FormInstance, FormRules, UploadProps, UploadUserFile } from 'element-plus'
 	import { workApplyApi } from '/@/api/specialWorkSystem/workApply';
-
+	import axios from 'axios';
 
 	interface stateType {
 		form: Object,
-		workerList: Array<any>,
 		csDepList: Array<any>,
 		otherWorkList: Array<any>,
-		workLevelList: Array<any>
+		workLevelList: Array<any>,
+		fileList: Array<file>,
+		uploadUrl: string,
+		dialogVisible: Boolean,
+		dialogImageUrl: string | null,
+		imgLimit: number,
+	}
+	interface file {
+		url: string;
 	}
 	export default defineComponent({
 		name: 'brokenForm',
 		components: {},
+		props:['workerList'],
 		setup() {
 			const userInfo = useUserInfo()
 			const { userInfos } = storeToRefs(userInfo);
@@ -220,7 +247,7 @@
 						bpMaterialQuality: '',
 						bpSpecification: '',
 						bpLocation: '',
-						bpLocationMapPath: '',
+						bpLocationMapPath: [],
 						installLine: [],
 						installBpTime: '',
 						uninstallBpTime: '',
@@ -230,24 +257,11 @@
 					expStartTime: '',
 					expEndTime: ''
 				},
-				workerList:[
-					{
-						label: "张三",
-						value: 53
-					},
-					{
-						label: "李四",
-						value: 54
-					},
-					{
-						label: "测试一",
-						value: 55
-					},
-					{
-						label: "测试二",
-						value: 56
-					}
-				],
+				fileList: [],
+				imgLimit: 5,
+				uploadUrl: '',
+				dialogVisible: false,
+				dialogImageUrl: null,
 				workLevelList: [
 					{
 						label: "抽盲板作业",
@@ -335,6 +349,7 @@
 				"workDetail.bpSpecification": [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
 				"workDetail.installLine": [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
 				"workDetail.bpLocation": [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
+				"workDetail.bpLocationMapPath": [{ required: true, message: '该内容不能为空', trigger: 'blur' }]
 			});
 			const submitForm = async (formEl: FormInstance | undefined) => {
 				if (!formEl) return
@@ -348,9 +363,9 @@
 						let { installLine, ...data2 } = JSON.parse(JSON.stringify(state.form.workDetail))
 						data.workDetail = data2
 						data.workDetail.otherSpecialWork = data.workDetail.otherSpecialWork.join(',')
+						data.workDetail.bpLocationMapPath = data.workDetail.bpLocationMapPath.join(',')
 						data.workDetail.temperature = Number(data.workDetail.temperature)
 						data.workDetail.pressure = Number(data.workDetail.pressure)
-						console.log(data,'data')
 						const res = await workApplyApi().postPlateApply(data)
 						if (res.data.code === '200') {
 								ElMessage({
@@ -358,6 +373,8 @@
 									message: '提交成功!'
 								});
 								formEl.resetFields()
+								state.form.workDetail.bpLocationMapPath = []
+								state.fileList = []
 						} else {
 							ElMessage({
 								type: 'warning',
@@ -369,6 +386,91 @@
 					}
 				})
 			}
+			const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
+				console.log(uploadFile);
+			};
+
+			const handlePictureCardPreview = (uploadFile: { url: string }) => {
+				state.dialogImageUrl = uploadFile.url!;
+				state.dialogVisible = true;
+			};
+
+			const getUploadUrl = async (rawFile: any) => {
+				const res = await workApplyApi().getUploadUrl(rawFile.name);
+				state.form.workDetail.bpLocationMapPath.push(res.data.data.fileName)
+				state.uploadUrl = res.data.data.uploadUrl;
+				console.log(res.data.data.fileName,'name')
+			};
+
+			const upload = async (params: any) => {
+				// const formData = new FormData();
+				// formData.append('file', state.fileList[0].raw);
+				let reader = new FileReader();
+				reader.readAsArrayBuffer(params.file);
+				reader.onload = async () => {
+					axios
+							.put(state.uploadUrl, reader.result, {
+								header: { 'Content-Type': 'multipart/form-data' }
+							})
+							.then(() => {
+								// if (state.fileList.length === 2) {
+								// 	state.fileList.splice(0, 1);
+								// }
+								// console.log(state.form.workDetail.bpLocationMapPath,'bpLocationMapPath')
+							});
+				};
+			};
+
+			const beforeRemove = (file: {}, fileList: []) => {
+				const result = new Promise((resolve, reject) => {
+					ElMessageBox.confirm('此操作将删除该图片, 是否继续?', '提示', {
+						confirmButtonText: '确定',
+						cancelButtonText: '取消',
+						type: 'warning'
+					})
+							.then(() => {
+								// console.log(state.workDetail.bpLocationMapPath,'path')
+								const list = JSON.parse(JSON.stringify(state.form.workDetail.bpLocationMapPath))
+								fileList.map((item,index)=>{
+									if(item.uid === file.uid){
+										fileList.splice(index,1)
+										state.form.workDetail.bpLocationMapPath.splice(index,1)
+										deletePic(list[index])
+									}
+								})
+								// 请求删除接口
+							})
+							.catch(() => {
+								reject(false);
+							});
+				});
+				return result;
+			};
+
+
+			// 删除图片接口
+			const deletePic = async(fileName)=>{
+				console.log(fileName,'fileName')
+				const res = await workApplyApi().deleteFile({fileName: fileName})
+				if (res.data.code === '200') {
+					ElMessage({
+						type: 'success',
+						message: '删除成功!'
+					});
+				} else {
+					ElMessage({
+						type: 'warning',
+						message: res.data.msg
+					});
+				}
+			}
+			const showTip =()=>{
+				ElMessage({
+					type: 'warning',
+					message: '超出文件上传数量'
+				});
+			}
+
 			// 折线图
 			const renderMenu = async (value: string) => {
 				Session.set('projectId',value)
@@ -380,7 +482,13 @@
 				Search,
 				ruleFormRef,
 				applyRules,
+				handlePreview,
+				getUploadUrl,
+				beforeRemove,
+				upload,
+				showTip,
 				submitForm,
+				handlePictureCardPreview,
 				...toRefs(state),
 			};
 		},
@@ -403,7 +511,7 @@
 		.applyBtn{
 			width: 100%;
 			background: #fff;
-			height: 80px;
+			padding-top: 15px;
 			z-index: 5;
 			box-shadow: 0 -3px 8px rgba(150,150,150,.1);
 			display: flex;

--
Gitblit v1.9.2