	var token = $.cookie("token");
	var table = $('#table1');
	var bs;//字典标识
	//左边表格
	initTable(token);
function initTable(token) {
    //先销毁表格
    table.bootstrapTable('destroy');
    //初始化表格,动态从服务器加载数据
    table.bootstrapTable({
        method: "get", //使用get请求到服务器获取数据
        url: huayi.config.callcenter_url + "Dictionary/GetList", //获取数据的Servlet地址
        contentType: 'application/x-www-form-urlencoded',
        //			url: "shuJuZiDian.json", //获取数据的Servlet地址
        striped: true, //表格显示条纹
        pagination: true, //启动分页
        pageSize: 10, //每页显示的记录数
        pageNumber: 1, //当前第几页
        pageList: [10, 15, 20, 30, 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 = {
                pageindex: params.pageNumber,
                pagesize: params.pageSize,
                token: token
            };
            return param;
        },
        onLoadSuccess: function () { //加载成功时执行
            //layer.msg("加载成功");
        },
        onLoadError: function () { //加载失败时执行
            //layer.msg("加载数据失败", { time: 1500, icon: 2 });
        }
    });
}
			/*获取选中行对象*/
table.on("click-row.bs.table", function (e, row, ele) {
    $('.success').removeClass('success');//去除之前选中的行的，选中样式
    $(ele).addClass('success');//添加当前选中的 success样式用于区别
    bs = row.flag;
    initTableRight(token, bs);
});
function oper(val, row) {
    return '<div class="pull-right">' +
        '<a class="del" title="删除" style="margin-right:5px;" onclick= SC("' + row.name + '","'+row.id+'")><i class="shanChu"></i></a>' +
        '<a class="xg" title="修改"><i class="xiuGai"></i></a>' +
        '</div>' +
        '<div class="pull-left">' + val + '</div>'
}
function setCodeLeft(val, row, index) {
    return index + 1;
}
	//====================添加功能开始=============================
$('.tjzd').click(function () {
    $('.addModel').css('display', 'block');
});
		//关闭按钮
$('.addBtr ').click(function () {
    $('.inps1').val('');
    $('.addzdz').val('');
    $('.addSort').val('');
    $('.addModel').css('display', 'none');
});
		//保存按钮
$('.addCunzd').click(function () {
    if ($('.inps1').val() == '' || $('.addzdz').val() == '') {
        layer.confirm('字典标识与字典分类不允许为空！', {
            btn: ['确定']
        });
        return;
    } else {
        tjCunzd(token);
        $('.addModel').css('display', 'none');
    }
});
function tjCunzd() {
    $.ajax({
        type: "post",
        url: huayi.config.callcenter_url + "Dictionary/AddDic",
        async: true,
        dataType: "json",
        data: {
            token: token,
            dicflag: $('.inps1').val(),
            Name: $('.addzdz').val(),
            sort: $('.addSort').val()
        },
        success: function (data) {
            debugger;
            if (data.state.toLowerCase() == 'success') {
                layer.msg("添加成功!");
                table.bootstrapTable('refresh');
                $('.inps1').val('');
                $('.addzdz').val('');
                $('.addSort').val('');
                bs = '';
            }
        }
    });
}
	//*****************添加功能结束==============================
	
			
	//=================字典删除功能开始==================================
		var leftId;
function SC(te,id) {
    $('.delModel').css('display', 'block');
    $('.delName').html(te);
    leftId = id;
}
$('.sure').click(function () {
    $('.delModel').css('display', 'none');
    //console.log(leftId);
    $.ajax({
        type: "post",
        url: huayi.config.callcenter_url + "Dictionary/DelDic",
        async: true,
        dataType: 'json',
        data: {
            ids: leftId,
            token: token
        },
        success: function (data) {
            if (data.state.toLowerCase() == 'success') {
                layer.msg("删除成功!");
//              table.bootstrapTable('refresh');
                initTable(token);
                bs = '';
            }
        }
    });
});
    
    	//关闭按钮
$('.delBtr').click(function () {
    $('.delModel').css('display', 'none');
});
    	//取消按钮
$('.return').click(function () {
    $('.delModel').css('display', 'none');
});
    	
	//*********************字典删除功能结束==================================
	//=====================字典修改功能开始==================================

window.operateEvents = {
    'click .xiuGai': function (e, value, row) {
        $('.changeModel').css('display', 'block');
        $('.chanName').html(row.name);
        getZiDian(row.id);
    }
}
function getZiDian(id) {
    $.ajax({
        type: "get",
        url: huayi.config.callcenter_url + "Dictionary/GetDic",
        async: true,
        dataType: 'json',
        data: {
            id: id,
            token: token
        },
        success: function (data) {
            var con = data.data;
            $('.inps4id').val(con.id);
            $('.inps4').val(con.flag);
            $('.chanzdz').val(con.name);
            $('.changeCode').val(con.sort);
        }
    });

}
		//关闭按钮
$('.changeBtr').click(function () {
    $('.changeModel').css('display', 'none');
});
	//保存按钮
$('.chanCun').click(function () {
    if ($('.inps4').val() == '' || $('.chanzdz').val() == '') {
        layer.confirm('字典标识与字典分类不允许为空！', {
            btn: ['确定']
        });
        return;
    }
    $('.changeModel').css('display', 'none');
    cunZiDian(token);
});
	
function cunZiDian(token) {
    $.ajax({
        type: "get",
        url: huayi.config.callcenter_url + "Dictionary/EditDic",
        async: true,
        dataType: 'json',
        data: {
            dicid: $('.inps4id').val(),
            dicflag: $('.inps4').val(),
            Name: $('.chanzdz').val(),
            sort: $('.changeCode').val(),
            token: token
        },
        success: function (data) {
            if (data.state.toLowerCase() == 'success') {
                layer.msg("修改成功!");
                table.bootstrapTable('refresh');
                $('.inps4id').val('');
                $('.inps4').val('');
                $('.chanzdz').val('');
                $('.changeCode').val('');
            }
        }
    });
}
	
	//*********************字典修改功能结束==================================
	
	//右边表格
	var tableRight=$('#table2');
	initTableRight(token,bs);
function initTableRight(token, bs) {
    //先销毁表格
    tableRight.bootstrapTable('destroy');
    //初始化表格,动态从服务器加载数据
    tableRight.bootstrapTable({
        method: "get", //使用get请求到服务器获取数据
        url: huayi.config.callcenter_url + "Dictionary/GetDicValueList", //获取数据的Servlet地址
        contentType: 'application/x-www-form-urlencoded',
        //			url: "shuJuZiDianTBR.json", //获取数据的Servlet地址
        striped: true, //表格显示条纹
        pagination: true, //启动分页
        pageSize: 10, //每页显示的记录数
        pageNumber: 1, //当前第几页
        pageList: [10, 15, 20, 30, 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 getParams(params) { //设置查询参数
            var param = {
                pageindex: params.pageNumber,
                pagesize: params.pageSize,
                token: token,
                flag: $('.sear_bs').val().replace(/\ +/g,""),
                name: $('.sear_name').val().replace(/\ +/g,""),
                id: bs
            };
            return param;
        },
        onLoadSuccess: function () { //加载成功时执行
            //layer.msg("加载成功");
        },
        onLoadError: function () { //加载失败时执行
            //layer.msg("加载数据失败", { time: 1500, icon: 2 });
        }
    });
}
	
function setCodeRight(val, row, index) {
    return index + 1;
}
	
	//========================字典列表添加功能开始==================================
$('.zdl_add').click(function () {
    if (bs) {
        $('.zdlist_addModel').css('display', 'block');
        $('.inps5').val(bs)
    } else {
        layer.confirm('请选择要添加的类！', {
            btn: ['确定']
        });
        return;
    }

});
	    //关闭按钮
$('.addListBtr').click(function () {
    $('.zdlist_addModel').css('display', 'none');
});
	    //保存按钮
$('.addList_cun').click(function () {
    $('.zdlist_addModel').css('display', 'none');
    addList();
});
function addList() {
    $.ajax({
        type: "post",
        url: huayi.config.callcenter_url + "Dictionary/AddDicValue",
        async: true,
        dataType: 'json',
        data: {
            token: token,
            dicflag: $('.inps5').val(),
            dicvalue: $('.inps5value').val(),
            dicvname: $('.addList_zdz').val(),
            dicdes: $('.addList_remark').val(),
            sort: $('.addList_sort').val()
        },
        success: function (data) {
            if (data.state.toLowerCase() == 'success') {
                layer.msg("添加成功!");
                initTableRight(token, bs);
                $('.inps5').val('');
                $('.inps5value').val('');
                $('.addList_zdz').val('');
                $('.addList_remark').val('');
                $('.addList_sort').val('');
            }
        }
    });
}
	    
	//************************字典列表添加功能结束==================================
		
	//========================字典列表修改功能开始==================================

var rlag;
$('.zdl_change').click(function () {
    var rvd = $.map(tableRight.bootstrapTable('getSelections'), function (row) {
        return row.F_DictionaryValueId;
        //console.log(row.F_DictionaryValueId);
    });
    rlag = rvd.toString();
    if (rvd.length != 1) {
        layer.confirm('请选择一行进行修改！', {
            btn: ['确定']
        });
        return;
    } else {
        $('.zdlist_chanModel').css('display', 'block');
        //console.log(rlag);
        getzdv(token, rlag);
    }
});
	    //关闭按钮
$('.chanListBtr').click(function () {
    $('.zdlist_chanModel').css('display', 'none');
});
function getzdv(token, rlag) {
    $.ajax({
        type: "get",
        url: huayi.config.callcenter_url + "Dictionary/GetDicValue",
        async: true,
        dataType: 'json',
        data: {
            token: token,
            dicvalueid: rlag
        },
        success: function (data) {
            var con = data.data;
            $('.inps6').val(con.dicflag);
            $('.inps6value').val(con.value);
            $('.chanList_zdz').val(con.name);
            $('.chanList_remark').val(con.remark);
            $('.chanList_sort').val(con.sort);
        }
    });
}
	    //保存按钮
$('.chanList_cun').click(function () {
    $('.zdlist_chanModel').css('display', 'none');
    tjc(token, rlag);

});
function tjc(token, rlag) {
    $.ajax({
        type: "post",
        url: huayi.config.callcenter_url + "Dictionary/EditDicValue",
        async: true,
        dataType: 'json',
        data: {
            token: token,
            dicflag: $('.inps6').val(),
            dicvalue: $('.inps6value').val(),
            dicvid: rlag,
            dicvname: $('.chanList_zdz').val(),
            dicdes: $('.chanList_remark').val(),
            sort: $('.chanList_sort').val()

        },
        success: function (data) {
            if (data.state.toLowerCase() == 'success') {
                layer.msg("修改成功");
                initTableRight(token, bs);
                $('.inps6').val('');
                $('.inps6value').val('');
                $('.chanList_zdz').val('');
                $('.chanList_remark').val('');
                $('.chanList_sort').val('');
            }

        }
    });
}
	//************************字典列表修改功能结束==================================
		
	//========================字典列表删除功能开始==================================
 		var did;
$('.zdl_del').click(function () {
    did = $.map(tableRight.bootstrapTable('getSelections'), function (row) {
        return row.F_DictionaryValueId;
    });
    //				did=idd.toString()
    if (did.length <= 0) {
        layer.confirm('请选择一行删除！', {
            btn: ['确定']
        });
        return;
    } else {
        $('.zdlist_delModel').css('display', 'block');
    }
});
	    //关闭按钮
$('.delListBtr').click(function () {
    $('.zdlist_delModel').css('display', 'none');
});
	    //取消按钮
$('.delList_return').click(function () {
    $('.zdlist_delModel').css('display', 'none');
});
	     //确定按钮
$('.delList_sure').click(function () {
    $('.zdlist_delModel').css('display', 'none');
    sctj(token, did);
});
function sctj(token, did) {
    //	        	console.log(did)
    $.ajax({
        type: "post",
        url: huayi.config.callcenter_url + "Dictionary/DelDicValue",
        async: true,
        dataType: 'json',
        data: {
            token: token,
            ids: did
        },
        success: function (data) {
            if (data.state == "success") {
                layer.msg("删除成功！");
                initTableRight(token, bs);
            }
        }
    });
}
	//************************字典列表删除功能结束==================================
		
	//搜索事件
$('.sousuo').click(function () {
    initTableRight(token, bs);
});

// 回车搜索
document.onkeydown = function (e) { // 回车提交表单
    var theEvent = window.event || e;
    var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code == 13) {
    	initTableRight(token, bs);
    }
}

