<template>
	<view class="content flex flex_column">
		<view class="head-info" v-if="detail">
			<view>
				<text>货架名称</text>
				<view>{{detail.shelfName}}</view>
			</view>
			<view>
				<text>盘点日期</text>
				<view>{{detail.checkDate}}</view>
			</view>
			<view>
				<text>盘点人</text>
				<view>{{detail.checkPersonName}}</view>
			</view>
			<view>
				<text>备注</text>
				<view>
					<u-input v-if="type=='submit'" v-model="remarks" placeholder="请输入备注" input-align="right" type="textarea" :height="60" :auto-height="true" />
					<text v-else>{{detail.remarks}}</text>
				</view>
			</view>
		</view>
		<view class="detail flex_1">
			<view class="detail-tongji" v-if="detail">
				<view>盘盈总数量：<text>{{detail.totalProfitQty}}</text>；盘盈总金额：<text>{{detail.totalProfitCost}}</text>；</view>
				<view>盘亏总数量：<text>{{detail.totalLossQty}}</text>；盘亏总金额：<text>{{detail.totalLossCost}}</text>；</view>
				<view>盈亏总数量：<text>{{detail.totalProfitLossQty}}</text>；盈亏总金额：<text>{{detail.totalProfitLossCost}}</text>；</view>
			</view>
			<view class="cpb_cart-list">
				<view class="nav-right-item flex" v-for="(item, index) in chooseList" :key="item.id" >
					<view class="uni-col-2">
						<u-image :src="item.product&&item.product.images?item.product.images:`../../static/${$config('themePath')}/def_img@2x.png`" width="100" height="100" border-radius="30"></u-image>
					</view>
					<view class="item-info uni-col-10">
						<view class="item-name">
							<text>{{item.shelfPlaceCode}}</text>
							{{item.productCode}}
						</view>
						<view class="item-detail">
							<view class="item-detail-info">
								<view class="flex justify_between">
									<view>
										<text class="item-detail-text">
											可用：
										</text>
										{{item.stockQty||0}}
									</view>
									<view>
										<text class="item-detail-text">
											冻结：
										</text>
										{{item.freezeQty||0}}
									</view>
									<view>
										<text class="item-detail-text">
											实际可用：
										</text>
										<text class="red">
											{{item.checkQty||0}}
										</text>
									</view>
								</view>
								<view class="flex justify_between">
									<view>
										<text class="item-detail-text">
											结算价：
										</text>
										￥{{item.cost||0}}
									</view>
									<view>
										<text class="item-detail-text">
											盈亏：
										</text>
										{{item.checkProfitLossQty||0}}
										(￥{{item.checkProfitLossCost||0}})
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部栏 -->
		<view class="footer-bar flex justify_between align_center" v-if="type=='submit'">
			<u-button size="medium" @click="goback" shape="circle" type="default" hover-class="none" >继续盘点</u-button>
			<u-button size="medium" @click="submitOrder" :custom-style="customBtnStyle" shape="circle" type="primary" hover-class="none" >盘点完成</u-button>
		</view>
	</view>
</template>

<script>
	import {
		stockCheckDetailQueryList, 
		stockCheckBySn, 
		stockCheckConfirm
	} from '@/api/stockCheck'
	import { clzConfirm } from '@/libs/tools'
	export default {
		data() {
			return {
				customBtnStyle: {  //  自定义按钮样式
					borderColor: this.$config('primaryColor'),
					backgroundColor: this.$config('primaryColor'),
					color: '#fff'
				},
				stockCheckSn: null,
				remarks: '',
				detail: null,
				chooseList: [],
				type: ''
			}
		},
		onLoad(opts) {
			this.stockCheckSn = opts.stockCheckSn
			this.type = opts.type
			this.getDetail()
			this.getChooseList()
			if(this.type == 'view'){
				uni.setNavigationBarTitle({
					title: '盘点单详情'
				})
			}
		},
		methods: {
			// 详细
			getDetail(){
				stockCheckBySn({stockCheckSn: this.stockCheckSn}).then(res => {
					this.detail = res.data || null
				})
			},
			// 获取盘点明细列表
			getChooseList(){
				stockCheckDetailQueryList({
					stockCheckSn: this.stockCheckSn
				}).then(res => {
					this.chooseList = res.data || []
				})
			},
			// 盘点完成
			submitOrder(){
				const _this = this
				clzConfirm({
				  title: '提示',
				  content: '盘点完成后，无法再修改数据，确认盘点完成吗？',
				  success (ret) {
					if (ret.confirm || ret.index == 0) {
						uni.showLoading({
							title:"正在提交.."
						})
						stockCheckConfirm({
							remarks: _this.remarks,
							stockCheckSn: _this.stockCheckSn
						}).then(res => {
							if(res.status == 200 && res.data){
								_this.goback()
								uni.$emit("resetStockCheck")
							}
							uni.hideLoading()
						})
					}
				  }
				})
			},
			goback(){
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="less">
	.content{
		width:100%;
		height: 100vh;
		background-color: #fff;
		.head-info{
			padding: 0 30upx;
			> view{
				display: flex;
				justify-content: space-between;
				padding: 15upx 10upx;
				color:#666;
				> text{
					color: #999;
					width: 150rpx;
				}
				border-bottom:2rpx solid #f8f8f8;
				> view{
					width: 80%;
					text-align: right;
					word-break: break-all;
				}
			}
		}
		.detail{
			flex-grow: 1;
			overflow: auto;
			.detail-tongji{
				padding: 15upx 30upx;
				> view{
					padding: 10upx;
					color:#999;
					text{
						color: #666;
					}
				}
				border-top:10rpx solid #f8f8f8;
				border-bottom:10rpx solid #f8f8f8;
			}
		}
		.cpb_cart-list{
			padding: 10upx 30upx;
			> view{
				border-bottom:2rpx solid #f8f8f8;
				padding: 15upx 0;
			}
			.item-name{
				font-size: 30rpx;
				text{
					background: #eef6ff;
					color: #174b76;
					border-radius: 1em;
					font-size: 0.8em;
					padding: 0 0.5em;
					margin-right: 10upx;
				}
				margin-bottom: 10upx;
			}
			.item-info{
				flex-grow: 1;
				padding-left: 0.2em;
			}
			.item-detail{
				.item-detail-info{
					padding: 10upx 0 4upx;
					font-size: 24upx;
					> view{
						padding-bottom: 10rpx;
						align-items: center;
						.item-detail-text{
							color: #999;
						}
						.red{
							color: red;
						}
					}
				}
			}
		}
		.footer-bar{
			background-color: #f8f8f8;
			padding: 20upx;
			button{
				width: 300upx;
			}
		}
	}
</style>
