123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- 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 '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
- }
- }
- ]
- ]
- });
- // 为表格绑定事件
- 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.starttime<Config.time && row.endtime>Config.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 '<a href="javascript:;" data-source-url="/admin/resource/edit?ids='+row.resource_id+'&aid='+row.id+'&resource_type='+ Config.activity_type +'&business_line='+Config.business_line+'" data-pop-type="edit" class="label label-success btn-resource-manage">编辑资源管理</a>';
- } else {
- return '<a href="javascript:;" data-source-url="/admin/resource/add?aid='+row.id+'&resource_type='+ Config.activity_type +'&business_line='+Config.business_line+'" data-pop-type="add" class="label label-success btn-resource-manage">资源管理</a>';
- }
- }
- },
- changestatus:function(value,row,index){
- var showName = '';
- if (row.status == 0){
- return '<b>隐藏</b> <input type="button" class="btn-start btn btn-success" data-id="'+row.id+'" data-pop-range="'+row.pop_range+'" value="点击打开" />';
- }else{
- return '<b>打开</b> <input type="button" class="btn-start btn btn-warning" data-id="'+row.id+'" value="点击隐藏" />';
- }
- },
- popstatus:function(value,row,index){
- var showName = '';
- if (row.pop_status == '0'){
- return '<b>关闭</b> <input type="button" class="btn-pop-start btn btn-success" data-id="'+row.id+'" data-pop-range="'+row.pop_range+'" data-ispay="'+row.pop_ispay+'" value="点击开启" />';
- }else{
- return '<b>开启</b> <input type="button" class="btn-pop-start btn btn-warning" data-id="'+row.id+'" value="点击关闭" />';
- }
- },
- 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;
- });
|