define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'floattips/index',
add_url: 'floattips/add',
edit_url: 'floattips/edit',
del_url: 'floattips/del',
multi_url: 'floattips/multi',
table: 'float_tips',
},
search: false
});
var table = $("#table");
$(document).on('click','.layer-open',function () {
Fast.api.open($(this).attr('href'), $(this).data('title')?$(this).data('title'):'配置公共信息', {});
return false;
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id'), operate: false},
{field: 'name', title: __('Name'), operate: 'LIKE'},
{field: 'image', title: __('Image'), formatter: Table.api.formatter.image, operate: false},
{field: 'image_pop', title: __('Image_pop'), formatter: Table.api.formatter.image, operate: false},
{field: 'chapter_show', title: __('Chapter_show'), operate: false},
{field: 'type', title: __('Type'), visible:false, searchList: {"activity":__('type activity'),"url":__('type url'),"book":__('type book')}},
{field: 'type_text', title: __('Type'), operate:false},
{field: 'link', title: __('Link'), operate: false},
{field: 'starttime', title: __('Starttime'), operate: false,formatter: Table.api.formatter.datetime},
{field: 'endtime', title: __('Endtime'), operate: false,formatter: Table.api.formatter.datetime},
{field: 'recharge_money', title: '充值金额/今日', operate:false, formatter: function(value, row){return value+'('+row.recharge_money_day+')'}},
{field: 'recharge_user', title: '充值人数/今日', operate:false, formatter: function(value, row){return value+'('+row.recharge_user_day+')'}},
{field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
{field: 'status_text', title: __('Status'), operate:false},
{field: 'createtime', title: __('Createtime'),formatter: Table.api.formatter.datetime, operate:false},
{field: 'updatetime', title: __('Updatetime'),formatter: Table.api.formatter.datetime, operate:false},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row){
var content = '';
content += ' ';
content += ' ';
content += '';
return content;
}}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
upload: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
$('#c-book').selectPage({
eSelect : function(d){
$('#c-book_book_name').val(d.name);
$('#select_book_id').val(d.id);
$('#c-chapter_text').val('');
$('#c-chapter').val('');
$('#select_chapter_id').val('');
},
params: function(){
return {'custom':{state:'1'}}
}
});
$('#c-chapter').selectPage({
eSelect : function(d){
$('#c-chapter_name').val(d.name);
$('#select_chapter_id').val(d.id);
},
params: function(){
return {'filter':'{"id":"'+$('#select_book_id').val()+'"}'}
}
});
$('#c-chapter_text').val($('#c-chapter').val());
$(document).delegate('input[name="row[type]"]', 'click', function () {
var val = $('input[name="row[type]"]:checked').val();
switch (val) {
case 'activity':
$('.activity').show();
$('.link,.book').hide();
break;
case 'url':
$('.link').show();
$('.activity,.book').hide();
break;
case 'book':
$('.book').show();
$('.activity,.link').hide();
break;
}
})
$("#add-form, #edit-form").data("validator-options", {
ignore: ':hidden',
beforeSubmit: function () {
var val = $('input[name="row[type]"]:checked').val();
var msg = [];
switch (val) {
case 'url':
if (!$('#c-link').val()) {
msg.push('url不可为空');
}
break;
case 'book':
if (!$('#select_book_id').val()) {
msg.push('书籍不可为空');
}
if (!$('#select_chapter_id').val()) {
msg.push('章节不可为空');
}
break;
}
if (msg.length > 0) {
Toastr.error(msg.join(','));
return false;
}
}
});
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});