define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'subscrip/activity/index', add_url: 'subscrip/activity/add', edit_url: 'subscrip/activity/edit', del_url: 'subscrip/activity/del', multi_url: 'subscrip/activity/multi', table: 'subscrip_activity', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id'),operate:false}, {field: 'title', title: __('Title')}, {field: 'old_price', title: __('Old_price'), operate:false}, {field: 'price', title: __('Price'), operate:false}, {field: 'created_at', title: __('创建时间'),operate:false,formatter:Table.api.formatter.datetime}, {field: 'days', title: __('活动周期(天)'),operate:false}, {field: 'begin_date', title: __('Begin_date'),operate:false}, {field: 'pop_space', title: __('弹窗位置'),operate:false}, // {field: 'pop_img', title: __('Pop_img'),operate:false}, {field: 'state', title: __("状态"),searchList: {"1":__('有效'),"2":__('失效')},formatter:function(value,row){ if (row.state == 1){ return '有效'; }else{ return '失效'; } }}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value,row) { var html = ''; if (row.is_begin == 0){ if (row.state == 2) { html += '有效  '; } else { html += '失效  '; } html += '修改  '; html += '关联用户  '; } html += '详情  '; html += '数据统计  '; return html; }} ] ] }); $(document).on('click','.upload-user',function () { var aid = $(this).data('id'); var date = $(this).data('date'); Fast.api.open('subscrip/activity/upload/aid/'+aid+'/date/'+date,'关联用户', {callback: function (data) { }}); }); $(document).on('click','.btn-collect',function () { var aid = $(this).data('id'); Fast.api.open('subscrip/activecollect/index/aid/'+aid,'活动统计', {callback: function (data) { }}); }); $(document).on('click','.btn-detail',function () { var id = $(this).data('id'); Fast.api.open('subscrip/activity/detail/id/'+id,'活动详情', {callback: function (data) { }}); }); // 失效 | 有效 $(document).on('click','.btn-lapse',function(){ var id = $(this).data('id'); var state = $(this).data('status'); var status_text = '确定要失效处理吗?'; if(state == 2){ status_text = '确定要设置为有效吗?'; } Layer.confirm(status_text, function (idx) { $.post( 'subscrip/activity/ajaxLapse', { 'id': id, 'state': state }, function (data) { layer.alert(data.msg); } ); }); }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { Controller.api.bindevent(); $(document).on('change', '#c-goods', function () { $('#c-price').val($(this).children('option:selected').data('money') ); }); }, 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()); Form.api.bindevent($("form[role=form]")); } } }; return Controller; });