<template>
	<view class="warehousingDtl">
		<view class="header-banner">
			<view @click="headerNavType = 1" :class="headerNavType == 1 ? 'active' : ''">
				面料
			</view>
			<view  @click="headerNavType = 2" :class="headerNavType == 2 ? 'active' : ''">
				墨水
			</view>
		</view>
		<commons-select-time @change="timeInit" v-model="req"></commons-select-time>
		<view  v-if="headerNavType == 2">
			<view class="commons-title">
				<view class="">
					领料详情
				</view>
			</view>
			<view style="margin: 0 30rpx;font-size: 12rpx;">
				<uni-table border stripe emptyText="暂无更多数据">
					<!-- 表头行 -->
					<uni-tr>
						<uni-th width="90rpx" align="left"></uni-th>
						<uni-th width="150rpx" align="left">件</uni-th>
						<uni-th width="150rpx" align="left">公斤</uni-th>
						<uni-th width="150rpx" align="left">金额</uni-th>
					</uni-tr>
					<!-- 表格数据行 -->
					<uni-tr>
						<uni-td><view class="pa-bg-2">合计</view>1</uni-td>
						<uni-td><view class="pa-bg-2">{{selectInkEWDetailsData.total}}</view></uni-td>
						<uni-td><view class="pa-bg-2">{{selectInkEWDetailsData.amountQuantity}}</view></uni-td>
						<uni-td><view class="pa-bg-2">{{selectInkEWDetailsData.amountTotal}}</view></uni-td>
					</uni-tr>
					<uni-tr v-for="(i,index) in selectInkEWDetailsData.details" :key="index">
						<uni-td>{{i.nickName}}</uni-td>
						<uni-td>{{i.count}}</uni-td>
						<uni-td>{{i.changeNum}}</uni-td>
						<uni-td>{{i.amount}}</uni-td>
					</uni-tr>
				</uni-table>
			</view>
		</view>
		<view v-if="headerNavType == 1">
			<view class="commons-title">
				<view class="">
					领料详情
				</view>
				<view>
					<uni-data-checkbox v-model="companyType" :localdata="companyList" />
				</view>
			</view>
			<view style="margin: 0 30rpx;font-size: 24rpx;">
				<uni-table border stripe emptyText="暂无更多数据" >
					<!-- 表头行 -->
					<uni-tr>
						<uni-th width="90rpx" align="left"></uni-th>
						<uni-th width="150rpx" align="left">领料</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">产出比</uni-th>
						<uni-th width="150rpx" align="left">排班</uni-th>
					</uni-tr>
					<!-- 表格数据行 -->
					<uni-tr>
						<uni-td><view class="pa-bg-2">合计</view>1</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left"><view class="pa-bg-2">{{totalData.amountTotal}}</view></uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left"><view class="pa-bg-2">{{totalData.total}}</view></uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left"><view class="pa-bg-2">{{totalData.amountQuantity}}</view></uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left"><view class="pa-bg-2">{{totalData.square}}</view></uni-th>
						<uni-th
							v-if="companyType == 3" 
							width="150rpx"  
							align="left">
							<div class="pa-bg-2">
								{{((totalData.amountQuantity / (totalData.square - totalData.totalReturnMaterial))*100 || 0).toFixed(3)}}%
							</div>
						</uni-th>
						<uni-th width="150rpx" align="left"><view class="pa-bg-2">{{companyType == 3 ? totalData.quantity : '-'}}</view></uni-th>
						<!-- <uni-th width="150rpx" align="left"><view class="pa-bg-2">{{companyType == 4 ? totalData.outputRatio : '-'}}</view></uni-th> -->
						
					</uni-tr>
					<uni-tr>
						<uni-td><view class="pa-bg">打纸</view>1</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left"><view class="pa-bg">{{totalData.beatingAmountTotal}}</view></uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left"><view class="pa-bg">{{totalData.beatingTotal}}</view></uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left"><view class="pa-bg">{{totalData.beatingAmountQuantity}}</view></uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left"><view class="pa-bg">{{totalData.beatingSquare}}</view></uni-th>
						<uni-th
							v-if="companyType == 3" 
							width="150rpx"  
							align="left">
							<div class="pa-bg">
								{{((totalData.beatingAmountQuantity / (totalData.beatingSquare - totalData.beatingReturnMaterial))*100 || 0).toFixed(3)}}%
							</div>
						</uni-th>
						<uni-th width="150rpx" align="left"><view class="pa-bg">{{companyType == 3? totalData.beatingQuantity : '-'}}</view></uni-th>
					</uni-tr>
					<uni-tr v-for="i in totalData.beatingDetails" :key="i.nickName">
						<uni-td>{{i.nickName}}</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left">{{i.amount}}</uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left">{{i.count}}</uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left">{{i.changeNum}}</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">{{i.square}}</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">{{(i.quantity / (i.square - i.returnMaterial)*100).toFixed((3))}}%</uni-th>
						
						<uni-th width="150rpx" align="left">{{companyType == 3? i.quantity : '-'}}</uni-th>
					</uni-tr>
					<uni-tr>
						<uni-td><view class="pa-bg">热转</view>1</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left"><view class="pa-bg">{{totalData.heatAmountTotal}}</view></uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left"><view class="pa-bg">{{totalData.heatTotal}}</view></uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left"><view class="pa-bg">{{totalData.heatAmountQuantity}}</view></uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left"><view class="pa-bg">{{totalData.heatSquare}}</view></uni-th>
						<uni-th
							v-if="companyType == 3" 
							width="150rpx"  
							align="left">
							<div class="pa-bg">
								{{((totalData.heatAmountQuantity / (totalData.heatSquare - totalData.heatReturnMaterial)*100) || 0).toFixed(3)}}%
							</div>
						</uni-th>
						<uni-th width="150rpx" align="left"><view class="pa-bg">{{companyType == 3 ? totalData.heatQuantity : '-'}}</view></uni-th>
					</uni-tr>
					<uni-tr v-for="i in totalData.heatDetails" :key="i.nickName">
						<uni-td>{{i.nickName}}</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left">{{i.amount}}</uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left">{{i.count}}</uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left">{{i.changeNum}}</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">{{i.square}}</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">{{(i.quantity / (i.square - i.returnMaterial)*100).toFixed((3))}}%</uni-th>
						<uni-th width="150rpx" align="left">{{companyType == 3? i.quantity : '-'}}</uni-th>
					</uni-tr>
					<uni-tr>
						<uni-td><view class="pa-bg">直喷</view>1</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left"><view class="pa-bg">{{totalData.directAmountTotal}}</view></uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left"><view class="pa-bg">{{totalData.directTotal}}</view></uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left"><view class="pa-bg">{{totalData.directAmountQuantity}}</view></uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left"><view class="pa-bg">{{totalData.directSquare}}</view></uni-th>
						<uni-th
							v-if="companyType == 3" 
							width="150rpx"  
							align="left">
							<div class="pa-bg">
								{{((totalData.directAmountQuantity / (totalData.directSquare - totalData.directReturnMaterial)*100) || 0).toFixed(3)}}%
							</div>
						</uni-th>
						<uni-th width="150rpx" align="left"><view class="pa-bg">{{companyType == 3 ? totalData.directQuantity : '-'}}</view></uni-th>
					</uni-tr>
					<uni-tr v-for="i in totalData.directDetails" :key="i.nickName">
						<uni-td>{{i.nickName}}</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left">{{i.amount}}</uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left">{{i.count}}</uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left">{{i.changeNum}}</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">{{i.square}}</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">{{(i.quantity / (i.square - i.returnMaterial)*100).toFixed((3))}}%</uni-th>
						<uni-th width="150rpx" align="left">{{companyType == 3? i.quantity : '-'}}</uni-th>
					</uni-tr>
					<uni-tr>
						<uni-td><view class="pa-bg">其他</view>1</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left"><view class="pa-bg">{{totalData.otherAmountTotal}}</view></uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left"><view class="pa-bg">{{totalData.otherTotal}}</view></uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left"><view class="pa-bg">{{totalData.otherAmountQuantity}}</view></uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left"><view class="pa-bg">{{totalData.otherSquare}}</view></uni-th>
						<uni-th 
							v-if="companyType == 3" 
							width="150rpx"  
							align="left">
							<div class="pa-bg">
								{{((totalData.otherQuantity / (totalData.otherSquare - totalData.otherReturnMaterial)*100) || 0).toFixed(3)}}%
							</div>
						</uni-th>
						<uni-th width="150rpx" align="left"><view class="pa-bg">{{companyType == 3? totalData.otherQuantity : '-'}}</view></uni-th>
					</uni-tr>
					<uni-tr v-for="i in totalData.otherDetails" :key="i.nickName">
						<uni-td>{{i.nickName}}</uni-td>
						<uni-th v-if="companyType == 0" width="150rpx" align="left">{{i.amount}}</uni-th>
						<uni-th v-if="companyType == 1" width="150rpx" align="left">{{i.count}}</uni-th>
						<uni-th v-if="companyType == 2" width="150rpx" align="left">{{i.changeNum}}</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">{{i.square}}</uni-th>
						<uni-th v-if="companyType == 3" width="150rpx" align="left">{{(i.quantity / (i.square - i.returnMaterial)).toFixed(3)}}</uni-th>
						<uni-th width="150rpx" align="left">{{companyType == 3? i.quantity : '-'}}</uni-th>
					</uni-tr>
				</uni-table>
			</view>
		</view>
	</view>
</template>

<script>
	import commonsSelectTime from '../../components/commons-select-time/index.vue'
	import {
	    getInfo
	} from "@/util/api.js";
	export default {
		components:{
			commonsSelectTime
		},
		data() {
			return {
				companyType:3,
				companyList:[
					{
						text:"金额",
						value:0
					},
					{
						text:"件",
						value:1
					},
					{
						text:"米",
						value:2
					},
					{
						text:"平方",
						value:3
					},
				],
				warehouseList:[{
					text:"全部",
					value:'0'
				},
				{
					text:"一楼",
					value:'1'
				},{
					text:"四楼",
					value:'2'
				}],
				req:{
					type: 0,
					time: [],
					beginTime: null,
					endTime: null,
				},
				headerNavType:1,
				totalData:[],
				selectInkEWDetailsData:[],
				
			}
		},
		onLoad(option) {
			console.log(option.type)
			if(option.type == 2){
				this.headerNavType = 2
			}
			const v = this
			v.timeInit()
		},
		methods: {
			timeInit(){
				const v = this
				v.getSelectInkEWDetails()
				v.getSelectFabricWDetails()
			},
			toRouter(url){
				console.log(123123)
				uni.navigateTo({
					url: '/pages' + url
				})
			},
			getSelectFabricWDetails(){
				const v = this
				v.$post('/applet/selectFabricEWDetails',v.req).then(res=>{
					res.data.otherReturnMaterial = 0
					res.data.directReturnMaterial = 0
					res.data.heatReturnMaterial = 0
					res.data.beatingReturnMaterial = 0
					for (var i = 0; i < res.data.beatingDetails.length; i++) {
						const element = res.data.beatingDetails[i]
						res.data.otherReturnMaterial += element.returnMaterial
					}
					for (var i = 0; i < res.data.directDetails.length; i++) {
						const element = res.data.directDetails[i]
						res.data.directReturnMaterial += element.returnMaterial
					}
					for (var i = 0; i < res.data.heatDetails.length; i++) {
						const element = res.data.heatDetails[i]
						res.data.directReturnMaterial += element.returnMaterial
					}
					for (var i = 0; i < res.data.beatingDetails.length; i++) {
						const element = res.data.beatingDetails[i]
						res.data.beatingReturnMaterial += element.returnMaterial
					}
					res.data.totalReturnMaterial = (res.data.otherReturnMaterial + res.data.directReturnMaterial + res.data.heatReturnMaterial + res.data.beatingReturnMaterial) / 4
					
					v.totalData = res.data
					console.log(v.totalData)
				})
			},
			getSelectInkEWDetails(){
				const v = this
				v.$post('/applet/selectInkEWDetails',v.req).then(res=>{
					v.selectInkEWDetailsData = res.data
				})
			},
			
			
			
		},
	}
</script>

<style lang="less">
	
	.uni-data-checklist{
		margin-top: 10rpx;
		padding:16rpx 10rpx;
	}
	.uni-table-td{
		font-size: 24rpx!important;
	}
	.uni-data-checklist .checklist-group .checklist-box{
		margin-right: 20rpx!important;
	}
	.warehousingDtl {
		background-color: #f1f1f1;
		min-height: 100vh;
		color: #333;
		.header-banner {
			display: flex;
			justify-content: center;
			border-bottom: 1px solid #dcdcdc;
			
			view {
				width: 40%;
				text-align: center;
				height: 100rpx;
				line-height: 100rpx;
				color: #333;
				margin: 0 5%;
			}

			.active {
				color: #487CFF;
				border-bottom: 2px solid #487CFF;
			}
		}

		
	}
</style>
