<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 applyCell from '../components/friendApplyCell'
    import im from '@/utils/im/index.js'

    export default {
        components: {
            applyCell
        },
        data() {
            return {
                pendings: []
            }
        },
        onLoad() {
            this.getPendingList()
            uni.$on('onContactNotification', this.getPendingList)
        },
        onUnload() {
            uni.$off('onContactNotification')
        },
        methods: {
            getPendingList() {
                im.getPendingList((pendings) => {
                    this.pendings = pendings
                })
            }
        }
    };
</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>
