<template>
	<!-- 物品信息 -->
	<view class="back">
		<view class="top">
			<view class="u-flex">
				<text class="title">{{i18n.item}}</text>
				<view class="mast">{{i18n.required}}</view>
			</view>
			<view v-if="goodname" class="" style="margin-top: 30rpx;">
				<view class="about u-flex"
					style="color: rgba(248, 50, 36, 1);border: 2rpx solid rgba(248, 50, 36, 1);justify-content: center;width: 420rpx;">
					<text style="margin-right: 18rpx;">{{goodname}}</text>
					<u-icon name="close" color="rgba(248, 50, 36, 1)" size="12" @click="goodname=''"></u-icon>
				</view>
			</view>
			<view class="">
				<view class="info">{{i18n.Filling}}</view>
				<view class="input">
					<input disabled type="text" :placeholder="i18n.Please" style="width: 100%;" @click="tosearch" />
				</view>
				<view v-if="goodname==''" class="u-flex " style="margin-top: 28rpx;flex-wrap: wrap;column-gap: 10rpx;">
					<view class="about" v-for="(item,idx) in goods" @click="activename(item)" style="overflow: hidden;">
						<text v-if="language =='zh-CN'">{{item.name_cn}}</text>
						<text v-if="language =='en-US'">{{item.name_en}}</text>
						<text v-if="language =='es-ES'">{{item.name_es}}</text>
						<text v-if="language =='it-IT'">{{item.name_ita}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="type  u-flex u-row-between">
			<view class="u-flex">
				<text class="title">{{i18n.shoptype}}</text>
				<image @click="toxieyi('product_type_description')" src="../static/express/explain.png" style="width: 32rpx;height: 32rpx;margin-left: 10rpx;"
					mode=""></image>
			</view>
			<view class="u-flex">
				<view class="u-flex" @click="type('normal')" style="margin-right: 24rpx;">
					<image v-if="goodtype=='normal'" style="width: 24rpx;height: 24rpx;margin-right: 6rpx;"
						src="../static/express/active.png" mode=""></image>
					<image v-if="goodtype=='special'" style="width: 24rpx;height: 24rpx;margin-right: 6rpx;"
						src="../static/express/noactive.png" mode=""></image>
					<text class='special'>{{i18n.Normal}}</text>
				</view>
				<view class="u-flex" @click="type('special')">
					<image v-if="goodtype=='special'" style="width: 24rpx;height: 24rpx;margin-right: 6rpx;"
						src="../static/express/active.png" mode=""></image>
					<image v-if="goodtype=='normal'" style="width: 24rpx;height: 24rpx;margin-right: 6rpx;"
						src="../static/express/noactive.png" mode=""></image>
					<text class='special'>{{i18n.special}}</text>
				</view>
			</view>
		</view>
		<view class="abouta">
			<view class="u-flex u-row-between">
				<view class="title">{{i18n.estimated}}</view>
				<view class="">
					<u-number-box v-model="value">
						<view @click="changeweight" slot="minus" class="minus">
							<u-icon name="minus" size="12"></u-icon>
						</view>
						<!-- <text slot="input" style="width: 150rpx;text-align: center;" class="inpu">{{value}}kg</text> -->
						<view slot="input" class="u-flex"
							style="width: 150rpx;text-align: center;background: #f4f4f4;padding: 10rpx 20rpx;">
							<input type="text" v-model="weight" />
							<text>kg</text>
							<!-- <text  class="inpu">{{value}}件</text> -->
						</view>
						<view @click="weight++" slot="plus" class="plus">
							<u-icon name="plus" color="#000000" size="12"></u-icon>
						</view>
					</u-number-box>
				</view>
			</view>
			<view class="u-flex u-row-between"
				style="border-top: 2rpx solid rgba(151, 151, 151, 0.1);padding-top: 30rpx;margin-top: 32rpx;">
				<view class="title">{{i18n.piece}}</view>
				<view class="">
					<u-number-box v-model="value">
						<view @click="changenumber" slot="minus" class="minus">
							<u-icon name="minus" size="12"></u-icon>
						</view>
						<view slot="input" class="u-flex"
							style="width: 150rpx;text-align: center;background: #f4f4f4;padding: 10rpx 20rpx;">
							<input type="text" v-model="number" />
							<text>件</text>
							<!-- <text  class="inpu">{{value}}件</text> -->
						</view>
						<view @click="number++" slot="plus" class="plus">
							<u-icon name="plus" color="#000000" size="12"></u-icon>
						</view>
					</u-number-box>
				</view>
			</view>
			<view class="u-flex u-row-between" style="margin-top: 30rpx;">
				<text style="font-weight: 600;">{{i18n.volume}}</text>
				<text style="font-size: 20rpx;
			color: rgba(34, 34, 34, 0.5);">{{i18n.accurately}}</text>
			</view>
			<view class="u-flex u-row-between" style="margin-top: 32rpx;">
				<view class="vite u-flex">
					<input type="text" :placeholder="i18n.length" v-model="length" />
					<text>cm</text>
				</view>
				<view class="">*</view>
				<view class="vite u-flex">
					<input type="text" :placeholder="i18n.wide" v-model="width" />
					<text>cm</text>
				</view>
				<view class="">*</view>
				<view class="vite u-flex">
					<input type="text" :placeholder="i18n.height" v-model="height" />
					<text>cm</text>
				</view>
			</view>
			<view class="u-flex" style="margin-top: 28rpx;">
				<view class="zhu">
					{{i18n.Note}}
					<text class="rule" @click="toxieyi('regole_di_fatturazione')"> {{i18n.rule}}</text>
				</view>
			</view>
		</view>
		<view class="btn">
			<view class="button" @click="enter">{{i18n.enter}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: 1,
				goods: [],
				language: 'zh-CN',
				goodname: '',
				number: 1,
				weight: 1,
				goodid: '', //物品信息id
				goodtype: 'normal', //商品类型
				length: '',
				width: '',
				height: '',
				typea:''
			};
		},
		computed: {
			i18n() {
				return this.$t('index')
			}
		},
		onLoad(options) {
			if (options.goodinfo) {
				var goodinfo = JSON.parse(decodeURIComponent(options.goodinfo));
				this.goodid = goodinfo.goodid
				this.goodname = goodinfo.goodname
				this.goodtype = goodinfo.goodtype
				this.height = goodinfo.height
				this.length = goodinfo.length
				this.number = goodinfo.number
				this.weight = goodinfo.weight
				this.width = goodinfo.width
			}
			if(options.goodtype){
				this.goodtype = options.goodtype
				console.log(this.goodtype);
				this.typea = 'pin'
			}
			this.getgoods()
		},
		onShow() {
			if (uni.getStorageSync('language') != '') {
				this.language = uni.getStorageSync('language')
			}
			uni.setNavigationBarTitle({
				title: this.i18n.item
			})
		},
		methods: {
			toxieyi(code){
				uni.navigateTo({
					url:'/pageB/xieyi?code='+ code
				})
			},
			enter() {
				if (this.goodid == '') {
					this.$u.toast(this.i18n.itemtoSend)
					return
				}
				if (this.goodtype == '') {
					this.$u.toast(this.i18n.selectitemType)
					return
				}
				const eventchannel = this.getOpenerEventChannel();
				eventchannel.emit('goodinfo', {
					goodid: this.goodid,
					goodtype: this.goodtype,
					goodname: this.goodname,
					number: this.number,
					weight: this.weight,
					length: this.length,
					width: this.width,
					height: this.height,
				})
				uni.navigateBack()
			},
			changeweight() {
				if (this.weight == 1) {
					this.$u.toast(this.i18n.Weightnotlessthan)
				} else {
					this.weight--
				}
			},
			changenumber() {
				if (this.number == 1) {
					this.$u.toast(this.i18n.cannotbelessthan)
				} else {
					this.number--
				}
			},
			//商品类型
			type(type) {
				if(this.typea == 'pin'){
					
				}else{
					this.goodtype = type
				}
			},
			//选中哪个物品
			activename(item) {
				if (this.language == 'zh-CN') {
					this.goodname = item.name_cn
				} else if (this.language == 'en-US') {
					this.goodname = item.name_en
				} else if (this.language == 'es-ES') {
					this.goodname = item.name_es
				} else if (this.language == 'it-IT') {
					this.goodname = item.name_ita
				}
				this.goodid = item.id
			},
			getgoods() {
				uni.$u.http.get('/api/express-goods-info', {
					params: {
						is_hot: 1
					}
				}).then((res) => {
					this.goods = res
				}).catch(() => {

				})
			},
			tosearch() {
				var that = this
				uni.navigateTo({
					url: "/pageB/search",
					events: {
						searchinfo: function(res) {
							if (that.language == 'zh-CN') {
								that.goodname = res.name_cn
							} else if (that.language == 'en-US') {
								that.goodname = res.name_en
							} else if (that.language == 'es-ES') {
								that.goodname = res.name_es
							} else if (that.language == 'it-IT') {
								that.goodname = res.name_ita
							}
							that.goodid = res.id
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.vite {
		width: 198rpx;
		height: 60rpx;
		background: #F4F4F4;
		border-radius: 36rpx;
		padding: 12rpx 28rpx;
		box-sizing: border-box;
	}

	.special {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		color: #444444;
		line-height: 36rpx;
		text-align: left;
		font-style: normal;
	}

	.minus {
		width: 22px;
		height: 22px;
		border-width: 1px;
		border-color: rgba(0, 0, 0, 0);
		border-style: solid;
		border-top-left-radius: 100px;
		border-top-right-radius: 100px;
		border-bottom-left-radius: 100px;
		border-bottom-right-radius: 100px;
		@include flex;
		justify-content: center;
		align-items: center;
	}

	.inpu {
		padding: 0 20px;
		width: 150rpx;
		height: 52rpx;
		background: #F4F4F4;
		text-align: center;
		line-height: 52rpx;
	}

	.plus {
		width: 22px;
		height: 22px;
		// background-color: #FF0000;
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}

	.back {
		padding: 20rpx 24rpx;

		.btn {
			width: 750rpx;
			height: 166rpx;
			background: #FFFFFF;
			position: fixed;
			bottom: 0;
			left: 0;
			padding: 18rpx 32rpx;
			box-sizing: border-box;

			.button {
				width: 686rpx;
				height: 88rpx;
				background: #F83224;
				border-radius: 44rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 88rpx;
				text-align: center;
				font-style: normal;
			}
		}

		.abouta {
			padding: 38rpx 20rpx;
			box-sizing: border-box;
			width: 702rpx;
			// height: 352rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin-top: 20rpx;

			.zhu {
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #7D7D7D;
				line-height: 42rpx;
				text-align: left;
				font-style: normal;
			}

			.rule {
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #F83224;
				line-height: 34rpx;
				text-align: left;
				font-style: normal;
			}
		}

		.title {
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 28rpx;
			color: #222222;
			line-height: 40rpx;
			text-align: left;
			font-style: normal;
		}

		.type {
			width: 704rpx;
			height: 96rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			margin-top: 20rpx;
			padding: 28rpx 20rpx;
			box-sizing: border-box;

			.change {
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
			}
		}

		.top {
			width: 702rpx;
			// height: 484rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 24rpx 28rpx;
			box-sizing: border-box;



			.mast {
				// width: 62rpx;
				height: 30rpx;
				border-radius: 16rpx;
				border: 1rpx solid #F83224;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 20rpx;
				color: #FF1515;
				line-height: 30rpx;
				text-align: center;
				font-style: normal;
				margin-left: 8rpx;
				padding: 0 6rpx;
				box-sizing: border-box;
			}

			.about {
				width: 202rpx;
				height: 60rpx;
				border-radius: 36rpx;
				border: 1rpx solid rgba(151, 151, 151, 0.5);
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #444444;
				line-height: 60rpx;
				text-align: center;
				font-style: normal;
				margin-bottom: 20rpx;
			}
		}

		.info {
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #222222;
			line-height: 34rpx;
			text-align: left;
			font-style: normal;
			margin-top: 20rpx;
		}

		.input {
			width: 646rpx;
			height: 68rpx;
			background: #F5F5F5;
			border-radius: 44rpx;
			padding: 14rpx 32rpx;
			margin-top: 20rpx;
			box-sizing: border-box;
		}
	}
</style>