<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="storelist.pic" mode=""></image>
					</view>
					<view class="detail_title_p2">
						<view class="detail_title_p3">{{storelist.name}}</view>
						<view class="detail_title_p4">
							{{storelist.renyantime}}
						</view>
						<view>
							<u-line-progress :percentage="storelist.munber" activeColor="#ff0000"></u-line-progress>
						</view>
						<view class="fram_oper_1">
							<view class="fram_oper_2">
								<view class="views1">品种</view>
								<view class="views1">周期</view>
								<view class="views1">收获</view>
							</view>
							<view class="fram_oper_2">
								<view class="views1">{{storelist.vname}}</view>
								<view class="views1">{{storelist.cycle}}天</view>
								<view class="views1">{{storelist.bonusway}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="farm_name_4">
				<view class="farm_name_7" @click="pkxunzhe">
					<view class="farm_name_5">
						操作类型
					</view>
					<view class="farm_name_6">
						{{operatorname}}
						<u-icon name="arrow-right" :bold="true" color="#999" size="18"></u-icon>
					</view>
				</view>
				<view class="bor_solp"></view>
				<view class="farm_name_7" @click="pkxun">
					<view class="farm_name_5">
						操作详情
					</view>
					<view class="farm_name_6">
						{{operatorname2}}
						<u-icon name="arrow-right" :bold="true" color="#999" size="18" ></u-icon>
					</view>
				</view>
			</view>
			<view class="content_detail">
				<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-picker :show="show1" :columns="columns1" @cancel='cancel1' @confirm='confirm1' 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: [],
				columns1: [],
				show: false,
			 
				show1: false,
			 
				storelist: '',
				operatorname: '',
				operatorname2:'',
				id:''

			}
		},
		onLoad(options) {
			this.id = options.id
			this.finantype()



		},
		methods: {

			finantype() {
				mineApi.finantype({
						id: this.id
					})
					.then(res => {
						this.storelist = res.data;
						this.columns = res.data.lable1;
						this.operatorname = res.data.lable1[0][0].label;
						this.columns1= res.data.lable1[0][0].lable2;
						console.log(res.data.lable1[0][0].lable2[0][0].label,'this.columns2')
						this.operatorname2 = res.data.lable1[0][0].lable2[0][0].label;

					})
			},
			confirmmodel() {
				this.show1 = false
				uni.navigateTo({
					url: '/pagesD/pages/inspection/inspection'
				})
			},
			confirm(e) {
				console.log(e, 'eeeeeee')
				this.show = false
				this.id = e.value[0].id
				this.operatorname = e.value[0].label
				this.operatorname2 = e.value[0].lable2[0][0].label;
				this.columns1= e.value[0].lable2;
				 
			},
			confirm1(e){
				this.show1= false
				this.operatorname2 = e.value[0].label
				 
			},
			cancel() {
				this.show = false
			},
			cancel1() {
				this.show1 = false
			},
			pkxunzhe() {
				this.show = true
			},
			pkxun() {
				this.show1 = 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 = {
					orderid: this.storelist.orderid,//订单表id
					operator_name: this.operatorname,
					type_name: this.operatorname2,
					detail_img: this.form.detailimg,
					remark: this.form.describe,
					operid: this.storelist.operid,
					work_id: this.storelist.work_id,
					finance_id: this.storelist.goodid,
					farm_id: this.storelist.farm_id,
				     name:this.storelist.opername
				}
				mineApi.getfinance(data)
					.then(res => {
						if (res.status === 1) {
							uni.showToast({
								title: res.msg,
								icon: "none"
							})
							setTimeout(() => {
								uni.redirectTo({
									url: '/pagesD/pages/financeoperator/financeoperator'
								})
							}, 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;
				flex-direction: column;
				// align-items: center;
				padding: 20rpx 20rpx;
				background: #fff;
				border-radius: 10upx;
				margin-top: 20rpx;

				.farm_name_7 {
					display: flex;
					justify-content: space-between;
				}

				.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 {
						width: 35%;

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

					.detail_title_p2 {

						width: 65%;

						 
						.detail_title_p3 {
							padding: 20rpx 0;
							font-size: 32rpx;
							line-height: 45rpx;
						}

						.detail_title_p4 {
							margin-bottom: 20rpx;
						}

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

						.fram_oper_1 {
							display: flex;
							flex-direction: column;

							.fram_oper_2 {
								display: flex;
								justify-content: space-between;
								align-items: center;
								padding: 10rpx 0;

								.views1 {
									font-size: 28rpx;
									width: 20%;
									-webkit-line-clamp: 1;
									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;
			}
		}

		.bor_solp {
			background-color: #999;
			height: 1rpx;
			width: 100%;
			transform: scaleY(0.3);
			margin: 25rpx 0;
		}

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

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

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