<template>
	<view>
		<!-- <uni-notice-bar v-if='dataList.length' text="左滑删除单据，删除后可返回注册页重新生成" /> -->
		<view class="list" style="margin-bottom: 30rpx;" v-for="(item, index) in dataList" :key="index">
			<u-empty v-if='dataList.length==0' mode="data">
			</u-empty>
			<view class="tab-bar-item" style="margin-top: 30rpx;" @click="inEdit(item)">
				<view class="list-item">
					<view style="font-weight: 800;">
						{{item.insuranceNo}}
					</view>
					<view style="color: #B5B4B4;display:flex;align-items:center;">
						{{formatCustom(item.claimDate,'YYYY-MM-DD')}}
					</view>
				</view>
				<view class="list-item">
					<view class="">
						{{item.tireDescription||'暂无描述'}}
					</view>
					<view class="">
            保单号:{{item.claimNo||'暂无保单号'}}
					</view>
				</view>
				<view class="list-item-end">
					<view class="">
						理赔原因:{{item.claimReason||'暂无原因'}}
					</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.auditStatus==0" style="color:#e6a23c">
							待审核
						</text>
						<text v-if="item.auditStatus==1" style="color:#409EFF">
							审核中
						</text>
						<text v-if="item.auditStatus==2" style="color:#67c23a">
							已通过
						</text>
						<text v-if="item.auditStatus==3" style="color:#f56c6c">
							已拒绝
						</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		formatDate,
		relativeTime
	} from '@/utils/formatDate.js'
	import {
		itemList,
		revokeApproval
	} from '@/api/home/insurance.js'
	export default {
		data() {
			return {
				dataList: [],
				optionId: null
			}
		},
		onLoad(option) {
			console.log(option)
			if (option && option.id) {
				this.optionId = option.id
				this.itemList()
			}
		},
		onPullDownRefresh() {
			this.itemList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		methods: {
			onClick(e) {
				console.log(e)
			},
			inEdit(row) {
				uni.navigateTo({
					url: '/pages/home/claim/details?id=' + row.claimId,
				});
			},
			inDel(row) {
				if (row.auditStatus == 1) {
					uni.showToast({
						title: '审核中状态不允许删除',
						icon: 'none',
						duration: 2000
					});
					return
				}
				if (row.auditStatus == 2) {
					uni.showToast({
						title: '已通过状态不允许删除',
						icon: 'none',
						duration: 2000
					});
					return
				}
				let _this = this
				uni.showModal({
					title: '提示',
					content: '是否确认删除？',
					success: function(res) {
						if (res.confirm) {
							let obj = {
								id: row.id
							}
							uni.showLoading({
								title: '加载中',
								mask: true
							});
							revokeApproval(obj).then(res => {
									setTimeout(() => {
										uni.showToast({
											title: '操作成功',
											icon: 'none',
											duration: 2000
										});
									}, 10);
									_this.itemList(row.insuranceId)
								})
								.finally(() => {
									uni.hideLoading()
								});
						}
					}
				});

			},
			formatCustom(date, format) {
				return formatDate(date, format)
			},
			itemList() {
				const obj = {
					insuranceId: this.optionId
				}
				this.loading = true
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				itemList(obj).then(res => {
						this.dataList = res.data
					})
					.finally(() => {
						uni.hideLoading()
					});
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-noticebar__content-text{
		font-size: 24rpx !important;
	}
	::v-deep .uni-noticebar {
		padding: 10rpx 62rpx !important;
		text-align: right;
	}
	.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;
			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>
