<template>
	<view class="pages">
		<view class="" :style="{height: navHeight+'px' }"></view>
		<view class="navbar-box">
			<u-navbar title="开票详情" :safeAreaInsetTop="true" @leftClick="leftClick" :titleStyle="{color:'#fff'}" leftIconColor="#fff" bgColor="#EF1818"></u-navbar>
		</view>
		<view class="page-wrap">
			<view class="block-wrap">
				<view class="title">开票详情</view>
				<!-- <view class="item u-flex">
					<view class="left">抬头类型 </view>
					<view class="right">{{抬头类型 }}</view>
				</view> -->
				<view class="item u-flex" v-for="(item,index) in detailsInfo[details.handlerType]" :key="index">
					<view class="left">{{item.name}}</view>
					<view class="con">
						<text v-if="item.key=='handlerType'">{{details[item.key]|filterHandlerType}}</text>
						<text :style="{color:details.status>2?'#EF0E0E':'#6CC079'}" class="status" v-else-if="item.key=='status'">{{details[item.key]|filterInvoiceState}}</text>
						<text v-else-if="item.key=='invoiceAmount'">￥ {{details[item.key]}}</text>
						<text v-else>{{details[item.key]}}</text>
					</view>
				</view>
				<view class="item u-flex" v-if="details.status>2">
					<view class="left">失败原因</view>
					<view class="con">
						{{details.errReason}}
					</view>
				</view>
			</view>
		</view>
		<view class="page-bottom" v-if="details.status===3">
			<view class="inner">
				<view class="btn active" v-if="cansubmit" @click="submitorder">重新开票</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { systemInfo } from "@/mixin.js";
	export default {
		mixins: [systemInfo], // 使用mixin
		data() {
			return {
				staticUrl:this.$commonConfig.staticUrl,
				orderId:'',
				details:{},
				detailsInfo:{//1:个人,2:企业
					1:[
						{name:'抬头类型',key:'handlerType'},
						{name:'抬头名称',key:'name'},
						// {name:'税    号',key:'creditCode'},
						{name:'开票金额 ',key:'invoiceAmount'},
						{name:'电子邮箱 ',key:'email'},
						{name:'开具状态 ',key:'status'},
					],
					2:[
						{name:'抬头类型',key:'handlerType'},
						{name:'抬头名称',key:'name'},
						{name:'税    号',key:'creditCode'},
						{name:'开票金额 ',key:'invoiceAmount'},
						{name:'电子邮箱 ',key:'email'},
						{name:'开具状态 ',key:'status'},
						// {name:'失败原因 ',key:'errReason'}
					],
				},
				cansubmit:true,
				formData:{
					orderId:'',
					invoiceAmount:'',
					invoiceHandler:{
						handlerType:'',
						name:'',
						email:''
					}
					
				}
			}
		},
		onShow() {
			if(this.orderId){
				this.getInvoiceDetail();
			}
		},
		onLoad(page) {
			this.orderId = page.id;
			this.getSystemInfo();
		},
		methods: {
			leftClick(e){
				let pages = getCurrentPages();
				if(pages.length==1){
					uni.$u.route('/pages/index/index')
				}else{
					uni.navigateBack()
				};
			},
			getInvoiceDetail(){
				this.$u.api.getInvoiceDetail({orderId:this.orderId}).then(res=>{
					// console.log('res',res);
					this.details = res.data;
				}).catch(err=>{
					console.log('getInvoiceInfo',err);
				})
			},
			submitorder(){
				uni.redirectTo({
					url: `/center/invoice?id=${this.orderId}`
				})
				return
				// this.formData.orderId =this.details.orderId;
				// this.formData.invoiceAmount = this.details.invoiceAmount;
				// this.formData.invoiceHandler.handlerType = this.details.handlerType;
				// this.formData.invoiceHandler.name = this.details.name;
				// this.formData.invoiceHandler.email = this.details.email;
				// if(this.details.handlerType===2){//企业
				// 	this.formData.invoiceHandler.creditCode = this.details.creditCode;
				// }
				// this.$u.api.submitInvoice(this.formData).then(res=>{
				// 	uni.$u.toast(res.msg)
				// 	// uni.navigateBack()
				// 	setTimeout(()=>{
				// 		uni.redirectTo({
				// 			url: `/center/orderdetails?id=${this.orderId}`
				// 		})
				// 	},1500)
				// }).catch(err=>{
				// 	console.log('submitorder',err);
				// })
			}

		}
	}
</script>
<style>
	page{background-color: #F7F7F9;}
</style>
<style lang="scss" scoped>
.block-wrap{
	background-color: #fff;
	border-radius: 16rpx;
	padding: 30rpx 32rpx 30rpx;
	margin-bottom: 24rpx;
	.title{
		font-size: 28rpx;
		font-weight: 500;
		color: #363636;
		margin-bottom: 28rpx;
	}
	.item{
		margin-bottom: 12rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #363636;
		line-height: 40rpx;
		.left{
			color: #999999;
			width: 184rpx;
		}
	}
}
.page-bottom{
	$height:98rpx;
	position: relative;
	z-index: 1001;
	height: $height;
	padding: 24rpx 20rpx;
	.inner{
		position: fixed;
		background-color: transparent;
		height: $height;
		left: 0;
		right: 0;
		bottom: 0;
		padding: 24rpx 20rpx;
		// box-shadow: 0rpx -4rpx 12rpx 0rpx rgba(215,215,215,0.5);
		.btn{
			font-size: 28rpx;
			height: 100%;
			line-height: $height;
			border-radius: 50rpx;
			padding: 0 50rpx;
			background-color: #eee;
			color: #333;
			text-align: center;
			&.active{
				background: linear-gradient(90deg, #FF7979 0%, #ED0000 100%);
				color: #fff;
			}
		}
	}
}
</style>