Namespace.register("U.MD.D.Blog.A");
//Blog帖子处理

//#region 朋友圈发表

//blog首页点击我要发布
U.MD.D.Blog.A.FBCKME = function () {
    U.MD.U.L.setLoginCallBack(function () {
        U.UF.UI.EditorLoad({
            imgt: 9,
            style: {
                width: "600px",
                height: "500px"
            },
            title: false,
            name: "朋友圈",
            car: {
                onpaste: "U.MD.D.H.CPTATGBL(this);"
            },
            fcb: U.MD.D.Blog.A.FBGBL,
            upload: true
        });
    });
}

//发帖子变化
U.MD.D.Blog.A.BHFBGBL = function (UDOD, UTF) {
    if (!UTF || !U.MD.U.L.isLogin()) {
        var i, j, _UDTD, _UDAD,
            _UMT = UTF ? "removeClass" : "addClass",
            _UDE = ["UD_SYSXZLRSAAO", "UD_SYSXZLRSAOO", "UD_SYSXZLRSATO"];
        UDOD = UDOD.length ? UDOD : [UDOD];
        for (i = 0; i < UDOD.length; i++) {
            _UDAD = (_UDTD = $(UDOD[i])).Child();
            _UDTD[_UMT](_UDE[0], 0);
            for (j = 1; j < _UDAD.length; j++) {
                $(_UDAD[j])[_UMT](_UDE[j]);
            }
            ; if (UTF) { _UDAD[1].focus() };
        }
    }
}

//发表文章字限制
U.MD.D.Blog.A.OKFBGBL = function (UDOD) {
    var _UHT = UDOD.innerText;
    if (!_UHT.count() > 300) {
        U.UF.EV.stopDefault();
        U.Alert("文字输入无法大于150");
    }
    //阻止输出
}

//发表文章
U.MD.D.Blog.A.FBGBL = function (UCT, UTI, UIMG) {
    var i;
    UCT = UCT.substrU(300);
    if (UIMG) {
        for (i = 0; i < UIMG.length; i++) {
            UCT += UIMG[i].outerHTML;
        }
    }
    //添加图片
    U.Alert("发表中...");
    U.A.Request(US.AUTH, ["addArticle", US.FORUMROOTID, "", UCT, "blog"], U.MD.D.Blog.A.AsynFBGBL, ["", UCT]);
    //发送文章
}

//发表文章异步
U.MD.D.Blog.A.AsynFBGBL = function (r) {
    var _UDE, _UKE, _UDTD, _UDOD = $("#UD_SYSXZBR")[0], _userid = US.userInfo.userid, _context = r.context;
    r = r.value;
    if (r) {
        _UDE = U.MD.D.Blog.A.BLEI([r, 0, 0, U.UF.D.toTimeStamp(new Date()), _context[1], _context[1].substr(0, 100), US.userInfo.userid, US.userInfo.username, US.userInfo.UserThumbnailImageHead, 0]);
        //添加实体
        _UKE = U.MD.D.H.ET["UL"]["HY"][_userid];
        (_UKE && (_UKE = _UKE[1])) && ((!_UKE.length) && (_UDOD.innerText = ""),
            _UKE.push(_UDE));
        U.MD.D.Blog.PGBL(_UDOD, [_UDE], null, 0, true);
        U.Alert("成功发表");
    }
}


//朋友圈的实体
U.MD.D.Blog.A.BLEI = function (UTE) {
    return {
        "ArticleID": UTE[0],
        "AricitleReadNumber": UTE[1],
        "ArticleReplayNumber": UTE[2],
        "ArticleAddTime": UTE[3],
        "ArticleContent": UTE[4],
        "ArticleContentBrief": UTE[5],
        "UserID": UTE[6],
        "UserName": UTE[7],
        "UserThumbnailImageHead": UTE[8],
        "ArticleZFN": UTE[9]
    }
}

//#endregion

//#region 转发朋友圈

//转发朋友圈
U.MD.D.Blog.A.PAZF = function (UDE, UDMD) {
    if (U.MD.U.L.isLogin()) {
        var _UDTD, _UDSD, _UDOD = $("#UD_SYR"), _UDAD = _UDOD.Child()
        _UDOD.css("display", "block");
        new U.UF.UI.form("<div class='UD_SYF_STI'>转发使用</div>",
            _UDOD[0],
            {
                "id": "UD_SYRA",
                "style": {
                    "width": "500px",
                    "height": "360px"
                }
            },
            {
                isdrag: false,
                isenlarge: false
            }).form;
        (_UDSD = $("div", _UDAD[1])[0]).innerHTML = "可添加内容...";
        U.MD.D.Blog.A.PAZFP(UDE, _UDAD[2]);
        (_UDTD = $(_UDAD[3]).Child())[1].onclick = function () {
            U.MD.D.Blog.A.SPAZFF(UDE, _UDSD, UDMD);
            _UDTD[0].onclick();
        }
        _UDSD.focus();
    }
}

//打印
U.MD.D.Blog.A.PAZFP = function (UDE, UDOD) {
    UDOD.innerHTML = "";
    var _UTC, _UDSD, _UDMD, _UDTD = $$("div", { "className": "UD_SYRML" }, UDOD);
    $$("img", {
        "onerror": U.MD.C.imgError,
        "title": "点击查看",
        "onclick": function () {
            U.UF.EV.stopBubble();
            U.MD.U.V.ViewOtherUserInfo(UDE.UserID);
        },
        "src": U.MD.C.getHeadImage(UDE.UserThumbnailImageHead)
    }, _UDTD);
    _UDTD = $$("div", "className": "UD_SYRMR"}, UDOD);
_UDSD = $$("div", { "className": "UD_SYRMRS" }, _UDTD);
$$("div", { "className": "UD_SYRMRSL", "innerHTML": UDE.UserNickName || UDE.UserName }, _UDSD);
$$("div", { "className": "UD_SYRMRSR", "innerHTML": U.UF.D.getDateInterval(UDE.ArticleAddTime) }, _UDSD);
_UDSD = $$("div", { "className": "UD_SYRMRX", "innerHTML": (_UTC = UDE["ArticleContentBrief"]) }, _UDTD);
_UDSD.innerText = (_UTC = _UDSD.innerText).length > 30 ? _UTC.substr(0, 50) + "..." : _UTC
}

//点击转发朋友圈
U.MD.D.Blog.A.SPAZFF = function (UDE, UDOD) {
    if (UDE.ArticleContent && !UDE["JZ"]) {
        U.MD.D.Blog.A.PAZFF(UDE, UDOD);
    }
    else {
        U.A.Request(US.CD, [US.DB, "UseStudio_Blog", "UB_P_S_SelectArticleInformation", UDE.ArticleID], U.MD.D.Blog.A.AsynSPAZFF, ["", UDE, UDOD]);
        // U.A.Request(US.AUTH,"pb.ArticleContent", [UDE.ArticleID, "Blog"], U.MD.D.Blog.A.AsynSPAZFF, ["", UDE, UDOD]);
    }
    //获取内容和回复内容
}

//异步获取消息内容
U.MD.D.Blog.A.AsynSPAZFF = function (r) {
    var _context = r.context;
    var _UDE = _context[1];
    var _UDOD = _context[2];
    //_$.Add(_UDE,r.value[0]);

    U.UF.C.AddObj(_UDE, r.value[0]);
    delete _UDE["JZ"];
    U.MD.D.Blog.A.SPAZFF(_UDE, _UDOD);
}

//发送转发
U.MD.D.Blog.A.PAZFF = function (UDE, UDOD) {
    var _UTF, _UKE = [], _UTH = UDOD.innerHTML;
    if (_UTH == "可添加内容...") { (_UTH = "") };
    U.Alert("转发中...");

    U.A.Request(US.CD, ([US.DB, "UseStudio_Blog", "UB_P_A_AddZFLR", US.userInfo.userid, Guid.newGuid(), UDE.ArticleID, US.FORUMROOTID,
        _UTH, UDOD.innerText.substr(200) + (UDOD.innerText.length > 200 ? "..." : "") + $("img", UDOD)[0].outerHTML]), U.MD.D.Blog.A.AsynSPAZFF, ["", UDE, UDOD]);

    //   U.A.Request(US.AUTH,"pb.ZFArticle", [US.userInfo.userid, US.FORUMROOTID, UDE.ArticleID, _UTH], U.MD.D.Blog.A.AsynPAZFF, ["", _UTH, UDE]);
    //服务器同步中
}

//发送转发异步
U.MD.D.Blog.A.AsynPAZFF = function (r) {
    var _UKE, _UDTD = $("#UD_SYSXZLLRTA").Child()[2];
    _userid = US.userInfo.userid,
        _UGE = U.MD.D.H.ET["UL"]["HY"],
        _context = r.context,
        _UTH = _context[1],
        _UDE = _context[2],
        _UDOD = $$("div", { "innerHTML": _UTH });
    r = r.value;
    _UKE = U.MD.D.Blog.A.BLEI[r, 0, 0, U.UF.D.toTimeStamp(new Date()), _UTH, _UDOD.innerText.substr(0, 100), US.userInfo.userid, US.userInfo.UserNickName, US.userInfo.UserThumbnailImageHead, 0];
    _UKE.Forward = _UDE["ArticleID"];
    _UKE.ZF = _UDE;
    if (_UGE = _UGE[_userid]) {
        _UGE[1] = _UGE[1] || [],
            _UGE[1].unshift(_UKE)
    };
    //添加转发的数据
    if (_UDTD.className == "UD_SYSXZLLRTO") {
        U.MD.D.Blog.PGBL($("#UD_SYSXZLRSRD")[0], [_UKE], null, 0, true);
    } else {
        U.MD.D.H.HDSY["none", "block"];
        _UDTD.onclick();
    }
    //显示转发
}

//#endregion