File: /web/data/www.tbbprovision.com/static/manage/js/onlineserver.js
/**
* author : liaoyaping
* createTime : 2017/5/22 9:48
* description :
*/
var onlineserver = {
list : function(){
window.$bootstrapTable = $('#table2').bootstrapTable({
url:'/admin/onlineServer/list_json/',
method:'post',
striped:true,
search:true,
height:'530',
toolbar:'#toolbar',
sortOrder:'desc',
showColumns:true,
showRefresh:true,
idField:'sid',
showToggle:false,
sidePagination:'server',
selectItemName:'id',
clickToSelect:true,
pageSize:40,
totalRows:5,
columns: [{
field: 'sid',
title: 'ID',
checkbox:true,
formatter: function(value,row){
row['post_id'] = value;
}
},{
title: '序号',
width:'5%',
align:'center',
formatter:function(value,row,index){
return ++index;
}
},{
field:'my_order',
title: '排序',
width:'5%',
align:'center',
sortable:true
},{
field: 'name',
title: '名称',
formatter:function(value){
return value;
}
},{
field: 'account',
title: '帐号',
formatter:function(value){
return value;
}
},{
field: 'type',
title: '图标',
formatter:function(value,row){
return '<a target="_blank" title="'+row.type_name+'" href="'+row.url+'" ><span class="'+row.class+'" style="color:'+row.color_style+'"></span></a>';
}
},{
field: 'is_close',
class: 'text-center',
title: '显示状态',
width: '10%',
formatter:function(value,row,index){
return '<div class="switch inline text-left"><div class="onoffswitch"><input type="checkbox" '+(value==0?" checked ":"")+' class="onoffswitch-checkbox" id="example'+index+'"><label data-id="'+row.post_id+'" class="onoffswitch-label" for="aexample'+index+'"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div></div>';
}
},{
field: '',
title: '操作',
width: '8%',
formatter: function(value,row,index){
return "<a href='/admin/onlineServer/edit/?sid="+row.post_id+"' class='item-edit-btn btn btn-info btn-list' title='编辑' data-id='"+row.post_id+"'><span class='fa fa-pencil'></span></a>";
}
}],
onLoadSuccess: function(){
$('.onoffswitch-label').click(function(){
var that = $(this);
$.ajax({
url: '/admin/onlineServer/close/',
method: 'post',
data: {sid:that.attr('data-id')},
timeout:5000,
dataType: 'json',
beforeSend: function(){layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});},
success: function(xhrData){
layer.msg(errorMessage(xhrData.response_content),{time:1000,icon:1});
that.siblings('input').click();
},
error:function(xhrData){layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:7});}
});
});
}
});
//删除
$('#remove').click(function(){
//询问框
layer.confirm('确定删除此记录?', {
skin:'layui-layer-molv',
'title':'<strong class="">提示</strong>',
btn: ['删除','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:'/admin/onlineServer/del/',
data:global.get_selected_str('input[name="id"]:checked','id'),
dataType:'json',
timeout:5000,
beforeSend: function(){layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});},
success:function($d){
$bootstrapTable.bootstrapTable('refresh');
layer.msg($d.response_content, {icon: 1,time:1000});
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
}
});
});
});
},
edit : function(){
$('#defaultForm').bootstrapValidator({
message: '这是个无效值',
feedbackIcons: {/*input状态样式图片*/
//valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
name: {//验证input项:验证规则
validators: {
notEmpty: { message: '客服名称不能为空'},
stringLength: { min: 2, max: 15, message: '请输入客服名称长度必须在2到15之间'}
}
},
account:{
validators:{
notEmpty:{message:'帐号不能为空'}
}
},
type:{
validators:{
notEmpty:{message:'帐号类型不能为空'}
}
},
my_order:{
validators:{
regexp: {
regexp: /^[0-9]{0,3}$/,
message: '排序只能是0~3位数字'
}
}
}
}
}).on('success.form.bv', function(e) {//点击提交之后
e.preventDefault();
var $form = $(e.target);
var bv = $form.data('bootstrapValidator');
$.ajax({
type: "post",
url: $('#defaultForm').attr('action'),
dataType: 'json',
timeout:5000,
data: $('body').find('form').serialize(),//表单数据
beforeSend:function(){
$('#validateBtn').button('loading');
layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});
},
success: function (d) {
window.location = '/admin/onlineServer/list/';
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function(){
$('#defaultForm').bootstrapValidator('validate');
});
//图片
global.upload();
//颜色选择器
$('#choice-color').colorpicker({
horizontal:true,
// 格式,十六进制
format : "hex"
}).on( 'colorChange',function(e){alert(1);});
init_img();
$('select').change(function(){
init_img();
});
$('#choice-color').colorpicker().on('changeColor', function(ev){
$('#icon-container').attr('style',"color:"+ev.color.toHex());
$('.add-on i').attr('style',"background:"+ev.color.toHex());
});
function init_img(){
var icon_class = $('option:selected').attr('data-id');
$('#icon-container').attr('class',icon_class);
$('#icon-container').attr('style',"color:"+$('input[name=color_style]').val());
}
}
}