123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- $('.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("短链生成失败")
- }
- })
- });
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'activity/index',
- add_url: 'activity/add',
- edit_url: 'activity/edit',
- 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: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'name', title: __('Name')},
- {field: 'copywriting', title: __('Copywriting')},
- {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: 'popstarttime', title: __('Popstarttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'popendtime', title: __('Popendtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {field:'activitstatus', title:'活动状态',formatter: Controller.api.formatter.activitstatus},
- {field:'money',title:'今日充值',formatter:Controller.api.formatter.money},
- {field:'allmoney',title:'累计充值',formatter:Controller.api.formatter.allmoney},
- {field: 'changestatus', title: __('显示状态'),addClass:'btn-start',formatter: Controller.api.formatter.changestatus},
- {field:'resource', title:'资源管理',formatter: Controller.api.formatter.resource},
- //{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- //{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- //启动和暂停按钮
- $(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();
- });
- });
- },
- 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.starttime<Config.time && row.endtime>Config.time){
- return '进行中';
- }else if (row.endtime < Config.time){
- return '已结束';
- }
- },
- resource: function (value, row, index) {
- return '<a href="/admin/resource/index?aid='+row.id+'" class="label label-success addtabsit">资源管理</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+'" value="点击打开" />';
- }else{
- return '<b>打开</b> <input type="button" class="btn-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';
- }
- },
- }
- }
- };
- return Controller;
- });
|