//音频
        function setCode(val) {
            if (val) {
                return '<div class="imgs">' +
                    '<img src="../img/vice.png" alt="" onclick="helper.luyin.view(this)" item="' + val + '" />' +
                    '</div>';
            } else {
                return '';
            }
        }
        //编号
        function Code(val, row, index) {
            return index + 1;
        }

        // 电话号码
        function formatterCallNum(val, row) {
            var phoneNumber
            if (val.length === 12) {
                phoneNumber = val.slice(1)
            } else if (val.length === 13) {
                phoneNumber = val.slice(2)
            } else {
                phoneNumber = val
            }
            return '<div class="imgs" ><p class="" onclick="viewList(\'' + phoneNumber + '\')" >' + phoneNumber +
                '</p></div>';
        }

        // 查看列表
//      function viewList(phoneNumber) {
//          layer.open({
//              type: 2,
//              content: "./CallRecordList.html?phoneNumber=" + phoneNumber, //iframe的url，no代表不显示滚动条
//              title: '通话记录',
//              area: ['90%', '90%'], //宽高
//          });
//      }

        //方向呼出
        function callType(val) {
            if (val == 0) {
                return '<div class="imgs">呼入</div>';
            } else {
                return '<div class="imgs">呼出</div>';
            }
        }
        //满意度
        function MYD(val, row) {
            var html = '';
            switch (val + '') {
                case '0':
                    html = '未评价';
                    break;
                case '1':
                    html = '满意';
                    if (row.CallState == 0) {
                        html = '';
                    }
                    break;
                case '2':
                    html = '一般';
                    break;
                case '3':
                    html = '不满意';
                    break;
            }
            return html;
        }

        function states(val, row) {
            if (val == 0) {  //CallState
            	if(row.CallType == 0){  //呼入
            		if(row.Business==1||row.Business==4){
            			return '<div class="imgs">自主完成</div>';
            		}else if( !row.UserCode){
            			return '<div class="imgs">主动放弃</div>';
            		}else{
            			return '<div class="imgs">未接通</div>';
            		}
            	}else{
            			return '<div class="imgs">未接通</div>';
            	}
            } else if (val == 1) {
                return '<div class="imgs">已接通</div>';
            } else if (val == 2) {
                return '<div class="imgs">接通未达</div>';
            } 
        }

        function ActionType(val) {
            if (val == 2) {
                return '<div class="imgs">转移</div>';
            } else if (val == 3) {
                return '<div class="imgs">三方通话</div>';
            } else {
                return '<div class="imgs">正常通话</div>';
            }
        }

        //处理
        function isDeal(val) {
            if (val == 0) {
                return '<div >未处理</div>';
            } else {
                return '<div >已处理</div>';
            }
        }

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

        // 回拨
        function formatCallback(val, row) { 
        	if (val) {
        		return "已回拨";
        	} else if(row.CallType ===0&&row.CallState ===0){
        		return "未回拨";
        	}

        }

        //格式化工单号
        function formatWorkOrderNum(val, row) { 
        	if (row.CallType ===0) {
        		if (val == null || val == '') {
	               return '<a class="xg" onclick="addWorkOrder(\'' + row.CallRecordsId  + '\',\'' +row.CallNumber+'\')" title="添加工单">添加工单</a>';
	            } else {
	                return '<a class="xg" onclick="ckxq(\'' + val + '\')" title="点击查看工单详情">' + val + '</a>';
	            }
        	}
            
        }
       
       function formatBusinessType(val, row){
        	if (row.CallType ===0) {
        		if (val ===2) {
        			return '市民咨询'
        		} else if (val ===3) {
        			return '营商环境'
        		} else if (val ===4) {
        			return '市长信箱'
        		}else {
        			return '市民咨询'
        		}
        	}
        }
        
        // 操作
        function operationFormatter(val, row) {
        	// CallType ===0呼入    row.CallState ===0 未接通
        	if (row.CallState ===0&&row.CallType ===0) {
	            if (row.Callback) {
	                return '<a class="operation" onclick="callbackRecord(\'' + row.CallId + '\')" title="">回拨记录</a>'
	            } else {
	                return '<a class="operation" onclick="backDial(\'' + row.CallNumber + '\',\'' + row.CallId +'\')" title="">回拨</a>'
	            }
            }
        }
        
        //获取通话类型
        function GetCallTypeList() {
            $.getJSON(huayi.config.callcenter_url + 'Dictionary/GetDicValueListById', {
                id: 45,
                token: $.cookie("token")
            }, function (result) {
                if (result.state.toLowerCase() == "success") {
                    var callTypeList = result.data;
                    $('#callType').empty();
                    $('#callType').append('<option value="">全部</option>');
                    $(callTypeList).each(function (i, n) {
                        $('#callType').append('<option value="' + n.F_ValueId + '">' + n.F_Value +
                            '</option>');
                    })
                }
            })
        }

        // 坐席
        function getAgentGroup(obj) {
            obj.empty();
            obj.append(
                '<option selected="selected" value="">请选择</option>'
            );
            $.getJSON(
                huayi.config.callcenter_url +
                "Dictionary/GetDicValueListById", {
                    token: $.cookie("token"),
                    id: 2522,
                },
                function (data) {
                    if (data.state.toLowerCase() == "success") {
                        var content = data.data;
                        $(content).each(function (i, n) {
                            $(
                                "<option value='" +
                                n.F_Value +
                                "'>" +
                                n.F_Value +
                                "</option>"
                            ).appendTo(obj);
                        });
                    }
                }
            );
        }

        // 查看工单详情
        function ckxq(str) {
            if (str) {
                layer.open({
                    type: 2,
                    content: "../../CommonHtml/WorkDatil.html?wid=" + str, //iframe的url，no代表不显示滚动条
                    title: '工单详情',
                    area: ['100%', '100%'], //宽高
                });
            }
        }
		
		// 添加工单
        function addWorkOrder(CallRecordsId,CallNumber) {
            if (CallRecordsId) {
            	layer.open({
                    type: 2,
                    content: "../../Appeal/AddAppeal.html?CallRecordsId=" + CallRecordsId+"&callerNum="+CallNumber , //iframe的url，no代表不显示滚动条
                    title: '工单详情',
                    area: ['100%', '100%'], //宽高
                });

            }
        }
        // 外呼
        function backDial(phoneNumber, callId) {
        	
            $.ajax({
                type: "get",
                url: huayi.config.callcenter_url + "CallOutOpt/GetCallOutprefix",
                async: true,
                dataType: "json",
                data: {
                    token: $.cookie("token"),
                    phone: phoneNumber,
                },
                success: function (result) {
                    if (result.state.toLowerCase() == "success") {
                    	top.callbackState = true
                        var guid = uuid();
                        top.obj.Type = "MakeCall";
                        top.obj.DestinationNumber = result.data.phone;
                        top.obj.Header = result.data.fix;
                        top.obj.TaskType = "2"; //0:拨号外呼；1:未接来电外呼；2:回访外呼
                        top.obj.TaskPhoneID = callId; //回访的电话ID
                        top.obj.TaskID = guid; //回访记录编号
                        top.obj.Callee = phoneNumber; //被叫号码
                        top.obj.Caller = $.cookie("extno"); //操作人分机号
                        top.Send();
                    }
                },
            });
        }

        // 更新外呼记录前
        function beforeUpdateCallOut (callId) {
            $.ajax({
                type: "get",
                url: huayi.config.callcenter_url + "Callrecords/UpdateCallback",
                async: true,
                dataType: "json",
                data: {
                    token: $.cookie("token"),
                    callid: callId,
                },
                success: function (result) {
                    if (result.state.toLowerCase() == "success") {
                    }
                },
            });
        }

        // 更新外呼记录后
        function afterUpdateCallOut (callId) {
            $.ajax({
                type: "get",
                url: huayi.config.callcenter_url + "Callrecords/UpdateCallbackid",
                async: true,
                dataType: "json",
                data: {
                    token: $.cookie("token"),
                    callid: callId,
                    p_callid: callId,
                },
                success: function (result) {
                    if (result.state.toLowerCase() == "success") {
                    }
                },
            });
        }

        // 回拨记录
        function callbackRecord(callId) {
            layer.open({
                type: 2,
                content: "./callbackRecordList.html?callId=" + callId, //iframe的url，no代表不显示滚动条
                title: '回拨记录',
                area: ['100%', '100%'], //宽高
            });
        }

        //电话类别
        function getPhoneType(obj) {
            obj.empty();
            $("<option value=''>请选择</option>").appendTo(obj);
            $.ajax({
                type: "get",
                url: huayi.config.callcenter_url + "Dictionary/GetDicValueListById",
                dataType: "json",
                async: true,
                data: {
                    "token": $.cookie("token"),
                    id: 2498,
                },
                success: function (data) {
                    if (data.state.toLowerCase() == "success") {
                        var content = data.data;
                        $(content).each(function (i, n) {
                            $("<option value='" + n.F_Value + "'>" + n.F_Remark + "</option>")
                                .appendTo(obj);
                        })
                    }
                }
            });
        }