<template>
	<view class="replenishment-putWarehousing-wrap" :style="`backgroundImage:linear-gradient(180deg, ${$config('primaryColor')}, #F5F6F7 12%)`">
		<view class="replenishment-putWarehousing-body">
			<view class="head-info" v-if="basicInfoData">
				<view class="states">
					<view>
						<u-icon name="icon_warehousing" custom-prefix="iscm-icon" size="48"></u-icon>
						<text>待签收</text>
					</view>
				</view>
				<view>
					<view class="label"><u-icon name="icon_delivery" custom-prefix="iscm-icon" size="32"></u-icon><text>配送方式</text></view>
					<view>{{basicInfoData.dispatchTypeDictValue || '--'}}</view>
				</view>
				<view>
					<view class="label"><u-icon name="icon_remark" custom-prefix="iscm-icon" size="32"></u-icon><text>出库备注</text></view>
					<view class="info-txt">{{basicInfoData.remarks || '--'}}</view>
				</view>
			</view>
			<view class="part-list">
				<!-- 补货产品 -->
				<partList :list="partList" title="补货产品" model="view" fromPage="replenishmentSign" ref="partList" noDataText="暂无产品" @numberChange="numberChange"></partList>
			</view>
		</view>
		<view class="replenishment-putWarehousing-footer">
			<u-button @click="confirmModal=true" type="success" :custom-style="customStyle" hover-class="none" shape="circle">确定签收（{{confirmQty}}/{{totalQty}}）</u-button>
		</view>
		<!-- 确认弹框 -->
		<common-modal :openModal="confirmModal" content="签收后数字货架的产品数量将增加，确认签收吗？" confirmText="确认签收" @confirm="modalConfirm" @close="confirmModal=false" />
	</view>
</template>

<script>
	import commonModal from '@/pages/common/commonModal.vue'
	import { shelfReplenishDetail, shelfReplenishDetailList, shelfReplenishPutStock } from '@/api/shelfReplenish'
	import partList from '@/pages/common/partList.vue'
	export default {
		components: { partList, commonModal },
		data() {
			return {
				allChecked: false,
				replenishBillSn: '',
				basicInfoData:null,
				partList: [],
				confirmQty: 0,  // 实发数量之和
				totalQty: 0,  // 应发数量之和
				customStyle: {
					borderRadius:'100rpx',
					fontSize:'30rpx',
					background: '#0485F6'
				},
				confirmModal: false
			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.$config('primaryColor')
			})
		},
		onLoad(option) {
			this.replenishBillSn = option.replenishBillSn
			this.getDetail()
			this.getPartList()
		},
		methods: {
			// 查询详情
			getDetail(){
				shelfReplenishDetail({ sn: this.replenishBillSn }).then(res => {
					if(res.status == 200){
						this.basicInfoData = res.data || null
					}else{
						this.basicInfoData = null
					}
				})
			},
			// 查询列表
			getPartList(){
				const _this = this
				shelfReplenishDetailList({ replenishBillSn: this.replenishBillSn }).then(res => {
					if(res.status == 200 && res.data){
						_this.totalQty = 0
						_this.confirmQty = 0
						res.data.map(item =>{
							item.confirmQty = item.confirmQty ? Number(item.confirmQty) : 0
							item.putQty = item.confirmQty ? Number(item.confirmQty) : 0
							if(item.confirmQty && Number(item.confirmQty)){
								_this.totalQty += Number(item.confirmQty)
							}
							if(item.putQty && Number(item.putQty)){
								_this.confirmQty += Number(item.putQty)
							}
						})
						this.partList = res.data || []
					}else{
						this.partList = []
					}
				})
			},
			// 确认签收 confirm
			modalConfirm(){
				const arr = []
				this.partList.map((item, index) => {
				  if (item.putQty || item.putQty == 0) {
				    arr.push({ productSn: item.productSn, putQty: item.putQty })
				  }
				})
				const params = {
				  replenishBillSn: this.replenishBillSn,
				  detailList: arr
				}
				shelfReplenishPutStock(params).then(res => {
					if(res.status == 200){
						uni.$emit('refreshBL')
						uni.navigateBack()
					}
					this.toashMsg(res.message)
				})
			},
			// 数量 change
			numberChange(value, index){
				const _this = this
				this.confirmQty = 0
				let list = this.$refs.partList.getAllData()
				list.map(item => {
					if(item.putQty && Number(item.putQty)){
						_this.confirmQty += Number(item.putQty)
					}
				})
			}
		}
	}
</script>

<style lang="less">
.replenishment-putWarehousing-wrap{
	position: relative;
	width: 100%;
	height: 100%;
	overflow: hidden;
	padding-bottom: 136upx;
	.replenishment-putWarehousing-body{
		padding: 0 30rpx;
		height: 100%;
		overflow: auto;
		> view{
			padding: 10rpx 25rpx;
			background-color: #fff;
			margin-bottom: 20rpx;
			border-radius: 25rpx;
			box-shadow: 2rpx 3rpx 5rpx #eee;
		}
		.head-info{
			.states{
				border: 0;
				padding: 20rpx 0;
				> view{
					color: #191919;
					text-align: center;
					font-size: 40rpx;
					text{
						margin-left: 20rpx;
					}
				}
			}
			.info-txt{
				word-break: break-word;
			}
			font-size: 30rpx;
			> view{
				display: flex;
				border-bottom: 2rpx solid #f5f5f5;
				padding: 20rpx 0;
				> view:last-child{
					flex-grow: 1;
					width: 80%;
				}
				&:last-child{
					border:0;
				}
			}
			.label{
				display: flex;
				align-items: center;
				width: 220rpx;
				height: 44rpx;
				color: #7C7D7E;
				text{
					margin-left: 10rpx;
				}
			}
		}
	}
	.replenishment-putWarehousing-footer{
		padding: 26upx 32upx 30upx;
		background-color: #fff;
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		box-shadow: 3px 1px 7px #eee;
	}
}
</style>
