<template>
	<view class="content">
		<navbar title="关于我们" leftClick @leftClick="$utils.navigateBack" />
		<view class="mt40">
			<view v-for="(item, index) in applicationList" :key="index" class="re-card-p32">
				<view v-if="isEmpty" class="re-empty">
					<view>暂无数据</view>
				</view>
				<view class="flex-sb">
					<view class="flex">
						<image class="re-from-car" src="/static/icons/icon11.png"></image>
						<text>{{ item.name }}</text>
					</view>
					<view v-if="item.isReviewing" class="re-card-show">
						<text style="color:limegreen">系统审核中</text>
					</view>
					<view v-if="item.isRejected" class="re-card-show">
						<text style="color:#F40000">未通过审核</text>
					</view>
				</view>
				
				<!-- 轴数选择 -->
				<view class="flex-sb re-card-select mt20" @click="selectAxleCount(item)">
					<view>轴数</view>
					<view class="flex" style="color:#9E9E9E">
						<text v-if="item.showAxlePlaceholder">请选择</text>
						<view v-if="item.showAxleValue" style="color:#0d0d0d">{{ item.axleCount }}</view>
						<uv-icon v-if="item.showAxleIcon" name="arrow-right" size="16" color="#999"></uv-icon>
					</view>
				</view>
				
				<!-- 上传证件 -->
				<view class="flex-sb re-card-select" @click="handleDocuments(item)">
					<view>上传证件</view>
					<view v-if="item.showUploadPlaceholder" class="flex" style="color:#9E9E9E">
						<text>未上传</text>
						<uv-icon name="arrow-right" size="16" color="#999"></uv-icon>
					</view>
					<view v-if="item.showDocumentInfo" class="flex" style="color:#0d0d0d">
						<text>查看证件信息</text>
						<uv-icon name="arrow-right" size="16" color="#999"></uv-icon>
					</view>
				</view>
				
				<!-- 操作按钮 -->
				<view class="action-buttons mt20">
					<button class="btn-edit" @click="editApplication(item)">编辑</button>
					<button class="btn-delete" @click="deleteApplication(item)">删除</button>
				</view>
			</view>
			
			<!-- 添加申请按钮 -->
			<view class="add-application-btn" @click="addApplication">
				<uv-icon name="plus" size="24" color="#007AFF"></uv-icon>
				<text>新增申请</text>
			</view>
		</view>
	</view>
</template>

<script>
	import navbar from '@/components/base/navbar.vue'
	
	export default {
		components: {
			navbar
		},
		name: 'BaseShen',
		data() {
			return {
				isEmpty: false,
				applicationList: [
					{
						id: 1,
						name: '湘A12345',
						isReviewing: true,
						isRejected: false,
						showAxlePlaceholder: false,
						showAxleValue: true,
						showAxleIcon: true,
						axleCount: '4轴',
						showUploadPlaceholder: false,
						showDocumentInfo: true
					},
					{
						id: 2,
						name: '湘A67890',
						isReviewing: false,
						isRejected: true,
						showAxlePlaceholder: false,
						showAxleValue: true,
						showAxleIcon: true,
						axleCount: '3轴',
						showUploadPlaceholder: true,
						showDocumentInfo: false
					}
				]
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '申请管理'
			});
		},
		methods: {
			selectAxleCount(item) {
				uni.showActionSheet({
					itemList: ['2轴', '3轴', '4轴', '5轴', '6轴'],
					success: (res) => {
						const axles = ['2轴', '3轴', '4轴', '5轴', '6轴'];
						item.axleCount = axles[res.tapIndex];
						item.showAxlePlaceholder = false;
						item.showAxleValue = true;
					}
				});
			},
			handleDocuments(item) {
				if (item.showUploadPlaceholder) {
					// 上传证件
					uni.chooseImage({
						count: 3,
						sizeType: ['compressed'],
						sourceType: ['camera', 'album'],
						success: (res) => {
							uni.showToast({
								title: '上传成功',
								icon: 'success'
							});
							item.showUploadPlaceholder = false;
							item.showDocumentInfo = true;
						}
					});
				} else {
					// 查看证件信息
					uni.navigateTo({
						url: `/pages_order/base/showcar?id=${item.id}`
					});
				}
			},
			editApplication(item) {
				uni.navigateTo({
					url: `/pages_order/base/yuan?id=${item.id}&mode=edit`
				});
			},
			deleteApplication(item) {
				uni.showModal({
					title: '确认删除',
					content: `确定要删除申请 ${item.name} 吗？`,
					success: (res) => {
						if (res.confirm) {
							const index = this.applicationList.findIndex(app => app.id === item.id);
							if (index > -1) {
								this.applicationList.splice(index, 1);
								uni.showToast({
									title: '删除成功',
									icon: 'success'
								});
							}
						}
					}
				});
			},
			addApplication() {
				uni.navigateTo({
					url: '/pages_order/base/yuan?mode=add'
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 20rpx;
		min-height: 100vh;
		background-color: #f5f5f5;
	}
	
	.mt40 {
		margin-top: 40rpx;
	}
	
	.mt20 {
		margin-top: 20rpx;
	}
	
	.re-card-p32 {
		background-color: #fff;
		border-radius: 10rpx;
		padding: 32rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}
	
	.re-empty {
		text-align: center;
		padding: 100rpx 0;
		color: #999;
		font-size: 28rpx;
	}
	
	.flex {
		display: flex;
		align-items: center;
		gap: 10rpx;
	}
	
	.flex-sb {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.re-from-car {
		width: 40rpx;
		height: 40rpx;
	}
	
	.re-card-show {
		padding: 8rpx 16rpx;
		border-radius: 20rpx;
		background-color: #f0f0f0;
		font-size: 24rpx;
	}
	
	.re-card-select {
		padding: 25rpx 0;
		border-bottom: 1rpx solid #f0f0f0;
		font-size: 28rpx;
		
		&:last-child {
			border-bottom: none;
		}
	}
	
	.action-buttons {
		display: flex;
		gap: 20rpx;
		justify-content: flex-end;
		
		button {
			padding: 15rpx 25rpx;
			border-radius: 25rpx;
			font-size: 26rpx;
			border: none;
			
			&.btn-edit {
				background-color: #007AFF;
				color: #fff;
			}
			
			&.btn-delete {
				background-color: #ff3b30;
				color: #fff;
			}
		}
	}
	
	.add-application-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 10rpx;
		background-color: #fff;
		border: 2rpx dashed #007AFF;
		border-radius: 10rpx;
		padding: 60rpx;
		margin-top: 20rpx;
		color: #007AFF;
		font-size: 28rpx;
	}
</style>