define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'qrcode'], function ($, undefined, Backend, Table, Form, Qrcode) { $(document).on('click', '.short_link_but', function () { var $this = $(this); $this.hide().siblings('.short_link').show(); }); $(document).on("click", '.qrcode', function () { var qrUrl = $(this).data("qrcode"); Fast.api.open('referral/referral/show_tpl?url='+qrUrl, '图片二维码', {}); }); $(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(); } } }); }); var Controller = { showActivityField:function(table){ var field = new Array(); field.push({checkbox: true}); field.push({field: 'id', title: __('Id')}); field.push({field: 'name', title: __('活动名称'), operate: 'LIKE %...%'}); field.push({field: 'copywriting', title: __('活动文案'), operate: 'LIKE %...%'}); field.push({field: 'starttime', title: __('开始时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}); field.push({field: 'endtime', title: __('结束时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}); field.push({field:'status', title:'活动状态',formatter: Controller.api.formatter.activitstatus, operate:false}); field.push({field:'money',title:'今日充值',formatter:Controller.api.formatter.money, operate:false}); field.push({field:'allmoney',title:'累计充值',formatter:Controller.api.formatter.allmoney, operate:false}); field.push({field: 'operate', title: __('Operate'), table: table, events: Controller.api.events.operate, buttons: [ { name: 'operate', text: __('添加渠道账号'), title: __('添加渠道账号'), classname: 'btn btn-xs btn-primary btn-add-channels', icon: 'fa fa-list', }, { name: 'operate', text: __('指定渠道分组'), title: __('指定渠道分组'), classname: 'btn btn-xs btn-success btn-add-group', icon: 'fa fa-pencil', } ], formatter: Table.api.formatter.buttons }); field.push({field: 'chakan', title: __("查看"), operate: false, formatter: function (value, row, index) { var str = ''; if (row.endtime > Config.time && row.starttime > Config.time) { //未开始的 str += ''; } return str +'查看'; }, }) return field; }, showChannelActivityField:function(table){ var field = new Array(); field.push({checkbox: true}); field.push({field: 'id', title: __('Id')}); field.push({field: 'admin_id', title: __('渠道ID')}); field.push({field: 'name', title: __('活动名称')}); field.push({field: 'copywriting', title: __('活动文案')}); field.push({field: 'starttime', title: __('开始时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}); field.push({field: 'endtime', title: __('结束时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}); field.push({field:'money',title:'今日充值',formatter:Controller.api.formatter.money}); field.push({field:'allmoney',title:'累计充值',formatter:Controller.api.formatter.allmoney}); field.push({field:'status', title:'活动状态',formatter: Controller.api.formatter.activitstatus}); return field; }, index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'vipactivity/index', add_url: 'activity/add?type='+Config.activity_type, table: 'activity', do_choose: 'vipactivity/doChoose', select_url: 'referral/vipreferral/selectchannel', disable_url: 'referral/referral/disable?isVip=1' } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', columns: [Controller.showActivityField(table)] }); // 为表格绑定事件 Table.api.bindevent(table); }, viewdata: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'vipactivity/viewdata?ids='+ Config.id, add_url: 'referral/vipreferral/selectchannel', }, showToggle: false, showColumns: false, visible: false, commonSearch: false, showExport: false, searchFormVisible: false, search: false }); var table = $("#table"); // 初始化表格 // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', columns: [Controller.showChannelActivityField(table)] }); //获取选中数据 $(document).on('click', ".btn-open-choose", function () { var url = 'referral/vipreferral/selectchannel'; Fast.api.open(url, __('Add'), { callback: function (data) { if (data.length > 0) { var qdsIds = ''; var doUrl = 'vipactivity/doChoose/ids/'+Config.referral_id; for (var i in data) { qdsIds += data[i].qds_id + ','; } $.ajax({ url: doUrl + '/qdsIds/' + qdsIds, type: 'get', success: function (res) { Toastr.success('操作成功'); //刷新页面 table.bootstrapTable('refresh'); } }); } } }); }); // 为表格绑定事件 Table.api.bindevent(table); }, selectchannel: function() { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'referral/vipreferral/selectchannel' }, searchFormVisible: true, search: false, }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'vip_admin_bind.id', sortOrder: 'desc', columns: [ [ {checkbox: true}, {field: 'bind_id', title: __('Id'), visible: false, operate: false}, {field: 'wx_nickname', title: __('公众号名称')}, {field: 'qds_id', title: __('账号ID'), operate: false}, {field: 'qds_username', title: __('用户名')}, {field: 'qds_nickname', title: __('用户昵称')}, {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); //获取选中数据 $(document).on('click', "#btn-chooseone", function () { var data = table.bootstrapTable('getSelections'); if (data.length < 1) { Toastr.error('请选择公众号'); } else { Fast.api.close(data); } }); }, add: function () { Controller.api.bindevent(); }, edit: function () { 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 '已结束'; } }, 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'; } }, }, source_url_1: function (value, row, index) { var html = []; html.push((row.wx_type == 1 ? '认证公众号' : '未认证公众号')); if (row.short_id > 0) { value = row.short_url; } else { if (Config.url_referral) { value = Config.url_referral + '/t/' + row.id; } else { value = row.url_referral; } } if (row.limited == 1) { html.push('
' + value); html.push('
'); } else { if (row.state == "1") { html.push('
' + value + '   '); html.push('点击显示短链
'); } else { html.push('
' + value + '
'); } } return html.join('
'); }, entry_page_1: function (value, row, index) { var html = []; if (row.type == 1) { html.push('' + row.book_name + ''); html.push(row.chapter_name); if (row.guide_chapter_idx) { html.push('关注章节:' + row.guide_chapter_idx); } else { html.push('关注章节:默认'); } } else if (row.type == 3) { html.push('落地页推广'); html.push('' + row.book_name + ''); html.push(row.chapter_name); if (row.guide_chapter_idx) { html.push('关注章节:' + row.guide_chapter_idx); } else { html.push('关注章节:默认'); } } else { html.push('书城首页推广'); } return html.join('
'); }, events: { operate: { 'click .btn-editone': function (e, value, row, index) { e.stopPropagation(); e.preventDefault(); var table = $(this).closest('table'); var options = table.bootstrapTable('getOptions'); var ids = row[options.pk]; row = $.extend({}, row ? row : {}, {ids: ids}); var url = options.extend.edit_url; Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {}); }, 'click .btn-add-channels': function (e, value, row, index) { e.stopPropagation(); e.preventDefault(); var table = $(this).closest('table'); var options = table.bootstrapTable('getOptions'); var ids = row[options.pk]; row = $.extend({}, row ? row : {}, {ids: ids}); var url = options.extend.select_url+'?not_in_qds='+row.channel_ids; Fast.api.open(Table.api.replaceurl(url, row, table), __('Add'), { callback: function (data) { if (data.length > 0) { var qdsIds = ''; var doUrl = options.extend.do_choose; doUrl = Table.api.replaceurl(doUrl, row, table); for (var i in data) { qdsIds += data[i].qds_id + ','; } $.ajax({ url: doUrl + '/qdsIds/' + qdsIds, type: 'get', success: function (res) { var data = JSON.parse(res); if (data.fail) { console.log(data.fail); Toastr.error(data.fail); } else { Toastr.success('操作成功'); } //刷新页面 table.bootstrapTable('refresh'); } }); } } }); }, 'click .btn-add-group':function (e, value, row, index) { e.stopPropagation(); e.preventDefault(); var table = $(this).closest('table'); var options = table.bootstrapTable('getOptions'); var ids = row[options.pk]; row = $.extend({}, row ? row : {}, {ids: ids}); var url = '/admin/vip/admin/group/select?not_in_ids='; Fast.api.open(Table.api.replaceurl(url, row, table), __('Add'), { callback: function (data) { if (data.length > 0) { var groupIds = ''; for (var i in data) { groupIds += data[i].id + ','; } var doUrl = options.extend.do_choose; doUrl = Table.api.replaceurl(doUrl, row, table); $.ajax({ url: doUrl + '/groupIds/' + groupIds, type: 'get', success: function (res) { var data = JSON.parse(res); if (data.fail) { console.log(data.fail); Toastr.error(data.fail); } else { Toastr.success('操作成功'); } //刷新页面 table.bootstrapTable('refresh'); } }); } } }); } } }, source_url: function (value, row, index) { var html = []; value = row.short_url; if (row.state == 0) { html.push('
'); } else { if(value.length < 10) { html.push('
'); } else { if (row.limited == 1) { html.push('
' + value); html.push('
'); } else { if (row.state == "1") { html.push('
' + value + '   '); } else { html.push('
' + value + '
'); } } } } return html.join('
'); }, entry_page: function (value, row, index) { var html = []; if (row.type == 1) { html.push('' + row.book_name + ''); html.push(row.chapter_name); if (row.guide_chapter_idx) { html.push('关注章节:' + row.guide_chapter_idx); } else { html.push('关注章节:默认'); } } else if (row.type == 3) { html.push('落地页推广'); html.push('' + row.book_name + ''); html.push(row.chapter_name); if (row.guide_chapter_idx) { html.push('关注章节:' + row.guide_chapter_idx); } else { html.push('关注章节:默认'); } } else { html.push('书城首页推广'); } return html.join('
'); }, index_operate: function (value, row, index) { var row_id = row.id return } } }; return Controller; });