floattips.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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: 'floattips/index',
  8. add_url: 'floattips/add',
  9. edit_url: 'floattips/edit',
  10. del_url: 'floattips/del',
  11. multi_url: 'floattips/multi',
  12. table: 'float_tips',
  13. },
  14. search: false
  15. });
  16. var table = $("#table");
  17. $(document).on('click','.layer-open',function () {
  18. Fast.api.open($(this).attr('href'), $(this).data('title')?$(this).data('title'):'配置公共信息', {});
  19. return false;
  20. });
  21. // 初始化表格
  22. table.bootstrapTable({
  23. url: $.fn.bootstrapTable.defaults.extend.index_url,
  24. pk: 'id',
  25. sortName: 'id',
  26. columns: [
  27. [
  28. {checkbox: true},
  29. {field: 'id', title: __('Id'), operate: false},
  30. {field: 'name', title: __('Name'), operate: 'LIKE'},
  31. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image, operate: false},
  32. {field: 'image_pop', title: __('Image_pop'), formatter: Table.api.formatter.image, operate: false},
  33. {field: 'chapter_show', title: __('Chapter_show'), operate: false},
  34. {field: 'type', title: __('Type'), visible:false, searchList: {"activity":__('type activity'),"url":__('type url'),"book":__('type book')}},
  35. {field: 'type_text', title: __('Type'), operate:false},
  36. {field: 'link', title: __('Link'), operate: false},
  37. {field: 'starttime', title: __('Starttime'), operate: false,formatter: Table.api.formatter.datetime},
  38. {field: 'endtime', title: __('Endtime'), operate: false,formatter: Table.api.formatter.datetime},
  39. {field: 'recharge_money', title: '充值金额/今日', operate:false, formatter: function(value, row){return value+'('+row.recharge_money_day+')'}},
  40. {field: 'recharge_user', title: '充值人数/今日', operate:false, formatter: function(value, row){return value+'('+row.recharge_user_day+')'}},
  41. {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
  42. {field: 'status_text', title: __('Status'), operate:false},
  43. {field: 'createtime', title: __('Createtime'),formatter: Table.api.formatter.datetime, operate:false},
  44. {field: 'updatetime', title: __('Updatetime'),formatter: Table.api.formatter.datetime, operate:false},
  45. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row){
  46. var content = '';
  47. content += '<a href="/admin/floattips/edit/ids/'+row.id+'" class="btn btn-xs btn-success btn-editone" title="" data-table-id="table"><i class="fa fa-pencil"></i></a> ';
  48. content += '<a href="/admin/floattips/upload/ids/'+row.id+'" class="btn btn-xs btn-success layer-open" title="" data-table-id="table"><i class="fa fa-upload"></i></a> ';
  49. content += '<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="" data-table-id="table"><i class="fa fa-trash"></i></a>';
  50. return content;
  51. }}
  52. ]
  53. ]
  54. });
  55. // 为表格绑定事件
  56. Table.api.bindevent(table);
  57. },
  58. add: function () {
  59. Controller.api.bindevent();
  60. },
  61. edit: function () {
  62. Controller.api.bindevent();
  63. },
  64. upload: function () {
  65. Controller.api.bindevent();
  66. },
  67. api: {
  68. bindevent: function () {
  69. $('#c-book').selectPage({
  70. eSelect : function(d){
  71. $('#c-book_book_name').val(d.name);
  72. $('#select_book_id').val(d.id);
  73. $('#c-chapter_text').val('');
  74. $('#c-chapter').val('');
  75. $('#select_chapter_id').val('');
  76. },
  77. params: function(){
  78. return {'custom':{state:'1'}}
  79. }
  80. });
  81. $('#c-chapter').selectPage({
  82. eSelect : function(d){
  83. $('#c-chapter_name').val(d.name);
  84. $('#select_chapter_id').val(d.id);
  85. },
  86. params: function(){
  87. return {'filter':'{"id":"'+$('#select_book_id').val()+'"}'}
  88. }
  89. });
  90. $('#c-chapter_text').val($('#c-chapter').val());
  91. $(document).delegate('input[name="row[type]"]', 'click', function () {
  92. var val = $('input[name="row[type]"]:checked').val();
  93. switch (val) {
  94. case 'activity':
  95. $('.activity').show();
  96. $('.link,.book').hide();
  97. break;
  98. case 'url':
  99. $('.link').show();
  100. $('.activity,.book').hide();
  101. break;
  102. case 'book':
  103. $('.book').show();
  104. $('.activity,.link').hide();
  105. break;
  106. }
  107. })
  108. $("#add-form, #edit-form").data("validator-options", {
  109. ignore: ':hidden',
  110. beforeSubmit: function () {
  111. var val = $('input[name="row[type]"]:checked').val();
  112. var msg = [];
  113. switch (val) {
  114. case 'url':
  115. if (!$('#c-link').val()) {
  116. msg.push('url不可为空');
  117. }
  118. break;
  119. case 'book':
  120. if (!$('#select_book_id').val()) {
  121. msg.push('书籍不可为空');
  122. }
  123. if (!$('#select_chapter_id').val()) {
  124. msg.push('章节不可为空');
  125. }
  126. break;
  127. }
  128. if (msg.length > 0) {
  129. Toastr.error(msg.join(','));
  130. return false;
  131. }
  132. }
  133. });
  134. Form.api.bindevent($("form[role=form]"));
  135. }
  136. }
  137. };
  138. return Controller;
  139. });