activity.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'subscrip/activity/index',
  8. add_url: 'subscrip/activity/add',
  9. edit_url: 'subscrip/activity/edit',
  10. del_url: 'subscrip/activity/del',
  11. multi_url: 'subscrip/activity/multi',
  12. table: 'subscrip_activity',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. columns: [
  20. [
  21. {checkbox: true},
  22. {field: 'id', title: __('Id'),operate:false},
  23. {field: 'title', title: __('Title')},
  24. {field: 'old_price', title: __('Old_price'), operate:false},
  25. {field: 'price', title: __('Price'), operate:false},
  26. {field: 'created_at', title: __('创建时间'),operate:false,formatter:Table.api.formatter.datetime},
  27. {field: 'days', title: __('活动周期(天)'),operate:false},
  28. {field: 'begin_date', title: __('Begin_date'),operate:false},
  29. {field: 'pop_space', title: __('弹窗位置'),operate:false},
  30. // {field: 'pop_img', title: __('Pop_img'),operate:false},
  31. {field: 'state', title: __("状态"),searchList: {"1":__('有效'),"2":__('失效')},formatter:function(value,row){
  32. if (row.state == 1){
  33. return '有效';
  34. }else{
  35. return '失效';
  36. }
  37. }},
  38. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value,row) {
  39. var html = '';
  40. if (row.is_begin == 0){
  41. if (row.state == 2) {
  42. html += '<a href="javascript:;" data-id="' + row.id + '" data-status="' + row.state + '" class="btn btn-xs btn-danger btn-lapse">有效</a>&nbsp;&nbsp;';
  43. } else {
  44. html += '<a href="javascript:;" data-id="' + row.id + '" data-status="' + row.state + '" class="btn btn-xs btn-primary btn-lapse">失效</a>&nbsp;&nbsp;';
  45. }
  46. html += '<a href="javascript:;" class="btn btn-dialog btn-xs btn-success btn-editone book_but">修改</a>&nbsp;&nbsp;';
  47. html += '<a href="javascript:;" data-id="'+row.id+'" data-date="'+row.begin_date+'" class="btn btn-xs btn-success upload-user" title="" data-table-id="table">关联用户</a>&nbsp;&nbsp;';
  48. }
  49. html += '<a href="javascript:;" data-id="'+row.id+'" class="btn btn-info btn-xs btn-detail">详情</a>&nbsp;&nbsp;';
  50. html += '<a href="javascript:;" data-id="'+row.id+'" class="btn btn-success btn-collect btn-xs">数据统计</a>&nbsp;&nbsp;';
  51. return html;
  52. }}
  53. ]
  54. ]
  55. });
  56. $(document).on('click','.upload-user',function () {
  57. var aid = $(this).data('id');
  58. var date = $(this).data('date');
  59. Fast.api.open('subscrip/activity/upload/aid/'+aid+'/date/'+date,'关联用户', {callback: function (data) {
  60. }});
  61. });
  62. $(document).on('click','.btn-collect',function () {
  63. var aid = $(this).data('id');
  64. Fast.api.open('subscrip/activecollect/index/aid/'+aid,'活动统计', {callback: function (data) {
  65. }});
  66. });
  67. $(document).on('click','.btn-detail',function () {
  68. var id = $(this).data('id');
  69. Fast.api.open('subscrip/activity/detail/id/'+id,'活动详情', {callback: function (data) {
  70. }});
  71. });
  72. // 失效 | 有效
  73. $(document).on('click','.btn-lapse',function(){
  74. var id = $(this).data('id');
  75. var state = $(this).data('status');
  76. var status_text = '确定要失效处理吗?';
  77. if(state == 2){
  78. status_text = '确定要设置为有效吗?';
  79. }
  80. Layer.confirm(status_text, function (idx) {
  81. $.post(
  82. 'subscrip/activity/ajaxLapse',
  83. {
  84. 'id': id,
  85. 'state': state
  86. },
  87. function (data) {
  88. layer.alert(data.msg);
  89. }
  90. );
  91. });
  92. });
  93. // 为表格绑定事件
  94. Table.api.bindevent(table);
  95. },
  96. add: function () {
  97. Controller.api.bindevent();
  98. $(document).on('change', '#c-goods', function () {
  99. $('#c-price').val($(this).children('option:selected').data('money') );
  100. });
  101. },
  102. edit: function () {
  103. Controller.api.bindevent();
  104. },
  105. upload: function () {
  106. Controller.api.bindevent();
  107. },
  108. api: {
  109. bindevent: function () {
  110. $('#c-book').selectPage({
  111. eSelect : function(d){
  112. $('#c-book_book_name').val(d.name);
  113. $('#select_book_id').val(d.id);
  114. $('#c-chapter_text').val('');
  115. $('#c-chapter').val('');
  116. $('#select_chapter_id').val('');
  117. },
  118. params: function(){
  119. return {'custom':{state:'1'}}
  120. }
  121. });
  122. $('#c-chapter').selectPage({
  123. eSelect : function(d){
  124. $('#c-chapter_name').val(d.name);
  125. $('#select_chapter_id').val(d.id);
  126. },
  127. params: function(){
  128. return {'filter':'{"id":"'+$('#select_book_id').val()+'"}'}
  129. }
  130. });
  131. $('#c-chapter_text').val($('#c-chapter').val());
  132. Form.api.bindevent($("form[role=form]"));
  133. }
  134. }
  135. };
  136. return Controller;
  137. });