123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 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 += '<a href="/admin/floattips/edit/ids/'+row.id+'" class="btn btn-xs btn-success btn-editone" title="" data-table-id="table"><i class="fa fa-pencil"></i></a> ';
- content += '<a href="/admin/floattips/upload/ids/'+row.id+'" class="btn btn-xs btn-success layer-open" title="" data-table-id="table"><i class="fa fa-upload"></i></a> ';
- content += '<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table"><i class="fa fa-trash"></i></a>';
- 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;
- });
|