var page = {
    messageDetailDialog: {}
};
layui.use(['element'], function () {
    var $ = layui.jquery;
    var element = layui.element;

    // 加载更多按钮点击事件
    $('#btn-more1').click(function () {
        var $that = $(this);
        var str = $that.prev()[0].outerHTML;
        for (var i = 0; i < 5; i++) {
            $that.before(str);
        }
    });

    // 清空公告点击事件
    $('.message-btn-clear').click(function () {
        $(this).css('display', 'none');
        $(this).prev().find('.message-list-item').remove();
        $(this).prev().find('.message-btn-more').remove();
        $(this).prev().find('.message-list-empty').css('display', 'block');
    });

    // 我收到的公告点击事件
    $('.messageAddresseeItem').click(function () {
        if ($(this).find('.layui-badge').html() == '未读') {

            var num = $("#addresseeMessageNum").html();
            if (Number(num) - 1 <= 0) {
                $("#addresseeMessageNum").html(0);
            } else {
                $("#addresseeMessageNum").html(Number(num) - 1);
            }
            parent.refreshNewMessageNum();
            $(this).find('.layui-badge').attr('class', 'layui-badge layui-bg-gray pull-right');
            $(this).find('.layui-badge').html('已读');
        }
        var addresseeId =$(this).attr('data-addresseeId');
        var messageCenterId =$(this).attr('data-messageCenterId');
        var url = "pc/message/received/dialog/look?messageCenterId="+messageCenterId+'&addresseeId='+addresseeId;
        setReaded(addresseeId);
        openUrl(url);
    });


    function setReaded(addresseeId){
        $.ajax({
            url: g.ctx + 'pc/message/addressee/rest/setRead',
            type: 'POST',
            data: {
                id:addresseeId,
            },
            error: function () {
                layer.alert('修改已读失败', {icon: 2});
            }
        });
    }
    function openUrl(url) {
        parent.layer.open({
            skin: 'layui-layer-molv',
            title: "公告详情",
            type: 2,
            scrollbar: false,
            area: ['60%', '90%'],
            maxmin: false,
            content: url,
            closeBtn: 0
        });
    }
});