123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- 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 += '<a href="/admin/ad/manage/edit/ids/' + row.id + '" class="btn btn-xs btn-success btn-editone" title="" data-table-id="table" data-field-index="8" data-row-index="0" data-button-index="1"><i class="fa fa-pencil"></i></a>';
- html += '<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table" data-field-index="8" data-row-index="0" data-button-index="2"><i class="fa fa-trash"></i></a>';
- html += '<a href="/admin/ad/user/group/viewgroup" class="btn btn-xs btn-success btn-usergroup" data-id="' + row.id + '" title="">关联用户组</a>';
- return html;
- }
- },
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|