From fd41f55c6178449e1802ff43f46a477247032d97 Mon Sep 17 00:00:00 2001
From: Admin <978517621@qq.com>
Date: 星期一, 26 九月 2022 15:41:31 +0800
Subject: [PATCH] Default Changelist

---
 src/views/specialWorkSystem/workTicket/workApply/components/broken.vue |  261 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 198 insertions(+), 63 deletions(-)

diff --git a/src/views/specialWorkSystem/workTicket/workApply/components/broken.vue b/src/views/specialWorkSystem/workTicket/workApply/components/broken.vue
index b5b8437..3800466 100644
--- a/src/views/specialWorkSystem/workTicket/workApply/components/broken.vue
+++ b/src/views/specialWorkSystem/workTicket/workApply/components/broken.vue
@@ -9,15 +9,13 @@
 						<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>
 				</el-col>
-			</el-row>
-			<el-row>
 				<el-col :span="12">
 					<el-form-item label="作业时间" prop="workTimeLine">
 						<el-date-picker
@@ -54,19 +52,29 @@
 					</el-form-item>
 				</el-col>
 			</el-row>
-
-
+			<el-row>
+				<el-col :span="12">
+					<el-form-item label="危害辨识" prop="hazardIdentification">
+						<el-input
+								v-model="form.hazardIdentification"
+								placeholder="请输入危害辨识"
+						/>
+					</el-form-item>
+				</el-col>
+			</el-row>
+				<el-divider border-style="dashed"/>
 			<el-row>
 				<el-col :span="12">
 					<el-form-item label="作业单位" prop="workDetail.operationDepId">
-						<el-select v-model="form.workDetail.operationDepId">
-							<el-option
-									v-for="item in csDepList"
-									:key="item.value"
-									:label="item.label"
-									:value="item.value"
-							/>
-						</el-select>
+<!--						<el-select v-model="form.workDetail.operationDepId">-->
+<!--							<el-option-->
+<!--									v-for="item in csDepList"-->
+<!--									:key="item.value"-->
+<!--									:label="item.label"-->
+<!--									:value="item.value"-->
+<!--							/>-->
+<!--						</el-select>-->
+						<el-cascader v-model="form.workDetail.operationDepId" :options="departList" :props="casProps2" :show-all-levels="false" @change="handleChange2" />
 					</el-form-item>
 				</el-col>
 				<el-col :span="12">
@@ -93,9 +101,19 @@
 				</el-col>
 				<el-col :span="12">
 					<el-form-item label="涉及相关部门" prop="workDetail.involvedDepIds">
-						<el-select v-model="form.workDetail.involvedDepIds" multiple>
-							<el-option v-for="item in otherWorkList" :key="item.value" :label="item.label" :value="item.value" />
-						</el-select>
+						<el-cascader v-model="form.workDetail.involvedDepIds" :options="departList" :props="casProps" :show-all-levels="false" @change="handleChange" />
+					</el-form-item>
+				</el-col>
+			</el-row>
+			<el-row>
+				<el-col :span="24">
+					<el-form-item label="图片上传" prop="workDetail.bcPath">
+						<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,最多可上传3张</div>
+							</template>
+						</el-upload>
 					</el-form-item>
 				</el-col>
 			</el-row>
@@ -105,6 +123,9 @@
 			<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>
 
@@ -115,20 +136,30 @@
 	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>
+		fileList: Array<file>,
+		uploadUrl: string,
+		dialogVisible: Boolean,
+		dialogImageUrl: string | null,
+		imgLimit: number,
+		casProps: {},
+		casProps2: {},
+		isOverSize: boolean
+	}
+	interface file {
+		url: string;
 	}
 	export default defineComponent({
 		name: 'brokenForm',
 		components: {},
+		props:['workerList','departList'],
 		setup() {
 			const userInfo = useUserInfo()
 			const { userInfos } = storeToRefs(userInfo);
@@ -139,35 +170,24 @@
 					workLevel: 0,
 					workContent: '',
 					workLocation: '',
+					hazardIdentification: '',
 					workDetail:{
 						operationDepId: null,
 						bcReason: '',
 						bcExplain: '',
-						bcPath: '',
+						bcPath: [],
 						involvedDepIds: []
 					},
 					workTimeLine: [],
 					expStartTime: '',
 					expEndTime: ''
 				},
-				workerList:[
-					{
-						label: "张三",
-						value: 53
-					},
-					{
-						label: "李四",
-						value: 54
-					},
-					{
-						label: "测试一",
-						value: 55
-					},
-					{
-						label: "测试二",
-						value: 56
-					}
-				],
+				isOverSize: false,
+				fileList: [],
+				imgLimit: 3,
+				uploadUrl: '',
+				dialogVisible: false,
+				dialogImageUrl: null,
 				csDepList: [
 					{
 						label: "单位一",
@@ -194,24 +214,20 @@
 						value: 6
 					}
 				],
-				otherWorkList: [
-					{
-						label: '部门一',
-						value: 1
-					},
-					{
-						label: '部门二',
-						value: 2
-					},
-					{
-						label: '部门三',
-						value: 3
-					},
-					{
-						label: '部门四',
-						value: 4
-					}
-				]
+				casProps: {
+					emitPath: false,
+					value: 'depId',
+					label: 'depName',
+					multiple: true
+				},
+				casProps2: {
+					emitPath: false,
+					value: 'depId',
+					label: 'depName',
+					multiple: false,
+					expandTrigger: 'hover',
+					checkStrictly: true
+				}
 			});
 			const ruleFormRef = ref<FormInstance>()
 			const applyRules = reactive<FormRules>({
@@ -219,11 +235,13 @@
 				workType: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
 				workContent: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
 				workLocation: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
+				hazardIdentification: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
 				workTimeLine: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
 				"workDetail.operationDepId": [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
 				"workDetail.bcReason": [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
 				"workDetail.bcExplain": [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
-				"workDetail.otherSpecialWork": [{ required: true, message: '该内容不能为空', trigger: 'blur' }]
+				"workDetail.bcPath": [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
+				"workDetail.involvedDepIds": [{ required: true, message: '该内容不能为空', trigger: 'blur' }]
 			});
 			const submitForm = async (formEl: FormInstance | undefined) => {
 				if (!formEl) return
@@ -233,7 +251,7 @@
 						state.form.expEndTime = JSON.parse(JSON.stringify(state.form.workTimeLine))[1]
 						let { workTimeLine, ...data } = JSON.parse(JSON.stringify(state.form))
 						data.workDetail.involvedDepIds = data.workDetail.involvedDepIds.join(',')
-						console.log(data,'data')
+						data.workDetail.bcPath = data.workDetail.bcPath.join(',')
 						const res = await workApplyApi().postBrokenApply(data)
 						if (res.data.code === '200') {
 								ElMessage({
@@ -241,6 +259,8 @@
 									message: '提交成功!'
 								});
 								formEl.resetFields()
+								state.form.workDetail.bcPath = []
+								state.fileList = []
 						} else {
 							ElMessage({
 								type: 'warning',
@@ -252,6 +272,115 @@
 					}
 				})
 			}
+
+			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 fileSize = rawFile.size / 1024 < 500 ? '1' : '0'
+				if(fileSize === '0'){
+					ElMessage({
+						type: 'warning',
+						message: '文件大小不能超过500k。'
+					});
+					state.isOverSize = true
+					return false
+				}else{
+					const res = await workApplyApi().getUploadUrl(rawFile.name);
+					state.form.workDetail.bcPath.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.bcPath,'bcPath')
+							});
+				};
+			};
+
+			const beforeRemove = (file: {}, fileList: []) => {
+				const result = new Promise((resolve, reject) => {
+					if(!state.isOverSize){
+						ElMessageBox.confirm('此操作将删除该图片, 是否继续?', '提示', {
+							confirmButtonText: '确定',
+							cancelButtonText: '取消',
+							type: 'warning'
+						})
+								.then(() => {
+									// console.log(state.workDetail.bcPath,'path')
+									const list = JSON.parse(JSON.stringify(state.form.workDetail.bcPath))
+									fileList.map((item,index)=>{
+										if(item.uid === file.uid){
+											fileList.splice(index,1)
+											state.form.workDetail.bcPath.splice(index,1)
+											deletePic(false,list[index])
+										}
+									})
+									// 请求删除接口
+								})
+								.catch(() => {
+									reject(false);
+								});
+					}else{
+						const list = JSON.parse(JSON.stringify(state.form.workDetail.bcPath))
+						fileList.map((item,index)=>{
+							if(item.uid === file.uid){
+								fileList.splice(index,1)
+								state.form.workDetail.bcPath.splice(index,1)
+								deletePic(true,list[index])
+							}
+						})
+						state.isOverSize = false
+					}
+				});
+				return result;
+			};
+
+
+			// 删除图片接口
+			const deletePic = async(isOverSize:boolean,fileName:string)=>{
+				console.log(fileName,'fileName')
+				const res = await workApplyApi().deleteFile({fileName: fileName})
+				if (res.data.code === '200') {
+					ElMessage({
+						type: isOverSize ? 'error' : 'success',
+						message: isOverSize ? '上传失败':'删除成功!'
+					});
+				} else {
+					ElMessage({
+						type: 'warning',
+						message: res.data.msg
+					});
+				}
+			}
+
+			const showTip =()=>{
+				ElMessage({
+					type: 'warning',
+					message: '超出文件上传数量'
+				});
+			}
+
 			// 折线图
 			const renderMenu = async (value: string) => {
 				Session.set('projectId',value)
@@ -263,7 +392,13 @@
 				Search,
 				ruleFormRef,
 				applyRules,
+				handlePreview,
+				getUploadUrl,
+				beforeRemove,
+				upload,
+				showTip,
 				submitForm,
+				handlePictureCardPreview,
 				...toRefs(state),
 			};
 		},
@@ -308,7 +443,7 @@
 		.el-select{
 			width: 100%;
 		}
-		.el-cascader{
+		:deep(.el-cascader){
 			width: 100% !important;
 		}
 	}

--
Gitblit v1.9.2