<template>
	<view class="updatePrice">

		<view class="dispatchContent">
			<view class="orderNum">
				订单号：{{orderInfo.order_no}}
			</view>
			<view class="dispatchItem" v-for="item in orderInfo.goods">
				<image :src="item.goods_image" mode="aspectFill"></image>
				<view class="right">
					<view class="title">
						{{item.goods_name}}
					</view>
					<view class="subTitle" v-for="p in item.goods_props" :key="p.group">
						{{p.group.name}}:{{p.value.name}}

					</view>
					<view class="num">
						x{{item.total_num}}
					</view>
					<view class="price">
						<text style="font-size: 26upx;">¥</text>
						<text>{{item.total_price}}</text>
					</view>
				</view>
			</view>

		</view>
		<view class="selectContent" style="border:none;background-color: #fff;">
			<picker @change="changeOption" mode="selector" range-key="express_name" :value="index" :range="wlList">
				<u-field v-model="expressName" :disabled="true" label="物流公司" placeholder="请选择物流公司"
					right-icon="arrow-right">
				</u-field>
			</picker>
			<view class="scan">
				<u-field style="flex: 1;padding:30upx 0 30upx 30upx" v-model="codeNum" label="物流单号"
					placeholder="请填写物流单号">
				</u-field>
				<image :src="$picUrl+'/static/news3/scan.png'" @click="scanCode" mode=""></image>
			</view>
			<view class="footerBtn" @click="onCheck" v-if="source==1">
				<view class="wuliuBtn">
					物流链接
				</view>
			</view>
		</view>
		<view class="goods-fd">
			<view class="btn" @click="sendGoodsHandle">{{source==1?'保存修改':'确认发货'}}</view>
		</view>
	</view>
</template>

<script>
	import * as newFunApi from '@/api/newFun'
	export default {
		data() {
			return {
				modifyInfo: false,
				newPrice: null,
				wlList: [

				],
				codeNum: '',
				orderInfo: {},
				expressList: [],
				expressId: null,
				expressName: '',
				source: 1
			}
		},
		methods: {
			/**
			 * 查快递
			 */
			onCheck() {
				if (!this.codeNum) {
					return this.$toast('请填写物流单号')
				}
				uni.navigateTo({
					url: "/pages/news3/LogisticsDetails?logisticsNum=" + this.codeNum
				})
			},
			scanCode() {
				uni.scanCode({
					success: (res) => {
						this.codeNum = res.result;
					},
					fail: (res) => {
						uni.showToast({
							title: '扫描失败',
							icon: 'none'
						})
					}
				})
			},
			// 选择物流
			changeOption(e) {
				this.expressName = this.wlList[e.detail.value].express_name;
				this.expressId = this.wlList[e.detail.value].express_id
			},
			async sendGoodsHandle() {
				if (!this.expressId) {
					return that.$toast('请选择物流公司')
				}
				if (!this.codeNum) {
					return that.$toast('请填写物流单号')
				}
				let goosList = this.orderInfo.goods.map(item => {
					return {
						orderGoodsId: item.order_goods_id,
						deliveryNum: item.delivery_num
					}
				})
				let params = {
					"orderId": this.orderInfo.order_id,
					"form": {
						"deliveryMethod": this.wuliu ? 10 : 20,
						"packGoodsData": goosList,
						"expressId": this.expressId,
						"expressNo": this.codeNum,
						"syncMpWeixinShipping": 1
					}
				}
				let {
					status,
					message,
					data
				} = await newFunApi.sendGoods(params);
				if (status == 200) {
					uni.hideLoading();
					uni.showToast({
						title: this.source == 1 ? '修改成功' : '发货成功',
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 1000)
				}
			},
			async getWuliuList() {
				let {
					status,
					message,
					data
				} = await newFunApi.wuliuList();
				if (status == 200) {
					uni.hideLoading();
					if (this.source == 1) {
						if (this.expressId) {
							data.list.forEach(item => {
								if (item.express_id == this.expressId) {
									this.expressName = item.express_name || '';
								}
							});
						}
					}
					this.wlList = data.list
				}

			},
		},
		onLoad(option) {
			this.orderInfo = JSON.parse(decodeURIComponent(option.item))
			this.source = option.source;
			if (this.source == 1) {
				this.expressId = this.orderInfo.delivery[0].express_id
				this.codeNum = this.orderInfo.delivery[0].express_no
			}
			this.getWuliuList()

		}
	}
</script>

<style lang="scss" scoped>
	page {
		min-height: 100%;
		background-color: #F7F8FA;
	}

	::v-deep .uni-input-wrapper {
		text-align: left !important;
	}

	.orderNum {

		font-size: 28upx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #707070;
		margin: 10upx 0upx;

	}

	.dispatchContent {
		margin: 20upx 0;
		background: #FFFFFF;
		// border-radius: 6px 6px 6px 6px;
		opacity: 1;
		padding: 20upx 30upx;
	}

	.dispatchItem {
		display: flex;
		align-items: center;

		image {
			width: 194upx;
			height: 194upx;
		}

		.right {
			flex: 1;
			margin-left: 40upx;
			position: relative;
			display: flex;
			flex-direction: column;
			justify-content: space-around;

			.title {

				font-size: 28upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #3B3B3B;

			}

			.subTitle {

				font-size: 28upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #7C7C7C;
				margin: 14upx 0;

			}

			.num {

				font-size: 28upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #1E1E1E;
			}

			.price {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				font-size: 32upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #F21A1C;
				position: absolute;
				right: 20upx;
				bottom: 0upx;
				z-index: 9;

			}
		}
	}

	.scan {
		display: flex;
		align-items: center;

		image {
			width: 40upx;
			height: 40upx;
			margin-right: 32upx;
		}
	}

	::v-deep .u-field {
		padding: 30upx;
	}

	::v-deep .uni-input-wrapper {
		text-align: right;
	}

	.footerBtn {
		padding: 30upx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}

	.wuliuBtn {
		// padding:8upx 46upx;
		text-align: center;
		height: 60upx;
		line-height: 60upx;
		border: 1px solid #F63116;
		font-size: 28upx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #F83F11;
		border-radius: 20px;
		width: 200upx;
	}

	.goods-fd {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		padding: 0.9375rem;
		z-index: 99;
		background-color: #fafafa;
		box-sizing: border-box;

		.btn {
			width: 630rpx;
			line-height: 88rpx;
			background: #F34A40;
			border-radius: 88rpx;
			text-align: center;
			font-size: 28rpx;
			font-weight: 500;
			color: #FFFFFF;
			margin: auto;
		}
	}
</style>
