<template>
    <div class="account_newFollow">
		<div class="account_generalMessage_title modal_title_text">
			<!-- <span>新增粉丝</span> -->
			<div class="account_generalMessage_title_setting" @click="allRead">{{$t('account.AllRead')}}</div>
		</div>
		<div class="account_generalMessage_center modal_title_text">
			<div class="account_generalMessage_item" v-for="item in dataList" :key="item.id" @click="setRead(item)">
				<a-badge :dot="item.isRead == 0"></a-badge>
				<div class="account_generalMessage_item_right">
					<div class="account_generalMessage_item_right_img" @click="openOtherUsers(item)">
						<img :src="item.avatar" alt="">
					</div>
					<div class="account_generalMessage_item_right_title">
						<div class="">{{ item.userName }}</div>
						<div class="modal_title_text_intro">{{ item.createTime }} {{$t('account.followedYou')}}</div>
					</div>
				</div>
				<div class="account_generalMessage_item_left">
					<div v-if="item?.isFollow == 0" @click.stop="setFollow(item)" >{{$t('newScaleImage.Follow')}}</div>
					<div v-else @click.stop="setFollow(item)" >{{$t('newScaleImage.Unfollow')}}</div>
				</div>
			</div>
			<div class="account_generalMessage_item" style="justify-content: center;" v-if="dataList.length == 0 && isNoData">
				{{$t('account.dataNull')}}
			</div>
			<div class="page_loading_box" v-show="!isNoData">
				<span class="page_loading" ref="loadingDom" v-show="!isShowMark"></span>
				<span v-show="isShowMark">
					<a-spin size="large" />
				</span>
			</div>
		</div>
    </div>
</template>
<script lang="ts">
import { defineComponent,computed,ref,reactive,nextTick,toRefs,createVNode, onMounted} from 'vue'
import { Https } from "@/tool/https";
import { useRouter,useRoute } from 'vue-router'
import { Modal,message } from 'ant-design-vue';
import { useStore } from "vuex";
import { setCookie, getCookie, WriteCookie } from "@/tool/cookie";
import { useI18n } from 'vue-i18n'
export default defineComponent({
    components:{
    },
	// emits:['setReadStatus','setAllmessage'],
    props:['setReadStatus','setAllmessage','getHistory'],
    setup(prop,{emit}) {
		const router = useRouter()
        const store = useStore();
		let accountMessage = reactive({
			activeKey: ref('1'),
			dataList:[
				
			],
			page:1,
			size:10,
			isNoData: false,
			isShowMark: false,
		})
		let loadingDom:any = ref(null)
		let setmessageList = ()=>{
			accountMessage.isShowMark = true
			let data = {
				page: accountMessage.page,
				size: accountMessage.size,
			}
			prop.getHistory(data).then((rv:any)=>{
				accountMessage.isShowMark = false
				if(rv.length == 0) {
					accountMessage.isNoData = true
					return
				}
				accountMessage.dataList = rv
			}).catch(() => {
				accountMessage.isShowMark = false
				accountMessage.isNoData = true
			})
		}
		let setRead = (item:any)=>{
			prop.setReadStatus(item).then((rv:any)=>{
				item.isRead = 1
			}).catch((err:any)=>{
			})
		}
		let allRead = ()=>{
			// emit('setAllmessage')
			prop.setAllmessage().then(()=>{
			}).catch((err:any)=>{
			})
		}
		let setFollow = (item:any) =>{
			let url = Https.httpUrls.porfolioFollow
			if(item.isFollow == 1)url = Https.httpUrls.porfolioCancelFollow
			Https.axiosGet(url, {params:{followeeId:item.senderId}})
			.then((rv) => {
				if(item.isFollow == 1){
					item.isFollow = 0
				}else{
					item.isFollow = 1
				}
			})
		}
		let openOtherUsers = (item:any)=>{
			const routeUrl = router.resolve({
				path:'/home/otherUsers',
				query:{
					userId:item.senderId
				}
			})
			window.open(routeUrl.href,'_blank')
		}
		onMounted (()=>{
			accountMessage.isNoData = false
			accountMessage.page = 0
			let imgParent:any = document.querySelector('.account_systemMessage .page_loading')
			new IntersectionObserver(
				(entries, observer) => {
					// 如果不是相交，则直接返回
					// console.log(entries[0]);
					if (!entries[0].intersectionRatio) return;
					accountMessage.page+=1
					setmessageList()
				},
				// { root:worksPage }
			).observe(loadingDom.value);
		})
        return{
           ...toRefs(accountMessage),
		   setmessageList,
		   setRead,
		   allRead,
		   setFollow,
		   openOtherUsers,
		   loadingDom,
        }
    },
    data(){
        return{
            
        }
    },
})
</script>
<style lang="less" scoped>
.account_newFollow{
	width: 100%;
	.account_generalMessage_center{
		.account_generalMessage_item{
			.account_generalMessage_item_right{
				display: flex;
				align-items: center;
				.account_generalMessage_item_right_img{
					width: 8rem;
					height: 8rem;
					margin-right: 2rem;
					cursor: pointer;
					img{
						width: 100%;
						height: 100%;
						object-fit: contain;
						border-radius: 50%;
					}
				}
			}
			.account_generalMessage_item_left{
				div{
					padding: .5rem 2rem;
					border-radius: 4rem;
					border: 2px solid #e9eaec;
					cursor: pointer;
				}
			}
		}
		.account_generalMessage_item:last-child{
			margin-bottom: 0;
			border-bottom: none;
		}
	}
}
</style>
