define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'ad/manage/index', add_url: 'ad/manage/add', edit_url: 'ad/manage/edit', del_url: 'ad/manage/del', multi_url: 'ad/manage/multi', table: 'ad_manage', } }); var table = $("#table"); // 初始化表格 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: 'ad_type', title: __('Ad_type'), searchList: {'0': 'Banner广告', '1': '插屏广告', '2': '福利广告'}, formatter: function (value) { if (value == 2) { return '福利广告'; } else if (value == 1) { return '插屏广告'; } else { return 'Banner广告'; } } }, { field: 'show_type', title: __('Show_type'), searchList: {'0': '不可轮播', '1': '可轮播'}, formatter: function (value) { if (value) { return '可轮播'; } else { return '不可轮播'; } } }, {field: 'chapter_num', title: __('间隔章节数(阅读器插屏位置)'), operate: false}, {field: 'show_starttime', title: __('Show_starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, {field: 'show_endtime', title: __('Show_endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, {field: 'group_name', title: __('User_group_name'), operate: false}, {field: 'weight', title: __('Weight'), operate: false}, { field: 'state', title: __('State'), searchList: {'0': '失效', '1': '有效'}, formatter: function (value) { if (value) { return '有效'; } else { return '失效'; } } }, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Controller.api.formatter.operate} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); $(document).on('click','.btn-usergroup',function (event) { var ad_manage_id = $(this).data('id'); Fast.api.open('ad/user/group/viewgroup', '关联用户组', { callback: function (data) { var user_group_id = data[0]['id']; $.ajax({ type:'post', url:'/admin/ad/manage/ajaxsaveusergroup', data:{ 'ad_id': ad_manage_id, 'user_group_id': user_group_id, }, dataType:'json', cache:false, async:false, success:function(data){ if (data.code == 1){ Toastr.error(data.msg); }; if(data.code == 0){ Toastr.success(data.msg); } } }); } }); return false; }); //批量生效 $('.btn-batch-validate').on('click', function () { var ids = Table.api.selectedids(table); Layer.confirm( '确定要把选中的' + ids.length + '项改为生效吗?', { icon: 3, title: __('Warning'), offset: 0, shadeClose: true }, function () { $.ajax({ url: '/admin/ad/manage/batchvalidate', type: "post", data: { ids: ids, state: 1 }, success: function () { layer.msg('操作成功'); table.bootstrapTable('refresh'); } }); } ); }); //批量失效 $('.btn-batch-invalidate').on('click', function () { var ids = Table.api.selectedids(table); Layer.confirm( '确定要把选中的' + ids.length + '项改为失效吗?', { icon: 3, title: __('Warning'), offset: 0, shadeClose: true }, function () { $.ajax({ url: '/admin/ad/manage/batchvalidate', type: "post", data: { ids: ids, state: 0 }, success: function () { layer.msg('操作成功'); table.bootstrapTable('refresh'); } }); } ); }); // 更新所有缓存 $(".btn-update-cache").click(function () { $.ajax({ type:'post', url:'/admin/ad/manage/ajaxupdatecache', dataType:'json', cache:false, async:false, success:function(data){ if (data.code == 1){ Toastr.error(data.msg); }; if(data.code == 0){ Toastr.success(data.msg); } } }); }); }, add: function () { Controller.api.bindevent(); $('#c-ad_type').change(function () { var type = $(this).val(); // type= 2=> 福利广告 1 => 插屏广告 0 => banner广告 if (type == 2) { $(".show-all-chapter-num").hide(); $(".show_position_zone").hide(); $(".welfare-zone").show(); $("#show_position-2").show(); $("#show_position-1").hide(); $("#show_position-0").hide(); $("#show_type").hide(); } else if (type == 1) { if ($(".chapter-screen").is(":checked")) { $(".show-all-chapter-num").show(); } $(".show_position_zone").show(); $(".welfare-zone").hide(); $("#show_position-2").hide(); $("#show_position-1").show(); $("#show_position-0").hide(); $("#show_type").hide(); } else { $(".show-all-chapter-num").hide(); $(".show_position_zone").show(); $(".welfare-zone").hide(); $("#show_position-0").show(); $("#show_position-1").hide(); $("#show_position-2").hide(); $("#show_type").show(); } }); // 勾选 阅读器插屏 $(".read-screen").change(function () { if ($(this).is(":checked")) { $(".show-chapter-num").show(); } else { $(".show-chapter-num").hide(); } }); // 勾选 阅读页插屏(整章) $(".chapter-screen").change(function () { if ($(this).is(":checked")) { $(".show-all-chapter-num").show(); } else { $(".show-all-chapter-num").hide(); } }); }, edit: function () { Controller.api.bindevent(); $('#c-ad_type').change(function () { var type = $(this).val(); // type= 2=> 福利广告 1 => 插屏广告 0 => banner广告 if (type == 2) { $(".show-all-chapter-num").hide(); $(".show_position_zone").hide(); $(".welfare-zone").show(); $("#show_position-2").show(); $("#show_position-1").hide(); $("#show_position-0").hide(); $("#show_type").hide(); } else if (type == 1) { if ($(".chapter-screen").is(":checked")) { $(".show-all-chapter-num").show(); } $(".show_position_zone").show(); $(".welfare-zone").hide(); $("#show_position-2").hide(); $("#show_position-1").show(); $("#show_position-0").hide(); $("#show_type").hide(); } else { $(".show-all-chapter-num").hide(); $(".show_position_zone").show(); $(".welfare-zone").hide(); $("#show_position-0").show(); $("#show_position-1").hide(); $("#show_position-2").hide(); $("#show_type").show(); } }); // 勾选 阅读器插屏 $(".read-screen").change(function () { if ($(this).is(":checked")) { $(".show-chapter-num").show(); } else { $(".show-chapter-num").hide(); } }); // 勾选 阅读页插屏(整章) $(".chapter-screen").change(function () { if ($(this).is(":checked")) { $(".show-all-chapter-num").show(); } else { $(".show-all-chapter-num").hide(); } }); }, api: { formatter: { operate: function (value, row, index) { var html = ''; html += ''; html += ''; html += '关联用户组'; return html; } }, bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });