<template>
	<view class="app-content">
		<view class="header">
			<view class="log" @tap="fall"></view>{{ navname }}

		</view>
		<view class="content">
			<view class="list">
				<p>操作位置</p>
				<uni-easyinput :inputBorder="false" style="line-height: 2.375rem;background-color: antiquewhite;" :placeholderStyle="placeholderStyle" :clearable="false"
					:styles="style" :disabled="false" v-model="location_code" type="text"
					placeholder="操作位置" />
				</uni-forms>
			</view>
			<view class="list">
				<p>操作描述</p>
				<uni-easyinput :inputBorder="false" style="line-height: 2.375rem;background-color: antiquewhite;" :placeholderStyle="placeholderStyle" :clearable="false"
					:styles="style" :disabled="false" v-model="location_descride" type="text"
					placeholder="操作描述" />
			</view>
			<view class="picturearea">
				<view class="name">图片上传</view>
				<mk-upload :imgList="imgList" @onDelete="onDelete" @onChoose="onChoose" />
			</view>
		</view>
		<view class="up" @tap="sendData()">提交</view>
	</view>
</template>
<script>
	import Nav from '../../components/header/nav.vue'
	import mkUpload from "@/components/mk-upload/mk-upload.vue"
	import {
		translateapp
	} from "@/utils/compress.js"
	import {
		pathToBase64,
		base64ToPath
	} from 'image-tools'
	export default {
		data() {
			return {
				placeholderStyle: "color:000;",
				style: {
					disableColor: "#fff",
					color: "#000"
				},
				isShow: true,
				dataheight: '20.75rem',
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				input: '',
				main: null,
				poll: null,
				filter: null,
				pusher: null,
				intentServer: null,
				arr: [],
				navname: '脱牌行李登记',
				imgList: [],
				ImgObjList: [],
				luggageNum: null,
				luggageData: {},
				index: 0,
				index1: 0,
				isGet:true,
				location_descride:"",
				location_code:"",
				picPath:""
			}
		},
		created(option) {},
		onLoad(option) {
			console.log(option)
			this.luggageNum = option.id
			if(this.luggageNum){
				this.getData()
			}
		},
		onUnload() {
		},
		onShow() {
		},
		onHide() {
		},
		mounted() {},
		components: {
			Nav,
			mkUpload
		},
		methods: {
			async getData(){
				let data = {
					"serviceId": 3011,
					"page": 1,
					"pageSize": 999,
					"dataContent": {
						"ID": this.luggageNum,
					},
					"event": "0"
				}
				await this.$http.httpPost('/openApi/query', data).then(res => {
					if (res.code == "0") {
						this.location_code = res.returnData[0].location_code
						this.location_descride = res.returnData[0].location_descride
						this.imgList = [res.returnData[0].picture]
						this.picPath = res.returnData[0].picture
				
					} else {
						uni.showToast({
							icon: 'none',
							title: "获取信息失败",
							duration: 5000
						});
					}
				})
			},
			async sendData() {
				// this.luggageData.ID = null;
				this.luggageData["agentNumber"] = this.$storage.getJson("users").user_name;
				// this.luggageData["agentNumber"] ="syq";
				this.luggageData["device_ID"] = uni.getDeviceInfo().deviceId;
				this.luggageData["secondary_code"]="H";
				this.luggageData["location_code"]=this.location_code;
				this.luggageData["location_descride"]=this.location_descride;
				this.luggageData["picture"]=this.picPath;
				let data = {
					"serviceId": 3011,
					"dataContent": [
						{
							"Value":this.luggageData
						}
					],
					"event": "1"
				}
				await this.$http.httpPost('/openApi/newdata', data).then(res => {
					if (res.code == "0") {
						uni.showToast({
							icon: 'none',
							title: "操作成功",
							duration: 5000
						});
					} else {
						this.$scanAudio.src = "../../static/czsb.mp3"
						this.$scanAudio.play()
						uni.showToast({
							icon: 'none',
							title: "操作失败",
							duration: 5000
						});
					}
				})
			},
			fall() {
				uni.navigateBack({
					delta: 1
				})
			},
			async sendImg(upImgList) {
				let data = {
					"serviceId": 30051,
					"dataContent": upImgList,
					"event": "1"
				}
				await this.$http.httpPost('/openApi/newdata', data).then(res => {
					if (res.code == "0") {
						uni.hideLoading();
						this.getImgList()
						uni.showToast({
							icon: 'none',
							title: "上传成功",
							duration: 5000
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: "上传失败",
							duration: 5000
						});
					}
				})
			},
			async getImgList() {
				let data = {
					"serviceId": 30051,
					"page": 1,
					"pageSize": 999,
					"dataContent": {
						"carrflights": this.luggageData.carrierFlights,
						"carrierFlightsDate": this.luggageData.carrierFlightsDate,
						"luggageNum": this.luggageData.luggageNum
					},
					"event": "0"
				}
				await this.$http.httpPost('/openApi/query', data).then(res => {
					if (res.code == "0") {
						this.imgList = [];
						this.ImgObjList = res.returnData;
						res.returnData.map(item => {
							if (item.luggagePic) {
								this.imgList.push(item.luggagePic);
							}
						})

					} else {
						this.imgList = [];
						uni.showToast({
							icon: 'none',
							title: "获取图片失败",
							duration: 5000
						});
					}
				})
			},
			async deleteImg(index) {
				let data = {
					"serviceId": 30051,
					"dataContent": [{
						"filter": [{
							"left": "(",
							"column": "id",
							"comparator": "=",
							"value": this.ImgObjList[index].id, 
							"right": ")",
							"connector": "and"
						}]
					}],
					"event": "3"
				}
				await this.$http.httpPost('/openApi/movedata', data).then(res => {
					if (res.code == "0") {
						this.getImgList()
						wx.showToast({
							title: '删除成功',
							icon: 'success',
							duration: 3000
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: "删除图片失败",
							duration: 5000
						});
					}
				})
			},
			onDelete(index) {
				console.log(index)
				//删除成功回调后执行 只做演示
				uni.showLoading({
					title: '删除中'
				});
				this.deleteImg(index)
			},
			onChoose(e) {
				console.log(e)
				uni.showLoading({
					title: '上传中'
				});
				// let upImgList = []
				// this.newImgList = []
				e.tempFilePaths.map(item => {
					translateapp(item, 70, imgUrl => {
						pathToBase64(imgUrl).then(path => {
							this.imgList=[path];
							this.picPath = path;
						}).catch(error => {
							uni.hideLoading();
						})
					})
				})
			},
			onPreviewTake(index) {
				console.log(index)
				wx.showActionSheet({
					itemList: ['预览图片', '删除图片'],
					success(res) {
						console.log(res.tapIndex)
					},
					fail(res) {
						console.log(res.errMsg)
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.app-content {
		>.up {
			position: fixed;
			bottom: 10px;
			left: calc((100% - 20.5625rem) / 2);
			width: 20.5625rem;
			height: 3rem;
			background: linear-gradient(179.10deg, rgba(51, 161, 165, 1.00) 11.326%, rgba(59, 111, 142, 1.00) 119.032%, rgba(59, 111, 142, 1.00) 119.032%, rgba(59, 111, 142, 1.00) 119.032%);
			border-radius: .25rem;
			color: rgb(255, 255, 255);
			font-family: Noto Sans SC;
			font-size: 1rem;
			margin: 0 auto;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		>.header {
			width: 100%;
			height: 4.375rem;
			display: flex;
			justify-content: center;
			align-items: center;
			// background: rgba(49,85,99,1);
			color: rgb(16, 17, 22);
			font-family: Noto Sans SC;
			font-size: 1rem;
			position: relative;

			>.log {
				width: .375rem;
				height: .75rem;
				font-size: .75rem;
				position: absolute;
				left: 1.5rem;
				background: url('../../static/ico@1x.png') no-repeat;
				background-size: 100% 100%;
			}


		}

		>.craids {
			margin-top: 10rem;
			height: 5.625rem;
			padding: 0 2.5625rem 0 2.5625rem;
			display: flex;
			justify-content: center;
			align-items: center;

			>p {
				color: rgb(75, 84, 91);
				font-family: Noto Sans SC;
				font-size: 13px;
				font-weight: 500;
			}
		}

		>.content {
			margin-left: 1.5rem;
			height: calc(100vh - 8rem);
			overflow-x: hidden;
			overflow-y: auto;

			>.list {
				height: 3.375rem;
				display: flex;
				align-items: center;
				border-bottom: 1px solid rgb(238, 238, 238);
				.uni-input {
							width: 240px;
							padding-left: 10px;
						}
				>p {
					color: rgb(0, 0, 0);
					font-family: Noto Sans SC;
					font-size: .8125rem;
					font-weight: 500;
					margin-right: 2.1875rem;
				}

				>.listup {
					width: .25rem;
					height: .5rem;
					background: url('../../static/icos.png') no-repeat;
					background-size: 100% 100%;
					position: absolute;
					right: 1.5rem;
				}
			}

			>.picturearea {
				margin-top: 1.875rem;

				>.name {
					color: rgb(0, 0, 0);
					font-family: Noto Sans SC;
					font-size: .8125rem;
					font-weight: 500;
					margin-bottom: 1.25rem;
				}

				>.content_list {
					width: 100%;
					display: flex;
					margin-top: 1.25rem;

					>.mg {
						width: 5.5rem;
						height: 5.5rem;
						background: rgb(197, 207, 211);
						display: flex;
						align-items: center;
						justify-content: center;
						margin-right: .625rem;

						>.mg_lg {
							width: 1.75rem;
							height: 1.75rem;
							background: url('../../static/shi.png') no-repeat;
							background-size: 100% 100%;
						}
					}
				}
			}
		}
	}
</style>