	<template>
		<scroll-view>
			<view class="background">

				<view class="uni-list">
					<view class="container" style="border-bottom: 1px solid #f8f8f8;">
						<view>
							工程名称
						</view>
						<!-- <view v-if="this.isEmpty(this.projectName)" style="margin-top: 10;" @click="pickerShow('gcmc',0)">
							<span style="color: darkgray;">请选择工程名称</span>
							<image :src="loadImgSrc('icon_right.png')" class="to-right-icon"></image>
						</view> -->
						<view  class="uni-list-cell-db" style="margin-top: 10;">
							<span style="color: black;">{{projectName}}</span>
							<!-- <image :src="loadImgSrc('icon_right.png')" class="to-right-icon"></image> -->
						</view>
					</view>
				</view>
				
				<view class="uni-list">
					<view class="container" style="border-bottom: 1px solid #f8f8f8;">

						<text>地点</text>
						<input class="uni-input" v-model="locations" disabled="true"
							style="margin-left: 10px;text-align: right;"></input>
					</view>
				</view>
				
				<SelectPicker :list="selectList" @change="changeSelect" v-if="open" @close="close" titleKey="name"
					subtitleKey="id" v-model="name"></SelectPicker>

				<SelectPicker :list="dictOptions" @change="changeSelectDict" v-if="openDict" @close="closeDict"
					titleKey="dictLabel" subtitleKey="dictValue" v-model="dictLabel"></SelectPicker>
			</view>

			<view class="background">
				<view>
					<view class="uni-list">
						<view
							style="font-size: 16px;margin-left: 10px;margin-top: 10px;display: flex; justify-content: space-between;margin-bottom: 10px;">
							{{objValue.value}}

							<span
								style="color: blue;font-size: 14px;  display: flex;justify-content:flex-end; margin-right: 10px;"
								@click="history">历史</span>
						</view>
						<view class="container" style="border-bottom: 1px solid #f8f8f8;">

							<view>
								施工时间
							</view>
							<view @click="openDatetimePicker()">
								<span style="color: black;">{{time}}</span>
								<image :src="loadImgSrc('icon_right.png')" class="to-right-icon"></image>
							</view>
						</view>
						<view class="uni-list" v-if="objValue.value=='管道压力'||objValue.value=='原有管线压力'">
							<view class="container" style="border-bottom: 1px solid #f8f8f8;">

								<text>{{objValue.value}}</text>
								<input class="uni-input" type="digit" v-model="pipePressure" :placeholder="placeholder"
									maxlength="100" style="margin-left: 10px;text-align: right;"></input>
							</view>
						</view>
						<view class="container" style="border-bottom: 1px solid #f8f8f8;">
							<view class="uni-common-mt" style="width: 100%;">
								<text class="uni-title uni-common-pl">施工内容</text>
								<view style="width: 100%;box-sizing: border-box;">
									<textarea class="textarea" placeholder="请输入施工内容" maxlength="255"
										placeholder-style="padding: 10rpx;"
										style="width: 100%;height: 100%;border: 1rpx solid #cccccc; border-radius: 15rpx;padding: 10rpx;line-height:normal;"
										auto-height v-model="projectContent"></textarea>
								</view>
							</view>
						</view>



						<view class="align-items" style="margin-top: 20px;margin-bottom: 20px;">
							<view class="container" style="color: #b2b2b2;">*请上传照片</view>
							<view class="" style="display: flex; flex-wrap: wrap;margin-top: 10px; margin-left: 10px;">
								<image :src="loadImgSrc('updateimg.png')" mode=""
									style="width: 200rpx; height: 150rpx; margin: 0 12rpx;; " @click="choose('other')">
								</image>
								<view v-for="(item,index) in imgArr" :key="index" style="position: relative;">
									<view
										v-if="item.substring(item.length - 3) == 'png' || item.substring(item.length - 3) == 'jpg'||item.substring(item.length-4)=='jpeg'  ">
										<image :src="item" mode="" style="width: 100rpx; height: 100rpx; margin: 0 12rpx;"
											@click="showPhoto(index,'other')">
										</image>
									</view>
									<view v-else>
										<video :src="item" style="width: 100rpx; height: 100rpx; margin: 0 12rpx;"></video>
									</view>
									<view @click="remove(index,'other')"
										style="position: absolute; top: 0; right: 14rpx; border-radius: 50%;">
										<image :src="loadImgSrc('icon_close.png')" style=" width: 15px; height: 15px;">
										</image>
									</view>
								</view>
							</view>
						</view>


					</view>
				</view>
			</view>
			<view class="action-btn">
				<button @click="submit" class="btn cu-btn block bg-blue lg round">确认上传</button>
			</view>

			<bottom-sheet ref="refShare" :data="historyList" :TitleType="objValue.value"></bottom-sheet>
			<yt-dateTimePicker ref="myPicker" @submit="handleSubmit" :start-year="2024" :end-year="2099"
				:time-hide="[true, true, true, true, true, true]" :time-label="['年', '月', '日', '时', '分', '秒']" />


		</scroll-view>
	</template>



	<script>
		import SelectPicker from '../../components/selectPicker/select_picker.vue'
		import bottomSheet from '../../components/bottomSheet/bottomSheetMoreNew.vue'

		import {
			getDicts
		} from "@/api/system/dict/data";
		import {
			SubmitMouth,
			getHistoryMouthDetails,
		} from '@/api/common'
		import {
			getToken
		} from '../../utils/auth';

		export default {
			components: {
				SelectPicker,
				bottomSheet,
			},
			data() {
				return {
					historyList: {}, //历史数据
					show_loding: false,
					popupText: '', //对话框内容
					titleText: '',
					cancelText: '',
					confirmText: '',
					conLists: [],
					headers: {
						Authorization: "Bearer " + getToken()
					},
					time: '', //施工时间

					loading: false,
					loadingFile: false,
					open: false,
					objValue: '', //上一页面传过来的值  新增接口用
					openDict: false,
					projectContent: '', //施工内容
					selectList: [],
					dictOptions: [],
					imgArr: [],
					type: '',

					projectName: '', //工程名称

					createTime: '',
					address: '',
					imgHtqArr: [],
					imgJspsArr: [],
					imgHthArr: [],
					pipePressure: '',
					placeholder: '',
					//新
					createBy: '',
					createTime: '',
					updateBy: '',
					updateTime: '',
					updateInfoTime: '',
					id: '',
					modeOperation: '',
					locations: '',
					remark: '',
					
					enginTitle: '',
					enginValue: '',
				}
			},

			created() {
				this.time = this.traversalTime(new Date().getTime()) //在data里定义变量-nowTime
			},

			onLoad(options) {
				if ('params' in options) {
					this.objValue = JSON.parse(decodeURIComponent(options.params));
					this.placeholder = '请输入' + this.objValue.value;
					this.id=this.objValue.id;
					this.projectName=this.objValue.name;
					this.enginTitle=this.objValue.title;
					this.enginValue=this.objValue.value;
					this.locations=this.objValue.address;
				}
			},
			methods: {
				//判断是否选择
				isEmpty(str) {
					return (!str || 0 === str.length);
				},
				handleSubmit(e) {
					this.time = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`;
				},
				//获取当前时间
				traversalTime(timestamp) {
					//timestamp(时间戳)是整数，否则要parseInt转换
					let time = new Date(timestamp);
					let y = time.getFullYear();
					let m = time.getMonth() + 1;
					let d = time.getDate();
					let h = time.getHours();
					let mm = time.getMinutes();
					let s = time.getSeconds();
					return y + '-' + this.addTimes(m) + '-' + this.addTimes(d) + ' ' + this.addTimes(h) + ':' + this.addTimes(
						mm) + ':' + this.addTimes(s);
				},
				addTimes(m) {
					return m < 10 ? '0' + m : m
				},
				// 打开picker
				openDatetimePicker() {
					this.$refs.myPicker.show();
				},

				// 关闭picker
				closeDatetimePicker() {
					this.$refs.myPicker.hide();
				},
				pickerShow(e, index) {
					this.SelectIndex = index;
					this.type = e; //赋值类型
					if (e == 'gcmc') { //工程名称
						// this.open = true;
						// //请求
						// getProjectName(this.objValue.title, "1", '999999').then(response => {
						// 	let result = JSON.parse(JSON.stringify(response.rows).replace(/enginName/g, 'name'));
						// 	this.selectList = result;
						// });

					}

				},

				showPhotoFile(index) {
					uni.previewImage({
						current: index,
						urls: this.fileImageArr,
					})
				},

				showPhoto(index, e) {
					let typeArr = [];
					let newArr = [];

					if (e == 'other') {
						typeArr = this.imgArr;
					}
					typeArr.forEach((item, index) => {
						if (item.substring(item.length - 3) == 'png' || item.substring(item.length - 3) == 'jpg' ||
							item.substring(item.length - 4) == 'jpeg') {
							newArr.push(item)
						}
					});
					uni.previewImage({
						current: index,
						urls: newArr,
					})

				},

				remove(index, e) {
					let _this = this;
					uni.showModal({
						title: '提示',
						content: '是否删除该图片或视频？',
						success: (res) => {
							if (res.confirm) {
								if (e == 'other') {
									_this.imgArr.splice(index, 1)
								}
							}
						}
					})
				},
				choose(e) {
					let _this = this;
					uni.showActionSheet({
						title: '上传',
						itemList: ['图片', '视频'],
						success: (res) => {
							if (res.tapIndex == 0) {
								this.chooseimage(e)
							} else {
								this.choosevideo(e)
							}
						}
					})
				},
				chooseimage(e) {

					let _this = this;
					uni.chooseImage({
						sizeType: ['album', 'camera'],
						success(resp) {
							resp.tempFiles.forEach((item, index) => {
								const task = uni.uploadFile({
									url: _this.$HTTP + `/obs`,
									filePath: item.path,
									name: 'file',
									formData: {},
									header: _this.headers,

									success: res => {

										let data = JSON.parse(res.data);
										if (![200].includes(data.code)) {
											_this.$modal.msg(data.msg)
										} else {
											if (_this.progress === 100) {
												if (e == 'other') {
													_this.imgArr.push(data.data.url)
												}
												_this.$modal.msg('上传成功！')
											}
										}
									},
									fail: e => {
										_this.$modal.msg('上传失败！')
									},
									complete: res => {
										uni.hideLoading();
										_this.uploading = false;

									}
								});
								task.onProgressUpdate(res => {
									_this.progress = res.progress;
									uni.showLoading({
										title: '上传中'
									})
									if (_this.progress != 100) {
										_this.loading = false
									} else {
										_this.loading = true
									}
								});

							})

						},
					})
				},

				choosevideo(e) {
					let _this = this;
					uni.chooseVideo({
						sourceType: ['album', 'camera'],
						maxDuration: 30,
						success(resp) {
							const task = uni.uploadFile({
								url: _this.$HTTP + `/obs`,
								filePath: resp.tempFilePath,
								name: 'file',
								formData: {},
								header: _this.headers,
								success: res => {
									// 判断是否json字符串，将其转为json格式
									let data = JSON.parse(res.data);
									if (![200].includes(res.statusCode)) {
										this.uploadError(index, data);
									} else {
										//上传成功
										if (_this.progress === 100) {
											if (e == 'other') {
												_this.imgArr.push(data.data.url)
											}
											_this.$modal.msg('上传成功！')
											//_this.photo = false;
										}
									}
								},
								fail: e => {
									_this.$modal.msg('上传失败！')
									this.uploadError(index, e);
								},
								complete: res => {
									uni.hideLoading();
									_this.uploading = false;
								}
							});
							task.onProgressUpdate(res => {
								_this.progress = res.progress;
								uni.showLoading({
									title: '上传中'
								})
								if (_this.progress != 100) {
									_this.loadingFile = false
								} else {
									_this.loadingFile = true
								}
							});

						},
					})
				},

				changeSelectDict(item, index) {
					this.openDict = false;
					// this.projectName = ''; //重置工程名称
					// this.createTime = '';
				},
				changeSelect(item, index) {
					// this.open = false;

					// if (this.type == 'gcmc') {
					// 	this.projectName = item.name;
					// 	this.createBy = item.createBy;
					// 	this.createTime = item.createTime;
					// 	this.updateBy = item.updateBy;
					// 	this.updateTime = item.updateTime;
					// 	this.updateInfoTime = item.updateInfoTime;
					// 	this.id = item.id;
					// 	this.modeOperation = item.modeOperation;
					// 	this.enginName = item.name;
					// 	this.locations = item.locations;
					// 	this.remark = item.remark;
					// }
				},
				//关闭弹窗
				close(e) {
					this.open = false
				},
				//关闭弹窗
				closeDict(e) {
					this.openDict = false
				},

				//历史
				history() {
					getHistoryMouthDetails(this.id, this.objValue.value).then(response => {
						this.historyList = response.data
						if (response.data.zEngineeringNodeBo != null) {
							this.$refs.refShare.handleShowShare();
						} else {
							this.$modal.msg("暂无历史信息")
						}
					});
				},

				submit() {
					if (this.isEmpty(this.projectName)) {
						this.$modal.msg('请选择工程名称')
						return
					}
					if (this.objValue.value == '原有管线压力' || this.objValue.value == '管道压力') {
						if (this.isEmpty(this.pipePressure)) {
							this.$modal.msg(this.placeholder)
							return
						}
					}
					if (this.imgArr.length <= 0) {
						this.$modal.msg('请上传照片或视频')
						return
					}
					if (this.loading == false) {
						this.$modal.msg('照片或视频未上传完毕，无法提交！')
						return
					}

					let param = {
						createBy: this.createBy,
						createTime: this.createTime,
						updateBy: this.updateBy,
						updateTime: this.updateTime,
						updateInfoTime: this.updateInfoTime,
						id: this.id,
						modeOperation: this.modeOperation,
						enginName: this.projectName,
						locations: this.locations,
						remark: this.remark,
						zEngineeringNodeBoList: [{
							type: this.objValue.value,
							zEngineeringInfoBo: {
								constructTime: this.time,
								zEngiineeringPhotoBoList: this.imgArr, //照片集合
								remark: this.projectContent,
								constructAccordingDrawings: this.pipePressure,
								constructAddre: this.pipePressure,
							}
						}]
					}
					uni.showLoading()
					SubmitMouth('new', param).then(res => {
						if (res.code == '200') {
							uni.hideLoading()
							uni.showToast({
								title: res.msg,
								icon: 'none',
								//显示持续时间为 3秒
								duration: 2000
							});
							setTimeout(function() {
								uni.navigateBack();
							}, 1000)
						}
					})
				}
			}
		}
	</script>

	<style lang="scss">
		.container {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 10px;
			position: relative;

		}

		.uni-list {
			border: 1xp solid #eee;
		}

		.to-right-icon {
			width: 15px;
			height: 15px;
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
		}

		.text {
			font-size: 16px;
			color: #333;
		}

		.background {
			// border: 15px solid hsla(0, 0%, 100%, .5);
			background: white;
			background-clip: padding-box;
			padding: 20rpx;
			border-radius: 20rpx;
			margin: 20rpx;
			/*从padding开始往外面裁剪背景*/


		}


		.btn {
			width: 715rpx;
			height: 69rpx;
			background: #79A4F0;
			border-radius: 6rpx;
			font-size: 25rpx;
			font-family: Microsoft YaHei;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 69rpx;
			margin-top: 40rpx;
			margin-bottom: 100rpx;
		}

		.number {
			display: flex;
			/* 水平居中显示子元素 */
			align-items: flex-start;
			/* 垂直居中显示子元素 */
			justify-content: space-between;
			/* 左右间距等于间距大小 */
			padding: 10px;
			/* 设置padding以提高视觉效果 */
		}

		.textarea {
			margin-top: 10upx;
			width: 100%;
			border: 1rpx solid red;
			min-height: 100upx;
			line-height: 20px;
		}


		.tj-btn {
			height: 69rpx;
			background: #3184f0;
			border-radius: 6rpx;
			font-size: 25rpx;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 69rpx;
			margin: 40rpx 70rpx;

		}

		.sc-btn {
			height: 69rpx;
			background: #f0686b;
			border-radius: 6rpx;
			font-size: 25rpx;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 69rpx;
			margin: 40rpx;

		}

		.num-style {
			background: #e8f4f9;
			margin: 20rpx;
			padding: 10rpx;
			border-radius: 20rpx;
			border: 1px solid #d4e3f0;
		}
	</style>