<template>
	<view class="p30 piles">
		<z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
			<view class="piles_card">
				<view class="piles_card_title">充电桩汇总</view>
				<view class="piles_card_view">
					<view>
						<text>{{ count.installCount || 0 }}</text>
						<text>已安装</text>
					</view>
					<view>
						<text>{{ count.installNotCount || 0 }}</text>
						<text>未安装数量</text>
					</view>
					<view>
						<text>0</text>
						<text>团队</text>
					</view>
				</view>
			</view>
			<up-subsection :list="list" keyName="name" :current="current" @change="upChange"></up-subsection>

			<view class="order_view" v-for="i in dataList" :key="i">
				<view class="piles_list" v-if="current == 0">
					<view class="piles_list_title">安装电站：{{ i.stationName || '-' }}</view>
					<view class="piles_list_view">
						<view>设备ID：</view>
						<view>{{ i.id }}</view>
					</view>
					<view class="piles_list_view">
						<view>设备功率：</view>
						<view>{{ i.deviceType }}KW</view>
					</view>
					<view class="piles_list_view" v-if="i.purposeType">
						<view>设备类型：</view>
						<view>{{ i.purposeType == 1 ? '商用运维版' : i.purposeType == 2 ? '商用合作版' : i.purposeType == 3 ? '家用专业版' : '' }}</view>
					</view>
					<view class="piles_list_view">地址：{{ i.stationAddress || '-' }}</view>
					<!-- 					<view class="piles_list_view">
						<view>电费费用：</view>
						<view>
							<text>1.00</text>
							/ 元
						</view>
					</view>
					<view class="piles_list_view">
						<view>昨日收益：</view>
						<view>
							<text>￥100.00 元</text>
						</view>
					</view> -->
					<view class="piles_list_view">
						<view>下单时间：</view>
						<view>{{ timeFormat(new Date(i.createTime).getTime(), 'yyyy-mm-dd hh:MM') }}</view>
					</view>
				</view>

				<view class="piles_list" v-if="current == 1">
					<view class="piles_list_view">
						<view>设备ID：</view>
						<view>{{ i.id }}</view>
					</view>
					<view class="piles_list_view">
						<view>设备功率：</view>
						<view>{{ i.deviceType }}KW</view>
					</view>
					<view class="piles_list_view" v-if="i.purposeType">
						<view>设备类型：</view>
						<view>{{ i.purposeType == 1 ? '商用运维版' : i.purposeType == 2 ? '商用合作版' : i.purposeType == 3 ? '家用专业版' : '' }}</view>
					</view>
					<view class="piles_list_view">
						<view>下单时间：</view>
						<view>{{ timeFormat(new Date(i.createTime).getTime(), 'yyyy-mm-dd hh:MM') }}</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script setup>
// import { getDeviceInfo, getDeviceCount } from '@/api/api.js';
import { reactive, ref } from 'vue';
import { onPullDownRefresh, onPageScroll, onReachBottom, onLoad } from '@dcloudio/uni-app';
import { timeFormat } from '@/uni_modules/uview-plus';
const paging = ref(null);
let dataList = ref([]);
let dataFrom = reactive({
	deviceStatus: 1
});
let count = ref({});

onLoad(async () => {
	count.value = await getDeviceCount();
});

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();
});

const queryList = (pageNo, pageSize) => {
	const params = {
		current: pageNo,
		pageSize: pageSize,
		...dataFrom
	};

	getDeviceInfo(params)
		.then((res) => {
			paging.value.complete(res.records);
		})
		.catch((res) => {
			paging.value.complete(false);
		});
};

const list = ref([
	{
		name: '已安装',
		id: 1
	},
	{
		name: '待安装',
		id: 0
	}
]);
const current = ref(0);

const upChange = (e) => {
	current.value = e;
	dataFrom.deviceStatus = list.value[e].id;
	paging.value.reload();
};
</script>

<style scoped lang="scss">
.piles {
	&_card {
		width: 690rpx;
		height: 192rpx;
		background: linear-gradient(179deg, #4874e5 0%, #3864d6 100%);
		border-radius: 8rpx 8rpx 0rpx 0rpx;
		padding: 30rpx;
		&_title {
			font-weight: bold;
			font-size: 28rpx;
			color: #ffffff;
			margin-bottom: 20rpx;
		}
		&_view {
			padding: 0 150rpx;
			flex-direction: column;
			@include flex($space: space-between);
			view {
				@include flex($direction: column, $space: space-between);
				text:nth-child(1) {
					font-weight: bold;
					font-size: 32rpx;
					color: #ffffff;
					margin-bottom: 15rpx;
				}
				text:nth-child(2) {
					font-size: 26rpx;
					color: #ffffff;
				}
			}
		}
	}

	&_list {
		padding: 25rpx;
		width: 690rpx;
		background: #ffffff;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin-top: 30rpx;
		&_title {
			font-weight: bold;
			font-size: 28rpx;
			color: #232323;
		}
		&_view {
			@include flex;
			color: #555555;
			font-size: 28rpx;
			margin-top: 15rpx;
			view:nth-child(2) {
				font-weight: bold;
				font-size: 28rpx;
				color: #232323;
			}
			text {
				color: #ff2727;
			}
		}
	}
}
</style>