<template>
	<!--详情流程图-->
	<view class="detail-flow-chart">
		<view class="flow-title">流程图</view>
		<u-steps direction="column" :current="current">
			<u-steps-item :key="i" v-for="(item, i) in proNodes">
				<view class="item-icon" slot="icon">
					<text class="item-title">{{ item.nodeType }}</text>
					<!--已激活状态 -->
					<u-icon
						v-if="i < current"
						class="status-icon"
						name="checkmark-circle-fill"
						color="#08BC62"
						size="17"
					></u-icon>
					<!--当前处于这一步-->
					<u-icon
						v-else-if="i === current"
						class="status-icon"
						name="more-circle-fill"
						color="#F08B14"
						size="17"
					></u-icon>
					<!--待审批-->
					<u-icon
						v-if="i > current"
						class="status-icon"
						name="checkmark-circle-fill"
						color="#CAD0DB"
						size="17"
					></u-icon>
				</view>

				<view class="steps-content" slot="desc">
					<view
						:key="i"
						v-for="(info, i) in item.list"
						class="info-row"
					>
						<detailAvatar :info="info"></detailAvatar>
						<view class="u-info">
							<text
								class="u-name"
								:class="{ 'mb-8': info.approvalTime }"
							>
								{{ info.userName }}
							</text>
							<text class="c-time">{{ info.approvalTime }}</text>
						</view>
					</view>
				</view>
			</u-steps-item>
		</u-steps>
	</view>
</template>

<script>
import detailAvatar from './detailAvatar.vue';

export default {
	name: 'detailFlowChart',
	props: {
		proNodes: {
			default: () => [],
			type: Array,
		},
	},
	data() {
		return {};
	},
	computed: {
		current() {
			return this.proNodes.findIndex((item) => item.current);
		},
	},
	components: {
		detailAvatar,
	},
};
</script>

<style scoped lang="scss">
.detail-flow-chart {
	background-color: #fff;
	border-radius: 6px;
	margin: 20rpx 0;
	padding: 20rpx;
	.flow-title {
		margin-bottom: 30rpx;
		position: relative;
		font-size: 15px;
		color: #333333;
		&:before {
			content: '';
			position: absolute;
			bottom: -6px;
			left: 0;
			width: 14px;
			height: 3px;
			background-color: #436ff6;
			border-radius: 6px;
		}
	}
	.u-steps {
		padding-left: 45px;

		.steps-content {
			.info-row {
				position: relative;
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				background-color: #f5f6f8;
				padding: 16rpx 30rpx;
				border-radius: 4px;

				.status-box {
					position: absolute;
					top: 0;
					right: 0;
					border-radius: 0px 5px 0px 10px;
					color: #fff;
					font-size: 12px;
					padding: 3px 6px;
				}

				.pend-approval {
					background-color: #848796;
				}
				.rejected {
					background-color: #ff5e59;
				}
				.agree {
					background-color: #08bc62;
				}
				&:last-child {
					margin-bottom: 0;
				}

				.u-info {
					display: flex;
					flex-direction: column;
					margin-left: 20rpx;

					.u-name {
						font-size: 14px;
						color: #333333;
					}
					.mb-8 {
						margin-bottom: 8px;
					}

					.c-time {
						font-size: 12px;
						color: #7b7e8c;
					}
				}
			}
		}
		.item-icon {
			position: relative;
			display: flex;
			align-items: center;

			.item-title {
				position: absolute;
				left: -45px;
				font-size: 14px;
				color: #595c62;
			}
			.status-icon {
				margin-top: 2px;
			}
		}
	}
}
</style>
