File: /web/data/www.tbbprovision.com/static/manage/js/article.js
/**
* author : liaoyaping
* createTime : 2017/5/12 11:21
* description :
*/
var articleobj = {
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/article/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:['0','20%'],
area: ['80%', '100%'],
content: '/admin/article/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)'],
offset:['0','20%'],
maxmin: true,
area: ['80%', '100%'],
content: '/admin/article/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/article/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/article/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');
});
},
/*products list */
list : function(){
var $bootstrapTable = $('#table2').bootstrapTable({
url:'/admin/article/list_json/',
method:'post',
striped:true,
search:true,
height:'600',
toolbar:'#toolbar',
sortOrder:'desc',
showColumns:true,
showRefresh:true,
idField:'aid',
showToggle:false,
sidePagination:'server',
selectItemName:'aid',
clickToSelect:true,
totalRows:5,
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',
sortable:true,
formatter: function (value, row, index) {
if (row['post_gid']!=1) {
return "<a class='edit-btn' href=\"#\" name=\"new_my_order\" data-type=\"text\" data-pk=\"" + value + "\" data-title=\"排序\">" + value + "</a>";
}else{
return value;
}
}
},{
field: 'title',
title: '标题'
},{
field: 'cate_id',
title: '分类',
formatter:function(value,row,index){
return row.cate_name;
}
},{
field: 'acc_time',
title: '添加时间',
sortable:true
},{
field: '',
title: '操作',
width: '8%',
formatter: function(value,row,index){
return "<a class='item-edit-btn btn btn-info btn-list' title='编辑' href='/admin/article/article_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/article/article_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位数字';
}
}
});
}
});
//分类搜索
$('#cate_id').change(function(){
$bootstrapTable.bootstrapTable('refresh');
});
//删除
$('#remove').click(function(){
//询问框
layer.confirm('确定删除此记录?', {
'title':'<strong class="">提示</strong>',
btn: ['删除','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:'/admin/article/article_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: {/*验证:规则*/
title: {//验证input项:验证规则
validators: {
notEmpty: { message: '标题不能为空'},
stringLength: { min: 2, max: 100, message: '标题长度必须在2到100之间'}
}
},
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) {
layer.msg(d.response_content, {icon: 1,time:1000});
setTimeout(function(){window.location = '/admin/article/list/';},1000);
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
}
};