define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'privatebookpage/index',
add_url: 'privatebookpage/add',
edit_url: 'privatebookpage/edit',
del_url: 'privatebookpage/del',
table: 'private_book_page',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'title', title: __('Title'),operate:false},
{field: 'url', title: __('页面地址'),operate:false, formatter: function (value, row, index) {
return '/index/recharge/singlepage?page_id='+ row.id;
}},
{field: 'status', title: __('状态'), operate:false, formatter: function (value, row, index) {
if (value == '0') {
return "隐藏";
}
return "正常";
}},
{field: 'end_time', title: __('结束时间'), operate:false,formatter:Table.api.formatter.datetime},
{field: 'createtime', title: __('创建时间'), operate:false,formatter:Table.api.formatter.datetime},
{field: 'updatetime', title: __('更新时间'), operate:false,formatter:Table.api.formatter.datetime},
{field: 'id', title: __('资源列表'),formatter: Controller.api.formatter.id},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,formatter:function (value,row) {
var html = '';
html += '清除缓存 ';
html += ' ';
html+='';
return html;
}}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
//btn-collect
$(document).on('click','.clean-cache',function () {
var id = $(this).attr('data-id');
$.post('Privatebookpage/cleancache/id/'+id,function(res){
console.log(res);
if(res.code == 1){
layer.alert('操作成功');
}else{
layer.alert('操作失败');
}
});
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
formatter: {
id: function (value, row, index) {
//这里手动构造URL
url = "privatebookpageresource/index?page_id="+row.id;
return '资源列表';
}
}
}
};
return Controller;
});