define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { business: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'clientmanage/clientconfig/shelfoperate/business', add_url: 'clientmanage/clientconfig/shelfoperate/add/funtype/'+Config.funtype, edit_url: 'clientmanage/clientconfig/shelfoperate/edit', del_url: 'clientmanage/clientconfig/shelfoperate/del', setlose_url: 'clientmanage/clientconfig/shelfoperate/setlose', multi_url: 'clientmanage/clientconfig/shelfoperate/multi', table: 'client_config', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, searchFormVisible: true, pk: 'id', sortName: 'id', onLoadSuccess: function () { //加载成功时执行 $(".assignment_but_box a").removeClass('hover'); $(".nav-"+Config.funtype).addClass('hover'); }, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'name', title: __('Name')}, /*{field: 'fun_type_text', title: __('Fun_type'), operate:false},*/ {field: 'type', title: __('Type'), visible:false, searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4')}}, {field: 'type_text', title: __('Type'), operate:false}, {field: 'book_id', title: __('Book_id'), visible: false, operate: false}, {field: 'url', title: __('Url'),visible: false, formatter: Table.api.formatter.url, operate: false}, {field: 'user_pay_type_text', title: __('User_pay_type'), operate:false}, {field: 'user_pay_type', title: __('User_pay_type'), visible: false,searchList: {"0":__('User_pay_type 0'),"1":__('User_pay_type 1'),"2":__('User_pay_type 2')}}, {field: 'version', title: __('Version'), operate: false}, /*{field: 'position_text', title: __('Position_text'), operate: false},*/ {field: 'pic_url', title: __('Pic_url'),visible: false, formatter: Table.api.formatter.url, operate: false}, {field: 'sort', title: __('Sort'), operate: false}, {field: 'start_time', title: __('Start_time'), addclass:'datetimerange', operate: false}, {field: 'end_time', title: __('End_time'), addclass:'datetimerange', operate: false}, {field: 'status', title: __('Status'), visible:false, searchList: {"1":__('Status 1'),"0":__('Status 0')}}, {field: 'status_text', title: __('Status'), operate:false}, {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate: false}, {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate: false}, { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [ { name: '失效', title: __('失效'), text: '失效', classname: 'btn btn-xs btn-success btn-magic btn-ajax', url: $.fn.bootstrapTable.defaults.extend.setlose_url, confirm: '确认失效', success: function () { table.bootstrapTable('refresh'); }, } ], formatter: Table.api.formatter.operate, } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, popup: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'clientmanage/clientconfig/shelfoperate/popup', add_url: 'clientmanage/clientconfig/shelfoperate/add/funtype/'+Config.funtype, edit_url: 'clientmanage/clientconfig/shelfoperate/edit', del_url: 'clientmanage/clientconfig/shelfoperate/del', setlose_url: 'clientmanage/clientconfig/shelfoperate/setlose', multi_url: 'clientmanage/clientconfig/shelfoperate/multi', table: 'client_config', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, searchFormVisible: true, pk: 'id', sortName: 'id', onLoadSuccess: function () { //加载成功时执行 $(".assignment_but_box a").removeClass('hover'); $(".nav-"+Config.funtype).addClass('hover'); }, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'name', title: __('Name')}, {field: 'fun_type_text', title: __('Fun_type'), operate:false}, {field: 'type', title: __('Type'), visible:false, searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4')}}, {field: 'type_text', title: __('Type'), operate:false}, {field: 'book_id', title: __('Book_id'), visible: false, operate: false}, {field: 'url', title: __('Url'),visible: false, formatter: Table.api.formatter.url, operate: false}, {field: 'user_pay_type_text', title: __('User_pay_type'), operate:false}, {field: 'version', title: __('Version'), operate: false}, {field: 'position_text', title: __('Position_text'), operate: false}, {field: 'pic_url', title: __('Pic_url'),visible: false, formatter: Table.api.formatter.url, operate: false}, {field: 'sort', title: __('Sort'), operate: false}, {field: 'start_time', title: __('Start_time'), addclass:'datetimerange', operate: false}, {field: 'end_time', title: __('End_time'), addclass:'datetimerange', operate: false}, {field: 'status', title: __('Status'), visible:false, searchList: {"1":__('Status 1'),"0":__('Status 0')}}, {field: 'status_text', title: __('Status'), operate:false}, {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate: false}, {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate: false}, { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [ { name: '失效', title: __('失效'), text: '失效', classname: 'btn btn-xs btn-success btn-magic btn-ajax', url: $.fn.bootstrapTable.defaults.extend.setlose_url, confirm: '确认失效', success: function () { table.bootstrapTable('refresh'); }, } ], formatter: Table.api.formatter.operate, } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, loading: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'clientmanage/clientconfig/shelfoperate/loading', add_url: 'clientmanage/clientconfig/shelfoperate/add/funtype/'+Config.funtype, edit_url: 'clientmanage/clientconfig/shelfoperate/edit', del_url: 'clientmanage/clientconfig/shelfoperate/del', setlose_url: 'clientmanage/clientconfig/shelfoperate/setlose', multi_url: 'clientmanage/clientconfig/shelfoperate/multi', table: 'client_config', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, searchFormVisible: true, pk: 'id', sortName: 'id', onLoadSuccess: function () { //加载成功时执行 $(".assignment_but_box a").removeClass('hover'); $(".nav-"+Config.funtype).addClass('hover'); }, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'name', title: __('Name')}, {field: 'fun_type_text', title: __('Fun_type'), operate:false}, {field: 'type', title: __('Type'), visible:false, searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4')}}, {field: 'type_text', title: __('Type'), operate:false}, {field: 'book_id', title: __('Book_id'), visible: false, operate: false}, {field: 'url', title: __('Url'),visible: false, formatter: Table.api.formatter.url, operate: false}, {field: 'user_pay_type_text', title: __('User_pay_type'), operate:false}, {field: 'version', title: __('Version'), operate: false}, {field: 'position_text', title: __('Position_text'), operate: false}, {field: 'pic_url', title: __('Pic_url'),visible: false, formatter: Table.api.formatter.url, operate: false}, {field: 'sort', title: __('Sort'), operate: false}, {field: 'start_time', title: __('Start_time'), addclass:'datetimerange', operate: false}, {field: 'end_time', title: __('End_time'), addclass:'datetimerange', operate: false}, {field: 'status', title: __('Status'), visible:false, searchList: {"1":__('Status 1'),"0":__('Status 0')}}, {field: 'status_text', title: __('Status'), operate:false}, {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate: false}, {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate: false}, { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [ { name: '失效', title: __('失效'), text: '失效', classname: 'btn btn-xs btn-success btn-magic btn-ajax', url: $.fn.bootstrapTable.defaults.extend.setlose_url, confirm: '确认失效', success: function () { table.bootstrapTable('refresh'); }, } ], formatter: Table.api.formatter.operate, } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { if (Config.funtype == 2) { $(".position-div").removeClass('hide'); } if (Config.funtype == 3) { $(".count_down-div").removeClass('hide'); } Controller.api.bindevent(); }, edit: function () { if (Config.funtype == 2) { $(".position-div").removeClass('hide'); } if (Config.funtype == 3) { $(".count_down-div").removeClass('hide'); } if (Config.type ==1) { $(".url").removeClass('hide') $('.book').addClass('hide'); $('.client_activity_name').addClass('hide'); } else if (Config.type ==2) { $('.book').removeClass('hide'); $('.url').addClass('hide'); $('.client_activity_name').addClass('hide'); } else if (Config.type ==3) { $('.book').removeClass('hide'); $('.url').addClass('hide'); $('.client_activity_name').addClass('hide'); } else if (Config.type ==4) { $('.url').addClass('hide'); $('.book').addClass('hide'); $('.client_activity_name').removeClass('hide'); } Controller.api.bindevent(); }, api: { bindevent: function () { $("#add-form, #edit-form").data("validator-options", { ignore: ':hidden', beforeSubmit: function (form) { if ($("#c-name").val().length < 1) { Toastr.error("请填写名称"); return false; } var type = $("#c-type").val(); if (type == 1) { if ($("#c-url").val() == '') { Toastr.error("请填写url"); return false; } } else if (type == 2 || type == 3) { if ($("#c-book_id").val() == '') { Toastr.error("请选择书籍"); return false; } } else if (type == 4) { if ($("#c-client_activity_id").val() == '') { Toastr.error("请选择活动"); return false; } } if ($("#c-version").val() == '') { Toastr.error("请填写版本号"); return false; } if (Config.funtype == 2) { if ($('#c-position input').is(":checked") == false) { Toastr.error("请选择展示位置"); return false; } } if ($("#c-sort").val() == '') { Toastr.error("请填写排序"); return false; } if (Config.funtype == 3) { if ($("#c-count_down").val() < 1 || $("#c-count_down").val() > 10) { Toastr.error("倒计时设置需要再1-10秒"); return false; } } } }); Form.api.bindevent($("form[role=form]")); var refreshkey = function (data) { Layer.closeAll(); $('#c-book_id').val(data[0].id); }; var refreshactkey = function (data) { Layer.closeAll(); $('#c-client_activity_id').val(data[0].id); $('#c-client_activity_name').val(data[0].name); }; $(document).on("change", "#c-type", function () { var type = $(this).val(); if (type == 1) { $('.url').removeClass('hide'); $('.book').addClass('hide'); $('.client_activity_name').addClass('hide'); } if(type == 2){ $('.book').removeClass('hide'); $('.url').addClass('hide'); $('.client_activity_name').addClass('hide'); } if(type == 3){ $('.book').removeClass('hide'); $('.url').addClass('hide'); $('.client_activity_name').addClass('hide'); } if(type == 4){ $('.url').addClass('hide'); $('.book').addClass('hide'); $('.client_activity_name').removeClass('hide'); } }); $(document).on('click', "#select-resources", function () { var block_id = Config.block_id; parent.Backend.api.open($(this).attr("href") + "?action=blockresoure&state=1&block_id=" + block_id, __('Select'), {callback: refreshkey}); return false; }); $(document).on('click', "#select-activity-resources", function () { var block_id = Config.block_id; parent.Backend.api.open($(this).attr("href") + "?type=2&action=blockresoure&state=1&block_id=" + block_id, __('Select'), {callback: refreshactkey}); return false; }); } } }; return Controller; });