<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个工作日内寄出</view>
			<view>3.单笔订单只支持开具一种发票类型</view>
			<view>4.云快充仅为平台方，实际开票主体以申请开票时展示的开票运营商公司为准</view>
			<view>5.发票由各家电站运营商提供，一起申请可能会生成多张发票</view>
			<view>6.若超过20个工作日仍未收到发票，您可以通过(区号)+12366向开票公司所在区域的主管税务机关进行反馈处理</view>
		</view>
		<view style="height: 20rpx"></view>

		<view>
			<z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
				<up-checkbox-group v-model="checkboxValue1" placement="column" @change="checkboxChange">
					<view class="invoice_list" style="margin-bottom: 20rpx" v-for="(item, index) in dataList" :key="index">
						<view style="display: flex; align-items: center; font-weight: bold; font-size: 30rpx; margin-bottom: 30rpx">
							<up-checkbox shape="circle" :customStyle="{ margin: '0' }" :name="item.id"></up-checkbox>
							充电单号：{{ item.orderNo }}
						</view>
						<view style="display: flex; align-items: center; justify-content: space-between; background-color: #f6f6f6; border-radius: 15rpx; padding: 20rpx">
							<view style="font-size: 28rpx">
								<view style="margin-bottom: 15rpx">即途展厅</view>
								<view style="margin-bottom: 15rpx">{{item.electricityAmount}}电费</view>
								<view>{{ item.serviceAmount }}服务费</view>
							</view>
							<view style="text-align: right">
								<view style="margin-bottom: 25rpx; font-size: 36rpx; font-weight: bold; color: #4879e6">
									{{ item.actuallyAmount }}
									<text style="font-size: 30rpx">元</text>
								</view>
								<view style="font-size: 28rpx">个人支付</view>
							</view>
						</view>
					</view>
				</up-checkbox-group>
			</z-paging>
		</view>
		<view
			style="
				position: fixed;
				bottom: 0;
				left: 0;
				width: 750rpx;
				padding: 20rpx 50rpx;
				background-color: #fff;
				display: flex;
				align-items: center;
				justify-content: space-between;
			"
		>
			<view style="display: flex; align-items: center">
				<up-checkbox label="本页全选" v-model:checked="allCel" shape="circle" usedAlone @change="allCheck" :customStyle="{ margin: '0 10rpx 0 0' }"></up-checkbox>
			</view>
			<view style="width: 230rpx">
				<up-button
					@click="navTo(`/pageMake/invoice/applyForDay?list=${encodeURIComponent(JSON.stringify(checkboxValue1))}`)"
					:customStyle="{ height: '80rpx', width: '230rpx' }"
					color="#4879e6"
					text="下一步"
					shape="circle"
					:disabled="checkboxValue1.length == 0"
				></up-button>
			</view>
		</view>
	</view>
</template>

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

let checkboxValue1 = ref([]);
const dataList = ref([]);
const paging = ref(null);
let allCel = ref(false);

const allCheck = (e) => {
	if (e) {
		checkboxValue1.value = dataList.value.map((item, index) => {
			return item.id;
		});
	} else {
		checkboxValue1.value = [];
	}
	allCel.value = e;
	console.log(e);
};

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

const checkboxChange = (e) => {
	if (e.length == dataList.value.length) {
		allCel.value = true;
	} else {
		allCel.value = false;
	}
	console.log(e);
};

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>
