<!-- 会话列表组件 -->
<template>
	<!-- 普通弹窗 -->
	<uni-popup ref="popup" >
		<view class="popup-content">
			<scroll-view id="sessionScrollview" class="sessionScrollview" scroll-y="true" :scroll-with-animation="true">
				<view class="sessionItem" v-for="(item, index) in allsessions" :key="index" @click="changeSession(item)">
					<view class="sessionItem-text">
						{{ item.name ? item.name : `话题 ${ dateFormat(item.createTime, 'MM-dd hh:mm') }` }} 
					</view>
					<view class="view-del" v-if="allsessions.length > 1" @click.stop="handleDelSesstion(item)">
						<span class="iconfont icon-del"></span>
					</view>
				</view>
				<view v-if="!sessionOver && allsessions.length >= 20" class="sessionItem loadmore" @click="loadMoreSession">
					加载更多……
				</view>
				<view class="sessionItem itemfix">
					<view class="itembtn" @click="handleDelAll">
						换个话题
					</view>
				</view>
			</scroll-view>
		</view>
	</uni-popup>
</template>

<script>
	import { dateFormat } from '@/common/util.js'
	export default {
		props: {
			allsessions: {
				type: Array,
				default: () => []
			},
			sessionOver: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				
			};
		},
		methods: {
			dateFormat,
			loadMoreSession() {
				this.$emit('loadMoreSession')
			},
			handleDelAll() {
				this.$refs.popup.close()
				this.$emit('handleDelAll')
			},
			handleShowAll() {
				this.$refs.popup.open('left')
			},
			handleClose() {
				this.$refs.popup.close()
			},
			handleDelSesstion(item) {
				this.$emit('handleDelSesstion', item)
			},
			changeSession(item) {
				this.$emit('changeSession', item)
			}
		}
	}
</script>

<style lang="less" scoped>

	.popup-content {
		height: 100vh;
		width: 500rpx;
		padding: 20rpx 0rpx 130rpx;
		background-color: #33373f;
		box-sizing: border-box;
		.sessionScrollview {
			padding: 0 36rpx 0 36rpx;
			height: 100%;
			position: relative;
			box-sizing: border-box;
		}
		.sessionItem {
			color: #FFF;
			padding: 24rpx 0;
			position: relative;
			.sessionItem-text {
				max-width: 360rpx;
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
				text-align: left;
			}
			&:not(:last-child) {
				border-bottom: 1px solid #43474f;
			}
			&.itemfix {
				position: fixed;
				bottom: 0;
				width: 100%;
				display: flex;
				justify-content: center;
				.itembtn {
					width: 200rpx;
					color: #FFF;
					border: 1px solid;
					border-radius: 8rpx;
					text-align: center;
					padding: 12rpx 10rpx;
				}
					
			}
			&.loadmore {
				text-align: center;
				color: @mainColor;
			}
			.view-del {
				position: absolute;
				right: 0;
				top: 0;
				height: 100%;
				width: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				&:active .icon-del {
					color: #dedede;
				}
			}
		}
	}
	
</style>
