<template>
	<!-- 我的私信 -->
	<view class="private">
		<loadlogo v-if="!loadlogo" />
		<view class="content" v-if="loadlogo" :style="{ height: phoneHight }">
			<far-bottom></far-bottom>
			<view class="private-list">
				<noneMores v-if="total == 0"></noneMores>
				<block v-if="total != 0">
					<view class="private-item dis-flex flex-x-between flex-y-center border-line border-bottom" v-for="(privateItem, index) in list" @click="skipChat(privateItem)">
						<view class="private-item-left dis-flex flex-y-center">
							<view class="private-avatar p-r m-right20" :style="{ 'background-image': 'url(' + privateItem.avatar + ')' }">
								<view class="private-init f-24 col-f t-c" v-if="privateItem.total !== '0'">
									<text>{{ privateItem.total }}</text>
								</view>
							</view>
							<view class="private-info">
								<view class="private-nickname f-30 col-3">{{ privateItem.nickname }}</view>
								<view class="f-24 col-9" v-if="privateItem.type == '0'"> <rich-text :nodes="privateItem.content"></rich-text> </view>
								<view class="f-24 col-9" v-if="privateItem.type == '1'"> [图片] </view>
								<view class="f-24 col-9" v-if="privateItem.type == '2'"> [视频] </view>
								<view class="f-24 col-9" v-if="privateItem.type == '3'"> [名片] </view>
								<view class="f-24 col-9" v-if="privateItem.type == '4'"> [简历] </view>
								<view class="f-24 col-9" v-if="privateItem.type == '5'"> [其他消息] </view>
							</view>
						</view>
						<view class="private-item-right f-24 col-9">{{ privateItem.date_time }}</view>
					</view>
				</block>
				<loadmore :isMore="isMore" v-if="total != 0"></loadmore>
			</view>
		</view>
		<TabBars :tabBarAct="0" :pageType="''" />
	</view>
</template>

<script>
import App from '@/common/js/app.js';
import Loadlogo from '@/components/template/loadlogo';
import Loading from '@/components/template/loading';
import noneMores from '@/components/template/nonemores.vue';
import loadmore from '@/components/template/loadmore';
import TabBars from '@/components/template/tabBar';
export default {
	data() {
		return {
			phoneHight: null,
			isMore: true,
			list: [],
			total: null,
			current_page: 1,
			loadlogo: false, //页面是否加载完成,
			loading: false //列表加载更多
		};
	},
	onLoad() {
		let _this = this;
		uni.getSystemInfo({
			success(res) {
				_this.phoneHight = res.windowHeight + 'px';
				_this.phoneHight1 = res.windowHeight;

				_this.scrollHeight = _this.phoneHight1 - uni.upx2px(120) + 'px';
			}
		});
	},
	components: {
		Loadlogo,
		Loading,
		noneMores,
		loadmore,
		TabBars
	},
	computed: {},
	mounted() {
		this.getMessageList();
	},
	methods: {
		getMessageList(page = 1, isPage = false) {
			let _this = this;
			_this.isMore = false;
			App._post_form(
				'&p=im&do=infoList',
				{
					page
				},
				res => {
					if (res.errno === 0) {
						let messageData = res.data;
						_this.isMore = true;
						if (isPage) {
							if (messageData.list.length > 0) {
								_this['list'].push(...messageData.list);
							} else {
								_this.loading = true;
							}
						} else {
							_this.setData(messageData);
							_this.loading = messageData.list.length === 0 || _this.current_page === messageData.total;
						}
					}
				},
				false,
				() => {
					_this.loadlogo = true;
				}
			);
		},
		skipChat(item) {
			let _this = this;
			_this.list.map((items,index)=>{
				if(items.id == item.id){
					_this.list[index].total = '0';
				};
			});
			// App.navigationTo({
			// 	url: 'pages/subPages/homepage/chat/chat?other_party_id=' + item.other_party_id + '&other_party_type=' + item.other_party_type + '&type=1' + '&id='
			// });
			// App.navigationTo({
			// 	url: 'pagesA/instantMessenger/instantMessenger?mid=' + item.other_party_id + '&other_party_type=' + item.other_party_type + '&type=1' + '&id='
			// });
			let getSetInfo = uni.getStorageSync('getSetInfo');
			if(getSetInfo.type == 1){
				App.navigationTo({
					url: 'pagesA/instantMessenger/instantMessenger?other_party_id=' + item.other_party_id + '&other_party_type=' + item.other_party_type+ '&type=1' + '&id='
				})
			}else{
				App.navigationTo({
					url: 'pages/subPages/homepage/chat/chat?other_party_id=' + item.other_party_id + '&other_party_type=' + item.other_party_type+ '&type=1' + '&id='
				})
			}
			console.log(item);
		}
	},
	onReachBottom() {
		let _this = this;
		if (_this.current_page >= _this.total) {
			_this.isMore = true;
			return false;
		}
		_this.getMessageList(++_this.current_page, true);
	}
};
</script>

<style lang="scss" scoped>
.content {
	background: #f8f8f8;
}
.private {
	background: #f8f8f8;
	padding-bottom: 400upx;
}
.private-list {
	margin: 0 30upx;

	.private-item {
		padding: 30upx 0;

		.private-item-left {
			.private-avatar {
				width: 80upx;
				// flex: 1;
				height: 80upx;
				border-radius: 50%;
				background-size: 80upx 80upx;
				background-repeat: no-repeat;

				.private-init {
					width: 40upx;
					height: 40upx;
					flex: 1;
					line-height: 40upx;
					background: rgba(255, 68, 68, 1);
					border-radius: 50%;
					position: absolute;
					right: -10upx;
					top: -10upx;
					transform: scale(0.75);
				}
			}
			.private-info{
				width: 440upx;
			}
		}
	}
}
</style>
