
<template>
	<view class="hl88-lr-operator" :style="{bottom:statusFootHeight + 60 +'px'}">
		<view class="hl88-lr-comment">
			<view class="hl88-lr-comment-item">
				 <scroll-view scroll-y="true" :scroll-into-view="scrollToView" :scroll-with-animation="true" class="hl88-lr-comment-item-scroll">
					<!-- #ifdef APP-PLUS -->
					<view class="hl88-lr-comment-item-scroll-app" v-for="(item, index) in msgList" :key="index" :id="'msg' + index">
						<view class="hl88-lr-comment-item-scroll-app-item">
							<text :class="[iscolor(item.form.id)]" class="hl88-lr-msgAppNm">{{item.form.nickname}}：</text>
							<text class="hl88-lr-msgAppBody">{{item.text}}</text>
						</view>
					</view>
					<!-- #endif -->
					<!-- #ifdef H5 -->
					<div class="hl88-lr-comment-item-scroll-h5" v-for="(item, index) in msgList" :key="index" :id="'msg' + index">
					 	<div class="hl88-lr-comment-item-tag">
					 		<text :class="[iscolor(item.form.id)]" class="hl88-lr-msgWebNm">{{item.form.nickname}}：</text>
							<text class="hl88-lr-msgWebBody">{{item.text}}</text>
					 	</div>
					</div>
					<!-- #endif -->
                    <!-- #ifdef MP -->
					<div class="hl88-lr-comment-item-scroll-mp" v-for="(item, index) in msgList" :key="index" :id="'msg' + index">
					 	<div class="hl88-lr-comment-item-tag">
					 		<text :class="[iscolor(item.form.id)]" class="hl88-lr-msgWebNm">{{item.form.nickname}}：</text>
							<text class="hl88-lr-msgWebBody">{{item.text}}</text>
					 	</div>
					</div>
                    <!-- #endif -->
                </scroll-view>
			</view>
			<view class="hl88-lr-comment-empty"> </view>
		</view>
		<uni-transition :mode-class="['slide-left']" :styles="{ 'position':'absolute', 'left':'0', 'top':'-60rpx', }" :show="comingShow">
			<view class="hl88-lr-coming">
				<text class="hl88-lr-coming-text">{{comingName}} 他来了他来了~</text>
			</view>
		</uni-transition>
	</view>
</template>

<script>
export default {
	name: 'LiveRoomComment',
	props: {
		statusFootHeight: {
			default: 0
		},
		state: {
			default: 0
		},
		liveid: {
			type: String,
			default: ''
		},
		commentData: {
			type: Object,
			default: function() {
				return {};
			}
		}
	},
	data() {
		return {
			scrollToView: '',
			comingShow: false,
			comingName: '',
			watchTimer: null,
			msgList: [],
			liveData: {
				state: 0,
				liveid: ''
			}
		};
	},
	created(){
		this.liveData.state = this.state;
		this.liveData.liveid = this.liveid;
		// 监听直播消息
		uni.$on('onLive', this.updateMsg);
		// #ifndef APP-PLUS
		setTimeout(() => {
			this.msgList.push({
				form: {
					id:0,
					nickname: 'Tips'
				},
				text: 'Please confirm that the purchased items match the host"s description when placing an order. Offline transactions are prohibited, beware of being deceived！'
			});
		}, 500);
		// #endif
	},
	methods: {
		updateMsg(msg){
			if (this.liveData.state == 1) {
				if (msg.group == this.liveData.liveid) {
					var message = msg.message;
					var form = msg.form;
					if (message.type == 'msg' || message.type == 'seek' || message.type == 'follow' || message.type == 'like' || message.type == 'review') {
						this.msgList.push({
							form: form,
							text: message.text
						});
						this.$nextTick(() => {
							this.scrollToView = 'msg' + (this.msgList.length - 1);
						});
					}
					if(message.type == 'coming'){
						if (this.comingShow ) {
							clearTimeout(this.watchTimer);
							this.comingShow = false;
						}
						this.comingName = form.nickname;
						this.openComing();
					}
				}else{
					console.log('其他直播间消息');
				}
			}
		},
		openComing(){
			this.comingShow = true;
			this.watchTimer = setTimeout(() => {
				this.comingShow = false;
			}, 1000);
		},
		iscolor(id){
			return ['text-white','text-orange','text-yellow','text-green','text-olive','text-green','text-purple','text-pink','text-pink','text-purple'][parseInt(id % 10)]
		}
	}
};
</script>

<style scoped>


.hl88-lr-operator{
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
}
	.hl88-lr-coming{
		margin-left: 25rpx;
		background-color: rgba(255,86,136,.7);
		padding-top: 8rpx;
		padding-right: 16rpx;
		padding-bottom: 8rpx;
		padding-left: 16rpx;
		border-radius: 10rpx;
	}
		.hl88-lr-coming-text{
			color: #ffffff;
			font-size: 28rpx;
		}
	
	.hl88-lr-comment{
		/* #ifndef APP-PLUS */
		-webkit-mask: -webkit-gradient(linear,left 30%,left top,from(#000),to(transparent));
		/* #endif */
		margin-left: 25rpx;
		flex-direction: row;
		position: relative;
	}
		.hl88-lr-comment-empty{
			flex: 1;
		}
		.hl88-lr-comment-item{
			flex: 2;
			overflow: hidden;
			color: #FFFFFF;
		}
			.hl88-lr-comment-item-scroll{
				/* #ifdef H5 || MP */
				max-height: 500rpx;
				min-height: 60rpx;
				/* #endif */
				/* #ifdef APP-PLUS */
				height: 500rpx;
				/* #endif */
			}
			
			
				
			/* #ifdef H5 || MP */
			.hl88-lr-comment-item-scroll-h5{
				margin-top: 6rpx;
				overflow: hidden;
				display: flex;
			}
			.hl88-lr-comment-item-scroll-mp{
				margin-bottom: 6rpx;
				overflow: hidden; 
				display: block;
			}
				.hl88-lr-comment-item-tag{
					background-color: rgba(0,0,0,.2);
					padding-top: 8rpx;
					padding-right: 16rpx;
					padding-bottom: 8rpx;
					padding-left: 16rpx;
					border-radius: 10rpx;
					overflow: hidden;
					display: inline-block;
				}
			/* #endif */
				
			
				
				
			.hl88-lr-comment-item-scroll-app{
				flex-direction: row;
				margin-top: 6rpx;
			}
				.hl88-lr-comment-item-scroll-app-item{
					background-color: rgba(0,0,0,.2); 
					padding-top: 8rpx;
					padding-right: 16rpx;
					padding-bottom: 8rpx;
					padding-left: 16rpx;
					border-radius: 10rpx;
					flex-direction: row;
				}
	.hl88-lr-msgAppNm{
		font-size: 29rpx;
	}
	.hl88-lr-msgAppBody{
		font-size: 29rpx;
		color: #ffffff;
	}
	.hl88-lr-msgWebNm{
		font-size: 26rpx;
	}
	.hl88-lr-msgWebBody{
		font-size: 26rpx;
		color: #ffffff;
	}

.text-white{
	color: #ffffff;
}
.text-orange{
	color: #f56f23;
}

.text-yellow{
	color: #ffee8a;
}

.text-olive{
	color: #7ed321;
}

.text-green{
	color: #50e3c2;
}

.text-purple{
	color: #9134fc;
}

.text-pink{
	color: #ff9fbf;
}
</style>

