<template>
	<view :class="[AppTheme]" class="all_box">

		<view class="content_box">
			<view class="content_detail_1">
				<view class="detail_title_1">
					<view class="detail_title_p1">
						<image class="image" :src="soil.soil_cover_pic" mode=""></image>
					</view>
					<view class="detail_title_p2">
						<view class="detail_title_p3">{{soil.soil_name}}</view>
						<view class="detail_title_p4">

							地块—{{soil.name}} ,面积 {{soil.area}} m²

						</view>
					</view>
				</view>
				<view class="detail_text_p1">
					<view class="detail_text_p2">巡检日期：{{soil.ntime}}</view>
					<view class="detail_text_p2">巡检土地：{{soil.soil_name}}</view>
					<view class="detail_text_p2">巡检地块：{{soil.name}}</view>
					<view class="detail_text_p2">巡检作物：{{soil.seed_name}}</view>
					<view class="detail_text_p2">巡检面积：{{soil.seed_num}} m²</view>
					<view class="detail_text_p2">巡检内容：{{soil.ipqc_name}}</view>
				</view>
			</view>

			<view class="farm_name_4" @click="pkxunzhe">
				<view class="farm_name_5">

					成熟度
				</view>
				<view class="farm_name_6">
					{{seedname}}
					<u-icon name="arrow-right" :bold="true" color="#999" size="18" ></u-icon>
				</view>
			</view>
			<view class="content_detail">
				<!-- <view class="detail_title">备注说明</view> -->
				<view class="detail_text">
					<textarea v-model="form.describe" class="detail_ipt" type="text" placeholder="请输入巡检备注" />
				</view>
				<view class="content_detail_img">
					<view v-if="detailimg.length!=0" class="detail_img" v-for="(item,index) in detailimg" :key="index"
						@click="preview(item,index)">
						<image class="image" :src="item" mode=""></image>
						<u-icon @click="deleteimg(index)" class="delete_img" name="close-circle" color="#fff" size="20">
						</u-icon>
					</view>
					<view class="detail_img" @click="uploadlogo(2)">
						<u-icon class="icon_plus" name="plus" size="50"></u-icon>
					</view>
				</view>
			</view>

			<view class="submit bg-linear-gradient" @click="submit">记录</view>
		</view>
		<u-picker :show="show" :columns="columns" @cancel='cancel' @confirm='confirm' keyName="label"></u-picker>
		<u-modal :show="show1" :title="title" :content='content' @confirm='confirmmodel'></u-modal>
	</view>
</template>

<script>
	import mineApi from "@/api/mine/index.js"
	import {
		pathToBase64
	} from "@/js/pathto64.js"

	export default {
		data() {
			return {
				primary: this.$theme.primary,
				settingFile: getApp().globalData.siteinfo,
				soil: '',
				detailimg: [], //农场描述附加图
				//表单数据
				form: {

					describe: "", //农场描述

					detailimg: [] //农场描述附加图
				},
				columns: [
					[{
						label: '幼苗期',
						id: 6

					}, {
						label: '生长期',
						id: 7

					}, {
						label: '成熟期',
						id: 3
					}, {
						label: '枯萎',
						id: 8
					}]
				],
				show: false,
				seed_status: '',
				show1: false,
				title: '提示',
				content: '暂无作物信息，无需记录',
				seedname:''

			}
		},
		onLoad(options) {

			console.log(JSON.parse(options.item), 'jsadfjkd')
			this.soil = JSON.parse(options.item)
			console.log(this.soil, 'this.soil')
			this.seedname=this.soil.seed_status
			if(this.soil.seed_status==''){
				this.show1=true
			}
		},
		methods: {
			confirmmodel(){
				this.show1=false
				uni.navigateTo({
					url:'/pagesD/pages/inspection/inspection'
				})
			},
			confirm(e) {
				console.log(e, 'eeeeeee')
				this.show = false
				this.seed_status = e.value[0].id
				this.seedname=e.value[0].label
				// console.log(orderid, 'orderidorderid')
				// this.lookorderbyid(orderid)
			},
			cancel() {
				this.show = false
			},
			pkxunzhe() {
				this.show = true
			},
			preview(url, idx) { //预览图片

				uni.previewImage({
					current: idx,
					urls: this.detailimg,
					success: function(res) {
						console.log(res, '预览')
					},
					fail: function(res) {
						console.log(res, '00000')
					}
				})
			},
			deleteimg(idx) { //图片删除
				this.detailimg.splice(idx, 1)
				this.form.detailimg.splice(idx, 1)
			},
			//提交资料
			submit() {
				let data = {
					id: this.soil.id,
					farm_detail: this.form.describe,
					seed_status: this.seed_status,
					detail_img: this.form.detailimg,
					seedid: this.soil.seedid,

				}
				mineApi.goinspection(data)
					.then(res => {
						if (res.status === 1) {
							uni.showToast({
								title: res.msg,
								icon: "none"
							})
							setTimeout(() => {
								uni.redirectTo({
									url: '/pagesD/pages/inspection/inspection'
								})
							}, 1000)
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none"
							})
						}
					})
					.catch(error => {
						console.log(error, 'error')
					})
			},
			//上传Logo和农场描述附加图
			uploadlogo(num) {
				let that = this
				// #ifdef MP

				uni.chooseImage({
					count: 9,
					success: function(res) {
						res.tempFilePaths.forEach(ele => {
							that.detailimg.push(ele)
							uni.getFileSystemManager().readFile({
								filePath: ele,
								encoding: 'base64',
								success: function(ress) {
									//返回不带data:image/jpeg;base64,'头的base64格式
									let imageurl = 'data:image/jpeg;base64,' + ress
										.data;
									that.form.detailimg.push(imageurl)
								}
							})
						})
					}
				})

				// #endif

				// #ifdef APP||H5

				uni.chooseImage({
					count: 9,
					success: function(res) {
						res.tempFilePaths.forEach(ele => {
							that.detailimg.push(ele)
							pathToBase64(res.tempFilePaths[0]).then(base64 => {
								console.log(base64, "base64")
								that.form.detailimg.push(base64)
							})
						})
					},
					fail: function(res) {

					}
				})

				// #endif
			},

		}
	}
</script>

<style lang="scss" scoped>
	.all_box {
		// background-color: #ffffff;

		.step_bar {
			padding: 50rpx;
			padding-bottom: 80rpx;
			color: #fff;
		}

		.reason {
			background-color: #f97c00;
			color: #fff;
			line-height: 50rpx;
			padding: 0 20rpx;

			.reason_text {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}

		.content_box {
			padding-bottom: 20rpx;

			.farm_name_4 {
				width: 90%;
				margin-left: 2.5%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 20rpx;
				background: #fff;
				border-radius: 10upx;
				margin-top: 20rpx;

				.farm_name_5 {
					display: flex;
					justify-content: flex-start;
					align-items: center;

					image {
						width: 45rpx;
						height: 45rpx;
					}

					font-size: 32rpx;
				}

				.farm_name_6 {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					color: #999;
					font-size: 26rpx;
					margin-right: 2vh;
				}
			}


			.content_detail_1 {

				width: 90%;
				margin-left: 2.5%;
				margin-top: 20rpx;
				border-radius: 10upx;
				background-color: #ffffff;
				padding: 20rpx;

				.detail_text_p1 {
					padding: 30rpx 0 0 0;

					// color: #999;
					.detail_text_p2 {
						padding: 20rpx 0;
					}
				}

				.detail_title_1 {
					display: flex;
					justify-content: flex-start;
					align-items: center;

					.detail_title_p1 {

						.image {
							border-radius: 10rpx;
							width: 150rpx;
							height: 150rpx;
						}
					}

					.detail_title_p2 {
						margin-left: 2vh;

						// color: #999;
						.detail_title_p3 {
							padding: 30rpx 0;
						}

						.detail_title_p4 {
							-webkit-line-clamp: 2;
							display: -webkit-box;
							-webkit-box-orient: vertical;
							overflow: hidden;
							text-overflow: ellipsis;
						}
					}
				}

			}

			// margin: 20rpx;
			.content_detail {
				margin: 15rpx;
				background: #fff;
				border-radius: 10upx;

				.detail_title {
					font-weight: 700;
					font-size: 30rpx;
					color: #999;
					// margin: 15rpx;


				}

				.detail_text {
					// font-size: 25rpx;
					margin-top: 20rpx;
					display: flex;

					.input {
						width: 100%;
						padding-left: 10rpx;
						height: 80rpx;
						border-radius: 5rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						border: 1rpx solid #eae8e9;
					}

					.detail_ipt {
						border: 1rpx solid #eae8e9;
						padding: 15rpx;
						width: 100%;

						.text {
							margin-bottom: 20rpx;
						}

						.detail_logo {
							margin-top: 20rpx;

							.img {
								width: 120rpx;
								height: 120rpx;
							}
						}

						.choose_img {
							margin-top: 20rpx;
							width: 120rpx;
							height: 120rpx;
							text-align: center;
							overflow: hidden;
							border: 1rpx solid #eae8e9;

							.icon_plus {
								margin: 15rpx;
							}
						}
					}

					.detail_ipt1 {
						border: 1rpx solid #eae8e9;
						padding: 15rpx;
						height: 70rpx;
					}

					.icon {
						position: absolute;
						top: 10rpx;
						right: 20rpx;
						z-index: 10;
					}
				}

				.detail_text_address {
					width: 100%;
					margin-top: 20rpx;
					height: 80rpx;
					border-radius: 5rpx;
					border: 1rpx solid #eae8e9;
					display: flex;
					align-items: center;
					justify-content: flex-start;

					.input {
						padding-left: 10rpx;
						width: 92%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.icon {}
				}

				.content_detail_img {
					display: flex;
					justify-content: space-between;
					align-items: center;
					flex-wrap: wrap;

					.detail_img {
						position: relative;
						margin-top: 10rpx;
						width: 200rpx;
						height: 200rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						border: 1rpx solid #eae8e9;
						// margin-right: 20rpx;

						.image {
							width: 200rpx;
							height: 200rpx;
						}

						.delete_img {
							position: absolute;
							top: 5rpx;
							right: 5rpx;
						}
					}
				}


			}

			.agree_terms {
				display: flex;
				justify-content: center;
				align-items: center;

				.agree_dot {
					margin-right: 10rpx;
				}

				text {
					color: #2375f4;
				}
			}

			.submit {
				font-size: 30rpx;
				color: #ffffff;
				padding: 25rpx 0;
				border-radius: 35rpx;
				text-align: center;
				width: 90%;
				margin: 20rpx auto;
				margin-bottom: 40rpx;
			}
		}

		.under_review {
			margin-top: 100rpx;
			text-align: center;

			image {
				width: 150rpx;
				height: 150rpx;
			}

			.text {
				margin-top: 20rpx;
			}
		}
	}
</style>
