var m_SystemTagCache = [];                  //系统所有标签缓存
var m_FriendCache = [];                     //当前查询出来的好友数据列表
var m_NowSelectPid = "";                    //当前选中的PID
var m_NowSelectFriendHeadImgKey = "";       //当前选中的好友头像KEY值
var m_NowSelectUin = "";                    //当前选中的UIN
var m_NowSelectFriendTags = "";             //查询条件--当前选中的标签数据
var alluserid = "";
var m_deptSection;//用于区分是否是自定义查询
var m_Cususername = "";//缓存客服名称
var m_CusWechatName = "";//缓存微信昵称
var m_FriendNicName = "";//缓存好友昵称
var m_strNowDay = "";//当天时间
var m_GroupItem;

var m_Groupitemjson = "";
var m_Colorsitemjson = "";
$(function () {
    $(function () { $("[data-toggle='tooltip']").tooltip(); });
    customquery();//自定义查询时间调用
    //键盘按下事件，判断文本框内容为空，是否显示清空按钮
    $("#txtQueryTagKey").keydown(function () {
        if (event.keyCode == "13") {        //判断如果按下的是回车键则执行查询
            if ($.trim($("#txtQueryTagKey").val()) == "") {
                $("#SearchTagByTremClose").hide();
            } else {
                $("#SearchTagByTremClose").show();
            }
            BindTagTree();
        }
    })
    //键盘按下事件，判断文本框内容为空，是否显示清空按钮
    $("#txtQueryTagKey").keyup(function () {
        if ($("#txtQueryTagKey").val() == "") {
            $("#SearchTagByTremClose").hide();
        } else {
            $("#SearchTagByTremClose").show();
        }
    });

    $("#txtDocMobile").keyup(function () {
        this.value = this.value.replace(/[^\d]/g, '');
    });
    $("#txtDocAge").keyup(function () {
        this.value = this.value.replace(/[^\d]/g, '');
    });
    $("#txtQueryMobile").keyup(function () {
        this.value = this.value.replace(/[^\d]/g, '');
    });
    $("#txtQueryAge").keyup(function () {
        this.value = this.value.replace(/[^\d]/g, '');
    });
    //好友时间查询控件
    $('#txtTimeFrom').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    $('#txtTimeEnd').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    //对话时间查询控件
    $('#talkTimeFrom').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    $('#talkTimeEnd').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });

    //绑定标签
    homeObj.gettagtree();
    //绑定本人管辖微信号列表
    //homeObj.getmywechatlist();
    homeObj.getgroupval();
    //获取部门
    var paraJson = $.toJSON({
        type: "friends"
    });
    homeObj.getdeptbyauth(paraJson);
    $("#myAlert").hide();
    $("#btnShowDocDiv").hide();

    //样式初始化
    friendscss();
    $("body").attr("style", "-webkit-user-select: text;user-select: text;");
    m_strNowDay = homeObj.gettoday();
});

//自定义查询时间插件
function customquery() {
    //好友时间查询控件
    $('#txtReportTimeFrom').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    $('#txtReportTimeEnd').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    //对话时间查询控件
    $('#talkReportTimeFrom').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    $('#talkReportTimeEnd').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
}

function friendscss() {
    $(".left").css({
        height: $(window).height()
    });
    $(".right").css({
        height: $(window).height()
    });
    $(".friends-menu").css({
        height: $(window).height()
    });
    $(".tiplist").css({
        height: $(window).height() - 59
    });
    $(".friends-table").css({
        height: $(window).height() - 110
    });
    $(".infor-detailed-m").css({
        height: $(window).height() - 57
    });
    $(".level1>a").click(function () {
        $(this).toggleClass("current").next().toggle(300)
    })
    $(".talk-content").css({
        height: $(window).height() - 150
    });
    $("#DivFooter").css({
        width: $(window).width() - 243
    });
}
$(window).resize(function () {
    friendscss();
});

//-------------------------------------------------标签-------------------------------------------------

function AsyncGetTagTreeResult(jsonResult) {
    if (jsonResult.success) {
        m_SystemTagCache = jsonResult.list;
        BindTagTree(jsonResult);
    }
}

function BindTagTree() {
    $("#txtQueryTagKey").val($.trim($("#txtQueryTagKey").val()));
    var strQueryKey = $("#txtQueryTagKey").val();

    var strTreeContent = "<ul class=\"tiplist\">";//树型菜单内容
    for (var i = 0; i < m_SystemTagCache.length; i++) {
        var jsonItem = m_SystemTagCache[i];
        var strGroupId = jsonItem.tgid;
        var nGroupType = Number(jsonItem.type);
        var strTagType = nGroupType == 1 ? "【互斥】" : "";

        var bIsQuery = false;
        var strTreeGroupHtml = "";
        strTreeGroupHtml += "<li class=\"level1\">";
        //父级标签组
        strTreeGroupHtml += "<a href=\"#\" class=\"current\"><span>" + jsonItem.tgname + strTagType + "</span></a>";
        strTreeGroupHtml += "<ul class=\"level2\" style=\"display: block;\">";
        for (var j = 0; j < jsonItem.tag.length; j++) {
            var tagItem = jsonItem.tag[j];
            if (strQueryKey.length == 0 || tagItem.tname.indexOf(strQueryKey) >= 0) {
                bIsQuery = true;
                strTreeGroupHtml += "<li id=\"liTag_" + tagItem.tid + "\" class=\"taggroup" + strGroupId + "\" onclick=\"ChangeFansTags('" + tagItem.tid + "','" + nGroupType + "','" + strGroupId + "');\"><span style=\"background:" + tagItem.color + ";\"></span><a href=\"#\"><span>" + tagItem.tname + "</span></a></li>";
            }
        }
        strTreeGroupHtml += "</ul>";
        strTreeGroupHtml += "</li>";

        if (bIsQuery) {
            strTreeContent += strTreeGroupHtml;
        }
    }
    strTreeContent += "</ul>";
    $("#divFriendSelectTag").html(strTreeContent);

    friendscss();
}
//绑定部门回调
function AsyncGetDeptByAuthResult(jsonResult) {
    if (jsonResult.success) {
        var deptlist = jsonResult.deptlist;
        $("#selDept").append("<option value='" + jsonResult.myself.userid + "' tag='user' name='" + jsonResult.myself.username + "'>本人</option>");
        if (jsonResult.deptlist.length > 0) {
            for (var index in deptlist) {
                var item = deptlist[index];
                $("#selDept").append("<option value='" + item.dgid + "'>" + item.dgname + "</option>");
                $("#selDept1").append("<option value='" + item.dgid + "'>" + item.dgname + "</option>");
            }
        } else {
            $("#selDept").hide();
            $("#selDept1").hide();
        }
        BindCompanyUsers("");
    } else {
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);
    }
    $(".loadingcover").hide();
    $(".loading").hide();
}
//绑定人员
function BindCompanyUsers(section) {
    var paraJson;
    m_deptSection = section;
    if (m_deptSection == "1") {
        $("#selectQueryCustomer1").empty();
        $("#selectQueryCustomer1").append("<option value=''>所属客服</option>");
        $("#selectQueryWechat1").empty();
        $("#selectQueryWechat1").append("<option value=''>微信号</option>");
        paraJson = $.toJSON({
            deptid: $("#selDept1").val()
        });
        homeObj.getpersonbydeptid(paraJson);
    } else {
        $("#selectQueryCustomer").empty();
        $("#selectQueryWechat").empty();
        $("#selectQueryWechat").append("<option value=''>微信号</option>");
        alluserid = "";
        var selectDom = $("#selDept").find("option:selected");
        if (selectDom.attr("tag") == "user") {
            $("#selectQueryCustomer").append("<option value='" + selectDom.val() + "' tag='user' selected='true'>" + selectDom.attr("name") + "</option>");
            alluserid = selectDom.val();
            CustomerOnchange('');
        } else {
            $("#selectQueryCustomer").append("<option value=''>所属客服</option>");
            paraJson = $.toJSON({
                deptid: $("#selDept").val()

            });
            homeObj.getpersonbydeptid(paraJson);
        }
    }
}

//绑定人员回调
function AsyncGetPersonByDeptidResult(jsonResult) {
    var objselectQueryCustomer = $("#selectQueryCustomer");
    var objselectQueryCustomer1 = $("#selectQueryCustomer1");
    if (jsonResult.success) {
        var jsonObj = jsonResult.user;
        var jsonList = jsonObj.list;
        var currentId = jsonObj.loginuid;
        if (m_deptSection == "1") {
            for (var i = 0; i < jsonList.length; i++) {
                var item = jsonList[i];
                objselectQueryCustomer1.append("<option value='" + item.userid + "'>" + item.name + "</option>");

            }
            // 自定义查询初始化页面
            $("#selectQueryCustomer1").val(CustomerDefault);
            CustomerDefault = "";
            CustomerOnchange(1);
        } else {
            alluserid = "";
            for (var i = 0; i < jsonList.length; i++) {
                var item = jsonList[i];
                alluserid += item.userid + ",";
                objselectQueryCustomer.append("<option value='" + item.userid + "'>" + item.name + "</option>");
            }
            //alluserid = alluserid.substr(0, alluserid.length - 1);
            CustomerOnchange('');
        }
    } else {
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);
    }
}

//判断标签是否存在
function TagIsExists(tid) {
    var strContent = "|" + tid + "|";
    return m_NowSelectFriendTags.indexOf(strContent) >= 0;
}

//选中、释放标签
function ChangeFansTags(tid, ishc, groupid) {
    var objLiClickTag = $("#liTag_" + tid);
    if (objLiClickTag.hasClass("active")) {
        //删除标签操作
        $("#liTag_" + tid).removeClass("active");
        m_NowSelectFriendTags = SuperReplace(m_NowSelectFriendTags, "|" + tid + "|", "|");
        m_NowSelectFriendTags = SuperReplace(m_NowSelectFriendTags, "||", "|");
    } else {
        //选择标签操作
        if (ishc == "1") {
            $(".taggroup" + groupid).removeClass("active");
            //移除此互斥标签组内所有标签
            for (var i = 0; i < m_SystemTagCache.length; i++) {
                if (m_SystemTagCache[i].tgid == groupid) {
                    //移除组内所有标签
                    for (var j = 0; j < m_SystemTagCache[i].tag.length; j++) {
                        m_NowSelectFriendTags = SuperReplace(m_NowSelectFriendTags, "|" + m_SystemTagCache[i].tag[j].tid + "|", "|");
                    }
                    break;
                }
            }
        }
        $("#liTag_" + tid).addClass("active");
        if (!TagIsExists(tid)) {
            m_NowSelectFriendTags += "|" + tid + "|";
            m_NowSelectFriendTags = SuperReplace(m_NowSelectFriendTags, "||", "|");
        }
    }
    if (m_NowSelectFriendTags == "|")
        m_NowSelectFriendTags = "";

    BindData();
}
//点击清空按钮时清空内容和隐藏按钮
function ClearQueryTagKey() {
    $("#txtQueryTagKey").val("");
    $("#SearchTagByTremClose").hide();
}
//-------------------------------------------------标签-------------------------------------------------

//-------------------------------------------------档案列表-------------------------------------------------
function BindData() {
    //好友时间查询时间限制
    var strFriendCreatTime = Date.parse(new Date("20" + $("#txtTimeFrom").val()));
    var strFriendCreatEndTime = Date.parse(new Date("20" + $("#txtTimeEnd").val()));
    var diff = parseInt((strFriendCreatEndTime - strFriendCreatTime) / 1000 / 3600 / 24);
    if (diff < 0) {
        ShowError("myPageAlert", "起始时间不能大于终止时间");
        return;
    }

    //对话时间查询时间限制
    var strTalkStartTime = Date.parse(new Date("20" + $("#talkTimeFrom").val()));//添加对话起始时间
    var strTalkEndTime = Date.parse(new Date("20" + $("#talkTimeEnd").val()));//添加对话结束时间
    var strTalkdiff = parseInt((strTalkEndTime - strTalkStartTime) / 1000 / 3600 / 24);
    if (strTalkdiff < 0) {
        ShowError("myPageAlert", "起始时间不能大于终止时间");
        return;
    }
    $(".loading").show();
    $(".loadingcover").show();

    $("#txtQueryFriendId").val($.trim($("#txtQueryFriendId").val()));
    $("#txtQueryFriendNick").val($.trim($("#txtQueryFriendNick").val()));
    $("#txtQueryPostion").val($.trim($("#txtQueryPostion").val()));
    $("#txtQueryNumber").val($.trim($("#txtQueryNumber").val()));
    $("#txtRemarkName").val($.trim($("#txtRemarkName").val()));
    $("#tbContent").empty();
    if (alluserid != "") {
        var strJson = GetSearchJson();
        homeObj.getqueryfriendslistbydoc(strJson);
    } else {
        $(".loading").hide();
        $(".loadingcover").hide();

        $("#divNoData").show();
        $("#DivFooter").hide();
        $("#divNoData").find("h2").text("没有数据！");
    }

    $("#DivAllTab").hide();
    $("#MoreSelectModal").modal("hide");
}

function AsyncGetQueryFriendsListByDocResult(jsonResult) {
    m_selectFriend = [];//遍历好友档案之前清空掉复选框选中好友的缓存  不支持分页选中好友添加标签
    //m_SelectTags = "";//选中标签的缓存(本页js共三个标签缓存)
    m_FriendCache = [];
    if (jsonResult.success) {
        if (jsonResult.result.list.length > 0) {
            $("#divNoLoginWechat").hide();
            m_FriendCache = jsonResult.result.list;

            var strContent = "";
            nPageCount = Math.ceil(Number(jsonResult.result.total) / nPageSize);
            strContent += "<tr>";
            var vcolisShowItem = GetReportCol($("#selectReport").val());
            if (vcolisShowItem == null) {
                vcolisShowItem = m_SelectColCacheFansOld;
            }
            strContent += "<th style=\"padding-bottom:0px;padding-top:0px\"><div class=\"checkbox checkbox-success\"><input pid=\"\" uin=\"\" id=\"AllSelect\" onclick=\"AllFriendSelect();\" class=\" styled\" type=\"checkbox\" value=\"1\"><label for=\"chkBissound\"></label></div></th>";
            strContent += GetTableHeadNoOrderStr("序号");
            strContent += GetTableHeadNoOrderStr("跟进");
            if (vcolisShowItem != null) {
                for (var order in vcolisShowItem) {
                    var item = vcolisShowItem[order];
                    if (item.isshow) {
                        if (item.name == "所属微信") {
                            strContent += "<th>" + item.name + "(备注)" + "(ID)" + "</th>";
                        } else {
                            strContent += "<th>" + item.name + "</th>";
                        }
                    }
                }
            }
            strContent += "</tr>";

            for (var i = 0; i < jsonResult.result.list.length; i++) {
                var item = jsonResult.result.list[i];

                var strSexMark = "未知";
                if (item.sex == "1") {
                    strSexMark = "男";
                } else if (item.sex == "2") {
                    strSexMark = "女";
                }

                var strWname = "[已删除]";
                if (item.wname != null && item.wname.length > 0) {
                    strWname = item.wname;
                } else {
                    strWname = item.wremark
                }

                ////当前行的多选框状态(设置批量打标签用)
                //var check = "";
                ////遍历选中好友缓存
                //for (var k = 0; k < m_selectFriend.length; k++) {
                //    if (m_selectFriend[k].pid == item.pid && m_selectFriend[k].uin == item.uin) {
                //        check = "checked=\"true\"";
                //        break;
                //    }
                //}
                var strTrClass = i % 2 == 0 ? "even" : "odd";
                strContent += "<tr style=\"cursor:pointer\" class=\"active" + strTrClass + "\"  onclick=\"GetItemDoc(this, '" + item.pid + "','','" + strWname + "','" + item.nickname + "');\">";
                strContent += "<td style=\"padding-bottom:0px;padding-top:0px\"><div class=\"checkbox checkbox-success\"><input id='friendCheck" + i + "' pid=" + item.pid + " uin=" + item.uin + " nickname='" + item.nickname + "' wname='" + item.wname + "' tagval='" + item.tagval + "' onclick=\"FriendTagBach(event," + item.pid + "," + item.uin + ",'" + item.nickname + "','" + item.wname + "','" + i + "','" + item.tagval + "')\" class=\"tag-select styled\" type=\"checkbox\" value=\"1\"><label for=\"chkBissound\"></label></div></td>";
                strContent += "<td>" + item.index + "</td>";
                strContent += "<td><a class='btn btn-success  btn-sm' href='javascript:void(0)' onclick=\"gotoTalk(" + item.uin + "," + item.pid + ");\">跟进</a></td>";
                //strContent += vcolisShowItem == null || vcolisShowItem.isheadurl ? "<td><img src=\"" + item.headimgurl + "\" style=\"width:30px;height:30px;\"onerror=\"nofind();\" /></td>" : "";
                if (vcolisShowItem != null) {
                    for (var order in vcolisShowItem) {
                        var showitem = vcolisShowItem[order];
                        if (showitem.isshow) {
                            if (showitem.id == "isopenid") {
                                strContent += "<td>" + item.pid + "</td>";
                            } else if (showitem.id == "state") {
                                if (item.friendstate == "") {
                                    strContent += "<td><span class=\"label label-info\" style=\"font-size:12px;\">正常</span></td>";
                                } else if (item.friendstate == "1") {
                                    strContent += "<td><span  class=\"label label-danger\" style=\"font-size:12px;\">已被好友拉黑</span></td>";
                                } else if (item.friendstate == "2") {
                                    strContent += "<td><span  class=\"label label-danger\" style=\"font-size:12px;\">已被好友删除</span></td>";
                                } else if (item.friendstate == "3") {
                                    strContent += "<td><span  class=\"label label-danger\" style=\"font-size:12px;\">好友已删除</span></td>";
                                } else {
                                    strContent += "<td><span  class=\"label label-warning\" style=\"font-size:12px;\">未知</span></td>";
                                }

                            } else if (showitem.id == "isnickname") {
                                var nickname = item.nickname;
                                nickname = nickname.length > 6 ? nickname.substr(0, 6) + ".." : nickname;
                                strContent += "<td>" + nickname + "</td>";
                            } else if (showitem.id == "iremark") {
                                strContent += "<td>" + item.remarkname + "</td>";
                            } else if (showitem.id == "isname") {
                                var name = item.name;
                                name = name.length > 4 ? name.substr(0, 4) + ".." : name;
                                strContent += "<td>" + name + "</td>";
                            } else if (showitem.id == "isphone") {
                                strContent += "<td>" + item.mobile + "</td>";
                            } else if (showitem.id == "isshxscode") {
                                //判断备注是否为空
                                if (item.wremark == null || item.wremark.trim() == "") {
                                    strWname = strWname.length > 6 ? strWname.substr(0, 6) + ".." : strWname;
                                } else {
                                    strWname = strWname.length > 6 ? strWname.substr(0, 6) + ".." : strWname + "(" + item.wremark + ")";
                                }
                                strContent += "<td>" + strWname + "(" + item.uin + ")</td>";
                            } else if (showitem.id == "issex") {
                                strContent += "<td>" + strSexMark + "</td>";
                            } else if (showitem.id == "ispostion") {
                                var location = item.province + "-" + item.city;
                                location = location.length > 6 ? location.substr(0, 6) + ".." : location;
                                strContent += "<td>" + location + "</td>";
                            } else if (showitem.id == "islastvisittime") {
                                strContent += "<td>" + item.lasttalktime.substr(5, 11) + "</td>";
                            } else if (showitem.id == "isexcode") {
                                var wxcode = item.wxcodemark;
                                wxcode = wxcode.length > 6 ? wxcode.substr(0, 6) + ".." : wxcode;
                                strContent += "<td>" + wxcode + "</td>";
                            } else if (showitem.id == "isage") {
                                strContent += "<td>" + item.age + "</td>";
                            } else if (showitem.id == "isgroupname") {
                                strContent += "<td>" + item.groupname + "</td>";
                            } else if (showitem.id == "createtime") {
                                strContent += "<td>" + item.createtime.substr(2, 14) + "</td>";
                            }
                        }
                    }
                }
                strContent += "</tr>";
            }
            $("#divNoData").hide();
            $("#tbContent").html(strContent);

            $("#DivFooter").html(GetPageFootStr(nPageIndex, jsonResult.result.total));
            $("#DivFooter").show();
        } else {
            $("#tbContent").html("");
            $("#divNoData").show();
            $("#DivFooter").hide();
            $("#divNoData").find("h2").text("没有数据！");
        }
    } else {
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);
    }
    $(".loadingcover").hide();
    $(".loading").hide();
    tableHisFileSlip();
    AllSelectState();//全选复选框状态
    $("#BatchFriend").attr("style", "display:none");//隐藏操作按钮
}

function gotoTalk(uin, pid) {
    $("#DivAllTab").hide();
    event.cancelBubble = true;//禁止触发父级div事件
    var wechatkey = homeObj.getwechatkeybyuin(uin + "");
    if (wechatkey.length == 0) {
        ShowError("myPageAlert", "该微信不在线或者在其它客服处登录！");
    } else {
        window.location.href = "talk.html?wechatkey=" + wechatkey + "&pid=" + pid;
    }
}

//显示一个人员详细档案
function GetItemDoc(obj, pid, cusname, wechatname, nickname) {
    m_Cususername = cusname;//缓存客服名称
    m_CusWechatName = wechatname;//缓存微信昵称
    m_FriendNicName = nickname;//缓存好友昵称
    event.cancelBubble = true;//禁止触发父级div事件
    ResetHisMsgPara();
    m_NowSelectPid = pid;
    $("#btnShowDocDiv").show();
    $("#divContent").find("tr").removeClass("active");
    $(obj).addClass("active");
    for (var i = 0; i < m_FriendCache.length; i++) {
        if (m_FriendCache[i].pid == pid) {
            var item = m_FriendCache[i];

            m_NowSelectFriendHeadImgKey = item.headimgkey;
            m_NowSelectUin = item.uin;

            var strSex = "未知";
            if (item.sex == "1") {
                strSex = "男";
            } else if (item.sex == "2") {
                strSex = "女";
            }
            $("#imgDocFriendHeadImg").attr("src", item.headimgurl);
            $("#imgDocFriendHeadImg").attr("onerror", "nofind()");
            $("#spDocNickName").html(item.nickname);
            $("#spDocSex").html(strSex);
            $("#spDocAddress").html(item.province + "-" + item.city);
            $("#spPID").html(item.pid);
            $("#spDocLastcallTime").html(item.lasttalktime);

            $("#hidDocWechatKey").val(item.uin);
            $("#hidtagval").val(item.tagval);
            $("#hidbisval").val(item.bisval);
            $("#hidgroupname").val(item.groupname);

            $("#txtDocName").val(item.name);
            $("#txtDocWXCode").val(item.wxcodemark);
            $("#txtDocAge").val(item.age);
            $("#txtDocMobile").val(item.mobile);
            $("#txtDocRemarkName").val(item.name);
            $("#txtDocRemark").val(item.remark);

            if (item.bisval.length > 0) {
                var status = item.bisval.replace(/#/g, ">>");
                $("#ulDocFriendSelectStutas").html(status.substr(0, status.length - 1))
            }
            else {
                $("#ulDocFriendSelectStutas").html("未设置");
            }

            //标签
            talkObj.gettaglistjson(item.tagval + ",");

            //消息获取
            var strJson = $.toJSON({
                uin: item.uin,
                pid: pid
            });
            homeObj.getcachelist(strJson);
            $("#DivAllTab").show();
            break;
        }
    }
}

function AsyncGetCacheListResult(jsonResult) {
    if (jsonResult.success) {
        if (jsonResult.list.length > 0) {
            BindCacheMsgs(jsonResult.list);
        } else {
            GetHisMsg();
        }
    } else {
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);
    }
}

//获取标签数据回执
function AsyncGetTagListResult(jsonResult) {
    if (jsonResult.success) {
        var strContent = "";
        if (jsonResult.list.length > 0) {
            for (var i = 0; i < jsonResult.list.length; i++) {
                var item = jsonResult.list[i];
                strContent += "<li><span style=\"background:" + item.color + ";\"></span><a>" + item.tname + "</a></li>";
            }
            $("#ulDocFriendSelectTags").html(strContent);
        } else {
            $("#ulDocFriendSelectTags").html("未设置");
        }

    } else {
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);

    }
}

function ResetFriendDocShow() {
    event.cancelBubble = true;//禁止出发父级div事件
    if (m_NowSelectPid.length == 0)
        return;

    if ($("#DivAllTab").is(":hidden")) {
        $("#DivAllTab").show();    //如果元素为隐藏,则将它显现
    } else {
        $("#DivAllTab").hide();     //如果元素为显现,则将其隐藏
    }
}

//-------------------------------------------------档案列表-------------------------------------------------
//绑定人员回调
function AsyncGetCompanyUsersResult(jsonResult) {
    var objselectQueryCustomer = $("#selectQueryCustomer");
    var objselectQueryCustomer1 = $("#selectQueryCustomer1");
    if (jsonResult.success) {
        var jsonObj = jsonResult.user;
        var jsonList = jsonObj.list;
        var currentId = jsonObj.loginuid;
        for (var i = 0; i < jsonList.length; i++) {
            var item = jsonList[i];
            alluserid += item.userid + ",";
            if (currentId != item.userid) {
                objselectQueryCustomer.append("<option value='" + item.userid + "'>" + item.name
                        + "</option>");
            } else {
                objselectQueryCustomer.append("<option value='" + item.userid + "' selected='true'>" + item.name
            + "</option>");
            }
            objselectQueryCustomer1.append("<option value='" + item.userid + "'>" + item.name
                    + "</option>");
        }
        BindData();
    } else {
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);
    }
}
//-------------------------------------------------绑定客服-----------------------------------------------End
//-------------------------------------------------绑定微信-----------------------------------------------Start
var IsCustom = "";
var CustomerDefault = "";
var WechatDefault = "";
var IsFirst = 1;//是否是第一次加载
// 发起绑定微信请求
function CustomerOnchange(custom) {
    IsCustom = custom;
    var strParaJson = "";
    if ("" != $("#selectQueryCustomer" + IsCustom).val()) {
        strParaJson = $.toJSON({
            uid: $("#selectQueryCustomer" + IsCustom).val()
        });
        homeObj.getwechatsallbyuid(strParaJson);
    }
}

function AsyncGetWeChatsAllByUidReportResult(jsonResult) {
    BindWechatList(jsonResult);
}

function AsyncGetMyWechatListResult(jsonResult) {
    BindWechatList(jsonResult);
}

// 绑定微信
function BindWechatList(jsonResult) {
    if (jsonResult.success) {
        var objselectQueryWechat = $("#selectQueryWechat" + IsCustom);
        objselectQueryWechat.empty();//清空
        objselectQueryWechat.append("<option value=''>微信号</option>");
        if (jsonResult.result.list.length > 0) {
            for (var i = 0; i < jsonResult.result.list.length; i++) {
                var item = jsonResult.result.list[i];
                //判断备注是否为空
                if (item.wremark == null || item.wremark.trim() == "") {
                    objselectQueryWechat.append("<option value='" + item.uin + "'>" + item.nickname + "</option>");
                } else {
                    objselectQueryWechat.append("<option value='" + item.uin + "'>" + item.nickname + "(" + item.wremark + ")"
                            + "</option>");
                }
            }
        }
        if (IsCustom == "" && 1 == IsFirst) {
            IsFirst = 0;
            $("#divNoData").show();
            $("#divNoData").find("h2").text("");
            //BindData();// 首次加载页面不查询数据 2018年03月14注释掉
        }
        // 绑定自定义查询页面
        if (IsCustom == "1" && WechatDefault != "") {
            $("#selectQueryWechat1").val(WechatDefault);
            WechatDefault = "";
        }
    } else {
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);
    }
}
//-------------------------------------------------绑定微信-----------------------------------------------End
// 高级搜索->好友分组绑定
function AsyncGetGroupValResult(jsonResult) {
    if (jsonResult.success) {
        if (jsonResult.wechats.length > 0) {
            m_GroupItem = jsonResult.wechats;
            var paraitem = jsonResult.wechats;
            for (var i = 0; i < paraitem.length; i++) {
                if (paraitem[i].key == "friendgroup") {
                    var groupitem = $.parseJSON(paraitem[i].valus);
                    m_Groupitemjson = $.parseJSON(paraitem[i].valus);
                }
            }
            var colorsitem = "";
            if (paraitem.length == "2") {
                for (var j = 0; j < paraitem.length; j++) {
                    if (paraitem[j].key == "friendgroupcolor") {
                        colorsitem = $.parseJSON(jsonResult.wechats[j].color);
                        m_Colorsitemjson = $.parseJSON(jsonResult.wechats[j].color);
                    }
                }
            }
            var strallgroup = "";
            var strallhisgroup = "";
            strallhisgroup += "<li onclick=\"SelecthisGroup('好友分组','1')\"><a href=\"#\"><span class=\"fgroup-color\"></span>好友分组</a></li>";
            strallgroup += "<li onclick=\"SelectGroup('好友分组','1')\"><a href=\"#\"><span class=\"fgroup-color\"></span>好友分组</a></li>";
            for (var i = 0; i < groupitem.length; i++) {
                var itemcolor = "";
                if (colorsitem.length > 0) {
                    itemcolor = colorsitem[i];
                }

                strallhisgroup += "<li onclick=\"SelecthisGroup('" + groupitem[i] + "','" + itemcolor + "')\"><a href=\"#\"><span class=\"fgroup-color\" style=\"background:" + itemcolor + ";\"></span>" + groupitem[i] + "</a></li>";
                strallgroup += "<li onclick=\"SelectGroup('" + groupitem[i] + "','" + itemcolor + "')\"><a href=\"#\"><span class=\"fgroup-color\" style=\"background:" + itemcolor + ";\"></span>" + groupitem[i] + "</a></li>";
            }
            $("#CustomBuddyGroups").html(strallhisgroup);
            $("#ulAllGroupFriends").html(strallgroup);
        }
    }
}
//-------------------------------------------------自定义查询-----------------------------------------------Start
//选择报表信息
function ChangeSelectReport() {
    var vselval = $("#selectReport").val();
    if (vselval != "0") {
        if (vselval == "") {
            $("[tag='MoreQuery']").show();
        } else {
            $("[tag='MoreQuery']").hide();
        }
        nPageIndex = 0;
        BindData();
    } else {
        $("[tag='MoreQuery']").show();
        GetReprot();
        $("#selectReport").val("");
    }
}

function GetSearchJson() {
    var vselval = $("#selectReport").val();
    var jsonstr = {};
    var cususerid = $("#selectQueryCustomer").val();
    if ("" == cususerid) {
        cususerid = alluserid.substr(0, alluserid.length - 1);
    }
    var groupname = $("#selectPersonDept").html() == "好友分组" ? "" : $("#selectPersonDept").html();
    if ("" == vselval || "0" == vselval) {
        jsonstr = $.toJSON({
            pid: $("#txtQueryNumber").val(),
            remarkname: $("#txtRemarkName").val(),
            name: $("#txtQueryName").val(),
            tel: $("#txtQueryMobile").val(),
            sex: $("#selectQuerySex").val(),
            point: $("#txtQueryPostion").val(),
            wxcode: $("#txtQueryFriendId").val(),
            age: $("#txtQueryAge").val(),
            group: groupname,
            remark: $("#txtQueryRemark").val(),
            state: $("#buddystatus").val(),
            createtimefrom: $("#txtTimeFrom").val(),
            createtimeto: $("#txtTimeEnd").val(),
            talktimefrom: $("#talkTimeFrom").val(),//对话起始添加时间
            talktimeto: $("#talkTimeEnd").val(),//对话截止添加时间
            uin: $("#selectQueryWechat").val(),
            tags: m_NowSelectFriendTags,
            nickname: $("#txtQueryFriendNick").val(),

            cususerid: cususerid,
            pageindex: nPageIndex,
            pagesize: nPageSize
        });
    } else {
        //自定义报表
        var json = GetReportPara(vselval);
        json.pageindex = nPageIndex;
        json.pagesize = nPageSize;
        json.tags = m_NowSelectFriendTags;
        jsonstr = JSON.stringify(json);
    }
    return jsonstr;
}
//-------------------------------------------------自定义查询-----------------------------------------------Start

//修改好友资料
function SetFriendDoc() {
    var Pid = $("#spPID").html();
    var objtxtDocName = $("#txtDocName");
    var objtxtDocWXCode = $("#txtDocWXCode");
    var objtxtDocAge = $("#txtDocAge");
    var objtxtDocMobile = $("#txtDocMobile");
    var objtxtDocRemark = $("#txtDocRemark");
    objtxtDocName.val($.trim(objtxtDocName.val()));
    objtxtDocWXCode.val($.trim(objtxtDocWXCode.val()));
    objtxtDocAge.val($.trim(objtxtDocAge.val()));
    objtxtDocMobile.val($.trim(objtxtDocMobile.val()));
    objtxtDocRemark.val($.trim(objtxtDocRemark.val()));
    //非空效验
    if (objtxtDocName.val().length < 1 && objtxtDocWXCode.val().length < 1 && objtxtDocAge.val().length < 1 && objtxtDocMobile.val().length < 1 && objtxtDocRemark.val().length < 1) {
        ShowMsg("myPageAlert", "请输入信息后再保存设置！");
        return;
    }
    //  //效验是否修改好友资料信息
    for (var i = 0; i < m_FriendCache.length; i++) {
        if (m_FriendCache[i].pid == Pid) {
            var item = m_FriendCache[i];
            if (objtxtDocName.val() == item.name && objtxtDocWXCode.val() == item.wxcodemark && objtxtDocAge.val() == item.age && objtxtDocMobile.val() == item.mobile && objtxtDocRemark.val() == item.remark) {
                ShowMsg("myPageAlert", "暂无修改任何好友资料信息！");
                return;
            }
        }
    }
    var strParaJson = $.toJSON({
        wechatkey: "",
        uin: $("#hidDocWechatKey").val(),
        tagval: $("#hidtagval").val(),
        bisval: $("#hidbisval").val(),
        groupname: $("#hidgroupname").val(),
        pid: Pid,
        name: objtxtDocName.val(),
        wxcode: objtxtDocWXCode.val(),
        age: objtxtDocAge.val(),
        fmobile: objtxtDocMobile.val(),
        remark: objtxtDocRemark.val()
    });
    homeObj.setfrienddoc(strParaJson);
}
function AsyncSetFriendDocResult(jsonResult) {
    if (jsonResult.success) {
        ShowMsg("myPageAlert", "保存成功！");
        BindData();
    } else {
        ShowError("myPageAlert", "修改好友信息异常：" + jsonResult.error);
    }
}

function HideAllTab() {
    $("#DivAllTab").hide();
}
//导出聊天记录
function ExportFriendHisList() {
    if (m_HisMsgList.length == 0) {
        ShowMsg("myPageAlert", "没有记录可导出！");
        return;
    }
    var objhidDocUin = $("#hidDocWechatKey");
    var pid = $("#spPID");
    var nickname = $("#spDocNickName");
    var strParaJson = $.toJSON({
        uin: objhidDocUin.val(),
        pid: pid.html(),
        hislist: m_HisMsgList,
        nickname: nickname.html(),
        cususername: m_Cususername,
        cnickname: m_CusWechatName,
        fnickname: m_FriendNicName
    });
    talkObj.exporthisrecord(strParaJson);
}

function AsyncExportHisRecordResult(jsonResult) {
    if (jsonResult.success) {
        ShowMsg("myPageAlert", "导出成功！");
    } else {
        ShowError("myPageAlert", "导出失败：" + jsonResult.error);
    }
}

//导出聊天记录到剪贴板（客户端缓存）
function ExportHisMsgToClipperHis() {
    //var objhidDocUin = $("#hidDocUin");
    var objhidDocPid = $("#hidDocPid");
    var objhidDocPidval = "";
    if (objhidDocPid == null || typeof (objhidDocPid.val()) == "undefined") {
        objhidDocPidval = m_NowSelectPid; //历史记录模块的聊天记录
    } else {
        objhidDocPidval = objhidDocPid.val();//对话模块的聊天记录
    }
    var objnickname = $("#spDocNickName");

    var strWechatNickName = $("#hidDocWechatNickName").val();
    var strParaJson = $.toJSON({
        pid: objhidDocPidval,
        hislist: m_HisMsgList,
        cnickname: m_CusWechatName,
        fnickname: objnickname.html(),
        nickname: objnickname.html(),
        cususername: m_Cususername
    });
    talkObj.exporthisrecordtoclipper(strParaJson);
}

//导出聊天记录到HTML（页面缓存）
function ExportHisMsgToHtmlHis() {
    //var objhidDocUin = $("#hidDocUin");
    var objhidDocPid = $("#hidDocPid");
    var objhidDocPidval = "";
    if (objhidDocPid == null || typeof (objhidDocPid.val()) == "undefined") {
        objhidDocPidval = m_NowSelectPid; //历史记录模块的聊天记录
    } else {
        objhidDocPidval = objhidDocPid.val();//对话模块的聊天记录
    }
    var objnickname = $("#spDocNickName");

    var strParaJson = $.toJSON({
        pid: objhidDocPidval,
        hislist: m_HisMsgList,
        cnickname: m_CusWechatName,
        fnickname: objnickname.html(),
        nickname: objnickname.html(),
        cususername: m_Cususername
    });
    talkObj.exporthisrecordtohtml(strParaJson);
}

// 导出好友列表信息
function Export() {
    HideAllTab();

    if (m_FriendCache.length == 0) {
        ShowMsg("myPageAlert", "没有记录可导出！");
        return;
    }
    var strParaJson = $.toJSON({
        friends: m_FriendCache,
    });
    homeObj.exporfriends(strParaJson);
}
//导出excle回调
function AsyncExporFriendsResult(jsonResult) {
    if (jsonResult.success) {
        ShowMsg("myPageAlert", "报表导出成功！");
    } else {
        ShowError("myPageAlert", "报表导出异常" + jsonResult.error);
    }
}

function SelecthisGroup(groupname, itemcolor) {
    $("#selectPersonDept1").html(groupname);
    if (itemcolor.length > 1) {
        $("#selectPersonDept1").css("border-left", "5px solid " + itemcolor + "");
    } else {
        $("#selectPersonDept1").css("border-left", "");
    }
}

function SelectGroup(groupname, itemcolor) {
    $("#selectPersonDept").html(groupname);
    if (itemcolor.length > 1) {
        $("#selectPersonDept").css("border-left", "5px solid " + itemcolor + "");
    } else {
        $("#selectPersonDept").css("border-left", "");
    }

}
//----------------------------------高级查询----->
//清除起始添加时间
function deleFriendStartTime() {
    $("#txtTimeFrom").val("");
}
//截止添加时间
function deleFriendEndTime() {
    $("#txtTimeEnd").val("");
}
//清除对话开始时间
function deleTalkStartTime() {
    $("#talkTimeFrom").val("");
}
//清除对话结束时间
function deleTalkEndTime() {
    $("#talkTimeEnd").val("");
}
//----------------------------------自定义报表------>
//清除起始添加时间
function deleCustomFriendStartTime() {
    $("#txtReportTimeFrom").val("");
}
//截止添加时间
function deleCustomFriendEndTime() {
    $("#txtReportTimeEnd").val("");
}
//清除对话开始时间
function deleCustomTalkStartTime() {
    $("#talkReportTimeFrom").val("");
}
//清除对话结束时间
function deleCustomTalkEndTime() {
    $("#talkReportTimeEnd").val("");
}

//----------------------------------------批量打标签功能--------------------------------------
var m_selectFriend = [];//选中的pid，uin ,uname ,nname的好友的缓存
var m_SelectTags = "";//选中标签的缓存(本页js共三个标签缓存)

//选中好友的checked事件
function FriendTagBach(event, pid, uin, nickname, wname, index, tagval) {
    event.stopPropagation();//阻止事件默认行为
    AllSelectState();//判断全选复选框状态函数
    if ($("#friendCheck" + index).is(':checked')) {
        //向好友缓存中添加数据        
        m_selectFriend.push({ "pid": pid.toString(), "uin": uin.toString(), "nickname": nickname, "uname": wname, "tagval": tagval });
    } else {
        //从好友缓存中删除数据
        for (var i = 0; i < m_selectFriend.length; i++) {
            if (m_selectFriend[i].pid == pid.toString() && m_selectFriend[i].uin == uin.toString()) {
                m_selectFriend.splice(i, 1);
                break;
            }
        }
    }
    //判断好友缓存是否存在数据，显示操作按钮用
    if (m_selectFriend.length == 0) {
        $("#BatchFriend").attr("style", "display:none");
    } else {
        $("#BatchFriend").attr("style", "display:inline;");
    }
}

//选中全部好友的checked单击事件
function AllFriendSelect() {
    if ($("#AllSelect").is(':checked')) {
        //当前页面全选时
        var FriendChecked = $("#tbContent").find("input");
        FriendChecked.each(function (i) {
            if ((!$(this).is(':checked')) && $(this).attr("pid") != "" && $(this).attr("uin") != "") {
                m_selectFriend.push({ "pid": $(this).attr("pid").toString(), "uin": $(this).attr("uin").toString(), "nickname": $(this).attr("nickname").toString(), "uname": $(this).attr("wname").toString(), "tagval": $(this).attr("tagval") });
            }
        });
        $(".tag-select").prop("checked", true);//选中当前页面所有的checkbox
        $("#BatchFriend").attr("style", "display:inline;");//显示操作按钮
    } else {
        //当前页面全取消时
        $(".tag-select").prop("checked", false);//取消选中当前页面所有的checkbox
        $("#BatchFriend").attr("style", "display:none");//隐藏操作按钮        
        var FriendChecked = $("#tbContent").find("input");
        FriendChecked.each(function (i) {
            for (var j = 0; j < m_selectFriend.length; j++) {
                if (m_selectFriend[j].uin == $(this).attr("uin").toString() && m_selectFriend[j].pid == $(this).attr("pid").toString()) {
                    m_selectFriend.splice(j, 1);
                }
            }
        });
    }
    //判断好友缓存是否存在数据，显示操作按钮用
    if (m_selectFriend.length == 0) {
        $("#BatchFriend").attr("style", "display:none");
    } else {
        $("#BatchFriend").attr("style", "display:inline;");
    }
}

//标签操作单击事件
function ShowEditTagModel() {
    if (m_selectFriend.length == 0) {
        ShowMsg("myPageAlert", "请选择需要打标签的好友!");
        return;
    }
    BindFansTagList();//遍历所有标签方法
    $("#selectFansTagModel").modal({ backdrop: 'static', keyboard: false });//显示标签所在容器
    m_SelectTags = "";//清空选中标签缓存
}

//取消按钮单击事件
function EmptySelectFriend() {
    m_selectFriend = [];//清空
    m_SelectTags = "";
    $("#BatchFriend").hide();
    $(".tag-select").prop("checked", false);
    $("#AllSelect").prop("checked", false);
}
//判断全选复选框状态
function AllSelectState() {
    var AllSelectCheck = true;//判断全选复选框状态
    var FriendChecked = $("#tbContent").find("input");
    FriendChecked.each(function (i) {
        if ($(this).attr("pid") != "" && !$(this).is(':checked')) {
            AllSelectCheck = false;
        }
    });
    $("#AllSelect").prop("checked", AllSelectCheck);
}
//树形标签内容遍历
function BindFansTagList() {
    $("#TagButton").show();
    var SelectTids = [];//选中好友的tid的集合
    //该循环生成选中好友的tid的list
    for (var i = 0; i < m_selectFriend.length; i++) {
        var list = m_selectFriend[i].tagval.split("|");
        for (var k = 0; k < list.length; k++) {
            SelectTids.push(list[k]);
        }
    }

    if (m_SystemTagCache != null && m_SystemTagCache.length > 0) {
        var strTreeContent = "<ul class=\"list-unstyled check-tags-ul\">";//树型菜单内容
        for (var i = 0; i < m_SystemTagCache.length; i++) {
            var jsonItem = m_SystemTagCache[i];
            var strGroupId = jsonItem.tgid;
            var nGroupType = Number(jsonItem.type);
            var strTagType = nGroupType == 1 ? "【互斥】" : "";
            strTreeContent += "<li class=\"check-tags-header\">";
            //父级标签组
            strTreeContent += "<h2 id=\"liTagGroup_" + strGroupId + "\" class=\"inactive-m\">" + jsonItem.tgname + strTagType + "</a>";
            strTreeContent += "<ul style=\"display: block\">";
            for (var j = 0; j < jsonItem.tag.length; j++) {
                var tagItem = jsonItem.tag[j];
                var state = "";
                for (var k = 0; k < SelectTids.length; k++) {
                    if (SelectTids[k] == tagItem.tid) {
                        state = "active";
                        break;
                    }
                }
                strTreeContent += "<li id=\"liTagSelect_" + tagItem.tid + "\" class=\"taggroupSelect" + strGroupId + "\" onclick=\"ChangeFansTagsSelect('" + tagItem.tid + "','" + nGroupType + "','" + strGroupId + "');\"><span style=\"background:" + tagItem.color + ";\"></span><a class=" + state + " href=\"#\">" + tagItem.tname + "</a></li>";
            }
            strTreeContent += "</ul>";
            strTreeContent += "</li>";
        }
        strTreeContent += "</ul>";
        $("#divFriendSelectTaging").html(strTreeContent);
    }
    else {
        $("#divFriendSelectTaging").html("暂无标签,请添加!");
        $("#TagButton").hide();
    }
}

//批量好友打标签选中的标签
function ChangeFansTagsSelect(tid, ishc, groupid) {
    var objLiClickTag = $("#liTagSelect_" + tid);
    if (objLiClickTag.hasClass("active")) {
        //删除标签操作
        $("#liTagSelect_" + tid).removeClass("active");
        m_SelectTags = SuperReplace(m_SelectTags, "|" + tid + "|", "|");
        m_SelectTags = SuperReplace(m_SelectTags, "||", "|");
    } else {
        //选择标签操作
        if (ishc == "1") {
            $(".taggroupSelect" + groupid).removeClass("active");
            //移除此互斥标签组内所有标签
            for (var i = 0; i < m_SystemTagCache.length; i++) {
                if (m_SystemTagCache[i].tgid == groupid) {
                    //移除组内所有标签
                    for (var j = 0; j < m_SystemTagCache[i].tag.length; j++) {
                        m_SelectTags = SuperReplace(m_SelectTags, "|" + m_SystemTagCache[i].tag[j].tid + "|", "|");
                    }
                    break;
                }
            }
        }
        $("#liTagSelect_" + tid).addClass("active");
        if (!TagIsExists(tid)) {
            m_SelectTags += "|" + tid + "|";
            m_SelectTags = SuperReplace(m_SelectTags, "||", "|");
        }
    }
    if (m_SelectTags == "|")
        m_SelectTags = "";

}

//好友打标签完成按钮
function SetFriendTags() {
    if (m_SelectTags.length == 0) {
        ShowMsg("myPageAlert", "请选择标签!");
        return;
    }
    var mergeSubmit = [];//合并标签数组和好友数组
    for (var i = 0; i < m_selectFriend.length; i++) {
        mergeSubmit.push({ "pid": m_selectFriend[i].pid, "uin": m_selectFriend[i].uin, "nickname": m_selectFriend[i].nickname, "uname": m_selectFriend[i].uname, "tags": m_SelectTags });
    }
    var json = $.toJSON({
        "friends": mergeSubmit
    });
    $(".loading").show();
    $(".loadingcover").show();
    homeObj.batchfriendstag(json);
}
function AsyncMostFriendsTagResult(jsonResult) {
    if (jsonResult.success) {
        $("#BatchFriend").attr("style", "display:none");//隐藏操作按钮
        m_selectFriend = [];//清空选中好友缓存
        m_SelectTags = "";//清空标签缓存
        BindData();
        ShowMsg("myPageAlert", "操作成功!");
    } else {
        $(".loading").hide();
        $(".loadingcover").hide();
        ShowError("myPageAlert", "操作失败!");
    }
}