<template>
    <div class="account_like">
		<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="account_generalMessage_item_right_title_name">{{ item.userName }} <span>{{$t('account.likedYourWork')}}</span></div>
						<div>{{ item.portfolioName }}</div>
					</div>
				</div>
				<div class="account_generalMessage_item_left">
					<div class="account_generalMessage_item_left_delete modal_title_text_intro">
						<!-- <span class="icon iconfont icon-shanchu operate_icon"></span> -->
					</div>
					<div class="modal_title_text_intro">{{ item.createTime }}</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";
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.content.length == 0) {
					accountMessage.isNoData = true
					return
				}
				accountMessage.dataList = rv.content
			}).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(()=>{
				accountMessage.dataList.forEach((item:any)=>{
					item.isRead = 1
				})
			}).catch((err:any)=>{
			})
		}
		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,
		   openOtherUsers,
		   loadingDom,
        }
    },
    data(){
        return{
            
        }
    },
})
</script>
<style lang="less" scoped>
.account_like{
	width: 100%;
	.account_generalMessage_title{
	}
	.account_generalMessage_center{
		.account_generalMessage_item{
			.account_generalMessage_item_right{
				display: flex;
				align-items: center;
				margin-right: 1rem;
				.account_generalMessage_item_right_img{
					width: 8rem;
					height: 8rem;
					margin-right: 2rem;
					flex-shrink: 0;
					cursor: pointer;
					img{
						width: 100%;
						height: 100%;
						object-fit: contain;
						border-radius: 50%;
					}
				}
				.account_generalMessage_item_right_title{
					.account_generalMessage_item_right_title_name{
						font-weight: 600;
						font-weight: 500;
						color: #000;
						span{
							font-weight: 500;
							color: #9999aa;
						}
					}
				}
			}
			.account_generalMessage_item_left{
				text-align: right;
				flex-shrink: 0;
				.account_generalMessage_item_left_delete{
					span{
						cursor: pointer;
					}
				}
				div{
					padding: .5rem 2rem;
					border-radius: 4rem;
				}
			}
		}
		.account_generalMessage_item:last-child{
			margin-bottom: 0;
			border-bottom: none;
		}
	}
}
</style>
