File: /web/data/www.tbbprovision.com/static/manage/js/links.js
/**
* author : liaoyaping
* createTime : 2017/5/22 9:48
* description :
*/
var servedobj = {
list : function(){
window.$bootstrapTable = $('#table2').bootstrapTable({
url:'/admin/links/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,
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: 'picture',
title: '公司图片',
width: '14%',
formatter:function(value){
if(value){
return "<img class='lazy' width='100' height='50' src='"+value+"'>";
}else{
return "<img width='100' height='50' src='/static/manage/img/webuploader.png'>";
}
}
},{
field: 'name',
title: '名称',
formatter:function(value){
return value;
},
sortable:true
},{
field:'url',
title:'链接',
formatter:function(value,row){
return value +" <a href='"+value+"' target='_blank'><i class='fa fa-external-link text-warning font-bold'></i></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/links/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/links/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/links/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: 50, message: '名称长度必须在2到50之间'}
}
},
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/links/list/';
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:2000,icon:7});
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function(){
$('#defaultForm').bootstrapValidator('validate');
});
//图片
global.upload();
}
};