<template>
	<view class="viewrecordsTop" v-if="datas.countList">
		<view style="padding:32rpx 16rpx;">
			<view @tap="getInOutType('in')">
				增加数量 &nbsp;<text
					style="color: #76ACF0;font-weight: bold;">{{datas.countList.inSumTotal?datas.countList.inSumTotal:'0'}}</text>
			</view>
			<view class="df viewdf">
				<view @tap="getNewdata('manual-in','in')"
					style="font-size: 24rpx;border-right: 1px solid #999; width: 142rpx;text-align: center;">
					<view style="color: #999999;">
						入库
					</view>
					<view class="">
						{{datas.countList.stockInNum?datas.countList.stockInNum:0}}
					</view>
				</view>
				<view @tap="getNewdata('win-in','in')" style="font-size: 24rpx;width: 178rpx;text-align: center;">
					<view style="color: #999999;">
						手动增加
					</view>
					<view class="">
						{{datas.countList.winInNum?datas.countList.winInNum:'0'}}
					</view>
				</view>
			</view>
		</view>
		<view style="padding:32rpx 16rpx;">
			<view class="" @tap="getInOutType('out')">
				减少数量 &nbsp;<text
					style="color: #52BDA4;font-weight: bold;">{{datas.countList.outSumTotal?datas.countList.outSumTotal:0}}</text>
			</view>
			<view class="df viewdf">
				<view @tap="getNewdata('loss-out','out')"
					style="font-size: 24rpx;border-right: 1px solid #999; width: 112rpx;text-align: center;">
					<view style="color: #999999;">
						手动减少
					</view>
					<view class="">
						{{datas.countList.lossOutNum?datas.countList.lossOutNum:0}}
					</view>
				</view>
				<view @tap="getNewdata('manual-out','out')"
					style="font-size: 24rpx;border-right: 1px solid #999; width: 82rpx;text-align: center;">
					<view style="color: #999999;">
						出库
					</view>
					<view class="">
						{{datas.countList.stockOutNum?datas.countList.stockOutNum:0}}
					</view>
				</view>
				<view @tap="getNewdata('order-out','out')" style="font-size: 24rpx;width: 112rpx;text-align: center;">
					<view style="color: #999999;">
						商品消耗
					</view>
					<view class="">
						{{datas.countList.consumeNum?datas.countList.consumeNum:0}}
					</view>
				</view>
			</view>
		</view>
	</view>
	<view class="viewrecords">
		<view v-for="item in datas.list" :key="item.id">
			<view class="">
				<view class=""> {{item.createTime}} </view>
				<view class=""> {{item.operator}} {{item.conName}} </view>
			</view>
			<view class="">
				<view class="">
					<view style="font-size: 24rpx;color: #666666;">
						库存 {{ item.beforeNumber }} <text
							:style="{color:item.inOutType=='in'?'#1bca72':'red'}"> → {{ item.inOutNumber|0 }}</text>
					</view>
					<view style="font-size: 24rpx;color: #666666;">
						剩余库存 {{item.afterNumber}}
					</view>
				</view>
				<view class="">
					<view :style="{color:item.inOutType=='in'?'#1bca72':'red'}" style="font-weight: 400;">
						{{ item.inOutType == 'in' ? '+' : '' }}{{ item.inOutNumber|0 }}
					</view>
					<view style="font-size: 24rpx;color: #666666;">
						变动库存
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { onMounted, reactive, ref, computed, getCurrentInstance } from 'vue';
	import { onLoad } from '@dcloudio/uni-app';
	import color from '@/commons/color.js';
	import { stockFlow,consStatistics } from '@/http/api/cons.js';
	
	let datas = reactive({
		list: [],
		countList: {},
		inOutType: '',
		inOutItem: '',
		item: null,
	})
	
	onLoad((options) => {
		datas.item = JSON.parse(options.item)
		getlist()
	})
	
	/**
	 * 时间筛选
	 * @param {Object} e
	 */
	function datePickerConfirm(e) {
		getlist("", e.start, e.end)
	}
	
	function getNewdata (d,e) {
		datas.inOutType = e
		datas.inOutItem = d
		getlist()
	}
	
	function getInOutType (e) {
		datas.inOutType = e
		getlist()
	}
	
	/**
	 * 获取数据
	 */
	function getlist (conTypeId = "", start, end, ) {
		// 列表
		stockFlow({
			conId: datas.item.id,
			inOutType: datas.inOutType,
			inOutItem: datas.inOutItem
		}).then(res => {
			datas.list = res.records
		})
		// 顶部数据
		consStatistics({
			id: datas.item.id,
		}).then(res => {
			datas.countList = res
		})

	}
</script>
<style>
	page {
		background-color: #f9f9f9;
	}
</style>
<style scoped lang="less">
	.viewrecordsType {
		height: 100rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.viewrecordsTop {
		display: flex;
		align-items: center;
		// justify-content: space-between;
		margin-top: 32rpx;
		margin-left: 32rpx;
		border-radius: 12rpx 12rpx 12rpx 12rpx;

		.viewdf {
			margin-top: 40rpx;
		}

		>view {
			background-color: #fff;
			width: 336rpx;
			height: 220rpx;
		}

		>view:last-child {
			margin-left: 26rpx;
		}
	}

	.viewrecords {
		padding: 0 28rpx;

		>view {
			margin-top: 32rpx;
			width: 694rpx;
			height: 284rpx;
			background: #FFFFFF;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			padding: 32rpx 16rpx;
			box-sizing: border-box;

			>view:first-child {
				display: flex;
				align-items: center;
				justify-content: space-between;

				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
			}

			>view:last-child {
				width: 622rpx;
				height: 156rpx;
				background: #F9F9F9;
				border-radius: 12rpx 12rpx 12rpx 12rpx;
				margin: 24rpx 16rpx;
				align-items: center;
				display: flex;
				justify-content: space-around;
				text-align: center;
			}
		}
	}

	.status {
		margin: 0 32rpx;
		position: absolute;
		// top: 100%;
		left: 0;
		right: 0;
		z-index: 10;
		background-color: #fff;
	}

	.df {
		display: flex;
		align-items: center;
	}
</style>