define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'ad/material/index', add_url: 'ad/material/add', edit_url: 'ad/material/edit', del_url: 'ad/material/del', multi_url: 'ad/material/multi', import_url: 'ad/material/import', table: 'ad_material', } }); var table = $("#table"); var list = { 1: '书籍详情页', 2: '追更页', 3: '阅读页底部', 4: '最近阅读', 5: '书架', 6: '阅读页顶部菜单下拉', 7: '阅读页中间1', 8: '阅读页中间2', 9: '阅读页中间3', 10: '充值返回插屏', 11: '阅读器插屏', 12: '签到成功插屏', 13: '个人中心', 14: '排行榜首页', 15: '分类首页', 16: '分类二级', 17: '书城首页轮播Banner', 18: '阅读页顶部浮窗Banner', 19: '阅读页插屏(整章)', 20: '书城首页Banner2', 21: '书城浮窗', 22: '书籍详情浮窗', }; // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', columns: [ [ {checkbox: true}, {field: 'id', title: __('Id'), operate: false}, { field: 'type', title: __('素材类型'), formatter: function (value) { var str = ''; if (value == 1) { str = 'JS链接'; } else if (value == 2) { str = '百度联盟'; } else if (value == 3) { str = '福利广告'; } else { str = '图片链接'; } return str; }, searchList: { 0: '图片链接', 1: 'JS链接', 2: '百度联盟', 3: '福利广告' } }, {field: 'img_url', title: __('Img_url'), formatter: Table.api.formatter.image, operate: false}, { field: 'link_url', title: __('Link_url'), operate: false, formatter: function (value) { if (value.length == 0) { return '-'; } else { return value; } } }, { field: 'link_game', title: __('Link_game'), operate: false, cellStyle:Controller.api.formatter.linkcss, formatter: function (value) { if (value.length == 0) { return '-'; } else { return value; } } }, { field: 'material_position', title: __('Material_position'), cellStyle:Controller.api.formatter.positioncss, searchList: list, formatter: function (value) { if(value == ''){ return '—'; } var str = ''; var arr = new Array(); arr = String(value).split(','); $.each(arr, function (i, n) { str += list[n] + '\n\r'; }); return str; },operate: 'FIND_IN_SET' }, {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: '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: Table.api.formatter.operate} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); //批量生效 $('.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/material/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/material/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(); // 选中素材类型 $("[name='row[type]']").change(function () { var selected_type = $(this).val(); $(".common-type").hide(); $(".type-" + selected_type).show(); if(selected_type == 1 || selected_type == 2){ $(".position-filter").hide(); }else{ $(".position-filter").show(); } if (selected_type == 3) { $(".material-position").hide(); } else { $(".material-position").show(); } }); }, edit: function () { Controller.api.bindevent(); // 选中素材类型 $("[name='row[type]']").change(function () { var selected_type = $(this).val(); $(".common-type").hide(); $(".type-" + selected_type).show(); if(selected_type == 1 || selected_type == 2){ $(".position-filter").hide(); }else{ $(".position-filter").show(); } if (selected_type == 3) { $(".material-position").hide(); } else { $(".material-position").show(); } }); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); }, formatter:{ linkcss:function(){ return { css: { "max-width": "200px", "word-wrap": "break-word", "word-break": "normal" } }; }, positioncss:function(){ return { css: { "max-width": "300px", "word-wrap": "break-word", "word-break": "normal" } }; }, } } }; return Controller; });