<template>
	<!-- 聊天消息 -->
	<view class="back">
		<view class="input u-flex">
			<u-icon name="search" color="rgba(153, 153, 153, 1)" size="40"></u-icon>
			<input type="text" placeholder="搜索聊天记录/团长" style="width: 600rpx;margin-left: 16rpx;" />
		</view>
		<!-- 客服 -->
		<view class="kefu u-flex" @click="tokefu">
			<image src="/pageA/static/images/kefu.png" style="width: 88rpx;height: 88rpx;" mode=""></image>
			<view class="u-row-between"
				style="height: 88rpx;display: flex;flex-direction: column;margin-left: 20rpx;width: 85%;">
				<view class="u-flex u-row-between">
					<view class="name">官方客服</view>
					<view class="time">14:09</view>
				</view>
				<view class="u-flex u-row-between">
					<text class="news">[卡片]</text>
					<u-badge :type="type" max="99" :value="value"></u-badge>
				</view>
			</view>
		</view>
		<view class="box ">
			<view class="u-flex " style="margin-bottom: 26rpx;" v-for="(item,idx) in  list" :key="idx"
				@click="chat(item.lastMessage)">
				<image :src="item.lastMessage.ext.image" style="width: 88rpx;height: 88rpx;" mode=""></image>
				<view class="u-row-between" style="display: flex;flex-direction: column;margin-left: 20rpx;width: 85%;">
					<view class="u-flex u-row-between">
						<view class="name">{{item.lastMessage.ext.shopname}}</view>
						<view class="name">{{item.lastMessage.ext.user}}</view>
						<view class="time">
							{{new Date(item.lastMessage.time).getFullYear()}}-{{new Date(item.lastMessage.time).getMonth() + 1}}-{{new Date(item.lastMessage.time).getDate()}}
							{{new Date(item.lastMessage.time).toTimeString().substr(0, 8)}}
						</view>
					</view>
					<view class="u-flex u-row-between"
						style="border-bottom: 2rpx solid #979797;padding-bottom: 26rpx;margin-top: 10rpx;">
						<text v-if="item.lastMessage.msg" class="news">{{item.lastMessage.msg}}</text>
						<text v-if="item.lastMessage.type == 'img'" class="news">图片</text>
						<u-badge :type="type" max="99" :value="item.unReadCount"></u-badge>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		conn,
	} from '@/utils/WebIM';
	export default {
		data() {
			return {
				type: "error",
				value: 1,
				list: []
			};
		},
		onLoad() {
			this.getlist()
		},
		methods: {
			getlist() {
				conn.getServerConversations({
					pageSize: 50,
					cursor: ''
				}).then((res) => {
					console.log(res);
					this.list = res.data.conversations
				})
			},
			tokefu() {
				uni.navigateTo({
					url: '/pageA/service/service'
				})
			},
			chat(item) {
				uni.navigateTo({
					// url: '/pageA/chat/chat?user_other_no=' + item.from + '&user_other=' + encodeURIComponent(JSON.stringify(item.ext.user)) 
					url: '/pageA/chat/chat?user_other_no=' + item.from 
				})
			}  
		}
	}
</script>

<style lang="scss">
	.back {
		width: 750rpx;
		// height: 1624rpx;
		background: #F4F4F4;
		padding: 20rpx 24rpx;
		box-sizing: border-box;

		.input {
			width: 702rpx;
			height: 72rpx;
			background: #FFFFFF;
			border-radius: 36rpx;
			padding: 0 24rpx;
			box-sizing: border-box;
		}

		.kefu {
			width: 702rpx;
			height: 156rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 36rpx 24rpx 32rpx;
			box-sizing: border-box;
			margin-top: 24rpx;
		}

		.name {
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 32rpx;
			color: #222222;
			line-height: 44rpx;
			text-align: left;
			font-style: normal;
		}

		.time {
			font-family: SFPro, SFPro;
			font-weight: 400;
			font-size: 20rpx;
			color: #666666;
			line-height: 24rpx;
			text-align: left;
			font-style: normal;
		}

		.news {
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #666666;
			line-height: 34rpx;
			text-align: left;
			font-style: normal;
		}

		.box {
			width: 702rpx;
			min-height: 1156rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 40rpx 24rpx 20rpx;
			box-sizing: border-box;
			margin-top: 20rpx;
		}
	}
</style>