<template>
	<view class="page">

		<view class="section-title">巡检点</view>

		<!-- 时间轴列表 -->
		<view class="timeline">
			<view v-for="(item, idx) in taskList" :key="idx" class="node"
				:class="[{ 'is-last': idx === taskList.length - 1 }]">
				<!-- 左侧：点 + 竖线 -->
				<view class="rail">
					<view class="dot" :class="{
              'dot-circle': item.dotShape === 'circle',
              'dot-square': item.dotShape === 'square',
              'dot-active': item.dotColor === 'blue'
            }"></view>
				</view>

				<!-- 右侧内容 -->
				<view class="card">
					<!-- 标题块 + 操作区（打包在一起，方便宽度同步） -->
					<view class="title-ops-wrapper">
						<!-- 标题块 -->
						<view v-if="item.headerStyle === 'solid'" class="title-solid">
							{{ item.pointName }}（{{ item.date }} {{ item.time }}）
						</view>
						<view v-else class="title-dashed">
							{{ item.pointName }}（{{ item.date }} {{ item.time }}）
						</view>

						<!-- 操作区：宽度跟随标题块，内部居中 -->
						<view class="ops" v-if="item.status === '待巡检'">
							<view class="btn-outline" @click="startTask(item)">立即巡检</view>
						</view>

						<view class="ops" v-else>
							<view class="btn-disabled">完成巡检</view>
							<view class="badge" :class="item.result === '正常' ? 'badge-success' : 'badge-warn'">
								{{ item.result }}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="footer-placeholder">巡检提醒</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				taskList: []
			}
		},
		onLoad() {
			this.getTaskListMock()
		},
		methods: {
			// ---- 模拟接口数据（可替换成 uni.request）----
			getTaskListMock() {
				this.taskList = [
					{
						pointName: 'A区花园',
						date: '2025-07-16',
						time: '09:00—10:00',
						status: '待巡检',
						headerStyle: 'solid',
						result: '',
						dotShape: 'circle',
						dotColor: 'gray'
					},
					{
						pointName: 'A区花园',
						date: '2025-07-16',
						time: '09:00—10:00',
						status: '已完成',
						headerStyle: 'dashed',
						result: '正常',
						dotShape: 'circle',
						dotColor: 'blue'
					},
					{
						pointName: 'A区花园',
						date: '2025-07-16',
						time: '09:00—10:00',
						status: '待巡检',
						headerStyle: 'solid',
						result: '',
						dotShape: 'square',
						dotColor: 'gray'
					},
					{
						pointName: 'A区花园',
						date: '2025-07-16',
						time: '09:00—10:00',
						status: '已完成',
						headerStyle: 'dashed',
						result: '异常',
						dotShape: 'square',
						dotColor: 'blue'
					}
				]
			},
			startTask(item) {
				uni.showToast({
					title: `开始巡检：${item.pointName}`,
					icon: 'none'
				})
			}
		}
	}
</script>

<style scoped>
	/* 页面基础 */
	.page {
		background: #f7f8fa;
		min-height: 100vh
	}

	.section-title {
		font-size: 28rpx;
		color: #333;
		margin: 24rpx 24rpx 8rpx
	}

	/* 时间轴容器 */
	.timeline {
		position: relative;
		padding: 16rpx 24rpx 40rpx 24rpx
	}

	/* 每个节点 */
	.node {
		position: relative;
		padding-left: 72rpx;
		margin-bottom: 32rpx
	}

	.node:last-child {
		margin-bottom: 0
	}

	/* 左侧导轨与连线 */
	.node::after {
		content: "";
		position: absolute;
		left: 37rpx;
		top: 35rpx;
		bottom: -32rpx;
		width: 2rpx;
		background: #e8e9ee
	}

	.node.is-last::after {
		display: none
	}

	/* 左栏（点的容器） */
	.rail {
		position: absolute;
		left: 0;
		top: 0;
		width: 72rpx;
		height: 100%;
		display: flex;
		justify-content: center
	}

	.dot {
		width: 16rpx;
		height: 16rpx;
		margin-top: 20rpx;
		background: #cfd3dc
	}

	.dot-circle {
		border-radius: 50%
	}

	.dot-square {
		border-radius: 4rpx
	}

	.dot-active {
		background: #2f6aff
	}

	/* 右侧卡片 */
	.card {
		padding: 16rpx 20rpx;
	}

	/* 标题 + 操作区包裹（宽度由标题决定） */
	.title-ops-wrapper {
		display: inline-block;
	}

	/* 标题两种样式 */
	.title-solid {
		background: #2f6aff;
		color: #fff;
		border-radius: 12rpx;
		padding: 12rpx 18rpx;
		display: inline-block;
		font-size: 26rpx
	}

	.title-dashed {
		border-radius: 12rpx;
		background: #fff;
		padding: 12rpx 18rpx;
		display: inline-block;
		font-size: 26rpx;
		color: #333
	}

	/* 操作区：宽度继承标题块，内部居中 */
	.ops {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 20rpx;
	}

	.btn-outline {
		border: 2rpx solid #2f6aff;
		color: #2f6aff;
		background: #fff;
		padding: 12rpx 28rpx;
		border-radius: 12rpx;
		font-size: 26rpx
	}

	.btn-disabled {
		background: #f2f3f5;
		color: #a0a0a0;
		padding: 12rpx 24rpx;
		border-radius: 12rpx;
		font-size: 26rpx
	}

	/* 结果徽标 */
	.badge {
		padding: 8rpx 18rpx;
		border-radius: 22rpx;
		font-size: 24rpx;
		margin-left: 16rpx;
	}

	.badge-success {
		color: #16a34a;
		border: 2rpx solid #16a34a;
		background: #fff
	}

	.badge-warn {
		color: #f59e0b;
		border: 2rpx solid #f59e0b;
		background: #fff
	}

	/* 底部占位文字 */
	.footer-placeholder {
		text-align: center;
		color: #e5e6eb;
		font-size: 28rpx;
		margin-top: 80rpx;
		letter-spacing: 2rpx
	}
</style>
