
$(document).ready(function () {
    //来电弹屏
    laydate.skin('molv');

    laydate({
        elem: '#old_startTime',
        event: 'focus'
    });

    laydate({
        elem: '#old_endTime',
        event: 'focus'
    });
    laydate({
        elem: '#con_startTime',
        event: 'focus'
    });

    laydate({
        elem: '#con_endTime',
        event: 'focus'
    });
    //弹屏右侧切换效果
    $(".ldtp-cr ul.ld-service li").click(function () {
        $(this).addClass("cr-click").siblings().removeClass("cr-click");

        loadOld();
    });

    //最大化 最小化效果
    //最小化
    $('.minClosed').click(function () {
        $('.ldtp-con').removeClass('fadeInDown');
        $('.ldtp-con').addClass('fadeOutUp');
        $('.ldtp-con').css("display", "none");
        $('.maxOpen').show();
        $('.maxOpen').addClass('fadeInDown');
    });

    //最大化
    $('.maxOpen').click(function () {
        $('.ldtp-con').removeClass('fadeOutUp');
        $('.ldtp-con').addClass('fadeInDown');
        $('.ldtp-con').css("display", "block");
        $('.maxOpen').hide();
        $('.maxOpen').removeClass('fadeInDown');
        $('.maxOpen').addClass('fadeInDown');

        $('.first').removeClass('first');
        $('.ldtp-con').addClass('first');

        $(".ldtp-cr ul.ld-service li").eq(0).trigger("click");
    })
    //关闭弹框
    $(".Bacha").click(function () {
        $('.ldtp-con').removeClass('fadeInDown');
        $('.ldtp-con').addClass('fadeOutUp');
        $('.ldtp-con').css("display", "none");
        clearworkorder();
        obj.Type = "SayFree";
        Send();
    })
    //顶部小头像
    var little_pic = $('.head-pic .hp-box img').attr("src");
    $('.maxOpen li .photo img').attr("src", little_pic);
    //点击左侧菜单来电弹屏显示
    $('.tantan').click(function () {
        $('.maxOpen').trigger("click");
        $('.head-pic .lahei .la-before').show();
        $('.head-pic .lahei .la-after').hide();
    })

    //点击挂断
    $('.head-pic .td-call .take').click(function () {
        obj.Type = "DropCall";
        Send();
    });

    //点击拉黑事件				
    $('.head-pic .lahei .la-before').click(function () {
        if (!$(".hidTel").val()) {
            layer.confirm('来电号码为空！', {
                btn: ['确定']
            });
            return;
        }
        $("#time-word").val('');
        $('.ldtp-con .hei-list').show();

    })
    //拉黑输入框事件
    $('.hei-list .bacha').click(function () {
        $('.ldtp-con .hei-list').hide();
        $("#time-word").val('');
    })
    var reg = /^\+?[1-9][0-9]*$/;

    $('#bc').click(function () {
        var n = $("#time-word").val();
        var val = $("input[name='time']:checked").val();
        if (n) {
            if (!(reg.test(n))) {
                layer.confirm('请输入整数时间！', {
                    btn: ['确定']
                });
                return;
            }
        }
        else {
            if (val == '4') {
                n = 0;
            }
            else {
                layer.confirm('请输入整数时间！', {
                    btn: ['确定']
                });
                return;
            }
        }
        $.post(huayi.config.callcenter_url + 'CallInScreen/AddBlack', { tel: $(".hidTel").val(), num: n, type: val, "token": $.cookie("token") }, function (result) {
            result = $.parseJSON(result);
            if (result.state.toLowerCase() == "success") {

                layer.msg("拉入黑名单成功");

                $(".la-time .lhtime").text(getNowFormatDate());
                $('.la-shichang .blackTime').html(result.data);
                $('.ldtp-con .hei-list').hide();
                $('.head-pic .lahei .la-before').hide();
                $('.head-pic .lahei .la-after').show();
                $('.head-pic .lahei .retur').show();
            }
        })
    })

    $('.la-after').click(function () {
        if (!$(".hidTel").val()) {
            layer.confirm('来电号码为空！', {
                btn: ['确定']
            });
            return;
        }
        $("#time-word").val('');
        $('.ldtp-con .hei-list').show();
        $('.ldtp-con .hei-list').removeClass('bounceOutUp');
        $('.ldtp-con .hei-list').addClass('bounceIn');
    })
    $('.head-pic .lahei .retur').click(function () {
        $.getJSON(huayi.config.callcenter_url + 'CallInScreen/DelBlack', { tel: $(".hidTel").val(), "token": $.cookie("token") }, function (result) {
            if (result.state.toLowerCase() == "success") {
                layer.msg("取消黑名单成功");
                $('.head-pic .lahei .retur').hide();
                $('.head-pic .lahei .la-after').hide();
                $('.head-pic .lahei .la-before').show();
            }
        })
    })

    if (/mobile/i.test(navigator.userAgent) || /android/i.test(navigator.userAgent)) {
        $(".title-box").hide();
    }
    obj.AgentExten = $.cookie("extno");
    $(".Gnum").text('(' + obj.AgentExten + ')');
    $.getJSON(huayi.config.callcenter_url + 'UserAccount/GetNowUser', {
        "token": $.cookie("token")
    }, function (result) {
        if (result.state.toLowerCase() == "success") {
            $(".username").text(result.data.user.F_UserName);
            if (result.data.role) {
                $(".rolename").text(result.data.role.F_RoleName);
            }
            $(".yhtx").attr("src", huayi.config.callcenter_url.substr(0, huayi.config.callcenter_url.length - 1) + result.data.user.F_See);

            obj.AgentID = result.data.user.F_UserCode;
            //obj.AgentExten = result.data.user.F_WorkNumber;
            $('.mgh').val(result.data.user.F_UserCode);
            $('.mn').val(result.data.user.F_UserName);
            if (result.data.user.F_SeatFlag) {
                Connect();
                $("#top-search").show();
                $(".zts").show();
                //签入
                //obj.Type = "Login";
                //obj.AgentGroup = "364";
                //obj.AgentType = "0";
                //Send();
            }
        }
    })
    $.ajaxSettings.async = false;
    $.getJSON(huayi.config.callcenter_url + 'Index/GetMenu', {
        "token": $.cookie("token")
    }, function (result) {
        $.ajaxSettings.async = true;
        if (result.state.toLowerCase() == "success") {
            $(result.data).each(function (i, n) {
                var html = '<li><a href="#" dataid=' + n.F_FunctionId + '><i class="fa iconfont">&#xe614;</i><span class="nav-label">' + n.F_FunctionName + '</span><span class="fa arrow"></span></a>';
                html += '<ul class="nav nav-second-level">';
                $(n.item).each(function (j, m) {
                    html += '<li><a class="J_menuItem" dataid=' + m.F_FunctionId + ' href="' + m.F_OptUrl + '">' + m.F_FunctionName + '</a></li>';
                })
                html += '</ul></li>';
                $(html).appendTo($("#side-menu"));
            })
            $(".J_menuItem").click(function () {
                if ($(this).text() == "来电弹屏") {
                    $('.maxOpen').trigger("click");
                    $('.head-pic .lahei .la-before').show();
                    $('.head-pic .lahei .la-after').hide();
                }
            })
        }
    })
    //分机号
    //话务相关
	//  获取转接号码
    $(".hw_show").click(function () {
  		obj.Type = "Meeting";
      	obj.DestinationNumber = huayi.config.TransferNum;
		$(".hw_show  i").removeClass("Turn110_c"); 
    	$(".hw_show  i").addClass("Turn110");
    	lineOutHang=true;
      	Send();
    })
    $("#top-search li").click(function () {
        if ($(this).find("i").hasClass("active")) {
            if (obj.AgentID) {
                var fun = $(this).attr("datafun");
                obj.Type = fun;
                switch (fun) {
                    case "Login":
                        obj.AgentGroup = "364";
                        obj.AgentType = "0";
                        Send();
                        break; //签入
                    case "MakeCall":
                        $(".hidCallID").val("");
                        $("#hidwhtype").val(fun);
                        whtp();
                        //obj.DestinationNumber = "1012";
                        break; //外呼
                    case "Meeting":
                        $("#hidwhtype").val(fun);
                        whtp();
                        //obj.DestinationNumber = "1012";
                        break; //多方通话
                    case "Transfer":
                        $("#hidwhtype").val(fun);
                        whtp();
                        //obj.DestinationNumber = "1012";
                        break; //转移
                    default:
                        Send();
                        break;

                }
            }
        }
    });
    //知识库查询
    $(".searIcon").click(function () {
        loadZSK();
    })
    //回车搜索
    $('.search').keypress('onkeyup',function(e){
    	if(e.keyCode==13){
    		loadZSK();
    	}
    })
    //历史记录查询
    $(".searchbtn").click(function () {
        loadOld();
    })
    //新增记录
    $(".addjl").click(function () {
        $(".addgd").show();
        $(".tbold").hide();
    })
    //关闭外呼弹屏
    $(".closes").click(function () {
        $(".WH").removeClass("fadeInDown").addClass("fadeOutUp");
        $(".WH").addClass("hidens");
    })
    //外呼呼出
    $(".CallOut").click(function (event) {
        event.stopPropagation();
        if ($("#Result").val()) {
            obj.Type = $("#hidwhtype").val();
            obj.DestinationNumber = $("#Result").val();
            Send();
        }
    })
    //外呼弹屏数字键盘样式
    $(".Num_ul div").mousedown(function () {
        $(this).addClass("actives");
        $(".img").removeClass("hidens");
    }).mouseup(function () {
        $(this).removeClass("actives");
    })
    //外呼弹屏数字键盘号码输入
    $(".Num_ul li div").click(function () {
        var rt = $("#Result").val() + "";
        if (rt.length < 18) {
            rt = rt + $(this).find("a").text();
            $("#Result").val(rt);
        }
    });
    //外呼弹屏数字键盘号码截取
    $(".img").click(function () {
        var Result = $("#Result").val() + "";
        Result = Result.substr(0, Result.length - 1);
        $("#Result").val(Result);
        if (Result.length == 0) {
            $(".img").addClass("hidens");
        }
    })
    //外呼电话列表
    $(".bg_title li").click(function () {
        $(this).addClass("lactive").siblings().removeClass("lactive");
        loadWH();
    })
    $(".ty").click(function () {
        loadWH();
    })

    //创建投诉工单
    $(".addts").click(function () {
        var type = $("#xxlb").val();
        var bigtype = $("#tsdl").val();
        var smalltype = $("#tsxl").val();
        var sourcearea = $("#FArea").val();
        var sourceaddress = $("#sfdz").val();
        if ($("#Town").val()) {
            sourceaddress = $("#Twon").find("option:selected").text() + sourceaddress;
        }
        var cusname = $("#tskh").val();
        var cusphone = $("#tsdh").val();
        var cussex = $("#sex").val();
        var email = $("#email").val();
        var zipcode = $("#postcode").val();
        var conname = $("#lxr").val();
        var conphone = $("#lxdh").val();
        var content = $("#content").val();
        var isprotect = $("input[name='baomi']:checked").val();
        var isresult = "false";
        var flag = 0;
        var hf = $("input[name='huifu']:checked").val();
        if (hf == '1') {
            isresult = "true";
        }
        else if (hf == '2') {
            flag = 1;
        }      
//      var result = $("#result").val();
        var areaid = $("#JArea").val();
        var depttype = $("#Jtype").val();
        var deptid = $("#Department").val();
        var obj = $("input[name='jiaoban']:checked");
        var opitionid = obj.val();
        var day = obj.parent().find("select").val();
        var assignedopinion = obj.parent().find(".head").text() + day + obj.parent().find(".end").text();
        var remark = $("#remark").val();
        var callid = $(".hidCallID").val();
        var result = $("#cljg").val();
        //if (!cusname) {
        //    layer.confirm('请输入投诉人！', {
        //        btn: ['确定']
        //    });
        //    return;
        //}
        if (!tsdh) {
            layer.confirm('请输入投诉电话！', {
                btn: ['确定']
            });
            return;
        }
        if (!smalltype) {
            layer.confirm('请选择信息分类！', {
                btn: ['确定']
            });
            return;
        }
        if (!content) {
            layer.confirm('请输入情况摘要！', {
                btn: ['确定']
            });
            return;
        }
        if (flag == 1) {
            if (!deptid) {
                layer.confirm('请选择部门！', {
                    btn: ['确定']
                });
                return;
            }
        }
        if (hf == '1') {
            if (!result) {
                layer.confirm('请输入处理结果！', {
                    btn: ['确定']
                });
                return;
            }
        }

        $.post(huayi.config.callcenter_url + 'WorkOrder/AddWorkOrder', {
            source: 27, type: type, bigtype: bigtype, smalltype: smalltype, sourcearea: sourcearea, cusname: cusname, cusphone: cusphone,
            email: email, zipcode: zipcode,cussex: cussex, conname: conname, conphone: conphone, content: content, isprotect: isprotect, isresult: isresult,
            result: result, isfile: "false", sourceaddress: sourceaddress, flag: flag, areaid: areaid, depttype: depttype, deptid: deptid,
            day:day,opitionid: opitionid, assignedopinion: assignedopinion, remark: remark, callid: callid, "token": $.cookie("token")
        }, function (result) {
            result = $.parseJSON(result);
            if (result.state.toLowerCase() == "success") {
                $(".ldtp-cr ul.ld-service li").eq(2).trigger("click");
                clearworkorder();
                layer.msg("创建工单成功");
            }
        })
    })
    //加载知识库
    loadZSK();
    //加载左侧导航菜单
    //loadMenu();

    //客户资料
    $('.khzl tbody>tr>td input').attr('readonly', true);
    $('.save').hide();
    $('.cancel').hide();
    $('.edit').click(function () {
        $('.save').show();
        $('.cancel').show();
        $('.edit').hide();
        $('.khzl tbody>tr>td input').attr('readonly', false);
        $('.khzl tbody>tr>td input').css('border-bottom', "1px solid #b3b3b3");
    })
    $('.cancel').click(function () {
        $('.khzl tbody>tr>td input').attr('readonly', true);
        $('.khzl tbody>tr>td input').css('border', "0");
        $('.save').hide();
        $('.cancel').hide();
        $('.edit').show();
        $("#khid").val('');
        $(".khmc").val('');
        $(".tsdh").val('');
        $(".lxr").val('');
        $(".lxdh").val('');
        $(".postcode").val('');
        $(".email").val('');
    })
    //保存客户
    $(".save").click(function () {
        var khid = $("#khid").val();
        var khmc = $(".khmc").val();
        var tsdh = $(".tsdh").val();
        var lxr = $(".lxr").val();
        var lxdh = $(".lxdh").val();
        var postcode = $(".postcode").val();
        var email = $(".email").val();

        if (!khmc) {
            layer.confirm('请输入客户名称！', {
                btn: ['确定']
            });
            return;
        }
        $.post(huayi.config.callcenter_url + 'Customer/AddCustomer', {
            cid: khid,
            name: khmc,
            lxr:lxr,
            mobile: tsdh,
            telphone: lxdh,
            postcode: postcode,
            email:email,
            "token": $.cookie("token")
        }, function (result) {
            result = $.parseJSON(result);
            if (result.state.toLowerCase() == "success") {
                $("#khid").val(result.data);
                $(".khmc").val(khmc);
                $(".tkhmc").text(khmc);
                $(".lxdh").val(lxdh);
                $(".tsdh").val(tsdh);
                $(".ttsdh").text(tsdh);
                $(".lxr").val(lxr);
                $(".postcode").val(postcode);
                $(".email").val(email);
                layer.msg("保存成功");
                $('.khzl tbody>tr>td input').attr('readonly', true);
                $('.khzl tbody>tr>td input').css('border', "0");
                $('.save').hide();
                $('.cancel').hide();
                $('.edit').show();
            }
        })
    })

    //关闭录音弹出
    $(".setwin").click(function () {
        $(".t-shade").removeClass("cx");
        $('audio')[0].pause();
    });

    //修改密码开始
    $('.shezhi').click(function () {
        $('.personal').show();
    })
    //tab切换
    $('.perTab li').click(function () {
        $(this).addClass('sel').siblings().removeClass('sel');
        var index = $(this).index();
        $('.perTab_con').children('div').eq(index).show().siblings().hide();
    })
    //编辑个人资料
    $('.grzl tbody>tr>td input.zhidu').attr('readonly', true);
    $('.grbj').click(function () {
        $('.grzl tbody>tr>td input.zhidu').attr('readonly', false);
        $('.grzl tbody>tr>td input.zhidu').css('border-bottom', "1px solid #b3b3b3");
    })
    //取消编辑
    $('.grqx').click(function () {
        $('.grzl tbody>tr>td input.zhidu').attr('readonly', true);
        $('.grzl tbody>tr>td input.zhidu').css('border-bottom', "none");
    })
    //关闭按钮
    $('.ptr').click(function () {
        $('.personal').hide();

    })
    //修改密码
    $('.grbtn').click(function () {
        var gh = $('.mgh').val();
        var xm = $('.mn').val();
        var ymm = $('.spwd').val();
        var xmm = $('.npwd').val();
        var qmm = $('.epwd').val();
        if (xmm !== qmm) {
            $('.wrong').show();
            $('.npwd').val('')
            $('.epwd').val('')
        } else if (xmm == '') {
            layer.msg("密码不允许为空！");
        } else {
            $('.wrong').hide();
            $('.grzl tbody>tr>td input').attr('readonly', true);
            $('.grzl tbody>tr>td input').css('border-bottom', "none");
            $.ajax({
                type: "post",
                url: huayi.config.callcenter_url + "UserAccount/UpdatePwd",
                async: true,
                dataType: 'json',
                data: {
                    token: $.cookie("token"),
                    usercode: gh,
                    pwd: $.md5(xmm),
                    oldpwd: $.md5(ymm)
                },
                success: function (result) {
                    if (result.state.toLowerCase() == "success") {
                        layer.msg("修改成功！");
                        $('.epwd').val('');
                        $('.spwd').val('');
                        $('.npwd').val('');
                    }
                }
            });
        }
    })

    //图片裁剪
    var o = $(".image-crop > img");
    $(o).cropper({
        aspectRatio: 1 / 1,
        resizable: false,
        dragCrop: false,
        preview: ".img-preview",
        done: function () { }
    });
    var r = $("#inputImage");
    if (window.FileReader) {
        r.change(function () {
            var e, i = new FileReader,
                t = this.files;
            if (t.length && (e = t[0], /^image\/\w+$/.test(e.type))) {
                i.readAsDataURL(e);
                i.onload = function () {
                    r.val("");
                    o.cropper("reset", !0).cropper("replace", this.result);
                }

            } else {
                layer.msg("请选择图片文件");
            }
        });
        $("#setDrag").click(function () {
            o.cropper("setDragMode", "crop");
            var img = o.cropper("getDataURL");
            $.post(huayi.config.callcenter_url + "Index/UploadTX64", {
                dataurl: encodeURIComponent(img),
                "token": $.cookie("token")
            }, function (result) {
                result = $.parseJSON(result);
                if (result.state.toLowerCase() == "success") {
                    $(".yhtx").attr("src", huayi.config.callcenter_url.substr(0, huayi.config.callcenter_url.length - 1) + result.data);
                    layer.msg("上传成功");
                    $('.personal').hide();
                }
            })
        });
        $("#zoomIn").click(function () {
            o.cropper("zoom", .1)
        });
        $("#zoomOut").click(function () {
            o.cropper("zoom", -.1)
        });
        $("#rotateLeft").click(function () {
            o.cropper("rotate", 45)
        });
        $("#rotateRight").click(function () {
            o.cropper("rotate", -45)
        });
    } else {
        r.addClass("hide");
    }

    //工单中的类型
    $("#xxlb").empty();
    $("#xxlb").append('<option selected="selected" value="">请选择</option>');
    $.getJSON(huayi.config.callcenter_url + "Dictionary/GetDicValueListById", { "token": $.cookie("token"), id: 2 }, function (data) {
        if (data.state.toLowerCase() == "success") {
            var content = data.data;
            $(content).each(function (i, n) {
                $("<option value='" + n.F_ValueId + "'>" + n.F_Value + "</option>").appendTo($("#xxlb"));
            })
        }
    })
    $("#xxlb").change(function () {
        $("#tsxl").empty();
        $("#tsxl").append('<option selected="selected" value="">请选择</option>');
        loadDic($("#tsdl"), $("#xxlb").val());
    })
    $("#tsdl").change(function () {
        loadDic($("#tsxl"), $("#tsdl").val());
    })

    loadArea($("#FArea"));
    loadArea($("#JArea"));
    $("#FArea").change(function () {
        $("#Twon").empty();
        $("#Twon").append('<option selected="selected" value="">请选择</option>');
        var aid = $("#FArea").val();
        if (!aid) { aid = -1; }
        $.getJSON(huayi.config.callcenter_url + "Department/GetTownList", { "token": $.cookie("token"), aid: aid }, function (data) {
            if (data.state.toLowerCase() == "success") {
                var content = data.data;
                $(content).each(function (i, n) {
                    $("<option value='" + n.F_TownId + "'>" + n.F_TownName + "</option>").appendTo($("#Twon"));
                })
            }
        })
    })
    $("#JArea").change(function () {
        $("#Jtype").empty();
        $("#Jtype").append('<option selected="selected" value="">请选择</option>');
        $("#Department").empty();
        $("#Department").append('<option selected="selected" value="">请选择</option>');
        var aid = $("#JArea").val();
        if (!aid) { aid = -1; }
        $.getJSON(huayi.config.callcenter_url + "Department/GetDeptTypeList", { "token": $.cookie("token"), aid: aid }, function (data) {
            if (data.state.toLowerCase() == "success") {
                var content = data.data;
                $(content).each(function (i, n) {
                    $("<option value='" + n.F_DeptTypeId + "'>" + n.F_DeptTypeName + "</option>").appendTo($("#Jtype"));
                })
            }
        })
    })
    $("#Jtype").change(function () {
        $("#Department").empty();
        $("#Department").append('<option selected="selected" value="">请选择</option>');
        var tid = $("#Jtype").val();
        if (!tid) { tid = -1; }
        $.getJSON(huayi.config.callcenter_url + "Department/GetDeptList", { "token": $.cookie("token"), tid: tid }, function (data) {
            if (data.state.toLowerCase() == "success") {
                var content = data.data;
                $(content).each(function (i, n) {
                    $("<option value='" + n.F_DeptId + "'>" + n.F_DeptName + "</option>").appendTo($("#Department"));
                })
            }
        })
    })

    $(".min_select").each(function () {
        $(this).empty();
        for (var i = 1; i <= 10; i++) {
            if (i == 5) {
                $("<option selected='selected' value='5'>5</option>").appendTo($(this));
            }
            else {
                $("<option value='" + i + "'>" + i + "</option>").appendTo($(this));
            }
        }
    })
})
function clearworkorder() {
    $("#xxlb").val("");
    $("#xxlb").trigger("change");
    $("#FArea").val("");
    $("#FArea").trigger("change");
    $("#sfdz").val("");
    $("#tskh").val("");
    $("#tsdh").val("");
    $("#email").val("");
    $("#postcode").val("");
    $("#lxr").val("");
    $("#lxdh").val("");
    $("#content").val("");
    $("#result").val("");
    $("#JArea").val("");
    $("#JArea").trigger("change");
    $("#remark").val("");

    $("#khid").val("");
    $(".khmc").val("");
    $(".tsdh").val("");
    $(".lxr").val("");
    $(".lxdh").val("");
    $(".postcode").val("");
    $(".email").val("");

    $("input[name='huifu'][value='0']").prop("checked", true);
}
//获取历史记录
function loadOld() {
    var type = $(".ldtp-cr ul.ld-service .cr-click").attr("itemtype");
    $(".complain").hide();
    $(".complain").eq(type * 1).show();
    if (type == '2') {
        //先销毁表格
        $('#orderlist').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#orderlist").bootstrapTable({
            method: "get", //使用get请求到服务器获取数据
            url: huayi.config.callcenter_url + "WorkOrder/GetList", //获取数据的Servlet地址
            contentType: "application/x-www-form-urlencoded",striped: true, //表格显示条纹
            pagination: true, //启动分页
            pageSize: 5, //每页显示的记录数
            pageNumber: 1, //当前第几页
            pageList: [5, 10, 50, 100], //记录数可选列表
            search: false, //是否启用查询
            showColumns: false, //显示下拉框勾选要显示的列
            showRefresh: false, //显示刷新按钮
            sidePagination: "server", //表示服务端请求
            //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
            //设置为limit可以获取limit, offset, search, sort, order
            queryParamsType: "undefined",
            queryParams: function queryParams(params) { //设置查询参数
                var param = {
                    page: params.pageNumber,
                    pagesize: params.pageSize,
                    tel: $(".hidTel").val(),
                    starttime: $("#con_startTime").val(),
                    endtime: $("#con_endTime").val(),
                    token: $.cookie("token")
                };
                return param;
            },
            onLoadSuccess: function () { //加载成功时执行
                //layer.msg("加载成功");
            },
            onLoadError: function () { //加载失败时执行
                //layer.msg("加载数据失败", { time: 1500, icon: 2 });
            }
        });
    } else if (type == '1') {
        //先销毁表格
        $('#oldlist').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#oldlist").bootstrapTable({
            method: "get", //使用get请求到服务器获取数据
            url: huayi.config.callcenter_url + "CallInScreen/GetOldList", //获取数据的Servlet地址
            contentType: "application/x-www-form-urlencoded",striped: true, //表格显示条纹
            pagination: true, //启动分页
            pageSize: 5, //每页显示的记录数
            pageNumber: 1, //当前第几页
            pageList: [5, 10, 50, 100], //记录数可选列表
            search: false, //是否启用查询
            showColumns: false, //显示下拉框勾选要显示的列
            showRefresh: false, //显示刷新按钮
            sidePagination: "server", //表示服务端请求
            //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
            //设置为limit可以获取limit, offset, search, sort, order
            queryParamsType: "undefined",
            queryParams: function queryParams(params) { //设置查询参数
                var param = {
                    page: params.pageNumber,
                    pagesize: params.pageSize,
                    tel: $(".hidTel").val(),
                    starttime: $("#old_startTime").val(),
                    endtime: $("#old_endTime").val(),
                    token: $.cookie("token")
                };
                return param;
            },
            onLoadSuccess: function () { //加载成功时执行
                //layer.msg("加载成功");
            },
            onLoadError: function () { //加载失败时执行
                //layer.msg("加载数据失败", { time: 1500, icon: 2 });
            }
        });
    }  
}

function GetCallState(val) {
    if (val == '1') {
        return '已接通';
    } else {
        return '未接通';
    }
}

//音频
function setCode(val) {
    if (val) {
        return '<div class="imgs" style="cursor: pointer;">' +
            '<img src="./img/vice.png" alt="" onclick= ck(this) item="' + val + '" />' +
            '</div>';
    } else {
        return '';
    }
}
//录音
function ck(val) {
    var path = $(val).attr("item");
    $(".t-shade").addClass("cx");
    $(".Ly_box").empty();
    $(".down").attr("href", path);
    $('<audio style="width: 100%;"class=" " src="' + path + '" loop="loop" controls="controls" ></audio>').appendTo(".Ly_box");
}


function GetLink(val) {
    if (val) {
        return '<a onclick="ckxq(' + val + ')">' + val + '</a>';
    } else {
        return '';
    }
}
//查看详情
function ckxq(str) {
    layer.open({
        type: 2,
        content: "./WorkOrder/WorkOrderDetail.html?wid=" + str, //iframe的url，no代表不显示滚动条
        title: '工单详情',
        area: ['85%', '80%'], //宽高
    });
}
//截取字符串
function GetCont(val) {
    if (val) {
        var str = '<div '
        if (val.length > 10) {
            str = str + ' title="' + val + '" ';
            val = val.substr(0, 10) + "...";
        }
        return str + '>' + val + '</div>';
    }
    else {
        return '';
    }
}

//加载字典
function loadDic(obj, pid) {
    obj.empty();
    obj.append('<option selected="selected" value="">请选择</option>');
    if (!pid) { pid = -1; }
    $.getJSON(huayi.config.callcenter_url + "Dictionary/GetDicValueListByParentId", { "token": $.cookie("token"), pid: pid }, function (data) {
        if (data.state.toLowerCase() == "success") {
            var content = data.data;
            $(content).each(function (i, n) {
                $("<option value='" + n.F_ValueId + "'>" + n.F_Value + "</option>").appendTo(obj);
            })
        }
    })
}

//加载区域
function loadArea(obj) {
    obj.empty();
    obj.append('<option selected="selected" value="">请选择</option>');
    $.getJSON(huayi.config.callcenter_url + "Department/GetAreaList", { "token": $.cookie("token") }, function (data) {
        if (data.state.toLowerCase() == "success") {
            var content = data.data;
            $(content).each(function (i, n) {
                $("<option value='" + n.F_AreaId + "'>" + n.F_AreaName + "</option>").appendTo(obj);
            })
        }
    })
}
//获取知识库
function loadZSK() {
    $.getJSON(huayi.config.callcenter_url + 'CallInScreen/GetZSKList', {
        "keywords": $(".search").val(),
        "token": $.cookie("token")
    }, function (result) {
        if (result.state.toLowerCase() == "success") {
            $(".ldcr-bottom .detail-con ul").empty();
            $(result.data).each(function (i, n) {
                var html = '<li>' +
                    '   <div class="zhishi-title clearfix">' +
                    '	    <a href="javascript:void(0);" >' + n.F_Title + '</a>' +
                    '	    <em >' + n.F_CreateOn + '</em>' +
                    '   </div>' +
                    '   <div class="explancon">' +
                    n.F_Content +
                    '   </div>' +
                    '</li>';
                $(html).appendTo($(".ldcr-bottom .detail-con ul")).find(".zhishi-title").click(function (event) {
                    event.stopPropagation();
                    if ($(this).hasClass("active")) {
                        $(this).removeClass("active")
                    } else {
                        $(".zhishi-title").removeClass("active");
                        $(this).addClass("active");
                    }
                })
            })
        }
    })
}

//外呼弹屏
function whtp() {
    $("#Result").val("");
    if ($(".WH").hasClass("fadeOutUp")) {
        $(".WH").removeClass("fadeOutUp").addClass("fadeInDown");
    }
    $(".WH").removeClass("hidens");

    $('.first').removeClass('first');
    $('.WH').addClass('first');

    loadWH();
}
//加载外呼电话列表
function loadWH() {
    $(".phonediv").hide();
    var n = $(".bg_title .lactive").attr("itemid");
    switch (n) {
        case '0':
            var obj = $(".phonediv").eq(0);
            obj.show();

            //先销毁表格
            var table = obj.find(".phonelist");
            table.bootstrapTable('destroy');
            //初始化表格,动态从服务器加载数据
            table.bootstrapTable({
                method: "get", //使用get请求到服务器获取数据
                url: huayi.config.callcenter_url + "CallOutScreen/GetPhoneList", //获取数据的Servlet地址
                contentType: "application/x-www-form-urlencoded",striped: true, //表格显示条纹
                pagination: true, //启动分页
                pageSize: 10, //每页显示的记录数
                pageNumber: 1, //当前第几页
                pageList: [10, 20, 50, 100], //记录数可选列表
                search: false, //是否启用查询
                showColumns: false, //显示下拉框勾选要显示的列
                showRefresh: false, //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) { //设置查询参数
                    var param = {
                        page: params.pageNumber,
                        pagesize: params.pageSize,
                        tel: $("#lastphone").val(),
                        token: $.cookie("token")
                    };
                    return param;
                },
                onLoadSuccess: function () { //加载成功时执行
                    //layer.msg("加载成功");
                },
                onLoadError: function () { //加载失败时执行
                    //layer.msg("加载数据失败", { time: 1500, icon: 2 });
                }
            });
            break;
        case '1':
            var obj = $(".phonediv").eq(1);
            obj.show();

            var table = obj.find(".phonelist");
            table.bootstrapTable('destroy');
            //初始化表格,动态从服务器加载数据
            table.bootstrapTable({
                method: "get", //使用get请求到服务器获取数据
                url: huayi.config.callcenter_url + "CallOutScreen/GetUserList", //获取数据的Servlet地址
                contentType: "application/x-www-form-urlencoded",striped: true, //表格显示条纹
                pagination: true, //启动分页
                pageSize: 10, //每页显示的记录数
                pageNumber: 1, //当前第几页
                pageList: [10, 20, 50, 100], //记录数可选列表
                search: false, //是否启用查询
                showColumns: false, //显示下拉框勾选要显示的列
                showRefresh: false, //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) { //设置查询参数
                    var param = {
                        page: params.pageNumber,
                        pagesize: params.pageSize,
                        tel: $("#gsphone").val(),
                        name: $("#gsname").val(),
                        token: $.cookie("token")
                    };
                    return param;
                },
                onLoadSuccess: function () { //加载成功时执行
                    //layer.msg("加载成功");
                },
                onLoadError: function () { //加载失败时执行
                    //layer.msg("加载数据失败", { time: 1500, icon: 2 });
                }
            });
            break;
        case '2':
            var obj = $(".phonediv").eq(2);
            obj.show();

            var table = obj.find(".phonelist");
            table.bootstrapTable('destroy');
            //初始化表格,动态从服务器加载数据
            table.bootstrapTable({
                method: "get", //使用get请求到服务器获取数据
                url: huayi.config.callcenter_url + "CallOutScreen/GetCustomerList", //获取数据的Servlet地址
                contentType: "application/x-www-form-urlencoded",striped: true, //表格显示条纹
                pagination: true, //启动分页
                pageSize: 10, //每页显示的记录数
                pageNumber: 1, //当前第几页
                pageList: [10, 20, 50, 100], //记录数可选列表
                search: false, //是否启用查询
                showColumns: false, //显示下拉框勾选要显示的列
                showRefresh: false, //显示刷新按钮
                sidePagination: "server", //表示服务端请求
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) { //设置查询参数
                    var param = {
                        page: params.pageNumber,
                        pagesize: params.pageSize,
                        tel: $("#khphone").val(),
                        name: $("#khname").val(),
                        token: $.cookie("token")
                    };
                    return param;
                },
                onLoadSuccess: function () { //加载成功时执行
                    //layer.msg("加载成功");
                },
                onLoadError: function () { //加载失败时执行
                    //layer.msg("加载数据失败", { time: 1500, icon: 2 });
                }
            });
            break;
    }
}

function view(val) {
    var str = '';
    if (val) {
        str = '<a onclick="call(\'' + val + '\')">' + val + '</a>';
    }
    return str;
}

function call(val) {
    $("#Result").val(val);
    $(".img").removeClass("hidens");
}

function ftime(val) {
    if (val) {
        return helper.DateFormat.getFormatTime(val);
    }
    else {
        return '';
    }
}

function logout() {
    $.ajax({
        url: huayi.config.callcenter_url + "Login/Logout",
        data: {
            token: $.cookie("token")
        },
        dataType: "json",
        success: function (res) {
            if (res.state) {
                location.href = "./login.html";
            }
        }
    });
}
//跳转
function Jumps() {
    $("iframe:visible")[0].src = "widgets.html"
}

