repair.vue 7.15 KB
<template>
	<view class="page">
		<view class="item">
			<view class="contents" style="background-color:#fff;padding:10px 20px;">
				<view class="feedback-data">
					<view>
						<view class="title">
							<text style="font-weight: bold;">*现场照片</text>
							
						</view>
					</view>
					<view class="voucher-img">
						<view class="voucher-list">
							<u-upload :action="$upload" :auto-upload="false" ref="uUpload" :max-count="1"
								@on-choose-complete="(response, file, fileList) => onsuccess1(response, file, fileList, 'uUpload')"></u-upload>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="item">
			<view class="contents">
				<view class="add-list">
					<view class="list">
						<view class="title">
							<text style="font-weight: bold;">*设备名称</text>
							
						</view>
						<view class="content">
							<input type="text" placeholder="请输入" v-model="ruleForm.deviceName">
						</view>
					</view>
					<view class="list">
						<view class="title">
							<text style="font-weight: bold;">*设备类型</text>
							
						</view>
						<view class="content"  @click="choose(1)" style="width: 25%;">
							<u-input v-model="ruleForm.deviceType" type="select" disabledColor="#ffffff"
								placeholder="请选择" :border="false" suffixIcon="arrow-right" style="pointer-events:none">
							</u-input>
						</view>
					</view>
					<view class="list">
						<view class="title">
							<text style="font-weight: bold;">*保修问题</text>
							
						</view>
						<view class="content" @click="chooseLocation(1)" style="width: 25%;">
							<u-input v-model="ruleForm.warrantyIssue" type="select" disabledColor="#ffffff"
								placeholder="请选择" :border="false" suffixIcon="arrow-right" style="pointer-events:none">
							</u-input>
						</view>
					</view>
					
					
				</view>
			</view>
		</view>
		
		
		
		<view class="item">
			<view class="contents" style="background-color:#fff;padding:10px 20px;">
				<view class="feedback-data">
					<view>
						<view class="title">
							<text style="font-weight: bold;">*备注信息</text>
							
						</view>
					</view>
					<view class="voucher-img">
						<view class="voucher-list" style="width: 100%;">
							<view class="" style="background-color: #F0F0F0;border-radius: 20rpx;">
								<textarea name="" id="" cols="30" rows="10" placeholder="请输入" style="font-size: 24rpx;background-color: #F0F0F0;border-radius: 20rpx;width: 96%;margin: 0 auto;padding: 20rpx;" v-model="ruleForm.memo"></textarea>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
			<u-select v-model="popup1" mode="mutil-column-auto" :list="list" @confirm="pops" label-name="label" value-name="value"></u-select>
			<u-select v-model="popup2" mode="mutil-column-auto" :list="list1" @confirm="pops1" label-name="label" value-name="value"></u-select>
		<!-- 保存按钮 -->
		<view class="page-footer">
			<u-button type="success" style="flex: 1; margin: 0 10px;" @click="submit">提交</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList:[],
				ruleForm:{
					onSitePhoto:[],
					deviceName:'',
					deviceType:'',
					warrantyIssue:'',
					memo:'',
					applicationTime:'',
					status:'1'
				},
				lableXian:'',
				shelei:'',
				list: [{
						value: '水管问题',
						label: '水管问题'
					},
					{
						value: '物业问题',
						label: '物业问题'
					}
				],
				list1: [{
						value: '类型1',
						label: '类型1'
					},
					{
						value: '类型2',
						label: '类型2'
					}
				],	
				popup1:false,
				popup2:false
			}
		},
		methods:{
			chooseLocation(val, item) {
				this.popup1 = true
			},
			choose(val, item) {
				this.popup2 = true
			},
			pops(val) {
				
				this.ruleForm.warrantyIssue =   val[0].label
			},
			pops1(val) {
				this.ruleForm.deviceType =  val[0].label
			},
			check(){
						if (this.ruleForm.onSitePhoto.length== 0) {
							uni.showToast({
								icon: 'none',
								title: '请上传现场图片'
							});
							return false;
						}
						if (!this.ruleForm.deviceName) {
							uni.showToast({
								icon: 'none',
								title: '请输入设备名称'
							});
							return false;
						}
						if (!this.ruleForm.deviceType) {
							uni.showToast({
								icon: 'none',
								title: '请选择设备类型'
							});
							return false;
						}
						if (!this.ruleForm.warrantyIssue) {
							uni.showToast({
								icon: 'none',
								title: '请选择保修问题'
							});
							return false;
						}
						if (!this.ruleForm.memo) {
							uni.showToast({
								icon: 'none',
								title: '请输入备注信息'
							});
							return false;
						}
				
					return true;
			},
			submit() {
							let show = this.check()
								if(show == false){
									return
								}
							this.ruleForm.applicationTime = this.currentTime()
							this.ruleForm.createUser = uni.getStorageSync('user').phone
							this.ruleForm.onSitePhoto = this.ruleForm.onSitePhoto.map(item=>{
										 return item.replace(this.$img,'');
									})
									let info = {
										...this.ruleForm,
										onSitePhoto:this.ruleForm.onSitePhoto.join(','),
									}
							this.$http.sendRequest('/cereReportIssuesRepairs/add', 'POST',info,1).then(res => {
							     uni.navigateTo({
							     	url: '/pages/serve/serve'
							     })
							}).catch(err => {
								console.log(err)
								//请求失败
							})
							
						},
						// 获取时间
						currentTime() {
						    let date = new Date();
						    let year = date.getFullYear();
						    let month = date.getMonth() + 1; // 月份从0~11,所以加一
						    let day = date.getDate();
						    let hours = date.getHours();
						    let minutes = date.getMinutes();
						    let seconds = date.getSeconds();
						
						    // 为月、日、时、分、秒添加前导零(如果需要)
						    month = month < 10 ? '0' + month : month;
						    day = day < 10 ? '0' + day : day;
						    hours = hours < 10 ? '0' + hours : hours;
						    minutes = minutes < 10 ? '0' + minutes : minutes;
						    seconds = seconds < 10 ? '0' + seconds : seconds;
						
						    // 拼接日期和时间字符串
						    let strDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
						    return strDate;
						},
						onsuccess1(e, file, fileList, ziduan) {
							console.error(e, file, fileList, ziduan)
							uni.uploadFile({
								url: this.$upload, // 仅为示例,请替换为您的服务器上传接口
								filePath: e[0].url,
								name: 'file', // 后端接收的文件参数名
								formData: {
									filePath: 'xcx', // 其他表单数据
								},
								success: (uploadFileRes) => {
										this.ruleForm.onSitePhoto.push(this.$img + JSON.parse(uploadFileRes.data).data)
									uni.showToast({
										title: '上传成功',
										icon: 'success',
									});
								},
								fail: (err) => {
									console.error('上传失败', err);
									uni.showToast({
										title: '上传失败',
										icon: 'none',
									});
								},
							});
						},
		}
	}
</script>

<style scoped lang="scss">
	@import 'repair.scss';
</style>