<template>
	<view class="content">
		<view class="center">
			<view class="box">
				<view>
					<view class="box_no">订单号：<span style="font-weight: 600;">{{pageData.order_no}}</span></view>
					<block v-for="(item,index) in pageData.goods_item" :key="index">
						<view class="items hflex acenter">
							<image :src="item.goods_cover" class="item-img"></image>
							<view class="item-right">
								<view class="hflex acenter jbetween">
									<view class="item_name text_hide">{{item.goods_name}}</view>
									<view class="item_price">￥<span style="font-size: 30rpx;">{{item.price_selling}}</span></view>
								</view>
								<view class="hflex jbetween" style="padding: 20rpx 0 0;">
									<view class="norm text_hide">{{item.goods_spec}}</view>
									<view class="left_text">X{{item.stock_sales}}</view>
								</view>
							</view>
						</view>
					</block>
					<view class="addr hflex jbetween">
						<view class="addr_left">{{address}}</view>
						<image src="/static/images/common/biyanjing.png" style="width: 32rpx;height: 32rpx;" v-if="!address_show" @click="showAddr"></image>
						<image src="/static/images/common/yanjing.png" style="width: 32rpx;height: 32rpx;" v-else @click="showAddr"></image>
					</view>
				</view>
			</view>
			<view class="box">
				<view class="cell2 hflex acenter jbetween">
					<view class="left">运单号</view>
					<u-input v-model="express_no" border="none" placeholder="请输入运单号或扫码获取"></u-input>
					<image src="/static/images/common/saoyisao.png" style="width: 32rpx;height: 32rpx;" @click="scan"></image>
				</view>
				<view class="cell2 hflex acenter jbetween">
					<view class="left">物流公司</view>
					<u-input v-model="express_name" border="none" placeholder="请输入物流公司"></u-input>
					<view></view>
				</view>
			</view>
			<view class="box">
				<view class="hflex jbetween cell3" @click="selectAddr('send')">
					<view class="label">发货地址</view>
					<view class="hflex acenter">
						<view class="text">{{send_addr}}</view>
						<u-icon name="arrow-right" size="12" color="#888"></u-icon>
					</view>
				</view> 
				<!-- <view class="hflex jbetween cell3" @click="selectAddr('send')">
					<view class="label">退货地址</view>
					<view class="hflex acenter">
						<view class="text">{{send_addr}}</view>
						<u-icon name="arrow-right" size="12" color="#888"></u-icon>
					</view>
				</view> -->
			</view>
		</view>
		<view class="bottom">
			<view class="btn hflex acenter jcenter" @click="send">立即发货</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				id: '',
				pageData: {},
				address: '',
				address_show: false,
				express_no: '',
				express_name:'',
				send_addr: '',
				return_addr: {}
			}
		},
		onLoad(options) {
			that = this
			that.id = options.id
			that.getData()
		},
		methods: {
			getData() {
				$api.req({
					url: '/data/api.business.Order/order_info',
					method: 'POST',
					data: {
						order_id: that.id
					}
				}, function(res) {
					if(res.code == 1) {
						that.pageData = res.data
						if(that.address_show) {
							that.address = that.pageData.user_address.address_name+ ',' + that.pageData.user_address.address_phone +',' +that.pageData.user_address.address_province+that.pageData.user_address.address_city+that.pageData.user_address.address_area+ that.pageData.user_address.address_content
						} else {
							that.address = that.pageData.user_address.address_name.slice(0,1)+ '**,' +'***********,' +that.pageData.user_address.address_province+that.pageData.user_address.address_city+that.pageData.user_address.address_area+ that.pageData.user_address.address_content.slice(0,5) + '******'
						}
					}
				})
			},
			showAddr() {
				that.address_show = !that.address_show
				if(that.address_show) {
					that.address = that.pageData.user_address.address_name+ ',' + that.pageData.user_address.address_phone +',' +that.pageData.user_address.address_province+that.pageData.user_address.address_city+that.pageData.user_address.address_area+ that.pageData.user_address.address_content
				} else {
					that.address = that.pageData.user_address.address_name.slice(0,1)+ '**,' +'***********,' +that.pageData.user_address.address_province+that.pageData.user_address.address_city+that.pageData.user_address.address_area+ that.pageData.user_address.address_content.slice(0,5) + '******'
				}
			},
			scan() {
				uni.scanCode({
					success: function (res) {
						that.express_no = res.result
						// console.log('条码类型：' + res.scanType);
						// console.log('条码内容：' + res.result);
					}
				});
			},
			selectAddr(select) {
				$api.jump('/pages/mine/service/address/address?select=' + select)
			},
			send() {
				$api.req({
					url: '/data/api.business.Order/order_send',
					method: 'POST',
					data: {
						order_no: that.pageData.order_no,
						send_number: that.express_no,
						company_name: that.express_name,
						name: that.return_addr.name,
						phone: that.return_addr.phone,
						province: that.return_addr.province,
						city: that.return_addr.city,
						area: that.return_addr.area,
						address: that.return_addr.address,
					}
				}, function(res) {
					if(res.code == 1) {
						$api.info(res.info)
						$api.jump(-1)
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F4F4F4;
		.center {
			width: 100%;
			box-sizing: border-box;
			padding: 0 30rpx;
			.box {
				margin-top: 20rpx;
				width: 100%;
				box-sizing: border-box;
				padding: 0 20rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				.box_no {
					padding: 28rpx 0;
					font-size: 26rpx;
					font-weight: 400;
					color: #333333;
					line-height: 36rpx;
				}
				.cell {
					padding-bottom: 24rpx;
					.left {
						width: 240rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #222222;
						line-height: 36rpx;
					}
					.right {
						font-size: 26rpx;
						font-weight: 400;
						color: #555555;
						line-height: 36rpx;
					}
					.right1 {
						font-size: 26rpx;
						font-weight: 400;
						color: #333333;
						line-height: 36rpx;
					}
				}
				.items {
					padding: 20rpx 0 32rpx;
					border-bottom: 1rpx solid #F4F4F4;
					.item-img {
						width: 160rpx;
						height: 160rpx;
						border-radius: 24rpx;
					}
					.item-right {
						width:calc(100% - 160rpx);
						padding-left: 20rpx;
						.item_name {
							font-size: 30rpx;
							font-weight: 400;
							color: #222222;
							line-height: 42rpx;
						}
						.item_price {
							font-size: 20rpx;
							font-weight: 600;
							color: #222222;
							line-height: 24rpx;
						}
						.norm {
							max-width: 300rpx;
							width: max-content;
							// height: 42px;
							background: #F5F5F5;
							border-radius: 12rpx;
							box-sizing: border-box;
							padding: 12rpx;
							font-size: 20rpx;
							font-weight: 400;
							color: #888888;
							line-height: 28rpx;
						}
						.left_text {
							font-size: 24rpx;
							font-weight: 500;
							color: #888888;
							line-height: 28rpx;
						}
					}
				}
				.addr {
					padding: 24rpx 0 26rpx;
					.addr_left {
						width: 492rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #333333;
						line-height: 36rpx;
					}
				}
				.cell2 {
					padding: 28rpx 0;
					border-bottom: 1rpx solid #F4F4F4;
					.left {
						width: 186rpx;
						font-size: 30rpx;
						font-weight: 600;
						color: #333333;
						line-height: 42rpx;
					}
				}
				.cell2:nth-last-child(1) {
					border: none;
				}
				.cell3 {
					padding: 36rpx 0 32rpx;
					.label {
						width: 186rpx;
						font-size: 30rpx;
						font-weight: 600;
						color: #333333;
						line-height: 42rpx;
					}
					.text {
						font-size: 28rpx;
						font-weight: 400;
						color: #333333;
						line-height: 40rpx;
					}
				}
			}
		}
		.bottom {
			width: 100%;
			height: 166rpx;
			background: #FFFFFF;
			box-sizing: border-box;
			padding: 0 30rpx;
			position: fixed;
			z-index: 99;
			bottom: 0; 
			.btn {
				margin-top: 16rpx;
				width: 100%;
				height: 84rpx;
				background: #506DFF;
				border-radius: 42rpx;
				font-size: 36rpx;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 50rpx;
			}
		}
	}
</style>