File: /web/data/www.tbbprovision.com/static/manage/js/download.js
/**
* author : liaoyaping
* createTime : 2017/5/19 11:21
* description :
*/
var downloadobj = {
/*ad list */
list : function(){
window.$bootstrapTable = $('#table2').bootstrapTable({
url:'/admin/download/list_json/',
method:'post',
striped:true,
search:false,
height:'600',
toolbar:'#toolbar',
sortOrder:'desc',
showColumns:false,
showRefresh:true,
idField:'did',
showToggle:false,
showFooter:false,
sidePagination:'server',
selectItemName:'did',
pagination:false,
clickToSelect:true,
totalRows:5,
pageSize:100,
queryParams:function(data){
return data;
},
columns: [{
field: 'did',
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: 'name',
title: '名称',
width: '15%'
},{
field: 'picture',
title: '列表图片',
width: '15%',
class: 'text-center',
formatter:function(value,row){
return value?"<a href='"+value+"' target='_blank'><img src='"+value+"' width='50' height='50' /></a>":'';
}
},{
field: 'add_time',
title: '添加时间'
},{
field: 'downloads',
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/download/download_edit/?did="+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/download/download_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('确定删除此记录?', {
skin:'layui-layer-molv',
'title':'<strong class="">提示</strong>',
btn: ['删除','关闭'] //按钮
}, function(){
jQuery.ajax({
method:'post',
url:'/admin/download/download_del/',
data:global.get_selected_str('input[name="did"]: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: 200, message: '下载文件名称长度必须在2到200之间'}
}
},
downloads:{
validators:{
regexp: {
regexp: /^[0-9]{0,10}$/,
message: '下载次数只能是0-10位数字'
}
}
},
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/download/list/';
},
error:function(xhrData){
layer.msg(errorMessage(xhrData.responseText),{time:1000,icon:2});
$('#validateBtn').button('reset');
}
});
});
$('#validateBtn').click(function() {
$('#defaultForm').bootstrapValidator('validate');
});
//图片
global.upload();
//时间选择
$('#datetimepicker').datetimepicker();
}
};