<template>
	<view>
		<view class="cmain">
			<view class="box order_detail" style="padding: 13px">
				<u-steps :current="current">
					<u-steps-item title="订单确认"></u-steps-item>
					<u-steps-item title="进口申报确认"></u-steps-item>
				</u-steps>
			</view>
			<view class="box order_detail">
				<view v-if="current == 0">
					<view class="item ctt">订单确认</view>
				</view>
				<view v-if="current == 1">
					<view class="item ctt">进口申报确认</view>
				</view>
				<view class="expand" v-if="current == 0" :style="{height:expand?'auto':'340px'}">
					<view class="item">
						<text class="label">订单编号</text>
						<text class="desc omit">{{ item.tradeNo }}</text>
					</view>
					<view class="item">
						<text class="label">结算单号</text>
						<text class="desc omit">{{ item.settleBillNo }}</text>
					</view>
					<view class="item">
						<text class="label">预申报编号</text>
						<text class="desc omit">{{ item.platSeqNo }}</text>
					</view>
					<view class="item">
						<text class="label">买家</text>
						<text class="desc omit">{{ item.buyUserName }}</text>
					</view>
					<view class="item">
						<text class="label">车牌号</text>
						<text class="desc">{{ item.veNo }}</text>
					</view>
					<view class="item">
						<text class="label">商品名称</text>
						<text class="desc">{{ item.goodsNames }}</text>
					</view>
					<view class="item">
						<text class="label">申报时间</text>
						<text class="desc">{{ item.applyTime }}</text>
					</view>
					<view class="item">
						<text class="label">申报金额</text>
						<text class="desc">¥ {{ item.totalPrice }}</text>
					</view>
					<view class="item">
						<text class="label">净重(kg)</text>
						<text class="desc">{{ item.netWt }}</text>
					</view>
					<view class="item">
						<text class="label">毛重(kg)</text>
						<text class="desc">{{ item.grossWt }}</text>
					</view>
					<view class="item">
						<text class="label">申报数量</text>
						<text class="desc">{{ item.buyQty }}</text>
					</view>
					<view class="item">
						<text class="label">商户名称</text>
						<text class="desc">{{ item.enterpriseName }}</text>
					</view>
					<view class="item">
						<text class="label">交易地区名称</text>
						<text class="desc">{{ item.tradeAreaName }}</text>
					</view>
					<view class="item">
						<text class="label">进口预申报号</text>
						<text class="desc">{{ item.preIeportNo }}</text>
					</view>
					<view class="item">
						<text class="label">批次预录入号</text>
						<text class="desc">{{ item.preNo }}</text>
					</view>
				</view>
				<view class="expand" v-else :style="{height:expand?'auto':'300px'}">
					<view class="item">
						<text class="label">业务编号</text>
						<text class="desc omit">{{ item2.platSeqNo }}</text>
					</view>
					<view class="item">
						<text class="label">预录入编号</text>
						<text class="desc">{{ item2.preNo }}</text>
					</view>
					<view class="item">
						<text class="label">进境申报单编号</text>
						<text class="desc">{{ item2.itrdclDeclareId }}</text>
					</view>
					<view class="item">
						<text class="label">申报类型</text>
						<text class="desc">
							<text v-if=" item2.declareType==1">个人申报</text>
							<text v-if=" item2.declareType==2">商铺或代理人</text>
							<text v-if=" item2.declareType==3">合作社</text>
							<text v-if=" item2.declareType==4">互助组</text>
						</text>
					</view>
					<view class="item">
						<text class="label">申报人姓名</text>
						<text class="desc">{{ item2.declareName }}</text>
					</view>
					<view class="item">
						<text class="label">申报人身份证号</text>
						<text class="desc">{{ item2.ciphertextIdno }}</text>
					</view>
					<view class="item" v-if="item2.declareType == '2'">
						<text class="label">商铺编码</text>
						<text class="desc">{{ item2.shopNo }}</text>
					</view>
					<view class="item" v-if="item2.declareType == '2'">
						<text class="label">商铺名称</text>
						<text class="desc">{{ item2.shopName }}</text>
					</view>

					<view class="item">
						<text class="label">商品名称</text>
						<text class="desc">{{ item2.goodsNames }}</text>
					</view>
					<view class="item">
						<text class="label">总金额</text>
						<text class="desc">{{ item2.sumAmt }}</text>
					</view>
					<view class="item">
						<text class="label">总毛重({{item.goodsUnit }})</text>
						<text class="desc">{{ item2.sumGrossWt }}</text>
					</view>
					<view class="item">
						<text class="label">总净重({{item.goodsUnit }})</text>
						<text class="desc">{{ item2.sumNetWt }}</text>
					</view>
					<view class="item">
						<text class="label">件数</text>
						<text class="desc">{{ item2.packNo }}</text>
					</view>
					<view class="item">
						<text class="label">车牌号</text>
						<text class="desc">{{ item2.veNo }}</text>
					</view>
					<view class="item" v-if="item2.declareType == '3' || item2.declareType == '4'">
						<text class="label" v-if="item2.declareType == '3'">互助组备案编号</text>
						<text class="label" v-if="item2.declareType == '4'">合作社备案编号</text>
						<text class="desc">¥ {{ item2.orgPutrecNo }}</text>
					</view>
					<view class="item" v-if="item2.declareType == '3' || item2.declareType == '4'">
						<text class="label" v-if="item2.declareType == '3'">互助组名称</text>
						<text class="label" v-if="item2.declareType == '4'">合作社名称</text>
						<text class="desc">¥ {{ item2.orgName }}</text>
					</view>
					<view class="item" v-if="item2.declareType == '4'">
						<text class="label">合作社信用代码</text>
						<text class="desc">¥ {{ item2.orgScc }}</text>
					</view>
					<view class="item">
						<text class="label">监管场所</text>
						<text class="desc">{{ item2.fieldName }}</text>
					</view>
					<view class="item">
						<text class="label">贸易国别</text>
						<text class="desc">{{ item2.tradeCountry }}</text>
					</view>
					<view class="item">
						<text class="label">企业编码</text>
						<text class="desc">{{ item2.entCode }}</text>
					</view>
					<view class="item">
						<text class="label">企业名称</text>
						<text class="desc">{{ item2.entName }}</text>
					</view>
				</view>
				<view class="more" @click="expand = !expand">
					<text class="icon">&#xe649;</text>
					<text>{{expand?'收起':'更多信息'}}</text>
				</view>
			</view>
		</view>
		<view class="mfooter">
			<view class="flex">
				<view class="f">
					<button class="btn" @click="ok()">确定</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ip: this.http.ip,
				imgList: [],
				expand: false, //展开
				current: 0,
				item: {},
				item2: {},
				orderId: '',
				peopleConfirmStatus: '',
				cooperEntrustStatus: '',
				applyConfirmStatus: '',
				cooper_entrust: 2
			};
		},
		onLoad(e) {
			if (e.orderId && e.peopleConfirmStatus && e.applyConfirmStatus) {
				this.orderId = e.orderId;
				this.peopleConfirmStatus = e.peopleConfirmStatus;
				this.cooperEntrustStatus = e.cooperEntrustStatus;
				this.applyConfirmStatus = e.applyConfirmStatus;
				if (this.peopleConfirmStatus == 0) {
					this.current = 0;
					this.getData1();
				} else if (this.peopleConfirmStatus == 1 && this.applyConfirmStatus == 0) {
					this.current = 1;
					this.getData2();
				}
			}

			//人脸认证回调
			uni.$on('face', res => {
				if (res) {
					this.confirmFn()
				}
			})
		},
		methods: {
			confirmFn() {
			

				if (this.current == 0) {
					this.http.request({
						url: '/level-one-server/app/TbOrder/confirmOrder',
						method: 'POST',
						data: {
							orderId: this.item.id
						},
						success: res => {
							uni.showToast({
								title: '订单确认成功'
							});
							this.current = 1;
							uni.setNavigationBarTitle({
								title: '互助委托确认'
							});
							this.getData2();
						}
					});
				}
				if (this.current == 1) {
					this.http.request({
						url: '/level-one-server/app/TbOrder/applyOrder',
						method: 'POST',
						data: {
							orderId: this.orderId
						},
						success: res => {
							uni.showToast({
								title: '进口申报确认成功'
							});
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/index/index'
								});
							}, 1000);
						}
					});
				}
			},
			getData1() {
				this.http.request({
					url: '/level-one-server/app/TbOrder/orderDetail',
					data: {
						orderId: this.orderId
					},
					success: res => {
						this.item = res.data.data;
					}
				});
			},
			getData2() {
				this.http.request({
					url: '/level-one-server/app/TbImportOrder/importOrderDetail',
					data: {
						orderId: this.orderId
					},
					success: res => {
						this.item2 = res.data.data;
						JSON.parse(this.item2.cooperEntrustImg).map(item => this.imgList.push(item))
						console.log("-----5-----" + this.imgList)
					}
				});
			},
			ok() {
				let user = this.getUser();
				if (user.wallet <= 0) {
					uni.showModal({
						title: '提示',
						content: '剩余服务点数不足，请先充值！',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url:'/pages/wallet/wallet'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
					return;
				}
				//根据不同的步骤提交不同的url或者状态参数
				if (this.current == 0) {
					uni.showModal({
						title: '提示',
						content: '我已核对信息无误',
						success: res => {
							if (res.confirm) {
								//return;
								//跳转到人脸认证
								uni.navigateTo({
									url: '/pages/face/faceRegister?type=2'
								})
							}
						}
					});
				}
				if (this.current == 1) {
					//进口确认不用刷脸
					uni.showModal({
						title: '提示',
						content: '我已核对信息无误',
						success: res => {
							if (res.confirm) {
								//return;
								//跳转到人脸认证
								this.confirmFn();
								//uni.navigateTo({url:'/pages/face/faceRegister?type=2'})
							}
						}
					});
				}
			}
		},
		destroyed() {
			uni.$off('face');
		}
	};
</script>

<style lang="scss">
	page {
		background-color: $pg;
	}

	.cmain {
		padding-bottom: 100px;
	}

	.expand {
		overflow: hidden;
	}

	.more {
		text-align: center;
		padding: 10px 10px 15px 10px;

		.icon {
			padding-right: 3px;
		}
	}

	.ctt {
		text-align: center;
		font-weight: bold;
	}
</style>