var alluserid = "";
var m_deptSection;//用于区分是否是自定义查询
var m_Cususername = "";//缓存客服名称
var m_CusWechatName = "";//缓存微信昵称
var m_FriendNicName = "";//缓存好友昵称
var m_HistoryCache = [];
var m_Groupitemjson = "";
var m_Colorsitemjson = "";
var m_strNowDay = "";//当天时间
$(function () {
    $("#txtDocMobile").keyup(function () {
        this.value = this.value.replace(/[^\d]/g, '');
    });
    $("#txtDocAge").keyup(function () {
        this.value = this.value.replace(/[^\d]/g, '');
    });
    $("#txtQueryTel").keyup(function () {
        this.value = this.value.replace(/[^\d]/g, '');
    });
    $("#txtQueryAge").keyup(function () {
        this.value = this.value.replace(/[^\d]/g, '');
    });
    $(function () { $("[data-toggle='tooltip']").tooltip(); });
    //获取部门
    var paraJson = $.toJSON({
        type: "history"
    });
    homeObj.getdeptbyauth(paraJson);
    m_strNowDay = homeObj.gettoday();

    //好友分组
    homeObj.getgroupval();
    $("#divNoLoginWechat").hide();
    $("#txtTimeSeniorFrom").val(homeObj.getweekday());//默认开始日期
    $('#txtTimeSeniorEnd').val(homeObj.gettoday());//设置时间为当前日期
    historycss();
    $("#btnShowDocDiv").hide();
    $("body").attr("style", "-webkit-user-select: text;user-select: text;");
});
function historycss() {
    $(".left").css({
        height: $(window).height()
    });
    $(".right").css({
        height: $(window).height()
    });
    $(".friends-table").css({
        height: $(window).height() - 110
    });
    $(".infor-detailed-m").css({
        height: $(window).height() - 59
    });
    $(".talk-content").css({
        height: $(window).height() - 150
    });
}
$(window).resize(function () {
    historycss();
});
//初始化控件
$(document).ready(function () {
    $('#txtTimeSeniorFrom').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    $('#txtTimeSeniorEnd').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    $('#txtTimeReportFrom').datetimepicker({
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: true,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        minView: "month",
        format: "yyyy-mm-dd"
    });
    $('#txtTimeReportEnd').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 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 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 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);
    }
}
//----------------------绑定微信start---------------------------------------------------
var IsCustom = "";
var CustomerDefault = "";
var WechatDefault = "";
var IsFirst = 1;//是否是第一次加载
// 发起绑定微信请求
function CustomerOnchange(custom) {
    IsCustom = custom;
    $("#selectQueryWechat" + IsCustom).empty();
    $("#selectQueryWechat" + IsCustom).append("<option value=''>微信号</option>");
    if ("" != $("#selectQueryCustomer" + IsCustom).val()) {
        var strParaJson = "";
        strParaJson = $.toJSON({
            uid: $("#selectQueryCustomer" + IsCustom).val()
        });
        homeObj.getwechatsallbyuid(strParaJson);
    }
}

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

// 绑定微信
function BindWechatList(jsonResult) {
    if (jsonResult.success) {
        var objselectQueryWechat = $("#selectQueryWechat" + IsCustom);
        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 BindData() {
    var time1 = Date.parse(new Date("20" + $("#txtTimeSeniorFrom").val()));
    var time2 = Date.parse(new Date("20" + $("#txtTimeSeniorEnd").val()));
    var diff = parseInt((time2 - time1) / 1000 / 3600 / 24);
    if (diff < 0) {
        ShowError("myPageAlert", "起始时间不能大于终止时间");
        return;
    }
    $(".loading").show();
    $(".loadingcover").show();
    $("#txtQueryNickName").val($.trim($("#txtQueryNickName").val()));
    $("#txtPid").val($.trim($("#txtPid").val()));
    $("#txtTimeSeniorFrom").val($.trim($("#txtTimeSeniorFrom").val()));
    $("#txtTimeSeniorEnd").val($.trim($("#txtTimeSeniorEnd").val()));
    $("#tbContent").empty();
    if (alluserid != "") {
        var strJson = GetSearchJson();
        homeObj.getfriendhistorylist(strJson);
    } else {
        $(".loading").hide();
        $(".loadingcover").hide();

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

function AsyncGetFriendHistoryListResult(jsonResult) {
    if (jsonResult.success) {
        if (jsonResult.result.list.length > 0) {
            $("#divNoLoginWechat").hide();
            m_HistoryCache = 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_SelectColCacheOld;
            }
            strContent += GetTableHeadNoOrderStr("序号");
            strContent += GetTableHeadNoOrderStr("跟进");
            if (vcolisShowItem != null) {
                for (var order in vcolisShowItem) {
                    var item = vcolisShowItem[order];
                    //列全显示
                    //if (item.isshow) {
                    //    strContent += "<th>"+item.name+"</th>";
                    //}
                    if (item.isshow && item.name != "发起人" && item.name != "结束时间" && item.name != "对话时长" && item.name != "是否留电" && item.name != "回复均时") {
                        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.fsex == "1") {
                    strSexMark = "男";
                } else if (item.fsex == "2") {
                    strSexMark = "女";
                }

                var strTrClass = i % 2 == 0 ? "even" : "odd";
                strContent += "<tr class=\"avtive" + strTrClass + "\"  style=\"cursor:pointer\" onclick=\"GetItemDoc(this, '" + item.pid + "','" + item.talkstarttime + "','" + item.talkendtime + "','" + item.cususername + "','" + item.cnickname + "','" + item.fnickname + "');\">";
                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>";
                if (vcolisShowItem != null) {
                    for (var order in vcolisShowItem) {
                        var showitem = vcolisShowItem[order];
                        if (showitem.isshow) {
                            if (showitem.id == "iscususername") {
                                strContent += "<td>" + item.cususername + "</td>";
                            } else if (showitem.id == "iscuswechat") {
                                //判断备注是否为空
                                if (item.wremark == null || item.wremark.trim() == "") {
                                    var cnickname = item.cnickname.length == 0 ? "未知" : item.cnickname;
                                } else {
                                    var cnickname = item.cnickname.length == 0 ? "未知" : item.cnickname + "(" + item.wremark + ")";
                                }
                                cnickname = cnickname.length > 10 ? cnickname.substr(0, 10) + ".." : cnickname;
                                strContent += "<td>" + cnickname + "</td>";
                            } else if (showitem.id == "isfriend") {
                                var fnickname = item.fnickname.length == 0 ? "未知" : item.fnickname;
                                fnickname = fnickname.length > 6 ? fnickname.substr(0, 6) + ".." : fnickname;
                                strContent += "<td>" + fnickname + "</td>";
                            } else if (showitem.id == "isremarkname") {
                                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 == "ismobile") {
                                strContent += "<td>" + item.mobile + "</td>";
                            } else if (showitem.id == "istalktype") {
                                var strTalkTypeMark = GetTalkTypeName(item.talktype);
                                strContent += "<td>" + strTalkTypeMark + "</td>";
                            }
                                //发起人
                                //else if (showitem.id == "isstartperson") {
                                //    var strStartType = "";
                                //    if (item.firstmsgsource == "0") {
                                //        strStartType = "访客";
                                //    } else {
                                //        strStartType = "客服";
                                //    }
                                //    strContent += "<td>" + strStartType + "</td>";
                                //}
                            else if (showitem.id == "isfriendmegcount") {
                                strContent += "<td>" + item.friendtalkcount + "</td>";
                            } else if (showitem.id == "iscusmsgcount") {
                                strContent += "<td>" + item.custalkcount + "</td>";
                            } else if (showitem.id == "isstarttime") {
                                strContent += "<td>" + item.talkstarttime.substr(2, 14) + "</td>";
                            }
                                //结束时间
                                //else if (showitem.id == "issEndtime") {
                                //    strContent += "<td>" + item.talkendtime.substr(5, 11) + "</td>";
                                //}
                                //对话时长
                                //else if (showitem.id == "istalktotaltime") {
                                //    item.talktotaltime = formatSeconds(item.talktotaltime);
                                //    m_HistoryCache[i].talktotaltime = item.talktotaltime;
                                //    strContent += "<td>" + item.talktotaltime + "</td>";
                                //}
                                //是否留电
                                //else if (showitem.id == "isSppohne") {
                                //    var strIsMobile = "否";
                                //    if (item.isphone == "1") {
                                //        strIsMobile = "是";
                                //    }
                                //    strContent += "<td>" + strIsMobile + "</td>";
                                //}
                                //回复均时
                                //else if (showitem.id == "ishftime") {
                                //    item.avgwatitime = formatSeconds(item.avgwatitime);
                                //    m_HistoryCache[i].avgwatitime = item.avgwatitime;
                                //    strContent += "<td>" + item.avgwatitime + "</td>";
                                //}
                            else if (showitem.id == "isfriendwechat") {
                                strContent += "<td>" + item.wxcodemark + "</td>";
                            } else if (showitem.id == "issexmark") {
                                strContent += "<td>" + strSexMark + "</td>";
                            } else if (showitem.id == "isprovince") {
                                strContent += "<td>" + item.province + "</td>";
                            } else if (showitem.id == "iscity") {
                                strContent += "<td>" + item.city + "</td>";
                            } else if (showitem.id == "ispid") {
                                strContent += "<td>" + item.pid + "</td>";
                            } else if (showitem.id == "isage") {
                                strContent += "<td>" + item.age + "</td>";
                            } else if (showitem.id == "isgroupname") {
                                strContent += "<td>" + item.groupname + "</td>";
                            }
                        }
                    }
                }
                strContent += "</tr>";
            }

            $("#divNoData").hide();
            $("#tbContent").html(strContent);
            $("#DivFooter").html(GetPageFootStr(nPageIndex, jsonResult.result.total));
            $("#DivFooter").show();
        } else {
            m_HistoryCache = [];
            $("#tbContent").empty();
            $("#divNoData").show();
            $("#DivFooter").hide();
            $("#divNoData").find("h2").text("没有数据！");
        }
    } else {
        m_HistoryCache = [];
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);
    }
    $(".loadingcover").hide();
    $(".loading").hide();
    tableHisFileSlip();
}

/**
* 将秒数换成时分秒格式
*/
function formatSeconds(value) {
    var theTime = parseInt(value);// 秒
    var theTime1 = 0;// 分
    var theTime2 = 0;// 小时
    if (theTime > 60) {
        theTime1 = parseInt(theTime / 60);
        theTime = parseInt(theTime % 60);
        if (theTime1 > 60) {
            theTime2 = parseInt(theTime1 / 60);
            theTime1 = parseInt(theTime1 % 60);
        }
    }
    var result = "" + parseInt(theTime) + "秒";
    if (theTime1 > 0) {
        result = "" + parseInt(theTime1) + "分" + result;
    }
    if (theTime2 > 0) {
        result = "" + parseInt(theTime2) + "小时" + result;
    }
    return result;
}

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, timefrom, timeend, cususername, cnickname, fnickname) {
    m_Cususername = cususername;
    m_CusWechatName = cnickname;
    m_FriendNicName = fnickname;
    event.cancelBubble = true;//禁止触发父级div事件
    ResetHisMsgPara();
    m_NowSelectPid = pid;
    $("#btnShowDocDiv").show();
    $("#divContent").find("tr").removeClass("active");
    $(obj).addClass("active");
    for (var i = 0; i < m_HistoryCache.length; i++) {
        if (m_HistoryCache[i].pid == pid) {
            var item = m_HistoryCache[i];
            var strSex = "未知";
            if (item.fsex == "1") {
                strSex = "男";
            } else if (item.fsex == "2") {
                strSex = "女";
            }
            $("#imgDocFriendHeadImg").attr("src", item.fheadimgurl);
            $("#imgDocFriendHeadImg").attr("onerror", "nofind()");
            $("#spDocNickName").html(item.fnickname);
            $("#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 + ",");
            GetHisMsg(pid, timefrom, timeend, item.fheadimgkey, item.uin);

            $("#DivAllTab").show();
            break;
        }
    }
}

//获取标签数据回执
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 ($("#DivAllTab").is(":hidden")) {
        $("#DivAllTab").show();    //如果元素为隐藏,则将它显现
    } else {
        $("#DivAllTab").hide();     //如果元素为显现,则将其隐藏
    }
}
//m_CusWechatName = fInfo.wechatnickname;
//m_BusinessCheckStstus = fInfo.bisval;

// 高级搜索->好友分组绑定
function AsyncGetGroupValResult(jsonResult) {
    if (jsonResult.success) {
        if (jsonResult.wechats.length > 0) {
            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>";
            }
            $("#ulAllGroupHistory").html(strallgroup);
            $("#groupHistory").html(strallhisgroup);
        }
    }
}

//-------------------------------------------------自定义查询-----------------------------------------------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;
    }
    var groupname = $("#selectPersonDept").html() == "好友分组" ? "" : $("#selectPersonDept").html();
    if ("" == vselval || "0" == vselval) {
        jsonstr = $.toJSON({
            nickname: $("#txtQueryNickName").val(),
            name: $("#txtQueryName").val(),
            tel: $("#txtQueryTel").val(),
            talkstarttime: $("#txtTimeSeniorFrom").val(),
            talkendtime: $("#txtTimeSeniorEnd").val(),
            //isphone: $("#selectIsPhone").val(),
            wechat: $("#txtQueryWechat").val(),
            fsex: $("#selectQuerySex").val(),
            city: $("#txtQueryCity").val(),
            age: $("#txtQueryAge").val(),
            group: groupname,
            remark: $("#txtQueryRemark").val(),

            uin: $("#selectQueryWechat").val(),
            cususerid: cususerid,
            talktype: $("#selectQueryTalkType").val(),
            pid: $("#txtPid").val(),
            pageindex: nPageIndex,
            pagesize: nPageSize
        });
    } else {
        //自定义报表
        var json = GetReportPara(vselval);
        json.pageindex = nPageIndex;
        json.pagesize = nPageSize;
        jsonstr = JSON.stringify(json);
    }
    return jsonstr;
}

//-------------------------------------------------自定义查询-----------------------------------------------End

//修改好友资料
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_HistoryCache.length; i++) {
        if (m_HistoryCache[i].pid == Pid) {
            var item = m_HistoryCache[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 GetTalkTypeName(index) {
    //1：极佳、2：较好、3：一般、4：错失、5：无效
    var strHtml = "";
    if (index == 1) {
        strHtml = "<span class=\"label label-info\" style=\"font-size:12px;\">极佳</span>";
    }
    else if (index == 2) {
        strHtml = "<span  class=\"label label-success\" style=\"font-size:12px;\">较好</span>";
    }
    else if (index == 3) {
        strHtml = "<span  class=\"label label-warning\" style=\"font-size:12px;\">一般</span>";
    }
    else if (index == 4) {
        strHtml = "<span  class=\"label label-default\" style=\"font-size:12px;\">错失</span>";
    }
    else if (index == 5) {
        strHtml = "<span  class=\"label label-danger\" style=\"font-size:12px;\">无效</span>";
    } else {
        strHtml = "<span  class=\"label label-danger\" style=\"font-size:12px;\">未知</span>";
    }
    return strHtml;
}

//导出历史记录
function ExportHisList() {
    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);
}
//导出聊天记录到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 AsyncExportHisRecordToHtmlResult(jsonResult) {
    if (jsonResult.success) {
        ShowMsg("myPageAlert", "导出成功！");
    } else {
        ShowError("myPageAlert", "导出异常！" + jsonResult.error);
    }
}

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);
}


function AsyncExportHisRecordToClipperResult(jsonResult) {
    if (jsonResult.success) {
        CopyTextMsg(jsonResult.result);
        ShowMsg("myPageAlert", "导出成功！");
    } else {
        ShowError("myPageAlert", "导出异常！" + jsonResult.error);
    }
}

// 导出好友列表信息
function Export() {
    if (m_HistoryCache.length == 0) {
        ShowMsg("myPageAlert", "没有记录可导出！");
        return;
    }
    var strParaJson = $.toJSON({
        friends: m_HistoryCache,
    });
    homeObj.exporhistory(strParaJson);
}
//导出excle回调
function AsyncExporHistoryResult(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 deleTimeSeniorFrom() {
    $("#txtTimeSeniorFrom").val("");
}
//清空截止时间
function deleTimeSeniorEnd() {
    $("#txtTimeSeniorEnd").val("");
}
//----------------------------------自定义报表---->
//清除开始时间
function deleTimeReportFrom() {
    $("#txtTimeReportFrom").val("");
}
//清除结束时间
function deleTimeReportEnd() {
    $("#txtTimeReportEnd").val("");
}