<template>
    <div class="account_message">
		<a-tabs class="account_message_body" v-model:activeKey="activeKey" @change="changeTabs">
			<a-tab-pane v-for="item in messageList" :key="item.key">
				<system v-if="item.key == 'system'" :ref="item.key" :setReadStatus="setReadStatus" :setAllmessage="setAllmessage" :getHistory="getHistory"></system>
				<privateChat v-if="item.key == 'privateChat'" :ref="item.key" :setReadStatus="setReadStatus" :setAllmessage="setAllmessage" :getHistory="getHistory"></privateChat>
				<comment v-if="item.key == 'comment'" :ref="item.key" :setReadStatus="setReadStatus" :setAllmessage="setAllmessage" :getHistory="getHistory"></comment>
				<likeMessage v-if="item.key == 'like'" :ref="item.key" :setReadStatus="setReadStatus" :setAllmessage="setAllmessage" :getHistory="getHistory"></likeMessage>
				<newFollow v-if="item.key == 'follow'" :ref="item.key" :setReadStatus="setReadStatus" :setAllmessage="setAllmessage" :getHistory="getHistory"></newFollow>
				<!-- <newFollow v-if="item.key == 'service'" :ref="item.key"></newFollow> -->
				<template #tab>
					<a-badge :count="messageSystem.messageType[item.key]" >
					<span>{{item.title}}</span>
					</a-badge>
				</template>
			</a-tab-pane>
			
<!-- 			
			<a-tab-pane key="1" tab="系统消息">
				<system ref="system"></system>
			</a-tab-pane>
		
			<a-tab-pane key="3" tab="评论">
				<comment></comment>
			</a-tab-pane>
			<a-tab-pane key="4" tab="点赞">
				<likeMessage></likeMessage>
			</a-tab-pane>
			<a-tab-pane key="6" tab="新增粉丝">
				<newFollow ref="newFollow"></newFollow>
			</a-tab-pane>
			<a-tab-pane key="5" tab="客服">Content of Tab Pane 3</a-tab-pane> -->
		</a-tabs>
    </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 system from '@/component/Account/message/system.vue'
import privateChat from '@/component/Account/message/privateChat.vue'
import newFollow from '@/component/Account/message/newFollow.vue'
import likeMessage from '@/component/Account/message/likeMessage.vue'
import comment from '@/component/Account/message/comment.vue'
import { useI18n } from 'vue-i18n'
export default defineComponent({
    components:{
		system,
		privateChat,
		newFollow,
		likeMessage,
		comment,
    },
    setup() {
		const {t} = useI18n()
		const router = useRouter()
        const store = useStore();
		let accountMessage = reactive({
			messageList:[
				{
					title:t('account.systemMessages'),
					key:'system',
				},
				// {
				// 	title:'私信',
				// 	key:'privateChat',
				// },
				{
					title:t('account.comment'),
					key:'comment',
				},{
					title:t('account.like'),
					key:'like',
				},{
					title:t('account.NewFans'),
					key:'follow',
				},
				// {
				// 	title:'客服',
				// 	key:'service',
				// },
			],
			activeKey: '',
		})
		let domRefs:any = reactive({
			system:ref(null),
			comment:ref(null),
			like:ref(null),
			follow:ref(null),
			service:ref(null)
		})
		let messageSystem = computed(()=>{
			return store.state.UserHabit.messageSystem
		})
		// provide('exhibitionList',exhibitionList)
		let setUserData = ()=>{
			router.push({path:'/home/account/accountEdit'})
		}
		let changeTabs = (key:any)=>{
			// if(accountMessage.activeKey == 'service')return
		}
		let setReadStatus = (value:any)=>{
			return new Promise((resolve,reject)=>{
				if(value.isRead == 1)return reject('')
				let data = {
					type:accountMessage.activeKey,
					notificationIdList:value.id
				}
				Https.axiosPost(Https.httpUrls.setReadStatus,'',{params:data}).then((rv)=>{
					if(rv){
						resolve(rv)
						// store.commit('setMessageSystem',rv)
					}
				}).catch((err)=>{
					reject(err)
				})
			})
			
		}
		let setAllmessage = ()=>{
			return new Promise((resolve,reject)=>{
				let data = {
					type:accountMessage.activeKey
				}
				Https.axiosPost(Https.httpUrls.oneClickRead,'',{params:data}).then((rv)=>{
					resolve(rv)
				}).catch((err)=>{
					reject(err
					)
				})
			})
		}
		let getHistory = (data:any)=>{
			return new Promise((resolve,reject)=>{
				data.type = accountMessage.activeKey
				let url = Https.httpUrls.getHistoryNotification
				// if(data.type == 'follow'){
				// 	url = Https.httpUrls.porfolioGetFollowerList
				// }
				Https.axiosPost(url,data).then((rv)=>{
					if(rv){
						// domRefs[data.type][0].setmessageList(rv,data)
						resolve(rv)
					}
				}).catch((err)=>{
					reject(err)
				})
			})
		}
		onMounted(()=>{
			let key = accountMessage.messageList[0].key
			accountMessage.activeKey = key
		})
        return{
           ...toRefs(accountMessage),
           ...toRefs(domRefs),
		   messageSystem,
		   setUserData,
		   setReadStatus,
		   changeTabs,
		   setAllmessage,
		   getHistory,
        }
    },
    data(){
        return{
            
        }
    },
})
</script>
<style lang="less" scoped>
.account_message{
	width: 100%;
	.account_message_body{
		padding-bottom: 3rem;
		:deep(.ant-badge){
			font-size: var(--aida-fsize2);
		}
		:deep(.ant-tabs-nav){
			padding: 0rem 5rem;
			&::before{
			    display: none;
			}
			.ant-tabs-nav-wrap{
				.ant-tabs-tab-btn{
					font-size: 2.4rem;
				}
				.ant-tabs-tab-active{
					.ant-tabs-tab-btn{
						font-weight: 900;
					}
				}
			}
			.ant-tabs-ink-bar{
				background: #000;
			}
		}
		
	}
}
</style>

