<template>
	<view class="app-content">
		<view class="header">
			<view class="log" @tap="fall"></view>{{ navname }}
			<view class="up" v-if="luggageData" @tap="sendData()">完成</view>
		</view>
		<view class="craids" v-if="!luggageData">
			<p>暂无行李信息</p>
			<p>请扫描需要操作的行李牌条码</p>
		</view>
		<view class="content" v-if="luggageData">
			<view class="list">
				<p>行李编号</p>
				<input class="input" name="yonghuming" type="text" v-model.trim="luggageData.luggageNum" disabled="true" value=""
					placeholder-style="font-size:.8125rem;color:rgb(197, 197, 197);" placeholder="" />
			</view>
			<view class="list">
				<p>航班信息</p>
				<input class="input" name="yonghuming" type="text" v-model.trim="luggageData.flightNo" disabled="true" value=""
					placeholder-style="font-size:.8125rem;color:rgb(197, 197, 197);" placeholder="" />
			</view>
			<view class="list">
				<p>航班日期</p>
				<input class="input" name="yonghuming" type="text" v-model.trim="luggageData.flightDate" disabled="true" value=""
					placeholder-style="font-size:.8125rem;color:rgb(197, 197, 197);" placeholder="" />
			</view>
			<view class="list">
				<p>当前节点</p>
				<picker @change="bindPickerChange1" :placeholderStyle="placeholderStyle" :value="index1" :range-key="'nodeName'" :range="nodeList">
					<view class="uni-input">{{nodeNameList[index]}}</view>
				</picker>
				<view class="listup"></view>
			</view>
			<view class="list">
				<p>当前位置</p>
				<uni-easyinput :inputBorder="false" :placeholderStyle="placeholderStyle" :clearable="false" :styles="style" :disabled="false"
					v-model="luggageData.location_describe" type="text" placeholder="操作位置" />
				</uni-forms>
				<view class="listup"></view>
			</view>
			<view class="list">
				<p>当前状态</p>
				<input class="input" name="yonghuming" type="text" v-model.trim="luggageData.currentResult"  value=""
					placeholder-style="font-size:.8125rem;color:rgb(197, 197, 197);" placeholder="" />
				<view class="listup"></view>
			</view>
			<view class="list">
				<p>异常类型</p>
				<picker @change="bindPickerChange" :value="index" :range-key="'name'" :range="exceptionList">
					<view class="uni-input">{{exceptionNameList[index]}}</view>
				</picker>
				<view class="listup"></view>
			</view>
			<view class="picturearea">
				<view class="name">图片上传</view>
				<!-- <view class="content_list">
          <view class="mg">
            <view class="mg_lg"></view>
          </view>
          <view class="mg">
            <view class="mg_lg"></view>
          </view>
          <view class="mg">
            <view class="mg_lg"></view>
          </view>
        </view> -->
				<!-- <sunui-upimg :url="upPicUrl" :before-upload="onBeforeUpload" ref="upload3" title="+" @upload="handleLoaded3" @change="handleChange3" :number="3">
          <template v-slot:icon>
              <text class="s-add-list-btn-icon">+</text>
          </template>
      </sunui-upimg> -->
				<mk-upload :imgList="imgList" @onDelete="onDelete" @onChoose="onChoose" />
			</view>
		</view>
	</view>
</template>
<script>
	import Nav from '../../components/header/nav.vue'
	import mkUpload from "@/components/mk-upload/mk-upload.vue"
	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: [],
				luggageNum:null,
				luggageData:null,
				index:0,
				index1:0,
				exceptionList:[
					{
						"type":null,
						"name":"非异常行李"
					},
					{
						"type":"DPR",
						"name":"破损"
					},
					{
						"type":"AHL",
						"name":"少收"
					},
					{
						"type":"OHD",
						"name":"多收"
					}
				],
				exceptionNameList:["非异常行李","破损","少收","多收"],
				nodeList:[],
				nodeNameList:[]
			}
		},
		created(option) {},
		onLoad(option) {
			this.luggageNum = option.luggageNum;
			this.getNode()
			if(this.luggageNum.length>9){
				this.getDetial(this.luggageNum)
			}
		},
		onUnload() {
			uni.$off("scancodemsg");
		},
		onShow() {
			uni.$on("scancodemsg", (data) => {
				if (data.msg.length > 9) {
					this.luggageNum = data.msg.trim()
					this.getDetial(this.luggageNum)
				}
				else{
				uni.showToast({
					icon:'none',
					title: "请扫描规范条码",
					duration: 5000
				});
				}
			})
				
		},
		onHide() {
		},
		mounted() {},
		components: {
			Nav,
			mkUpload
		},
		methods: {
			async getNode() {
				let data = {
					"serviceId": 3003,
					"dataContent": {},
					"event": "0"
				}
				await this.$http.httpPost('/openApi/query', data).then(res => {
					if (res.code == "0") {
						this.nodeList = res.returnData;
						this.nodeList.map(item => {
							this.nodeNameList.push(item.nodeName)
						})
					}
				})
			},
			async getDetial(num) {
				let data = {
					"serviceId": 3002,
					"page": 1,
					"pageSize": 1,
					"dataContent": {
						"luggageNum": num, //行李号
					},
					"event": "0"
				}
				await this.$http.httpPost('/openApi/query', data).then(res => {
					if (res.code == "0" && res.returnData.length>0){
						this.luggageData = res.returnData[0]
						this.nodeList.map((item,index)=>{
							if(res.returnData[0].nodeCode == item.nodeCode){
								this.index1 = index
							}
						})
					}
					else{
						uni.showToast({
							icon:'none',
							title: "未查询到该行李信息",
							duration: 5000
						});
					}
				})
			},
			bindPickerChange(e){
				this.index = e.detail.value
				this.luggageData.exception_type = this.exceptionList[this.index].type;
			},
			bindPickerChange1(e){
				this.index1 = e.detail.value
				this.luggageData.nodeCode = this.nodeList[this.index1].nodeCode;
				this.luggageData.location_describe = this.nodeList[this.index1].nodeDescribe;
			},
			async sendData(){
				this.luggageData.sourceAirport = this.$storage.get('airportName');
				this.luggageData.ID = null;
				this.luggageData.dataType = "BPM";
				this.luggageData.agentNumber = this.$storage.getJson("users").user_name;
				this.luggageData.device_ID = uni.getDeviceInfo().deviceId;
				let data = {
					"serviceId": 3005,
					"dataContent": [
						this.luggageData
					],
					"event": "0"
				}
				await this.$http.httpPost('/openApi/query', data).then(res => {
					if (res.code == "0") {
						uni.showToast({
							icon:'none',
							title: "操作成功",
							duration: 5000
						});
					}
					else{
						uni.showToast({
							icon:'none',
							title: "操作失败",
							duration: 5000
						});
					}
				})
			},
			fall() {
				uni.navigateBack({
					delta: 1
				})
			},
			onDelete(index) {
				console.log(index)
				//删除成功回调后执行 只做演示
				uni.showLoading({
					title: '删除中'
				});
				setTimeout(() => {
					this.imgList.splice(index, 1);
					wx.showToast({
						title: '删除成功',
						icon: 'success',
						duration: 1000
					});
				}, 1000);
			},
			onChoose(e) {
				console.log(e)
				//上传成功后回调执行push  只做演示
				uni.showLoading({
					title: '上传中'
				});
				setTimeout(() => {
					const tempFilePaths = e.tempFilePaths;
					this.imgList.push(tempFilePaths[0]);
					uni.hideLoading();
				}, 1000);
			},
			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 {
		>.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%;
			}

			>.up {
				position: absolute;
				right: 1.5rem;
				color: rgb(37, 121, 160);
				font-family: Noto Sans SC;
				font-size: .875rem;
				font-weight: 500;
			}
		}
		>.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;

			>.list {
				height: 3.375rem;
				display: flex;
				align-items: center;
				border-bottom: 1px solid rgb(238, 238, 238);

				>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>