var m_NewLoginWechatKey;
var m_OperationType = 0;//0添加，1修改
var m_PublicType = 0;//
var m_ResultList = [];//所有微信号缓存

$(function () {
    //隐藏提示框
    $("#myPageAlert").hide();
    $("#myDeleteAlert").hide();
    $("#divWelcome").hide()
    BindData();
    PageLoadTrees();
    // 获取全部客服
    manageObj.getuserslist();
});

function AsyncGetUsersListResult(jsonResult) {
    if (jsonResult.success) {
        var jsonList = jsonResult.result.list;
        for (var i = 0; i < jsonList.length; i++) {
            var item = jsonList[i];
            $("#selectQueryCustomer").append("<option value='" + item.uid + "'>" + item.name
                    + "</option>");
        }
    } else {
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
    }
}

//微信号批量删除
var m_struin = "";
function ShowDelete(index, uin) {
    if ($("#btnDelete" + index).is(":checked")) {
        m_struin += uin + "|";
    } else {
        if (m_struin.indexOf(uin) != -1) {
            m_struin = m_struin.replace(uin + "|", "");
        }
    }
    if (m_struin.length > 0) {
        $("#btndeleteWechat").attr("style", "display:block;margin-left: 85%;margin-top:-35px");
    } else {
        $("#btndeleteWechat").attr("style", "display:none;");
    }
}
//批量删除按钮
function WeChatBatchcDeletion() {
    $("#DeleteModal").modal("show");
}
function CommitDelete() {
    var strParaJson = $.toJSON({
        appid: m_struin.substr(0, m_struin.length - 1)
    })
    manageObj.deletewechat(strParaJson);
}

//批量删除微信号回调
function AsyncDeleteWeChatResult(jsonResult) {
    if (jsonResult.success) {
        m_struin = "";
        nPageIndex = 0;
        BindData();
        ShowMsg("myPageAlert", "操作成功！");
    } else {
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
    }
    $("#DeleteModal").modal("hide");
}


//获取列表数据
function BindData() {
    $(".loading").show();
    $(".loadingcover").show();
    var objtxtQueryPublicName = $("#txtQueryPublicName");

    $("#DivContent").empty();
    var strParaJson = $.toJSON({
        nickname: Canceller(objtxtQueryPublicName.val()),
        cususerid: $("#selectQueryCustomer").val(),
        pagesize: nPageSize,
        pageindex: nPageIndex
    });
    manageObj.getwechatsall(strParaJson);
}


//查询微信号回调方法
function AsyncGetWeChatsAllResult(jsonResult) {
    if (jsonResult.success) {
        var jsonData = jsonResult.result.list;
        m_ResultList = jsonResult.result.list;
        nPageCount = Math.ceil(Number(jsonResult.result.total) / nPageSize);
        var strContent = "";
        if (jsonData.length > 0) {
            strContent += "<table class=\"table table-hover tabel-border tabel-borderlh\"><thead><tr>";
            strContent += GetTableHeadNoOrderStr("序号");
            strContent += GetTableHeadNoOrderStr("客服");
            strContent += GetTableHeadNoOrderStr("头像");
            strContent += GetTableHeadNoOrderStr("微信昵称");
            strContent += GetTableHeadNoOrderStr("性别");
            strContent += GetTableHeadNoOrderStr("好友数量");
            strContent += GetTableHeadNoOrderStr("创建时间");
            strContent += GetTableHeadNoOrderStr("备注");
            strContent += GetTableHeadNoOrderStr("操作");
            strContent += "</tr></thead>";
            strContent += "<tbody>";
            for (var i = 0; i < jsonData.length; i++) {
                var item = jsonData[i];
                var strTrClass = i % 2 == 0 ? "even" : "odd";
                var strTypeName = "";

                var strStatusName = "";
                var strStatusButton = "";

                strContent += "<tr class=\"" + strTrClass + "\">";
                strContent += "<td>" + (i + 1) + "</td>";
                strContent += "<td>" + item.cusname + "</td>";
                strContent += "<td><img src='" + item.headimgurl + "' style=\"width:30px;height=30px;\" onerror='nofind()'></td>";//" + item.WeChatID + "
                strContent += "<td style=\"width:190px;\">" + item.nickname + "</td>";
                var sex = "";
                if (item.sex == 1) {
                    sex = "男";
                }
                else if (item.sex == 2) {
                    sex = "女";
                } else {
                    sex = "未知";
                }
                strContent += "<td>" + sex + "</td>";
                strContent += "<td>" + item.friendcount + "</td>";
                strContent += "<td>" + item.createtime.substr(2, 14) + "</td>";
                strContent += "<td>" + item.remark + "</td>";
                strContent += "<td>";
                var nickname = item.nickname.replace(/"/g, '\\\'');//适配手机表情符号
                strContent += "&nbsp;<input id='btnDelete" + i + "' type=\"checkbox\" onclick=\"ShowDelete('" + i + "','" + item.uin + "');\">";
                //strContent += "&nbsp;<a id='btnDelete" + item.Appid + "' class='btn btn-danger  btn-xs' href='javascript:void(0)' onclick=\"ShowDelete('" + item.uin + "','" + nickname + "');\"><i class=\"glyphicon glyphicon-trash\"></i> 删除</a>";
                strContent += "</td></tr>";
            }
            strContent += "</tbody>";
            strContent += "</table>";
            $("#DivContent").html(strContent);
            $("#DivFooter").show();
            $("#divWelcome").hide();
            $("#DivFooter").html(GetPageFootStr(nPageIndex, jsonResult.result.total));
        }
        else {
            $("#divWelcome").show();
            //$("#DivContent").html("没有查询到有效数据！");
            $("#DivFooter").hide();
        }
    }
    else {
        //错误信息
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
    }
    m_struin = "";
    $("#btndeleteWechat").attr("style", "display:none;");
    $(".loadingcover").hide();
    $(".loading").hide();
}

//搜索按钮
function QueryWeChats() {
    nPageIndex = 0;
    BindData();
}


//左侧菜单高度设置
function PageLoadTrees() {
    $(".left-list-l").css({
        height: $(window).height() - 40
    });

    $(".talklist-m").css({
        height: $(window).height() - 130
    });
    $("#right").css({
        height: $(window).height() - 40
    });
    $("#left").css({
        height: $(window).height() - 40
    });
    $(".robat-default-l").css({
        height: $(window).height() - 80
    });
    $(".robat-default-l").css({
        width: $(window).width() - 110
    });

}


$(window).resize(function () {
    PageLoadTrees();
});
//得到表格表头一列内容，非排序字段
function GetTableHeadNoOrderStr(thisColumnsMark) {
    var strTh = "<th>" + thisColumnsMark + "</th>";
    return strTh;
}

