<template>
	<movable-area style="width: auto;height: auto;" :scale="true" :out-of-bounds="true">
		<movable-view :x="x" :y="y" direction="all" :scale="true" style="width: 100%;height: auto;" :out-of-bounds="true">
			<view style="margin: 25rpx 25rpx 75rpx 25rpx;">
				<view style = "text-align: center;font-size: 43rpx; margin-bottom:10rpx">国电投国际贸易（北京）有限公司<br>境内付款申请及确认单 </view>
				<view style = "margin-bottom:10rpx;text-align: right;">编号：{{form.number}}</view>
				<view style = "margin-bottom:10rpx;text-align: center;">日期：{{form.date}}</view>
				<view class="h-table" :style = "tableFontSize">
					<view class="h-tr h-tr-8">
						<view class="h-td">客户信息</view>
						<view class="h-td h-td-colspan">{{form.stockType=='00'?form.buyName:form.companyName}}</view>
					</view>
					<view class="h-tr h-tr-8">
						<view class="h-td">货源单位</view>
						<view class="h-td h-td-colspan"></view>
					</view>
					<view class="h-tr h-tr-8">
						<view class="h-td">合同号</view>
						<view class="h-td h-td-colspan">{{form.contractNo}}</view>
						<view class="h-td">合同总额</view>
						<view class="h-td">{{(!!form.original)?form.original:form.localAmt}}</view>
						<view class="h-td">已结金额</view>
						<view class="h-td">{{form.payedAmt}}</view>
					</view>
					<view class="h-tr h-tr-8">
						<view class="h-td">仓库名称</view>
						<view class="h-td h-td-colspan">{{form.wareName}}</view>
						<view class="h-td">备注</view>
						<view class="h-td h-td-colspan">{{form.remark}}</view>
					</view>
					<view class="h-tr h-tr-8">
						<view class="h-td h-td-colspan h-td-left">本次结算明细：</view>
					</view>
					<view class="h-tr h-tr-8">
						<view class="h-td">商品名称</view>
						<view class="h-td">发票份数</view>
						<view class="h-td">规格型号</view>
						<view class="h-td">数量</view>
						<view class="h-td">含税单价</view>
						<view class="h-td">不含税金额</view>
						<view class="h-td">税额</view>
						<view class="h-td">价税合计</view>
					</view>
					<view class="h-tr h-tr-8" v-for="(item, index) in dataArray" :key="item.id">
						<view class="h-td">{{item.proName}}</view>
						<view class="h-td">{{item.invoiceNum}}</view>
						<view class="h-td">{{item.value}}</view>
						<view class="h-td">{{item.weight}}</view>
						<view class="h-td">{{item.afbsrPrice}}</view>
						<view class="h-td">{{item.excludingTax}}</view>
						<view class="h-td">{{item.tax}}</view>
						<view class="h-td">{{item.amount}}</view>
					</view>
					<view class="h-tr h-tr-8">
						<view class="h-td">合计</view>
						<view class="h-td">{{AllinvoiceNum}}</view>
						<view class="h-td"></view>
						<view class="h-td">{{Allweight}}</view>
						<view class="h-td"></view>
						<view class="h-td">{{AllexcludingTax}}</view>
						<view class="h-td">{{Alltax}}</view>
						<view class="h-td">{{Allamount}}</view>
					</view>
					<view class="h-tr h-tr-8">
						<view class="h-td">经办人</view>
						<view class="h-td h-td-colspan">{{form.createName}}</view>
						<view class="h-td">部门复核</view>
						<view class="h-td h-td-colspan">{{sessionName}}</view>
					</view>
					<view class="h-tr h-tr-8">
						<view class="h-td">财务确认</view>
						<view class="h-td h-td-colspan"></view>
						<view class="h-td">财务签收</view>
						<view class="h-td h-td-colspan"></view>
					</view>
				</view>
				<view style = "margin-bottom:10rpx;margin-top:10rpx;text-align: left;">注：本单据一式两份，财务部和业务部各执一份 </view>
			</view>
		</movable-view>
	</movable-area>
</template>

<script>
	export default {
		props:["businessKey"],
		data(){
			return{
				form : {},
				dataArray : [],
				AllinvoiceNum : '0',
				Allweight : '0',
				AllexcludingTax : '0',
				Alltax : '0',
				Alltax : '0',
				sessionName : '',
				x: 0,
				y: 0,
				tableFontSize : 'font-size:22rpx'
			}
		},
		beforeMount() {
			let self = this;
			this.admRequest({
				action : 'FinanceManageAction/financeDetail',
				data : {
					id : self.businessKey
				},
				success(res){
					let dataArray = res.data.data;
					self.sessionName = res.data.sessionName;
					if (dataArray.length > 0) {
						self.form = dataArray[0];
					}
					self.dataArray = dataArray;
					for (let d of dataArray) {
						self.AllinvoiceNum = self.accAdd(self.AllinvoiceNum, d.invoiceNum, 0);
						self.Allweight = self.accAdd(self.Allweight, d.weight, 4);
						self.AllexcludingTax = self.accAdd(self.AllexcludingTax, d.excludingTax, 2);
						self.Alltax = self.accAdd(self.Alltax, d.tax, 2);
						self.Allamount = self.accAdd(self.Allamount, d.amount, 2);
					}
				}
			})
			// 竖屏
			if (uni.getSystemInfoSync().screenHeight > uni.getSystemInfoSync().screenWidth) {
				this.tableFontSize = 'font-size:22rpx';
			} else {
				this.tableFontSize = 'font-size:15rpx';
			}
		},
		methods:{
			accAdd(arg1, arg2,pointWs) {
			    var r1, r2, max;
			    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
			    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
			    max = Math.pow(10, Math.max(r1, r2));
			    if (!pointWs) {
			    	return ((arg1 * max + arg2 * max) / max) + "";
			    } else {
			    	if (!arg1) {
			    		arg1 = 0;
			    	}
			    	if (!arg2) {
			    		arg2 = 0;
			    	}
			    	arg1 = parseFloat(arg1);
			    	arg2 = parseFloat(arg2);
			    	return this.fomatFloat((arg1 + arg2), pointWs);
			    }
			},
			fomatFloat(num,n){
				if (!n) {
					n = 2;
				}
			    var f = parseFloat(num);
			    if(isNaN(f)){
			        return num;
			    } 
			    var start = "";
				if (f < 0) {
					start = "-";
				}
				f = Math.abs(f);
			    f = Math.round(f*Math.pow(10, n))/Math.pow(10, n); // n 幂   
			    var s = f.toString();
			    var rs = s.indexOf('.');
			    //判定如果是整数，增加小数点再补0
			    if(rs < 0){
			        rs = s.length;
			        s += '.'; 
			    }
			    while(s.length <= rs + n){
			        s += '0';
			    }
			    s = start + s;
			    return s;
			},
			getCallBackData(){
				let data = {};
				data.param = {approvalName : this.sessionName};
				data.callBackUrl = "FlowableApiAction/payBackDeal";
				return data;
			}
		}
	}
</script>

<style lang="scss">
	/* 引入表格样式表 */
	@import "@/static/css/helang-table.scss";
</style>
