From d92ab3161161f1f038680c6b52e5baf5a259f574 Mon Sep 17 00:00:00 2001
From: Liuyi <candymxq888@outlook.com>
Date: 星期六, 21 十二月 2024 16:55:28 +0800
Subject: [PATCH] 添加设备维护及巡检新增功能

---
 pagesAdmin/adminPlatform/maintain.vue |  218 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 212 insertions(+), 6 deletions(-)

diff --git a/pagesAdmin/adminPlatform/maintain.vue b/pagesAdmin/adminPlatform/maintain.vue
index 6626516..d012a22 100644
--- a/pagesAdmin/adminPlatform/maintain.vue
+++ b/pagesAdmin/adminPlatform/maintain.vue
@@ -1,6 +1,6 @@
 <script setup>
 	import { ref ,onMounted} from 'vue';
-	import { searchMaintainApi } from '../../api/index.js'
+	import { searchMaintainApi,createMaintainApi } from '../../api/index.js'
 	import { BASE_URL } from '../../config/baseUrl.js';
 	
 	const baseUrl = ref(BASE_URL)
@@ -14,6 +14,101 @@
 				})
 			}
 		})
+	}
+	//添加记录
+	const popup = ref()
+	const rules = ref({
+		content: {
+			rules:[{required: true, errorMessage:'请输入', trigger: "blur"}],
+		},
+		inspectUser: {
+			rules:[{required: true, errorMessage:'请输入', trigger: "blur"}],
+		},
+		resultType: {
+			rules:[{required: true, errorMessage:'请输入', trigger: "blur"}],
+		},
+	})
+	const formRef =ref()
+	const form = ref({
+	 url:undefined,
+	 content: '',
+	 inspectUser: '',
+	 resultType:1,//2:未完成,1:已完成
+	})
+	function openForm(){
+		popup.value.open()
+	}
+	function radioChange(e){
+		form.value.resultType = e.detail.value
+		console.log('e',e,'form',form.value.resultType)
+	}
+	//上传图片
+	function uploadImg(val){
+		uni.chooseImage({
+			success: async(res) =>{
+				 //建立表单,请求参数传表单形式
+				 let fileForm = {
+					 file1:res.tempFiles,
+					 path:'qingyuan'
+				 }
+				uni.uploadFile({
+					url:BASE_URL+ '/file/upload', 
+					filePath:res.tempFilePaths[0],
+					name: 'file',
+					formData:fileForm,
+					success: (success) => {
+						console.log('文件上传响应',success);
+						let dataObj = JSON.parse(success.data)
+						form.value.url = dataObj.data.newFileName
+						console.log('url',form.value.url)
+					},
+					fail: (err) => {
+						uni.showToast({
+							title: '上传失败,请重试',
+							duration: 2000,
+							icon:'none'
+						});
+						console.log('err',err,res.tempFilePaths[0])
+					}
+				});
+			}
+		});
+	}
+	function concel(){
+		form.value = { 
+			url:undefined,
+			content: '',
+			inspectUser: '',
+			resultType:1,
+		 }
+		formRef.value.clearValidate()
+		popup.value.close()
+	}
+	async function confirmAdd(){
+		formRef.value.validate().then(async(validate)=>{
+			if(form.value.url){
+				let res = await createMaintainApi(form.value)
+				if(res.code === 200){
+					uni.showToast({
+						title:'添加成功'
+					})
+					concel()
+					await searchMaintain()
+				}else{
+					uni.showToast({
+						title:'添加失败',
+						icon:'none'
+					})
+					concel()
+				}
+			}else{
+				uni.showToast({
+					title:'请上传图片',
+					icon:'none'
+				})
+			}
+			
+		}).catch((err)=>{})
 	}
 	onMounted(async() =>{
 		await searchMaintain()
@@ -31,16 +126,16 @@
 					</view>
 					<view class="item-child-area">
 						<view>维修内容:</view>
-						<textarea class="text-area value">{{item.content}}</textarea>
+						<textarea class="text-area value" :maxlength='100'>{{item.content}}</textarea>
 					</view>
 					<view class="item-child">
 						<text>维修状态:</text>
 						<text class="value">{{item.resultTypeView}}</text>
 					</view>
-					<view class="item-child">
+					<!-- <view class="item-child">
 						<text>备注:</text>
 						<text class="value remark">{{item.remark}}</text>
-					</view>
+					</view> -->
 					<view class="item-child">
 						<text>维修时间:</text>
 						<text class="value-time">{{item.createTimeView}}</text>
@@ -48,7 +143,7 @@
 					<view class="item-child-area">
 						<text>上传图片:</text>
 						<view class="item-img-box">
-							<image class="item-img" :src="baseUrl + '/upload' + item.inspectUrl" mode="aspectFit"></image>
+							<image class="item-img" :src="baseUrl + '/upload' + item.url" mode="aspectFit"></image>
 						</view>
 					</view>
 				</view>
@@ -56,8 +151,49 @@
 			<view class="nodata" v-else>
 				<image class="nodata-img" src="../../static/images/other/nodata.png" mode="widthFix"></image>
 			</view>
-			<view class="add-record">添加记录</view>
+			<view @click="openForm" class="add-record">添加记录</view>
 		</view>
+		<!-- 新增弹窗 -->
+		<uni-popup ref="popup" :is-mask-click ='false' type="center" border-radius="20px">
+			<view class="dialog-box">
+				<view>
+					<uni-forms ref="formRef" :model="form" :rules="rules">
+						<uni-forms-item label="维护人员:" label-width='85' name="inspectUser">
+							<uni-easyinput class="input" v-model="form.inspectUser" placeholder="请输入维护人员">></uni-easyinput> 
+						</uni-forms-item>
+						<uni-forms-item label="维护内容:" label-width='85' name="content">
+							<uni-easyinput class="input" v-model="form.content" placeholder="请输入维护内容">></uni-easyinput> 
+						</uni-forms-item>
+						<uni-forms-item label="是否完成:" label-width='85' name='resultType'>
+							<radio-group @change="radioChange">
+								<view class="radio-box">
+									<radio :value="1" :checked="form.resultType == 1"/>
+									<text class="radio-text">完成</text>
+								</view>
+								<view>
+									<radio :value="2" :checked="form.resultType == 2"/>
+									<text class="radio-text">未完成</text>
+								</view>
+							</radio-group>
+						</uni-forms-item>
+					</uni-forms>
+				</view>
+				<!-- 上传图片 -->
+				<view class="upload-box">
+					<view class="upload-title">选择照片</view>
+					<view class="upload-img">
+							<view @click="uploadImg()" class="upload-img-item">
+								<image v-if="form.url" :src="baseUrl + '/upload' + form.url" mode="aspectFit"></image>
+								<image v-else class="default-img" src="../../static/images/other/img-add.png" alt=""></image>
+							</view>
+					</view>
+				</view>
+				<view class="button-box">
+					<button class="btn1" @click="concel">取消</button>
+					<button class="btn2" @click="confirmAdd">确认</button>
+				</view>
+			</view>
+		</uni-popup>
 	</view>
 </template>
 
@@ -166,6 +302,76 @@
 				font-weight:500;
 			}
 		}
+		.dialog-box{
+			width:650rpx;
+			// height:500rpx;
+			background: #fafbfc;
+			padding:40rpx;
+			box-sizing: border-box;
+			display: flex;
+			justify-content:center;
+			flex-direction: column;
+			border-radius:20rpx;
+			.input{
+				align-items: center;
+			}
+			.button-box{
+				width:100%;
+				display: flex;
+				justify-content: center;
+				align-items: center;
+				.btn1{
+					line-height:60rpx;
+					width:180rpx;
+					height:60rpx;
+					background: #fcfcfc;
+					color: #505354;
+				}
+				.btn2{
+					line-height:60rpx;
+					width:180rpx;
+					height:60rpx;
+					background: #b7cafc;
+					color: #484b4c;
+				}
+			}
+			.upload-box{
+				width:100%;
+				.upload-title{
+					color: #6a717e;
+					margin-top: 10rpx;
+				}
+				.upload-img{
+					display: flex;
+					padding:30rpx 14rpx;
+					box-sizing: border-box;
+					.upload-img-item{
+							width: 180rpx;
+							height:180rpx;
+							border-radius:20rpx;
+							border:1rpx dashed #b7d4ff;
+							margin-bottom: 10rpx;
+							display: flex;
+							justify-content: center;
+							align-items: center;
+							image{
+								width:170rpx;
+								height:170rpx;
+							}
+							.default-img{
+								width:120rpx;
+								height:120rpx;
+							}
+					}
+				}
+			}
+			.radio-box{
+				margin-bottom:6rpx;
+			}
+			.radio-text{
+				color: #5b93dc;
+			}
+		}
 	}
 	       
 </style>

--
Gitblit v1.9.3