layui.use(["layim", "laypage"],
function() {
    var layim = layui.layim,
    $ = layui.jquery,
    layer = layui.layer,
    laytpl = layui.laytpl,
    laypage = layui.laypage,
    islogin = 0,
    userdata = {};
    layim.config({
        init: {
            url: "/include/chat/friend_json.asp",
            type: "get",
            data: {}
        },
        members: {
            url: "",
            type: "get",
            data: {}
        },
        uploadImage: {
            url: "/include/inc/upload.asp?dopost=image&chat=1",
            type: ""
        },
        uploadFile: {
            url: "/include/inc/upload.asp?dopost=file&chat=1",
            type: ""
        },
        skin: [],
        brief: false,
        title: "内部沟通",
        initSkin: "1.jpg",
        isgroup: false,
        chatLog: "/include/chat/chatlog.asp",
        copyright: true
    });
    layim.on("ready",
    function(options) {
        layim.on("sendMessage",
        function(res) {
            var toid = res.to.id,
            content = res.mine.content,
            type = res.to.type;
            $.post("/include/chat/pm.asp?dopost=send", {
                toid: toid,
                content: content,
                type: type
            },
            function() {},
            "json")
        });
        var onmessage = function() {
            $.get("/include/chat/pm.asp?dopost=get",
            function(res) {
                if (res.length != 0) {
                    for (var key in res) {
                        if (res.type == "notice") {
                            workfriend(res[key])
                        }
                        layim.getMessage(res[key])
                    }
                }
            },
            "json")
        };
        setInterval(onmessage, 10000)
    })
});