<template>
	<view class=" ">
		<cu-custom class="main-totextbar bg-main-oil" :isBack="true" bgColor="bg-main-oil">
			<block slot="backText">返回</block>
			<block slot="content">申请开发票</block>
		</cu-custom>
		<view class="bg-main-oil padding-bottom-xl  padding">
			<view class="ext-center text-lg padding-sm ">
				开票金额 ：{{realAmount}}
			</view>
		</view>
		<view
			class="text-center shadow radius move-top bg-gray margin margin-top-0 margin-bottom-sm  bg-white  text-bold text-xl padding-lg">
			<view class="Invoicing-header">
				<view class="Invoicing-header-text text-df">
					开票信息
				</view>
			</view>
			<uni-forms ref="form" :rules="rules">
				<uni-forms-item label="" class='cu-form-group fixed-group' name="">
					<view class="  text-df">发票类型</view>
					<view class=" text-df margin-left-lg"> 普通电子发票 </view>
				</uni-forms-item>
				<uni-forms-item label="" class='cu-form-group fixed-group' name="">
					<view class="   text-df">抬头类型</view>
					<view class=" text-df margin-left-lg"> 企业 </view>
				</uni-forms-item>
				<uni-forms-item label="" class='cu-form-group' name="">
					<view class="   text-df">发票抬头</view>
					<input placeholder="请输入发票抬头" name="input" class=" text-df  text-left margin-left-lg"
						v-model="Invoicing.invoicName"></input>
				</uni-forms-item>
				<uni-forms-item label="" class='cu-form-group' name="">
					<view class="  text-df margin-right-lg">税 号</view>
					<input placeholder="请输入税号" name="input" class=" text-df  text-left margin-left-xl"
						v-model="Invoicing.invoicTaxIdentiNumber"></input>
				</uni-forms-item>
				<uni-forms-item label="" class='cu-form-group' name="">
					<view class=" text-df">公司地址</view>
					<input placeholder="请输入公司地址" name="input" class=" text-df  text-left margin-left-lg"
						v-model="Invoicing.invoicAddress"></input>
				</uni-forms-item>
				<uni-forms-item label="" class='cu-form-group' name="">
					<view class="  text-df">电话号码</view>
					<input placeholder="请输入电话号码" name="input" class=" text-df  text-left margin-left-lg"
						v-model="Invoicing.invoicTel"></input>
				</uni-forms-item>
				<uni-forms-item label="" class='cu-form-group' name="">
					<view class="   text-df">开户银行</view>
					<input placeholder="请输入开户银行" name="input" class=" text-df  text-left margin-left-lg"
						v-model="Invoicing.invoicOpenBank"></input>
				</uni-forms-item>
				<uni-forms-item label="" class='cu-form-group' name="">
					<view class="   text-df">银行账号</view>
					<input placeholder="请输入银行账号" name="input" class=" text-df  text-left margin-left-lg"
						v-model="Invoicing.invoicBankNumber"></input>
				</uni-forms-item>
				<uni-forms-item label="" class='cu-form-group' name="">
					<view class="   text-df">发票备注</view>
					<input placeholder="请输入发票备注" name="input" class=" text-df  text-left margin-left-lg"
						v-model="Invoicing.remark"></input>
				</uni-forms-item>
			</uni-forms>
		</view>
		<view class="text-center shadow radius  margin  bg-white  text-bold text-xl padding-lg">
			<view class="Invoicing-header">
				<view class="Invoicing-header-text text-df">
					接收信息
				</view>
			</view>
			<uni-forms ref="form" :rules="rules">
				<uni-forms-item label="" class='cu-form-group' name="">
					<view class=" text-df">电子邮箱</view>
					<input placeholder="请输入电子邮箱" name="input" class="text-df  text-left margin-left-lg"
						v-model="Invoicing.invoicEmail"></input>

				</uni-forms-item>
				<view class="text-xs text-left padding-left-sm  text-red">
					请仔细核验邮箱号是否正确
				</view>
			</uni-forms>
		</view>
		<view class="btn-box">
			<view class="cu-btn width-50 text-lg height-80 padding text-center" @tap="backtodetail">
				取消
			</view>
			<view @tap="saveInvoicRecord"
				class="cu-btn width-50 text-lg height-80 padding text-center bg-blue text-white">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	import financelApi from '@/api/oil-finance.js'

	export default {
		data() {
			return {
				code: 0,
				realAmount: null,
				InvoiceType: '普通电子发票',
				InvoiceHeader: '企业',
				orderId: '',
				Invoicing: { //发票信息
					customerId: '',
					invoicName: '', //发票抬头
					invoicTaxIdentiNumber: '', //税号
					invoicAddress: '', //公司地址
					invoicTel: '', //公司电话号码
					invoicOpenBank: '', //开户银行
					invoicBankNumber: '', //银行账号
					remark: '', //发票备注
					invoicEmail: '', //电子邮箱,
					orderSerialNumber: '' ,//订单编号,
					"clientBelong":"ZHONGPIN",
					
				}
			}
		},
		onLoad(options) {
			console.log(options);
			
			this.Invoicing.orderSerialNumber = options.orderId
			this.orderId = options.orderId
			this.Invoicing.customerId = options.customerId
			let realAmount = options.payRealAmount 
			console.log(realAmount,'++++++++++++')
			this.code = options.code
			if (options.code == 2) {
				this.getchange(realAmount)
			} else if (options.code == 1) {
				this.realAmount = realAmount
			}

		},
		methods: {
			backtodetail() {
				uni.switchTab({
					url: '../../pages/tabbar/order/orderList/orderList'
				})
			},
			getchange(realAmount) {
				console.log(realAmount)
				let _that = this
				financelApi.getRecordByOrderId(this.orderId).then((res) => {
					console.log('这里是修改处')
					console.log(res)
					_that.realAmount = parseFloat(realAmount)
					console.log(_that.realAmoun)
					_that.Invoicing = res.data
				})
			},
			saveInvoicRecord() {
				console.log(this.code)
				if (this.code == 1) {
					console.log('这里是发布')
					console.log(this.Invoicing)
					financelApi.save( Object.assign(this.Invoicing,{invoicAmount:this.realAmount}) ).then((res) => {
						if (res.code == 20000) {
							if (res.data != null && res.data.remark != null) {
								uni.showToast({
									title: res.data.remark,
									icon: 'none'
								})
								return
							}
							uni.navigateTo({
								url: '/BagStation/InvoiceProgress/InvoiceProgress?orderId=' + this
									.Invoicing.orderSerialNumber
							})
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}

					})
				} else if (this.code == 2) {
					console.log('这里是更新')
					financelApi.orderUpdate(Object.assign(this.Invoicing,{invoicAmount:this.realAmount})).then((res) => {
						console.log(res)
						if (res.code == 20000) {
							if (res.data != null && res.data.remark != null) {
								uni.showToast({
									title: res.data.remark,
									icon: 'none'
								})
								return
							}
							uni.navigateTo({
								url: '/BagStation/InvoiceProgress/InvoiceProgress?orderId=' + this
									.Invoicing.orderSerialNumber
							})
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})
				}

			}
		}
	}
</script>

<style>
	.fixed-group {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	. {
		font-weight: 100;
	}

	.btn-box {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.Invoicing-header {
		border-bottom: 2upx solid #efefef;
		padding-bottom: 2%;
		padding-left: 2%;
	}

	.Invoicing-header-text {
		border-left: 6upx solid #007AFF;
		text-align: left;
		color: #333333;
		padding-left: 2%;
	}

	.move-top {
		margin-top: -2rem;
	}

	.width-50 {
		width: 50%;
		flex: 0 0 auto;
	}

	.height-80 {
		height: 80upx;
	}
</style>
