<template>
	<view class="content flex flex_column">
		<view class="uni-icon-error tits">以下产品需设置结算价（即修理厂的进货价），否则无法上架入库</view>
		<view class="proudct-body">
			<view class="partList-list-box" v-for="(item,index) in partList" :key="item.id">
				<view class="product flex align_center">
					<view class="flex align_center justify_between">
						<view class="pimgs">
							<u-image :src="item.product.images?item.product.images:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
						</view>
						<view class="pinfo">
							<view class="pname">
								<text>{{item.shelfPlaceCode}}</text>
								{{item.productCode}}
							</view>
							<view class="pname pname1">
								{{item.product.productName}}
							</view>
						</view>
					</view>
				</view>
				<view class="pcurnums flex align_center justify_end">
					<text>结算价</text>
					<view class="u-ninput">
						<u-input trim border type="digit" clearable @blur="numberToFixed(item,2,999999)" v-model="item.cost" placeholder="请输入价格，最多两位小数"/>
					</view>
				</view>
			</view>
		</view>
		<view class="footer-bar">
			<u-button type='primary' shape="circle" size="medium" @click="submitForm">设置完成</u-button>
		</view>
	</view>
</template>

<script>
	import { clzConfirm, numberToFixed } from '@/libs/tools';
	import {updateBatchById, shelfCartConfirm} from '@/api/shelfCart.js'
	export default {
		data() {
			return {
				partList:[],
			}
		},
		onLoad() {
			this.partList = this.$store.state.vuex_tempData
			this.partList.map(item => {
				item.cost = ''
			})
		},
		onUnload() {
			this.$store.state.vuex_tempData = null
		},
		methods: {
			// 小数点后两位
			numberToFixed: function (item, num, max) {
				let val = item.cost
				let ret = numberToFixed(val, num, max)
				this.$set(item,'cost',Number(ret <= 0 ? '' : ret))
				this.partList = JSON.parse(JSON.stringify(this.partList))
			},
			submitForm(){
				const hasEmpty = this.partList.filter(item => !item.cost)
				console.log(hasEmpty)
				if(hasEmpty.length){
					this.toashMsg("请输入结算价")
				}else{
					uni.showLoading({
						mask: true,
						title: '正在设置价格...'
					})
					updateBatchById(this.partList).then(res => {
						uni.hideLoading()
						if(res.status == 200){
							uni.$emit("setCostOk")
							uni.navigateBack()
						}
					})
				}
			}
		}
	}
</script>

<style lang="less">
.content{
	width: 100%;
	height: 100vh;
	.tits{
		padding: 20upx 30upx;
		color: darkorange;
		font-size: 24rpx;
	}
	.proudct-body{
		flex-grow: 1;
		width: 100%;
		overflow: auto;
		background-color: #fff;
		padding: 0 20upx;
	}
	.partList-list-box{
		padding: 10px 0;
		border-bottom: 2rpx solid #f5f5f5;
		.product{
			flex-grow: 1;
			.pinfo{
				flex-grow: 1;
				padding-left: 20rpx;
				.pname{
					color: #191919;
					margin-bottom: 5rpx;
					text{
						font-weight: normal;
						margin-right: 10rpx;
						padding: 0 10rpx;
						background: rgba(3, 54, 146, 0.15);
						border-radius: 30rpx;
						color: #033692;
						font-size: 24rpx;
					}
				}
			}
		}
		.pcurnums{
			color: #999;
			.u-ninput{
				width: 60%;
				padding: 0 10rpx;
			}
		}
	}
	.footer-bar{
		padding: 20upx;
		button{
			width: 80%;
		}
		text-align: center;
	}
}
</style>
