123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte'], function ($, undefined, Backend, Table, Form, Adminlte) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'clientmanage/bookcity/blockresource/index',
- add_url: 'clientmanage/bookcity/blockresource/add?block_id='+Config.block_id+'&page_id='+Config.page_id,
- edit_url: 'clientmanage/bookcity/blockresource/edit?block_id='+Config.block_id+'&page_id='+Config.page_id,
- del_url: 'clientmanage/bookcity/blockresource/del?block_id='+Config.block_id+'&page_id='+Config.page_id,
- },
- showToggle:false,
- showColumns:false,
- showExport:false
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'weigh',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'block_id', title: __('Block_id')},
- {field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
- {field: 'type_text', title: __('Type'), operate:false},
- {field: 'book.name', title: __('Book_name')},
- //{field: 'activity.name', title: __('Book_name')},
- {field: 'url', title: __('Url'), formatter: Table.api.formatter.url},
- {field: 'free_stime', title: __('Free_stime'), formatter: Table.api.formatter.datetime},
- {field: 'free_etime', title: __('Free_etime'), formatter: Table.api.formatter.datetime},
- {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
- {field: 'weigh', title: __('Weigh')},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ],
- onPostBody:function () {
- $(".btn-dragsort").hide();
- }
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- Controller.api.bindevent();
- },
- add: function () {
- var blockType = $("#c-block_id").find("option:selected").data('option-type');
- if (blockType == 11) {
- $(".image").remove();
- }
- Controller.api.bindevent();
- Controller.api.onload();
- },
- edit: function () {
- Controller.api.bindevent();
- Controller.api.onload();
- $("#c-activity_id").val(Config.row.client_activity_id);
- var blockType = $("#c-block_id").find("option:selected").data('option-type');
- var type = Config.row.type;
- if (blockType == 11) {
- //活动运营位
- if(type==1){
- $('.book').removeClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==2){
- $('.book').addClass('hide');
- $('.url').removeClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==3){
- $('.book').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==4){
- $('.book').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').removeClass('hide');
- }
- } else {
- if(type==1){
- $('.book').removeClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==2){
- $('.book').addClass('hide');
- $('.url').removeClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==3){
- $('.book').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==4){
- $('.book').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').removeClass('hide');
- }
- }
- },
- api: {
- bindevent: function () {
- $("#add-form, #edit-form").data("validator-options", {
- ignore: ':hidden',
- beforeSubmit: function (form) {
- var blockType = $("#c-block_id").find("option:selected").data('option-type');
- if (blockType == 11) {
- if ($("#c-activity_title").val() == '') {
- Toastr.error("请填写活动文案");
- return false;
- }
- var type = $(".resource_type:checked").val();
- if (type == 1) {
- if ($("#c-book_id").val() == '') {
- Toastr.error("请选择书籍");
- return false;
- }
- }
- if (type == 2) {
- if ($("#c-url").val() == '') {
- Toastr.error("请填写url");
- return false;
- }
- }
- if (type == 4) {
- if ($("#c-activity_id").val() == null) {
- Toastr.error("请选择活动");
- return false;
- }
- }
- } else {
- if ($("#c-image").val() == '') {
- Toastr.error("请上传图片");
- return false;
- }
- if (type == 1) {
- if ($("#c-book_id").val() == '') {
- Toastr.error("请选择书籍");
- return false;
- }
- }
- if (type == 2) {
- if ($("#c-url").val() == '') {
- Toastr.error("请填写url");
- return false;
- }
- }
- if (type == 4) {
- if ($("#c-activity_id").val() == null) {
- Toastr.error("请选择活动");
- return false;
- }
- }
- }
- return true;
- }
- });
- Form.api.bindevent($("form[role=form]"));
- var refreshkey = function (data) {
- Layer.closeAll();
- $('#c-book_id_text').val(data[0].id);
- $('#c-book_id').val(data[0].id);
- $('#c-image').val(data[0].image);
- $('#c-image').trigger('change');
- $('#c-book_id_text').trigger('change');
- };
- $(document).on("click", ".resource_type", function () {
- var type = $("input[name='row[type]']:checked").val();
- var blockType = $("#c-block_id").find("option:selected").data('option-type');
- if (blockType == 11) {
- //活动运营位
- if(type==1){
- $('.book').removeClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==2){
- $('.book').addClass('hide');
- $('.url').removeClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==3){
- $('.book').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==4){
- $('.book').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').removeClass('hide');
- }
- } else {
- if(type==1){
- $('.book').removeClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==2){
- $('.book').addClass('hide');
- $('.url').removeClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==3){
- $('.book').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- if(type==4){
- $('.book').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').removeClass('hide');
- }
- }
- });
- var refreshactkey = function (data) {
- Layer.closeAll();
- $('#c-activity_id').val(data[0].id);
- $('#c-client_activity_name').val(data[0].name);
- };
- $(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("change", "#c-block_id", function () {
- var type = $(this).find("option:selected").data('option-type');
- Controller.api.showTypeOptions(type);
- });
- $(document).on('click', "#select-activity-resources", function () {
- parent.Backend.api.open($(this).attr("href") + "?type=2&action=blockresoure&state=1", __('Select'), {callback: refreshactkey});
- return false;
- });
- },
- onload: function () {
- var type = $("#c-block_id").find("option:selected").data('option-type');
- this.showTypeOptions(type);
- },
- showTypeOptions: function (type) {
- if (type == 11) {
- //运营位
- $('.activity_title').removeClass('hide');
- $('.image').addClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- } else {
- $('.activity_title').addClass('hide');
- $('.image').removeClass('hide');
- $('.url').addClass('hide');
- $('.activity').addClass('hide');
- }
- }
- }
- };
- return Controller;
- });
|