<template>
	<view class="invoice">
		<view class="invoice-bd">
			<view class="item" :class="tabIndex == index?'item-on':''" v-for="(item,index) in invoicList" :key="index">
				<view class="hd">
					<view class="l" @click="toDetail(item.id,item)">
						<view class="a">
							<text>{{item.source==2?'单位':'个人'}}</text>{{item.header}}
						</view>
						<view class="b">
							<text>税号</text>{{item.duty_no}}
						</view>
					</view>
					<view class="r" @click.stop="onUse(item)">使用</view>
				</view>
				<view class="bd">
					<view class="c" @click.stop="selectItem(index,item.id)">
						<u-icon :name="tabMo == index?'checkmark-circle-fill':'checkmark-circle'" :color="tabMo == index?'#E02E24':'#999'" customStyle="margin-right:6rpx" size="45"></u-icon>
						{{tabMo == index?'已设为默认':'设为默认'}}
					</view>
					<view class="d">
						<text @click.stop="toDetail(item.id,item)">编辑</text>
						<text @click.stop="onDel(item.id)">删除</text>
					</view>
				</view>
			</view>
		</view>
		<view class="invoice-fd" @click="onAddInvoice">
			<text>+</text>添加发票抬头
		</view>
	</view>
</template>

<script>
	import Empty from '@/components/empty'
	import * as InvoiceApi from '@/api/invoice'
	export default {
		data() {
			return {
				isLoading: false,
				tabIndex: 1,
				isShow: true,
				invoicList: [],
				orderId: '',
				tabMo:0
			};
		},
		onLoad(op) {
			this.orderId = op.orderId
			this.getMyInvoicing()
		},
		methods: {
			// 确认收货
			onDel(Id) {
				const app = this
				uni.showModal({
					title: '友情提示',
					content: '确认删除了吗?',
					success(o) {
						if (o.confirm) {
							InvoiceApi.invoicingDelNew({id:Id})
								.then(result => {
									// 显示成功信息
									app.$success(result.message)
									// 刷新订单列表
									app.getMyInvoicing()
								})
						}
					}
				});
			},
			getMyInvoicing() {
				let app = this;
				InvoiceApi.myInvoicing()
					.then(result => {
						app.invoicList = result.data.list

					})
			},
			selectItem(i, Id) {
				this.tabMo = i
			},
			onUse(item) {
				uni.redirectTo({
					url: "/pages/invoice/edit?detail=" + JSON.stringify(item) + '&source=' + 1 + '&orderId=' + this.orderId
				})
			},
			toDetail(id,item) {
				uni.navigateTo({
					url: "/pages/invoice/editset?id=" + id+'&detailObj='+JSON.stringify(item)
				})
			},
			onAddInvoice() {
				uni.navigateTo({
					url: "/pages/invoice/editset"
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.invoice {
		padding: 0 0 30rpx;
		overflow: hidden;

		&-bd {
			overflow: hidden;

			.item {
				padding: 10rpx 14rpx 10rpx 60rpx;
				box-sizing: border-box;
				overflow: hidden;
				margin-top: 20rpx;
				background-color: #FFFFFF;

				&:first-child {
					margin-top: 0;
				}

				.hd {
					display: flex;
					align-items: center;
					justify-content: space-between;
					overflow: hidden;
					border-bottom: 1px solid #F3F3F3;

					.a {
						padding-top: 15rpx;
						display: flex;
						align-items: center;
						font-size: 32rpx;
						font-weight: 400;
						color: #262626;

						text {
							width: 98rpx;
							height: 44rpx;
							background: #FDF4F4;
							border-radius: 8rpx;
							text-align: center;
							display: block;
							margin-right: 30rpx;
							font-size: 32rpx;
							font-weight: 500;
							color: #E02E24;
							line-height: 44rpx;
						}
					}

					.b {
						padding: 20rpx 0;
						font-size: 32rpx;
						font-weight: 400;
						color: #838383;

						text {
							color: #262626;
							margin-right: 30rpx;
						}
					}

					.r {
						width: 104rpx;
						height: 60rpx;
						background: #FFFFFF;
						border-radius: 4rpx;
						text-align: center;
						line-height: 60rpx;
						border: 1px solid #CACACA;
						font-size: 28rpx;
						font-weight: 400;
						color: #555555;
					}
				}

				.bd {
					padding: 20rpx 0;
					overflow: hidden;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.c {
						flex: 1;
						display: flex;
						align-items: center;
						font-size: 32rpx;
						font-weight: 400;
						color: #A2A2A2;

						image {
							width: 40rpx;
							height: 40rpx;
							margin-right: 30rpx;
						}
					}

					.d {
						width: 200rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #B8B8B8;

						text {
							margin-left: 30rpx;
							cursor: pointer;
						}
					}
				}

				&-on {
					.bd .c {
						color: #E02E24;
					}
				}
			}

		}

		&-fd {
			width: 664rpx;
			height: 104rpx;
			background: #F55349;
			border-radius: 8rpx;
			text-align: center;
			margin: 0 auto;
			margin-top: 30rpx;
			font-size: 32rpx;
			font-weight: 500;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;

			text {
				font-size: 60rpx;
				margin-right: 14rpx;
				margin-top: -5px;
			}
		}
	}
</style>