<template>
	<view style="height: 100vh;">
		<uni-nav-bar title="注册列表" backgroundColor='#03803B' color="#fff" left-icon="left" fixed statusBar
			@clickLeft='goBack()' @clickRight="addDetails">
			<block slot="right">
				<view>
					<image class="nav-right" src="@/static/images/home/insurance/add.png" />
				</view>
			</block>
		</uni-nav-bar>
		<scroll-view scroll-y="true" :refresher-enabled="true" :refresher-triggered="triggered"
			@refresherrefresh="onRefresh" class="scroll-view">
			<view class="list">
				<u-empty v-if='dataList.length==0' mode="list">
				</u-empty>
				<view class="tab-bar-item" v-for="(item, index) in dataList" :key="index" @click="inEdit(item)">
					<view class="list-item">
						<view style="font-weight: 800;">
							{{item.insuranceNo}}
						</view>
						<view style="color: #B5B4B4;">
							{{item.createTime}}
						</view>
					</view>
					<view class="list-item">
						<view style="font-weight: 800;color: #03803B;">
							{{item.vehicleNumber||'暂无车牌'}}
						</view>
						<view class="">
							轮胎规格: {{item.tyreSpecs||'-'}}
						</view>
					</view>
					<view class="list-item">
						<view class="">
							轮胎:{{item.tireQuantity||0}}条
						</view>
						<view style="display: flex;align-items: center;color: #03803B;">
							<image style="width: 32rpx;height: 32rpx;margin-right: 18rpx;"
								src="@/static/images/home/insurance/ap.png" />
							<text v-if="item.status==0" style="color:#e6a23c">
								录入
							</text>
							<text v-if="item.status==1" style="color:#e6a23c">
								在保
							</text>
							<text v-if="item.status==2" style="color:#409EFF">
								受理中
							</text>
							<text v-if="item.status==3" style="color:#67c23a">
								已通过
							</text>
							<text v-if="item.status==4" style="color:#f56c6c">
								已拒绝
							</text>
						</view>
					</view>
					<view class="list-item-end">
						<view style="color: #B5B4B4;">
							有效截至日期:{{item.insuranceTime||'暂无日期'}}
						</view>
					</view>
				</view>
			</view>
			<view v-if="loading" class="loading">加载中...</view>
			<view v-if="noMore" class="no-more">没有更多数据了</view>
		</scroll-view>

	</view>
</template>

<script>
	import {
		getList
	} from '@/api/home/insurance.js'
	export default {
		data() {
			return {
				triggered: false,
				searchValue: null,
				page: {
					current: 1,
					size: 10,
					total: 0,
				},
				dataList: [],
				loading: false,
				noMore: false
			}
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			if (!this.noMore) {
				this.page.current += 1
				this.getList()
			}
		},
		filters: {
			statusMap(value) {
				// 状态 0录入，1已提交（在保），2受理中（理赔提交），3已通过（工厂审核通过）
				const statusList = ['录入', '在保', '受理中', '已通过']
				return statusList[value] || '未知状态'
			}
		},
		methods: {
			onRefresh() {
				this.triggered = true;
				this.noMore = false;
				// 模拟异步请求
				setTimeout(() => {
					this.page.current = 1
					this.dataList = []
					this.getList()
				}, 500);
			},
			addDetails() {
				uni.navigateTo({
					url: '/pages/home/insurance/rules'
				});
			},
			inEdit(row) {
				uni.navigateTo({
					url: '/pages/home/insurance/details?id=' + row.id,
				});
			},
			getList() {
				const obj = {
					current: this.page.current,
					size: this.page.size
				}
				this.loading = true
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				getList(obj).then(res => {
						this.dataList = [...this.dataList, ...res.data.records]
						console.log(this.dataList.length)
						if (res.data.total <= this.dataList.length) {
							this.noMore = true
						}
					})
					.finally(() => {
						uni.hideLoading()
						this.loading = false
						this.triggered = false
					});
			},
			goBack() {
				uni.navigateBack({
					delta: 1,
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scroll-view {
	  height: 100%;
	}
	.loading,
	.no-more {
		text-align: center;
		padding: 20px;
		color: #999;
	}

	.uni-lastmsg {
		width: 80rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		display: block;
		/* 需明确设置display */
	}

	.uni-lastmsg2 {
		width: 140rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		display: block;
		/* 需明确设置display */
	}

	.nav-right {
		width: 37rpx;
		height: 42rpx;
	}

	.list {
		width: 100%;

		.tab-bar-item {
			background-color: #fff;
			margin-top: 30rpx;
			padding: 0rpx 62rpx;
			font-size: 28rpx;
			line-height: 32rpx;
			color: #5F5F5F;
			font-weight: 400;

			.list-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				height: 100rpx;
				border-bottom: 2px solid #F6F6F6;
			}

			.list-item-end {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				height: 100rpx;
			}
		}
	}
</style>