<template>
	<view class="my-fapiao">
		<view class="ad-header u-flex">
			<view class="header-item u-flex-1 u-flex u-row-center">
				<view class="item-box u-flex-col u-col-bottom" :class="{'item-box1':current == 1}" @click="changetabs(1)">
					<text>我的发票</text>
					<text></text>
				</view>
			</view>
			<view class="header-item u-flex-1 u-flex u-row-center">
				<view class="item-box u-flex-col u-col-bottom" :class="{'item-box1':current == 2}" @click="changetabs(2)">
					<text>发票抬头</text>
					<text></text>
				</view>
			</view>
		</view>
		<view class="fapiao-list1" v-if="current == 1">
			<view class="list1-item" v-for="(item,index) in list" :key="index" @click="toinfo(item)">
				<view class="list1-top u-flex u-row-between">
					<text>订单编号 {{item.order_no}}</text>
					<text style="color: #F2413A;" v-if="item.status == 1">待开票</text>
					<text style="color: #FF8635;" v-if="item.status == 2">待发送</text>
					<text style="color: #61BF60;" v-if="item.status == 3">待签收</text>
					<text style="color: #61BF60;" v-if="item.status == 4">已签收</text>
				</view>
				<view class="list1-user u-flex">
					<text>{{item.order_resume_name.resume_name.name}}</text>
					<text>/{{item.order_job_name.job_name.job_name}}</text>
				</view>
				<view class="list1-body u-flex u-col-bottom u-row-between">
					<view class="u-flex-col">
						<text class="text1">{{item.invoice_format == 1 ? '纸质发票' : '电子发票'}}-{{item.taitou_type == 1 ? '个人' : '公司'}}</text>
						<text class="text2">抬头名称 {{item.name}}</text>
						<text class="text3">申请时间 {{item.createtime}}</text>
					</view>
					<text class="price">¥{{item.money}}</text>
				</view>
				<view class="list1-down u-flex u-row-right">
					<text v-if="item.status == 3" @click.stop="shoudao(item)">确认收到</text>
					<text v-else style="border: 2rpx solid #A3A3A3;color: #222222;">查看详情</text>
				</view>
			</view>
		</view>
		<view class="fapiao-list2" v-if="current == 2">
			<view class="list2-item" v-for="(item,index) in list" :key="index">
				<view class="list2-top">
					普通发票-{{item.taitou_type == 1 ? '个人' : '公司'}}抬头
				</view>
				<view class="list2-down u-flex u-row-between">
					<text>{{item.name}}</text>
					<image src="static/fapiao-edit.png" @click="toedit(item)" mode=""></image>
				</view>
			</view>
			<view style="height: 130rpx;"></view>
			<view class="safe-area-inset-bottom"></view>
		</view>
		<view style="height: 70vh;" v-if="list.length == 0">
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view>
		<view class="list-down-btn" v-if="current == 2">
			<view class="down-btn u-flex u-row-center">
				<text @click="toadd">添加发票抬头</text>
			</view>
			<view class="safe-area-inset-bottom"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 1,
				page: 1,
				list: [],
				total: 0,
			}
		},
		onShow() {
			this.page = 1
			this.list = []
			this.getlist()
		},
		onReachBottom() {
			if (this.current == 1 && (this.total != this.list.length)) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			shoudao(item) {
				uni.showModal({
					title: "提示",
					content: "确认收到吗？",
					success: (e) => {
						if (e.confirm) {
							uni.showLoading({
								mask: true,
								title: "请稍后"
							})
							this.$u.post('/api/hr.invoice/invoice_receipt', {
								id: item.id
							}).then(res => {
								this.$u.toast(res.msg)
								if (res.code == 1) {
									setTimeout(() => {
										this.page = 1
										this.list = []
										this.getlist()
									}, 800)
								}
							})
						}
					}
				})
			},
			changetabs(type) {
				this.current = type
				this.page = 1
				this.list = []
				this.getlist()
			},
			getlist() {
				if (this.current == 1) {
					this.$u.post('/api/hr.invoice/my_invoice', {
						page: this.page
					}).then(res => {
						this.total = res.data.total
						this.list = this.list.concat(res.data.data)
					})
				} else {
					this.$u.post('/api/hr.invoice/invoice_info').then(res => {
						this.list = res.data
					})
				}
			},
			toadd() {
				uni.navigateTo({
					url: "/pagesD/add-fapiao"
				})
			},
			toinfo(item) {
				uni.navigateTo({
					url: "/pagesD/fapiao-info?id=" + item.id
				})
			},
			toedit(item) {
				uni.navigateTo({
					url: "/pagesD/add-fapiao?id=" + item.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.my-fapiao {
		.list-down-btn {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			z-index: 99;
			background-color: #fff;

			.down-btn {
				padding: 12rpx 0;

				text {
					width: 686rpx;
					line-height: 92rpx;
					background: #0C66C2;
					border-radius: 12rpx;
					text-align: center;
					font-size: 36rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}
			}
		}

		.fapiao-list2 {
			.list2-item {
				width: 702rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				margin: 20rpx auto;
				padding: 0 20rpx;

				.list2-down {
					height: 98rpx;

					text {
						font-size: 32rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #222222;
					}

					image {
						width: 36rpx;
						height: 36rpx;
					}
				}

				.list2-top {
					line-height: 72rpx;
					border-bottom: 2rpx solid #F3F3F3;
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #777777;
				}
			}
		}

		.fapiao-list1 {
			.list1-item {
				width: 686rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				margin: 20rpx auto;
				padding: 0 20rpx;

				.list1-down {
					height: 108rpx;

					text {
						width: 164rpx;
						line-height: 64rpx;
						border-radius: 12rpx;
						border: 1rpx solid #0C66C2;
						text-align: center;
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #0C66C2;
					}
				}

				.list1-body {
					background: #F3F3F3;
					border-radius: 12rpx;
					padding: 20rpx;

					.price {
						font-size: 40rpx;
						font-family: JDZhengHT-Regular, JDZhengHT;
						font-weight: 500;
						color: #222222;
					}

					.text1 {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #1A1C24;
						margin-bottom: 12rpx;
					}

					.text2 {
						font-size: 20rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #777777;
						margin-bottom: 12rpx;
					}

					.text3 {
						font-size: 20rpx;
						font-family: SFPro-Regular, SFPro;
						font-weight: 400;
						color: #777777;
					}
				}

				.list1-user {
					height: 78rpx;

					text:first-child {
						font-size: 28rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
						margin-right: 12rpx;
					}

					text:last-child {
						font-size: 22rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #555555;
					}
				}

				.list1-top {
					height: 72rpx;
					border-bottom: 2rpx solid #F3F3F3;

					text:first-child {
						font-size: 22rpx;
						font-family: SFPro-Regular, SFPro;
						font-weight: 400;
						color: #777777;
					}

					text:last-child {
						font-size: 24rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;

					}
				}
			}
		}

		.ad-header {
			position: sticky;
			top: 0;
			left: 0;
			z-index: 99;
			background-color: #fff;
			height: 80rpx;

			.header-item {
				.item-box {
					text:first-child {
						font-size: 30rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #444444;
					}

					text:last-child {
						width: 44rpx;
						height: 8rpx;
						border-radius: 4rpx;
						margin-top: -14rpx;
						position: relative;
						z-index: -1;
					}
				}

				.item-box1 {
					text:first-child {
						font-size: 30rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #141414;
					}

					text:last-child {
						background: linear-gradient(270deg, #0C66C2 0%, #FFFFFF 100%);
					}
				}
			}
		}
	}

	page {
		background-color: #F3F3F3;
	}
</style>