<template>
    <view class="pending">
        <u-sticky>
            <view class="header-search" @click="$Router.push({ name: 'SearchFriend' })">
                <u-search placeholder="输入手机号码搜索" height="74" searchIcon="search" inputAlign="center" bgColor="white"
                    :disabled="true" :show-action="false" />
            </view>
        </u-sticky>
        <view v-for="(item, index) in pendings" :key="index">
            <apply-cell :message="item.latestMessage" @success="getPendingList" />
        </view>
    </view>
</template>

<script>
    import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
    import applyCell from '../components/friendApplyCell'

    export default {
        components: {
            applyCell
        },
        data() {
            return {
                pendings: []
            }
        },
        onLoad() {
            this.getPendingList()
            uni.$on('onContactNotification', this.getPendingList)
        },
        onUnload() {
            uni.$off('onContactNotification')
        },
        methods: {
            getPendingList() {
                // 获取系统中的好友关系会话列表
                RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], 1000, 0, (res) => {
                    if (res.code === 0) {
                        this.pendings = res.conversations.filter((item) => {
                            return item.objectName == RongIMLib.ObjectName.ContactNotification
                        })
                    }
                })
            }
        }
    };
</script>

<style lang="scss" scoped>
    .header-search {
        padding: $padding/2 $padding;
        background: $window-color;
    }

    .no-lists {
        padding-top: $padding * 3;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        font-size: $title-size-m;
        color: $text-gray-m;

        span {
            padding-top: $padding;
        }
    }
</style>
