<template>
	<view class="uni-steps">
		<view :class="[direction==='column'?'uni-steps__column':'uni-steps__row']">
			<view :class="[direction==='column'?'uni-steps__column-container':'uni-steps__row-container']">
				<view :class="[direction==='column'?'uni-steps__column-line-item':'uni-steps__row-line-item']"
					v-for="(item,index) in options" :key="index" @click="toStep(item, index)">
					<view
						:class="[direction==='column'?'uni-steps__column-line':'uni-steps__row-line',direction==='column'?'uni-steps__column-line--before':'uni-steps__row-line--before']"
						:style="{backgroundColor:index<=active&&index!==0?activeColor:index===0?'transparent':deactiveColor}">
					</view>
					<view :class="[direction==='column'?'uni-steps__column-check':'uni-steps__row-check']"
						v-if="index === active">
						<view class="uni-steps__row-circle activeRound"
							:class="[ taskId == item.taskId ?'circleActive': 'activeRound']">{{index + 1}}</view>
					</view>
					<view
						:class="[direction=='column'?'uni-steps__column-circle': taskId == item.taskId ?'circleActive' :'uni-steps__row-circle']"
						v-else>
						{{index + 1}}
					</view>
					<view
						:class="[direction==='column'?'uni-steps__column-line':'uni-steps__row-line',direction==='column'?'uni-steps__column-line--after':'uni-steps__row-line--after']"
						:style="{backgroundColor:index<active&&index!==options.length-1?activeColor:index===options.length-1?'transparent':deactiveColor}">
					</view>
				</view>
			</view>
			<view :class="[direction==='column'?'uni-steps__column-text-container':'uni-steps__row-text-container']"
				style="margin-top:10upx;">
				<view v-for="(item,index) in options" :key="index"
					:class="[direction==='column'?'uni-steps__column-text':'uni-steps__row-text']">
					<view :style="{color:index<=active?activeColor:deactiveColor}"
						:class="[direction==='column'?'uni-steps__column-title':'uni-steps__row-title']">{{item.taskTypeName}} </view>
					<text :style="{color:index<=active?activeColor:deactiveColor}" v-if="clientEnvironmentId == 3"
						:class="[direction==='column'?'uni-steps__column-desc':'uni-steps__row-desc']">[投:{{item.feedExistNum || 0}}报:{{item.reportExistNum  || 0}}]</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'UniSteps',
		components: {

		},
		props: {
			direction: {
				// 排列方向 row column
				type: String,
				default: 'row'
			},
			activeColor: {
				// 激活状态颜色
				type: String,
				default: '#157A2C'
			},
			deactiveColor: {
				// 未激活状态颜色
				type: String,
				default: '#999999'
			},
			active: {
				// 当前步骤
				type: Number,
				default: 0
			},
			options: {
				type: Array,
				default () {
					return []
				}
			} // 数据
		},
		data() {
			return {
				taskId: null,
				clientEnvironmentId: uni.getStorageSync("userInfo") && uni.getStorageSync("userInfo").clientEnvironmentId,
			}
		},
		methods: {
			toStep(item, index) {

				if (item.taskId == -2) {
					uni.showToast({
						title: "工序已到完结状态",
						icon: "none",
					})
					return false
				}
	
				if(this.clientEnvironmentId == 3) { // 碳谷
					this.taskId = item.taskId
					this.$emit('selectStep', item);
				} else {
					if(item.count > 0 || index == this.active) {
						this.taskId = item.taskId
							this.$emit('selectStep', item);
					} else {
						uni.showToast({
							title: "还未执行到此工序",
							icon: "none",
						})
					}
				}

		

			

			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-steps {
		/* #ifndef APP-NVUE */
		display: flex;
		width: 100%;
		/* #endif */
		/* #ifdef APP-NVUE */
		flex: 1;
		/* #endif */
		flex-direction: column;

		margin-top: 10rpx;
	}

	.uni-steps__row {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
	}

	.uni-steps__column {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row-reverse;
	}

	.uni-steps__row-text-container {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	.uni-steps__column-text-container {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		flex: 1;
	}

	.uni-steps__row-text {
		/* #ifndef APP-NVUE */
		display: inline-flex;
		/* #endif */
		flex: 1;
		flex-direction: column;
	}

	.uni-steps__column-text {
		padding: 12upx 0upx;
		border-bottom-style: solid;
		border-bottom-width: 2upx;
		border-bottom-color: $uni-border-color;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
	}

	.uni-steps__row-title {
		font-size: 28rpx;
		line-height: 40upx;
		text-align: center;
		min-width: 200rpx;
	}

	.uni-steps__column-title {
		font-size: 28rpx;
		text-align: left;
		line-height: 40upx;
	}

	.uni-steps__row-desc {
		font-size: 24upx;
		line-height: 28upx;
		text-align: center;
	}

	.uni-steps__column-desc {
		font-size: $uni-font-size-sm;
		text-align: left;
		line-height: 36upx;
	}

	.uni-steps__row-container {
		height: 60upx;
		border: 1px soild red;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	.uni-steps__column-container {
		/* #ifndef APP-NVUE */
		display: inline-flex;
		/* #endif */
		width: 60upx;
		flex-direction: column;
	}

	.uni-steps__row-line-item {
		/* #ifndef APP-NVUE */
		display: inline-flex;
		/* #endif */
		flex-direction: row;
		flex: 1;
		height: 60upx;
		line-height: 60upx;
		align-items: center;
		justify-content: center;
		min-width: 200rpx;
	}

	.uni-steps__column-line-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		flex: 1;
		align-items: center;
		justify-content: center;
	}

	.uni-steps__row-line {
		flex: 1;
		height: 2upx;
		background-color: $uni-text-color-grey;
	}

	.uni-steps__column-line {
		width: 2upx;
		background-color: $uni-text-color-grey;
	}

	.uni-steps__row-line--after {
		transform: translateX(1px);
	}

	.uni-steps__column-line--after {
		flex: 1;
		transform: translate(0px, 1px);
	}

	.uni-steps__row-line--before {
		transform: translateX(-1px);
	}

	.uni-steps__column-line--before {
		height: 12upx;
		transform: translate(0px, -1px);
	}

	.uni-steps__row-circle {
		border: 1px solid #999999;
		background: transparent;
		width: 50upx;
		height: 50upx;
		border-radius: 50%;
		text-align: center;
		line-height: 50upx;
	}

	.uni-steps__column-circle {
		width: 10upx;
		height: 10upx;
		border-radius: 200upx;
		background-color: $uni-text-color-grey;
		margin: 8upx 0upx 10upx 0upx;
	}

	.uni-steps__row-check {
		margin: 0upx 12upx;
	}

	.uni-steps__column-check {
		height: 28upx;
		line-height: 28upx;
		margin: 4upx 0upx;
	}

	.activeRound {
		background: $theme-color;
		color: #fff;
	}

	.circleActive {
		border: 1px solid #FFA929;
		background: #FFA929;
		width: 50upx;
		height: 50upx;
		border-radius: 50%;
		text-align: center;
		line-height: 50upx;
		color: #fff;
	}
</style>