<template>
	<view class="page1">
		<view class="content-box">
			<view class="right-box">
				<view class="box-left">
					<img class="img-radius" :src="dataList.productPicture" alt="" v-if="dataList.productPicture">
					<view class="noPic" v-else>暂无图片</view>	
				</view>
				<view class="box-right">
					<view class="box-right-name">{{dataList.productName == null ? '暂无':dataList.productName}} ({{dataList.productSn == null ? '暂无':dataList.productSn}})</view>
					<view class="box-right-num">供应商：{{dataList.supplierName == null ? '暂无':dataList.supplierName}}</view>
					<view class="box-right-num" style="color:#ffa200;">
						<text style="padding-right: 20rpx;">{{dataList.delFlag==1?'已上架':'已下架'}}</text>
					</view>
				</view>
			</view>
		</view>
		<view style="display: flex;background: #fff;height: 70rpx;line-height: 70rpx;">
			<view style="width: 53%;text-align: center;">规格</view>
			<view style="width: 15%;text-align: center;">库存数</view>
			<view style="width: 27%;text-align: center;">盘点数</view>
		</view>
		<view style="padding-bottom: 200rpx;">
			<view class="container-box" v-for="(item,index) in pecsList" :key='index'>
				<view class="prec-list">
					<view class="prec-list-box" style="width: 53%;text-align: center;">
						{{item.attributeList | sliceMsg}}
					</view>
					<view class="prec-list-box" style="width: 15%;font-size: 26rpx;">
						{{item.stockCount}}
					</view>
					<view style="width: 27%;font-size: 26rpx;padding-top: 5px;">
						<uni-number-box min="-10000" max='1000000' v-model="item.pdNum" />
					</view>
				</view>
			</view>
		</view>
		<view class="bottom-box">
			<view class="bottom-btn" @tap="clickList">确认无误</view>
		</view>
	</view>
</template>

<script>
	import util from '@/components/kk-printer/utils/util.js';
	export default {
		data() {
			return {
				pageNum: 1, //分页的页码
				dataList: [],
				pecsList:[],
			}
		},
		filters: {
			sliceMsg(val) {
				var name = ''
				if (typeof(val) == 'string') {
					let newObj = JSON.parse(val)
					for (let as in newObj) {
						name += newObj[as] + '/'
					}
				}
				return name;
			},
			maxNum(val){
				if(val >= 10){
					return 10
				}else if(val < 0){
					return 0
				} 
			}
		},
		onLoad(option) {
			this.dataList = JSON.parse(option.item);
		},
		onShow(){
			this.getShareList();
		},
		methods: {
			//库存商品详情
			getShareList() {
				this.tui.request("/app/stock/productCount", "GET", {
					productId: this.dataList.id
				}, false, true).then((res) => {
					if (res.code == 200) {
						let checkStockAttributeVos = this.dataList.checkStockAttributeVos
						for(let i= 0;i<res.result.length;i++){
							if(checkStockAttributeVos == null){
								res.result[i].pdNum = res.result[i].stockCount
							}else{
								for(let j = 0;j<checkStockAttributeVos.length;j++){
									if(checkStockAttributeVos[j].attributeList == res.result[i].attributeList){
										res.result[i].pdNum = checkStockAttributeVos[j].pdNum
									}
								}
							}
						}
						this.pecsList = res.result
					} else {
						this.tui.toast(res.message)
					}
				}).catch((res) => {})
			},
			//点击选择列表，带参数 返回上一页
			clickList() {
				var data = []
				for(let i=0;i<this.pecsList.length;i++){
					var item = {
						attributeList:this.pecsList[i].attributeList,
						stockCount:this.pecsList[i].stockCount,
						pdNum:this.pecsList[i].pdNum
					}
					data.push(item)
					 //炘旺和提钱，盘点整款商品全传过去
					/* if(uni.getStorageSync('shopId') == '1842761269212483585' || uni.getStorageSync('shopId') == '1810179818189361152'){
						
					}else{
						if(this.pecsList[i].stockCount != this.pecsList[i].pdNum){
							var item = {
								attributeList:this.pecsList[i].attributeList,
								stockCount:this.pecsList[i].stockCount,
								pdNum:this.pecsList[i].pdNum
							}
							data.push(item)
						}
					} */
					
				}
				this.dataList.checkStockAttributeVos = data
				let dataList = []
				var itemData;
				itemData = {
					checkStockId:uni.getStorageSync('stockId'),
					productId: this.dataList.id,
					productName:this.dataList.productName,
					productPicture:this.dataList.productPicture,
					productSn:this.dataList.productSn,
					checkStockAttributeVos:this.dataList.checkStockAttributeVos
				}
				dataList.push(itemData)
				this.tui.request("/app/checkStockDetail/addCheckStockDetail", "POST", dataList, false, false).then((res) => {
					if (res.code == 200) {
						let pages = getCurrentPages();
						let prevPage = pages[pages.length - 2];
						prevPage.$vm.pdList = this.dataList
						uni.navigateBack({
							delta: 1
						})
					} else {
						this.tui.toast(res.message)
					}
				}).catch((res) => {})	
			},
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		font-size: 24rpx;
	}

	.page1 {
		display: flex;
		flex-direction: column;
		height: 100%;
		font-size: 28rpx;
	}

	.content-box {
		background: #fff;
	}

	.right-box {
		width: 100%;
		height: 220rpx;
		display: flex;
		border-bottom: 1px solid #eee;
		position: relative;
	}

	.box-left {
		width: 170rpx;
		height: 170rpx;
		background-size: 100%;
		margin: 25rpx;
		border-radius: 20rpx;
	}

	.box-left img {
		width: 100%;
		height: 100%;

	}

	.box-right {
		margin-top: 20rpx;
		flex: 1;
		display: flex;
		flex-direction: column;
		position: relative;
	}

	.box-right-name {
		font-size: 30rpx;
		font-weight: bold;
		padding-left: 20rpx;
		height: 30%;
	}

	.box-right-num {
		padding: 5rpx 0;
		color: #777;
		padding-left: 20rpx;
		height: 30%;
	}

	.box-right-price {
		display: flex;
		font-size: 25rpx;
		height: 100rpx;
	}

	.price-box {
		flex: 1;
		text-align: center;
		display: flex;
		flex-direction: column;
		margin-top: 20rpx;
	}

	.container-box {
		border-top: 10px solid #eee;
	}

	.price-box text:first-child {
		color: #ffa200
	}

	.edit-btn {
		    width: 100rpx;
		    height: 60rpx;
		    line-height: 60rpx;
		    color: #fff;
		    background: #0072E3;
		    position: absolute;
		    top: 105rpx;
		    right: 40rpx;
		    border-radius: 10px;
		    text-align: center;
	}

	.prec-list {
		    height: 80rpx;
			line-height: 80rpx;
		    background: #fff;
		    display: flex;
		    font-size: 32rpx;
			border-bottom: 1px solid #eee;
	}

	.prec-list-box {
		height: 70rpx;
		line-height: 70rpx;
		padding-left: 30rpx;
		overflow: hidden;
	}
	.noPic{
		border-radius: 10px;
		width: 150rpx;
		height: 150rpx;
		// margin: 30rpx 0 0 30rpx;
		text-align: center;
		line-height: 140rpx;
		color: #777;
		background: #eee;
	}
	.uni-numbox--text {
		font-size: 40rpx !important;
	}
	.uni-numbox__value{
		font-size: 35rpx !important;
	}
	.bottom-box{
		width: 100%;
		height: 110rpx;
		background: #fff;
		position: fixed;
		bottom: 0;
		z-index: 99;
	}
	.bottom-btn{
		width: 95%;
		background: #5fd9ee;
		height: 80rpx;
		color: #fff;
		margin: 20rpx auto 0;
		border-radius: 10px;
		text-align: center;
		line-height: 80rpx;
	}
</style>