<template>
	<view class="page">
		<pyh-nv ref="nv" :config="nvConfig"></pyh-nv>
		<view class="listBox" :style="{'padding-top':(pageTop+'px')}">
			<view class="content">
		<!-- 		<view class="top-box" @click="gopath('/pages/declaration/declarationList?type='+OrderType)">
					<view>巡检记录</view>
					<view class="top-box-img">
						<image src="../../static/right2.png"></image>
					</view>
				</view> -->
				<view class="titleall-left">
					<view class="titleall-left-line"></view>我要巡检
				</view>
				<view class="message-list" >
					<view class="info-box">
						<view class="info-box-list">
							<view class="serve">
								<view class="serve-title">界桩id</view>
				<!-- 				<view>
									<input disabled id="pileId" @input="oninput" v-module="from.pileId"
										placeholder="请输入" style="text-align: right;"
										placeholder-style="color:#3d3d3d;font-weight: bold;" />
								</view> -->
								<view class="serve-right">
									<view class="uni-input">{{from.pileId?from.pileId:'-'}}
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="info-box">
						<view class="info-box-list">
							<view class="serve">
								<view class="serve-title">巡检状态</view>
								<view class="serve-right">
									<picker @change="e=> bindPickerChange1(e,3)" :value="index" :range="array1">
										<view class="uni-input">{{from.patrolStatus?from.patrolStatus:'请选择'}}
										</view>
									</picker>
									<image src="../../static/down3.png"></image>
								</view>
							</view>
						</view>

					</view>

					<view class="info-box">
						<view class="info-box-list">
							<view class="serve">
								<view class="serve-title">巡检内容</view>
								<view>
									<input id="patrolContent" @input="oninput" v-module="from.patrolContent"
										placeholder="请输入" style="text-align: right;"
										placeholder-style="color:#3d3d3d;font-weight: bold;" />
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="message-list">
					<view class="info-box">
						<view class="info-box-list">
							<view class="info-box-width" style="width: 100%;">
								<view class="info-box-small">图片</view>
								<view style="margin-top: 20rpx;width: 100%;">
									<u-upload name="1" multiple :fileList="fileList" @delete="deletePic"
										@afterRead="afterRead" :previewFullImage="true" :maxCount="1"></u-upload>
								</view>
								<!-- <view class="info-box-list-img"><image src="../../static/img.png"></image></view> -->
							</view>
						</view>
					</view>
				</view>
				<view class="page-footer">
					<view class="footer-buy">
						<view class="cart-add" @click="mapdoorplatesuccess">
							<image src="../../static/btn5.png"></image>
							<text>提交</text>
						</view>
					</view>
				</view>

			</view>
		</view>
		<uni-calendar ref="calendar" :insert="false" @confirm="confirm" />
	</view>
</template>

<script>
	import service from '@/service/service.js'
	import BASE_URL from "@/common/config.js"
	import sczl from "@/components/sczl.vue"
	export default {
		data() {
			return {
				BASE_URL,
				fileList: [],
				OrderType: 0,
				nvConfig: {
					title: "巡检记录",
					bgColor: "#ffffff",
					color: "#000000",
					fixedAssist: {
						hide: true,
					},
				},
				time: null,
				
				from: {
					userId: uni.getStorageSync('USERS_KEY').phonenumber,
					status: '未处理',
					patrolTime:new Date().getTime(),
					patrolStatus:null,//状态
					pileId:null,
					patrolContent:null,
					patrolImage:null
				},
				array1: ['正常', '异常'],
			};
		},
		onPageScroll(e) {
			this.$refs.nv.pageScroll(e)
		},
		components:{sczl},
		computed: {
			pageTop() {
				return parseInt(88 * uni.getSystemInfoSync().windowWidth / 750) + uni.getSystemInfoSync().statusBarHeight
			}
		},
		onLoad(params) {
			this.from.pileId = params.id
		},
		methods: {
			onchangfileJsonfile(e) {
				console.log('e',e);
				this.filelist = e
				console.log('this.filelist',this.filelist);
			},
			oninput(e) {
				this.from[e.target.id] = e.target.value
			},
			opentime(e) {
				this.$refs.calendar.open();
				this.time = e
			},
			confirm(e) {
				console.log(e);
				if (this.time == 1) {
					// this.community.validStartDate = e.fulldate
					this.$set(this.community, 'validStartDate', e.fulldate)
				} else if (this.time == 2) {
					this.community.validEndDate = e.fulldate
				} else if (this.time == 3) {
					this.community.establishTime = e.fulldate
				} else if (this.time == 4) {
					this.street.validStartDate = e.fulldate
				} else if (this.time == 5) {
					this.street.validEndDate = e.fulldate
				} else if (this.time == 6) {
					this.build.validStartDate = e.fulldate
				} else if (this.time == 7) {
					this.build.validEndDate = e.fulldate
				}
				console.log(this.community);
			},
			gopath(e) {
				uni.navigateTo({
					url: e
				})
			},
			async afterRead(event) {
				for (let i = 0; i < event.file.length; i++) {
					var res = await this.uploadImg(event.file[i].url)
					// console.log(res)
					res = JSON.parse(res.data)
					this.fileList.push({
						name: res.fileName,
						fileId: res.newFileName,
						url: this.BASE_URL + res.fileName
					})
				}
			},
			uploadImg(url) {
				return new Promise((r, e) => {
					uni.uploadFile({
						url: this.BASE_URL + "/common/upload",
						filePath: url,
						name: "file",
						success: (d) => r(d)
					})
				})
			},
			deletePic(event) {
				this.fileList.splice(event.index, 1)
			},
			bindPickerChange1: function(e, e1) {
				console.log('picker发送选择改变，携带值为', e, e1)
				this.from.patrolStatus = this.array1[e.detail.value]
				console.log(this.from)
			},
			mapdoorplatesuccess() {
				console.log('this.community', this.community)
				for (let i = 0; i < this.fileList.length; i++) {
					if (i == 0) {
						this.from.patrolImage = this.fileList[i].name
					} else {
						this.from.patrolImage = this.sign.patrolImage + ',' + this.fileList[i].name
					}
				}
				// return
				this.API.addpatrol(this.from).then(res => {
					console.log(res);
					if (res.code == 200) {
						uni.showToast({
							icon: 'success',
							title: "提交成功",
						})
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 800)
				
					}
				})
			},
			openaddress(e) {
				let that = this
				// 用户已经同意小程序使用录音功能，后续调用 wx.startRecord 接口不会弹窗询问
				wx.chooseLocation({
					success: function(res) {
						console.log(res);
						// that.from.latitude = res.latitude
						if (e == 1) {
							that.community.locationPoint = res.longitude + ',' + res.latitude
							that.community.address = res.address
						} else if (e == 2) {
							that.street.startLocation = res.longitude + ',' + res.latitude
						} else if (e == 3) {
							that.street.endLocation = res.longitude + ',' + res.latitude
						} else if (e == 4) {
							that.build.locationPoint = res.longitude + ',' + res.latitude
						} else if (e == 5) {
							that.applicatio.map = res.longitude + ',' + res.latitude
							that.applicatio.address = res.address
						}
						// that.arr1.plot=res.name
					},
					fail(err) {
						console.log(err)
					}
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.listBox {
		position: relative;
		z-index: 1;
	}

	.content {
		width: 100%;
		padding-bottom: 120rpx;
	}

	.titleall-left {
		font-size: 28rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		margin: 30rpx;

		.titleall-left-line {
			width: 10rpx;
			height: 25rpx;
			border-radius: 18rpx;
			background-color: #547DFF;
			margin-right: 20rpx;
			box-shadow: inset 0rpx 4rpx 9rpx 0rpx rgba(255, 255, 255, 0.34), 5rpx 7rpx 9rpx 0rpx rgba(80, 161, 255, 0.33);
		}
	}

	.top-box {
		display: flex;
		justify-content: space-between;
		margin: 30rpx;
		font-size: 28rpx;
		font-weight: bold;
		background-color: #fff;
		border-radius: 21rpx;
		padding: 30rpx;

		.top-box-img {
			image {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}

	.titleall-box {
		display: flex;
		justify-content: space-between;
		padding: 40rpx 20rpx 20rpx 0;

		.titleall-left {
			font-size: 32rpx;
			font-weight: bold;
			display: flex;
			align-items: center;

			.titleall-left-line {
				width: 14rpx;
				height: 36rpx;
				border-radius: 0 10rpx 10rpx 0;
				background-color: #667FFF;
				box-shadow: 0 0 10rpx 5rpx #d1d9ff;
				margin-right: 20rpx;
			}

			text {
				font-size: 28rpx;
				color: #999999;
			}
		}
	}

	.message-list {
		// background-color: #FFFFFF;
		// border-radius: 20rpx;
		font-size: 25rpx;
		margin: 25rpx;

		.info-box {
			padding: 0 40rpx;
			background: #FFFFFF;
			border-radius: 21rpx;
			margin-bottom: 15rpx;

			.info-box-list {
				display: flex;
				align-items: center;
				border-bottom: 2rpx solid #ececec;
				padding-top: 20rpx;
				padding-bottom: 20rpx;

				.width100 {
					width: 100% !important;
				}

				.info-box-width {
					width: 50%;
					font-size: 30rpx;
					font-weight: bold;

					.info-box-small {
						font-size: 26rpx;
						color: #a8a8a8;
						font-weight: 500;
						margin-top: 10rpx;
					}

					.info-box-list-img {
						margin-top: 30rpx;

						image {
							width: 180rpx;
							height: 180rpx;
							border-radius: 20rpx;
						}
					}

					.input-text {
						font-size: 30rpx;
					}

					.inputtext {
						color: #3d3d3d;
					}

					.textarea {
						background-color: #F7F7F7;
						border-radius: 20rpx;
						width: 100%;
						margin-top: 20rpx;
						padding: 20rpx;
						font-size: 28rpx;
						font-weight: normal;
						min-height: 80rpx;
					}
				}

				.serve {
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 100%;

					.serve-title {
						font-size: 25rpx;
						color: #909090;
					}

					.serve-right {
						font-size: 25rpx;
						font-weight: bold;
						display: flex;
						align-items: center;
						justify-content: flex-end;

						text {
							color: #FC4444;
						}

						image {
							width: 20rpx;
							height: 20rpx;
							margin-left: 10rpx;
						}
					}
				}
			}

			.info-box-list:last-child {
				border-bottom: 0;
			}
		}
	}

	/* 底部 */
	.page-footer {
		margin: 30rpx;
		display: flex;
		height: 100rpx;

		.footer-buy {
			height: 100%;
			width: 100%;

			.cart-add {
				display: flex;
				align-items: center;
				justify-content: center;
				margin-top: 60rpx;

				image {
					position: absolute;
					z-index: 0;
					width: 95%;
					height: 83rpx;
					box-shadow: 5rpx 10rpx 20rpx 0 #b7c8ff;
					border-radius: 100rpx;
				}

				text {
					font-size: 30rpx;
					font-weight: bold;
					color: #fff;
					position: absolute;
					z-index: 1;
				}
			}
		}
	}
</style>