define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'custommain'], function ($, undefined, Backend, Table, Form, Custommain) { Custommain.checkbox_relation('#dyhradio', '#dyhcheck'); $('.btnlink').click(function(){ var id = $(this).data('id'); $.get('/admin/activity/sorturl?ids='+id,{},function(data){ if(data.error == 0){ window.location.reload(); }else{ layer.msg("短链生成失败") } }) }); $(document).on('click', '.btn-config', function () { layer.open({ type: 2, title: '活动配置管理', maxmin: true, area: ['90%', '90%'], shadeClose: true, //点击遮罩关闭层 content: '/admin/activity/config?type='+Config.activity_type }); }); $(document).on('click', '.btn-resource-manange', function () { layer.open({ type: 2, title: '活动配置管理', maxmin: true, area: ['90%', '90%'], shadeClose: true, //点击遮罩关闭层 content: '/admin/resource/index?aid=0&resource_type='+Config.activity_type }); }); $(document).on('click','.btn-edit-row',function(){ //btn-edit-row Fast.api.open($(this).data('href'), "编辑活动", { callback: function (data) { if(data.code){ window.location.reload(); } } }); }); $(document).on('change','.pop_status',function(){ //btn-edit-row if ($(this).val() == 1) { $(".position-div").removeClass("hide"); } else { $(".position-div").addClass("hide"); } }); $(document).on('click', '.btn-resource-manage', function () { var url = $(this).data('source-url'); var title = $(this).data('pop-type') == 'edit' ? '编辑资源' : '添加资源'; Fast.api.open(url, title, { callback: function (data) { } }); return false; }); //启动和暂停按钮 //$(document).on("click", ".btn-start,.btn-pause", function () { // //在table外不可以使用添加.btn-change的方法 // //只能自己调用Table.api.multi实现 // var id = $(this).data('id'); // var thisvalue = $(this).val(); // var status = 1; // if(thisvalue=='点击打开'){ // status = 1; // }else{ // status = 0; // } // var textval = thisvalue.substring(2,4); // layer.confirm('确定要'+textval+'吗?', { // btn: ['确定','取消'] //按钮 // }, function(){ // $.post('/admin/activity/changestatus',{id:id,status:status},function(data){ // if(data == 1){ // layer.msg('操作成功'); // table.bootstrapTable('refresh'); // }else{ // layer.msg('操作失败'); // } // }); // // }, function(){ // layer.close(); // }); //}); var Controller = { shwoActivityField:function(table){ var field = new Array(); field.push({checkbox: true}); field.push({field: 'id', title: __('Id')}); if(parseInt(Config.activity_type)){ field.push({field: 'admin_id', title: '渠道ID'}); } field.push({field: 'name', title: __('Name')}); field.push({field: 'copywriting', title: __('Copywriting')}); field.push({field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}); field.push({field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}); field.push({field:'activitstatus', title:'活动状态',formatter: Controller.api.formatter.activitstatus}); field.push({field:'money',title:'今日充值',formatter:Controller.api.formatter.money}); field.push({field:'allmoney',title:'累计充值',formatter:Controller.api.formatter.allmoney}); field.push({field: 'changestatus', title: __('显示状态'),addClass:'btn-start',formatter: Controller.api.formatter.changestatus}); field.push({field: 'popstatus', title: __('弹窗状态'),formatter: Controller.api.formatter.popstatus}); field.push({field: 'pop_range', title: __('弹窗位置'),formatter: function (value, row, index) { if (row.pop_status == '0') { return "-"; } else { var popRangeVal = ''; if (row.pop_range.length > 0 || row.pop_range == '0') { var popRangeKey = row.pop_range.split(','); for (let k in popRangeKey) { var j = popRangeKey[k]; popRangeVal += Config.popRangeList[j] + ' '; } } else { popRangeVal = '-'; } return popRangeVal; } }}); if(!parseInt(Config.activity_type) || Config.activity_type == 2){ field.push({field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}); field.push({field:'resource', title:'资源管理',formatter: Controller.api.formatter.resource}); } return field; }, index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'activity/index?type='+Config.activity_type, add_url: 'activity/add?type='+Config.activity_type, edit_url: 'activity/edit?type='+Config.activity_type, del_url: 'activity/del', multi_url: 'activity/multi', table: 'activity', }, showToggle: false, showColumns: false, showExport: false, commonSearch: false, operate: false, search:false, }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', columns: [Controller.shwoActivityField(table)] }); // 为表格绑定事件 Table.api.bindevent(table); $(document).on('click','.btn-add-activity',function(){ Fast.api.open('activity/add?type='+Config.activity_type, "添加活动", { callback: function (data) { if(data.code){ window.location.reload(); } } }); }); //启动和暂停按钮 $(document).on("click", ".btn-start,.btn-pause", function () { //在table外不可以使用添加.btn-change的方法 //只能自己调用Table.api.multi实现 var id = $(this).data('id'); var thisvalue = $(this).val(); var status = 1; if(thisvalue=='点击打开'){ status = 1; }else{ status = 0; } var textval = thisvalue.substring(2,4); var reloadfrom = $(this).data('reload'); layer.confirm('确定要'+textval+'吗?', { btn: ['确定','取消'] //按钮 }, function(){ $.post('/admin/activity/changestatus',{id:id,status:status},function(data){ if(data == 1){ layer.msg('操作成功'); if (reloadfrom == 1) { window.location.reload(); } else { table.bootstrapTable('refresh'); } }else{ layer.msg('操作失败'); } }); }, function(){ layer.close(); }); }); //启动和暂停按钮 $(document).on("click", ".btn-pop-start", function () { //在table外不可以使用添加.btn-change的方法 //只能自己调用Table.api.multi实现 var id = $(this).data('id'); var thisvalue = $(this).val(); var status = 1; var textval = thisvalue.substring(2,4); var reloadfrom = $(this).data('reload'); if(thisvalue=='点击开启'){ $("#dyhradio").find('input:checkbox').prop("checked", false); $("#dyhcheck").find('input:checkbox').prop("checked", false); status = 1; var has_select = $(this).data("pop-range"); var stis_pay = $(this).data("ispay"); if(stis_pay == 1){ $('#ispay_1').prop("checked", true); }else if (stis_pay == 2){ $('#ispay_2').prop("checked", true); }else if (stis_pay == 3){ $('#ispay_3').prop("checked", true); } if (has_select.length > 0 || has_select >= 0) { has_select+=','; } var selectArr = has_select.length > 0 ? has_select.split(',') : []; $("#dyhcheck").find('input:checkbox').each(function (i, item) { var val = $(item).val(); if (selectArr.indexOf(val) != -1) { $(item).prop("checked", true); } }); if (selectArr.length > 7) { $("#dyhradio").find('input:checkbox').prop("checked", true); } layer.open({ type: 1, title: '选择弹窗位置', maxmin: true, area: ['60%', '80%'], btn: ['确定', '取消'], shadeClose: true, //点击遮罩关闭层 content: $(".pop_position"), yes: function (data) { var newSelect = []; $("#dyhcheck").find('input:checkbox').each(function (i, item) { if ($(item).is(":checked")) { newSelect.push($(item).val()); } }); var popRange = ''; if (newSelect.length > 0) { popRange = newSelect.join(','); } var ppval=$('input:radio[name="row[pop_ispay]"]:checked').val(); $.post('/admin/activity/set_pop_range',{id:id,status:status,pop_range:popRange,pop_ispay:ppval},function(data){ if(data == 1){ layer.msg('操作成功'); if (reloadfrom == 1) { window.location.reload(); } else { table.bootstrapTable('refresh'); } }else{ layer.msg('操作失败'); } }); layer.closeAll(); } }); }else{ status = 0; layer.confirm('确定要'+textval+'吗?', { btn: ['确定','取消'] //按钮 }, function(){ $.post('/admin/activity/changepopstatus',{id:id,status:status},function(data){ if(data == 1){ layer.msg('操作成功'); if (reloadfrom == 1) { window.location.reload(); } else { table.bootstrapTable('refresh'); } }else{ layer.msg('操作失败'); } }); }, function(){ layer.close(); }); } }); $(document).on("click", '.js_recharge_on', function () { var id = $(this).data('id'); upShowRechargePage(id, 'on'); }); $(document).on("click", '.js_recharge_off', function () { var id = $(this).data('id'); upShowRechargePage(id, 'off'); }); function upShowRechargePage(id, status) { var msg = status == 'on' ? '确定要在充值页面显示此活动吗?' : '确定要在充值页面移除此活动吗?'; layer.confirm(msg, { btn: ['确定', '取消'] }, function () { $.post('/admin/activity/showrechargepage', {id: id, status: status}, function (data) { if (data == 1) { layer.msg('操作成功'); window.location.reload(); } else { layer.msg('操作失败'); } }); }, function () { layer.close(); }); } }, config:function(){ $('#config_id').val(Controller.api.formatter.getUid()); //btn-add-resource $('.btn-add-resource').on('click',function(){ Fast.api.open("/admin/resource/index?aid=0&resource_type="+Config.activity_type, "选择活动资源", null); }); $(document).on('click','.btn-del-money',function(){ $(this).parent().parent().remove(); }); $('.btn-append-money').on('click',function(){ var html = $('#money-list-model').html().replace(/uid_value/ig, Controller.api.formatter.getUid()); $('#money-list-container').append(html); }); $(document).on("click", '.fachoose-resource_id', function () { let this_obj = $(this); Fast.api.open("/admin/resource/select?aid=0&resource_type="+Config.activity_type, "选择活动资源", { callback: function (data) { this_obj.parent().parent().find('input').val(data.id) } }); return false; }); Controller.api.bindevent(); }, add: function () { Form.api.bindevent($("form[role=form]"), function (data, ret) { Fast.api.close(ret); return true; }); //Controller.api.bindevent(); }, addchannel: function () { Controller.api.bindevent(); }, pop_range: function () { Controller.api.bindevent(); }, edit: function () { Form.api.bindevent($("form[role=form]"), function (data, ret) { Fast.api.close(ret); return true; }); }, select: function () { Table.api.init({ extend: { index_url: 'activity/select', table: 'activity', }, showToggle: false, showColumns: false, showExport: false, searchFormVisible: true, search: false, commonSearch:true, }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ queryParams: function (params) { //自定义搜索条件 params.type = Config.type; return params; }, url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'weigh', columns: [ [ {field: 'name', title: __('Name'), operate: false}, {field: 'copywriting', title: __('copywriting'), operate: false}, {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, { field: 'operate', title: __('Operate'), events: { 'click .btn-chooseone': function (e, value, row, index) { Fast.api.close([row]); }, }, formatter: function () { return ' ' + __('Choose') + ''; } } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); },formatter: { activitstatus: function (value, row, index) { if(row.starttime > Config.time){ return '未开始'; }else if (row.starttimeConfig.time){ return '进行中'; }else if (row.endtime < Config.time){ return '已结束'; } }, resource: function (value, row, index) { if(!parseInt(Config.activity_type) || Config.activity_type == 2){ if (row.resource_id > 0) { return '编辑资源管理'; } else { return '资源管理'; } } }, changestatus:function(value,row,index){ var showName = ''; if (row.status == 0){ return '隐藏  '; }else{ return '打开  '; } }, popstatus:function(value,row,index){ var showName = ''; if (row.pop_status == '0'){ return '关闭  '; }else{ return '开启  '; } }, money:function(value, row, index) { if (value){ return value; }else{ return '0.00'; } }, allmoney:function(value, row, index) { if (value){ return value; }else{ return '0.00'; } }, getUid:function(){ return Math.random().toString().substr(3,5) + (new Date()).getTime(); } } } }; return Controller; });