<template>
	<view class="content">
		<view class="" style="height: 30rpx;">
			
		</view>
		<!-- 门店选择 -->
		<view class="yt-list tc-wrap" @click="navTo('/pages/index/shopTab?select=1')">
			<view class="top-wrap flex">
				<view class="top-left">
					选择门店
				</view>
			</view>
			<view class="store-wrap flex" v-if="selctStore && selctStore.id">
				<view class="imgBox">
					<image class="logo" :src="selctStore.image" mode="aspectFit"></image>
				</view>
				<view class="padding-l-20 flex-grow-true">
					<view class="title clamp flex">
						<view class="name">
							{{selctStore.name}}
						</view>
						<view class="km" v-if="selctStore.range">
							{{selctStore.range<1?selctStore.distance+'m':selctStore.range+'km'}}
						</view>
					</view>
					<view class="flex addressBox margin-t-20">
						<image class="iconA margin-r-10" src="../../static/icon/shop.png" mode="">
						</image>
						<text class="clamp">
							{{selctStore.detailed_address}}
						</text>
					</view>
					<view class="addressBox flex">
						<image class="iconA margin-r-10" src="../../static/icon/shopPhone.png" mode="">
		
							<text class="clamp">
								{{selctStore.phone}}
							</text>
					</view>
					<view class="yysj">
						营业时间：{{selctStore.day_time}}
					</view>
				</view>
			</view>
			<view class="store-wrap-empty" v-else>
				选择门店
			</view>
		</view>
		<view class="yt-list tc-wrap" @click="chooseGood">
			<view class="top-wrap flex">
				<view class="top-left">
					选择商品
				</view>
			</view>
			<view class="good flex" v-if="selctGood && selctGood.id" >
				<view class="good-img">
					<image :src="selctGood.image" mode=""></image>
				</view>
				<view class="good-info flex">
					<view class="good-name clamp2">
						{{selctGood.title}}
					</view>
					<view class="good-price">
						<view class="new-price flex">
							<view class="stock">
								库存：{{selctGood.stock}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="store-wrap-empty" v-else>
				选择商品
			</view>
		</view>
		<view class="yt-list tc-wrap" style="padding-bottom: 20rpx;">
			<view class="top-wrap flex">
				<view class="top-left">
					输入编码
				</view>
				
			</view>
			<view class="flex dcm" >
				<input type="text" v-model="code" placeholder="请输入编码"
					placeholder-class="hx-placeholder" style="margin-bottom: 0;" />
				<image src="../../static/icon/scend.png" mode="widthFix" style="width: 50rpx;" @click="smget">
				</image>
			</view>
		</view>
		<view class="tapBottom" @click="loading?'':changeTab()">
			确认入库
		</view>
	</view>
</template>

<script>
	import { getGoods,storeInStock } from '@/api/product.js'
	export default {
		data() {
			return {
				selctStore: {},
				selctGood: {},
				code: '',
				loading: false
			}
		},
		onLoad() {
			this.selctStore = uni.getStorageSync('selctStore') || {}
		},
		onShow() {
			console.log(this.selctStore.id,'selctStore');
			if(this.selctStore.id) {
				uni.setStorageSync('selctStore',this.selctStore)
				this.getGoods()
			}
		},
		methods: {
			// 确认入库
			changeTab() {
				let that = this
				if(!that.selctStore.id) {
					return that.$api.msg('请选择门店')
				}
				if(!that.selctGood.id) {
					return that.$api.msg('请选择商品')
				}
				if(!that.code) {
					return that.$api.msg('请输入编码')
				}
				that.loading = true
				storeInStock({
					store_id: that.selctStore.id,
					code: that.code,
					product_id: that.selctGood.id
				}).then(res => {
					uni.showToast({
						title: '入库成功',
						mask: true,
						duration: 1500
					});
					// that.selctGood = {}
					that.code = ''
					that.loading = false
				}).catch(err => {
					that.loading = false
				})
			},
			smget() {
				let that = this
			
				uni.scanCode({
					success: (res) => {
						that.code = res.result
					}
				})
			},
			navTo(url) {
				uni.navigateTo({
					url,
					fail() {
						uni.switchTab({
							url
						})
					}
				})
			},
			getGoods() {
				let that = this
				getGoods({
					store_id: that.selctStore.id
				}).then(res => {
					console.log(res);
				})
			},
			chooseGood() {
				let that = this
				if(!that.selctStore.id) {
					return that.$api.msg('请选择门店')
				}
 				that.navTo('/pages/shop/accessory?type=3&id=' + that.selctStore.id)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tc-wrap {
		width: 702rpx;
		background: #FFFFFF;
		border-radius: 15rpx;
		// padding: 25rpx 25rpx 45rpx;
		
	
	}
	.store-wrap-empty {
		text-align: center;
		height: 100rpx;
	}
	.yt-list {
		background: #fff;
		margin: 0 $page-row-spacing 20rpx $page-row-spacing ;
		border-radius: 20rpx;
		
	}
	
	.store-wrap {
		background-color: #FFFFFF;
		margin-bottom: 30rpx;
		padding: 30rpx;
		border-radius: 20rpx;
	
		.list,
		.km {
			color: $font-color-light;
			font-size: $font-sm;
		}
	
		.logo {
			height: 200rpx;
			width: 200rpx;
			border-radius: 20rpx;
		}
	
		.title {
			font-size: 36rpx;
			color: $font-color-dark;
		}
	
		.iconR {
			height: 24rpx;
		}
	
		.iconA {
			width: 24rpx;
			height: 24rpx;
		}
	
		.addressBox {
			font-size: 24rpx;
			color: $font-color-light;
			justify-content: flex-start;
			padding: 10rpx 0;
		}
	
		.yysj {
			display: inline-block;
			// width: 239rpx;
			padding: 0 10rpx;
			height: 32rpx;
			background: #ddf8f1;
			border-radius: 16rpx 16rpx 16rpx 0rpx;
			font-size: 20rpx;
			font-weight: bold;
			color: #5FCCA7;
			text-align: center;
			line-height: 32rpx;
			margin-top: 10rpx;
		}
	}
	.top-wrap {
		justify-content: space-between;
		padding: 0 25rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #00001A;
		height: 85rpx;
	
		.top-left {}
	
		.top-right {
			text {
				font-size: 25rpx;
				font-weight: 500;
				color: #999999;
			}
	
			image {
				height: 22rpx;
				margin-left: 10rpx;
			}
		}
	}
	.good {
		width: 690rpx;
		height: 276rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 10rpx;
		margin: auto;
		padding: 20rpx 15rpx;
		margin-bottom: 20rpx;
		&:last-of-type {
			margin-bottom: 0rpx;
		}
		
		.good-img {
			flex-shrink: 0;
			width: 236rpx;
			height: 236rpx;
			border-radius: 10rpx;
			margin-right: 22rpx;
		
			image {
				width: 236rpx;
				height: 236rpx;
				border-radius: 10rpx;
			}
		}
		
		.good-info {
			flex-grow: 1;
			height: 100%;
			flex-direction: column;
			justify-content: space-between;
			align-items: flex-start;
		
			.good-name {
				font-size: 32rpx;
				font-weight: bold;
				padding-top: 10rpx;
				color: #333333;
			}
		
			.good-price {
				width: 100%;
				.new-price {
					width: 100%;
					font-size: 36rpx;
					font-weight: bold;
					color: #FF4C4C;
					justify-content: space-between;
					.stock {
						color: #333333;
						font-size: 28rpx;
					}
				}
			}
		}
	}
	.dcm {
		width: 600rpx;
		margin:20rpx auto 0;
		align-items: center;
		height: 68rpx;
	
		input {
			flex-grow: 1;
			height: 68rpx;
			background: #fff;
			border-radius: 10rpx;
			margin: auto 10rpx auto 0;
			padding-left: 26rpx;
		}
	
		image {
			flex-shrink: 0;
		}
	}
	.tapBottom {
		margin: 0 50rpx;
		text-align: center;
		color: #FFFFFF;
		border: 1px solid $color-green;
		background-color: $color-green ;
		line-height: 1;
		padding: 25rpx;
		border-radius: 100rpx;
		margin-top: 50rpx;
	}
</style>