<template>
	<view class="invoice">
		<view class="invoice_tip">
			<view style="display: flex; align-items: center">
				<up-icon name="error-circle-fill" color="#3c9cff"></up-icon>
				温馨提示：
			</view>
			<view>1.云充电仅为平台方，实际开票主体以下方展示的开票公司为准</view>
			<view>2.若超过20个工作日仍未收到发票，您可以通过(区号)+12366向开票公司所在区域的主管税务机关进行反馈处理</view>
		</view>
		<view style="height: 20rpx"></view>

		<z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
			<view class="invoice_list" v-for="(item, index) in dataList" :key="index">
				<view class="invoice_list_view">
					<view class="invoice_list_view_left" style="display: flex; align-items: center">
						<up-icon name="clock-fill"></up-icon>
						{{item.createTime}}
					</view>
					<up-icon name="arrow-right"></up-icon>
				</view>
				<view class="invoice_list_view">
					<view class="invoice_list_view_left">发票抬头</view>
					<view class="invoice_list_view_right">{{item.invoiceTitle}}</view>
				</view>
				<view class="invoice_list_view">
					<view class="invoice_list_view_left">开票运营商</view>
					<view class="invoice_list_view_right">{{item.merchantInvoice || '-'}}</view>
				</view>
				<view style="border: 1px dashed #eee"></view>
				<view style="height: 20rpx"></view>
				<view style="display: flex; align-items: center; justify-content: space-between">
					<view>
						<up-tag v-if="item.status == 0" text="待开票" type="warning" plain plainFill></up-tag>
						<up-tag v-if="item.status == 1" text="已开票" type="success" plain plainFill></up-tag>
						<up-tag v-if="item.status == -1" text="取消" type="error" plain plainFill></up-tag>
					</view>
					<view style="font-size: 36rpx; font-weight: bold">
						{{item.invoiceAmount}}
						<text style="font-size: 30rpx">元</text>
					</view>
				</view>
			</view>
		</z-paging>
		<view style="height: 150rpx;"></view>
		<view style="position: fixed; bottom: 0; left: 0; width: 750rpx; padding: 20rpx 50rpx; background-color: #fff">
			<up-button @click="navTo('/pageMake/invoice/applyFor')" :customStyle="{ height: '80rpx' }" color="#4879e6" text="申请开票" shape="circle"></up-button>
		</view>
	</view>
</template>

<script setup>
import { onLoad, onShow, onPullDownRefresh, onPageScroll, onReachBottom } from '@dcloudio/uni-app';
import { useNav } from '@/hooks/useNav.js';
import { ref } from 'vue';
const { nav, navTo } = useNav();
import { invoiceList } from '@/api/api.js';
const dataList = ref([]);
const paging = ref(null);

const queryList = async (pageNo, pageSize) => {
	const params = {
		current: pageNo,
		pageSize: pageSize
	};
	invoiceList(params)
		.then((res) => {
			paging.value.complete(res);
			uni.hideLoading();
		})
		.catch((res) => {
			paging.value.complete(false);
			uni.hideLoading();
		});
};

let isPagingRefNotFound = () => {
	return !paging.value;
};

onPullDownRefresh(() => {
	if (isPagingRefNotFound()) return;
	paging.value.reload().catch(() => {});
});

onPageScroll((e) => {
	if (isPagingRefNotFound()) return;
	paging.value.updatePageScrollTop(e.scrollTop);
	e.scrollTop < 10 && paging.value.doChatRecordLoadMore();
});

onReachBottom(() => {
	if (isPagingRefNotFound()) return;
	paging.value.pageReachBottom();
});
</script>

<style scoped lang="scss">
.invoice {
	&_tip {
		padding: 20rpx;
		font-size: 24rpx;
		color: #3c9cff;
		background-color: rgba(60, 156, 255, 0.2);
		view {
			line-height: 40rpx;
		}
	}
	&_list {
		padding: 15rpx 30rpx;
		background-color: #fff;
		&_view {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 28rpx;
			margin-bottom: 25rpx;
			&_left {
				color: #646368;
			}
			&_right {
				color: #262626;
			}
		}
	}
}
</style>
