File: /web/data/www.tbbprovision.com/static/manage/js/ad.js
/**
* author : liaoyaping
* createTime : 2017/5/19 11:21
* description :
*/
var adobj = {
cate_list : function(){
//删除
$('.del-btn').click(function(){
var cate_id = $(this).attr('data-id');
//询问框
layer.confirm('确定删除此记录?', {
'title':'警告',
icon:3,
btn: ['删除','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:'/admin/ad/cate_del/',
data:{cate_id:cate_id},
timeout:5000,
dataType:'json',
beforeSend:function(){
layer.msg('数据处理中',{icon:16,time:0,shade:[0.8,'#000']});
},
success:function($d){
layer.msg($d.response_content, {icon: 1,time:1000},function(){
window.location.reload();
});
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:7});
}
});
},function(){
layer.msg('操作取消',{time:500});
});
});
//新增
$('#add').click(function(){
var index = layer.open({
type: 2,
title: ['新增广告图分类'],
shadeClose: true,
shade: [true,'rgba(0,0,0,.5)'],
maxmin: true,
shift:2,
offset:['50%','0'],
area: ['100%', '50%'],
content: '/admin/ad/cate_add/'
});
});
//编辑
$('.edit-btn').click(function(){
var cate_id = $(this).attr('data-id');
var index = layer.open({
type: 2,
title: ['编辑产品分类'],
shadeClose: true,
shift:2,
shade: [true,'rgba(0,0,0,.5)'],
maxmin: true,
offset:['50%','0'],
area: ['100%', '50%'],
content: '/admin/ad/cate_edit/?cate_id='+cate_id
});
});
},
cate_edit : function(){
$('#defaultForm').bootstrapValidator({
message: '这是个无效值',
feedbackIcons: {/*input状态样式图片*/
//valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
cate_name: {//验证input项:验证规则
validators: {
notEmpty: { message: '分类名称不能为空'},
stringLength: { min: 2, max: 30, message: '分类名称长度必须在2到30之间'}
}
},
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: "/admin/ad/cate_edit_post/",
dataType: 'json',
timeout:10000,
data: $('body').find('form').serialize(),//表单数据
beforeSend:function(){
layer.msg('数据处理中', {
time:0,
icon:16,
shade: [0.8,'#000'] //0.1透明度的白色背景
});
$('#validateBtn').button('loading');
},
success: function (d) {
parent.location.reload();
parent.layer.closeAll('iframe');//关闭弹窗
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
layer.closeAll('msg');
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
},
cate_add:function(){
$('#defaultForm').bootstrapValidator({
message: '这是个无效值',
feedbackIcons: {/*input状态样式图片*/
//valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
cate_name: {//验证input项:验证规则
validators: {
notEmpty: { message: '分类名称不能为空'},
stringLength: { min: 2, max: 30, message: '分类名称长度必须在2到30之间'}
}
},
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: "/admin/ad/cate_add_post/",
dataType: 'json',
timeout:10000,
data: $('body').find('form').serialize(),//表单数据
beforeSend:function(){
layer.msg('数据处理中', {
time:0,
icon: 16
,shade: [0.4,'#000']
});
$('#validateBtn').button('loading');
},
success: function (d) {
parent.location.reload();
parent.layer.closeAll('iframe');//关闭弹窗
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
layer.closeAll('msg');
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
},
/*ad list */
list : function(){
window.$bootstrapTable = $('#table2').bootstrapTable({
url:'/admin/ad/ad_list_json/',
method:'post',
striped:true,
search:false,
height:'600',
toolbar:'#toolbar',
sortOrder:'desc',
showColumns:false,
showRefresh:true,
idField:'aid',
showToggle:false,
showFooter:false,
sidePagination:'server',
selectItemName:'aid',
pagination:false,
clickToSelect:true,
totalRows:5,
pageSize:100,
queryParams:function(data){
data.cate_id = $('#cate_id').val();
return data;
},
columns: [{
field: 'aid',
title: 'ID',
checkbox:true,
formatter: function(value,row){
row['post_id'] = value;
}
},{
field: 'my_order',
title: '排序',
width:'5%',
align:'left',
formatter: function (value, row, index) {
return "<a class='edit-btn' href=\"#\" name=\"new_my_order\" data-type=\"text\" data-pk=\"" + value + "\" data-title=\"排序\">" + value + "</a>";
}
},{
field: 'picture',
title: '广告图',
width: '15%',
formatter:function(value){
if(value){
return "<img style='max-width:100px;max-height:50px;' class='img img-thumbnail' src='"+value+"'>";
}else{
return "<img width='50' height='50' src='/static/manage/img/webuploader.png'>";
}
}
},{
field: 'name',
title: '广告图名称'
},{
field: 'cate_id',
title: '分类',
formatter:function(value,row,index){
return row.cate_name;
}
},{
field: 'add_time',
title: '添加时间'
},{
field: 'update_time',
title: '修改时间'
},{
field: '',
title: '操作',
width: '8%',
formatter: function(value,row,index){
return "<a class='item-edit-btn btn btn-info btn-list' title='编辑' href='/admin/ad/ad_edit/?aid="+row.post_id+"' data-id='"+row.post_id+"'><span class='fa fa-pencil'></span></a>";
}
}],
onClickRow: function (row, $element) {
curRow = row;
},
onLoadSuccess: function(data){
$("#table2 .edit-btn").editable({
url: function (params) {
var sName = $(this).attr("name");
curRow[sName] = params.value;
$.ajax({
type: 'POST',
url: "/admin/ad/ad_order/",
data: curRow,
dataType: 'JSON',
success: function (xhrData) {
layer.msg(xhrData.response_content,{icon:1,time:500},function(){
$bootstrapTable.bootstrapTable('refresh');
});
},
error: function (xhrData) {
//失败了重新刷新
layer.msg(xhrData.responseText,{icon:7,time:1000},function () {
$bootstrapTable.bootstrapTable('refresh');
});
}
});
},
type: 'text',
// mode : 'inline',
placement:'right',
validate: function (value) { //字段验证
if (!$.trim(value)) {
return '不能为空';
}
var patten = /^[0-9]{1,3}$/;
if(!patten.test(value)){
return '排序只能为1~3位数字';
}
}
});
}
});
//删除
$('#remove').click(function(){
//询问框
layer.confirm('确定删除此记录?', {
'title':'提示',
icon:3,
btn: ['删除','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:'/admin/ad/ad_del/',
data:global.get_selected_str('input[name="aid"]:checked','id'),
dataType:'json',
timeout:10000,
beforeSend:function(){
layer.closeAll('confirm');
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状态样式图片*/
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {/*验证:规则*/
name: {//验证input项:验证规则
validators: {
notEmpty: { message: '广告图名称不能为空'},
stringLength: { min: 2, max: 255, message: '广告图名称长度必须在2到255之间'}
}
},
cate_id: {//验证input项:验证规则
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:10000,
data: $('body').find('form').serialize(),//表单数据
beforeSend:function(){
layer.msg('数据处理中', {time:0,icon:16,shade: [0.8,'#000']});
$('#validateBtn').button('loading');
},
success: function (d) {
window.location = '/admin/ad/ad_list/';
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
//图片
global.upload();
}
};