manage.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'cp/vip/manage/index',
  8. add_url: 'cp/vip/manage/add',
  9. //edit_url: 'cp/vip/manage/edit',
  10. del_url: 'cp/vip/manage/del',
  11. multi_url: 'cp/vip/manage/multi',
  12. manage_url: 'cp/vip/manage/bookcplist',
  13. table: 'cp_vip_list',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id'), operate: false},
  26. {field: 'book_id', title: __('Book_id')},
  27. {field: 'name', title: __('书籍名称'), operate:'like'},
  28. {field: 'cp_name', title: __('Cp_name')},
  29. {
  30. field: 'createtime',
  31. title: __('Createtime'),
  32. operate: false,
  33. formatter: Table.api.formatter.datetime
  34. },
  35. {
  36. field: 'operate',
  37. title: __('Operate'),
  38. table: table,
  39. events: Table.api.events.operate,
  40. formatter: Table.api.formatter.operate
  41. }
  42. ]
  43. ]
  44. });
  45. // 为表格绑定事件
  46. Table.api.bindevent(table);
  47. // btn-add-cp
  48. $(document).on('click', ".btn-add-cp", function () {
  49. Backend.api.open('cp/vip/manage/bookcplist' , __('Select'), {callback: function () {
  50. table.bootstrapTable('refresh');
  51. }});
  52. return false;
  53. });
  54. },
  55. bookcplist: function () {
  56. // 初始化表格参数配置
  57. Table.api.init({
  58. extend: {
  59. manage_url: 'cp/vip/manage/bookcplist',
  60. }
  61. });
  62. var table = $("#book-cp-table");
  63. // 初始化表格
  64. table.bootstrapTable({
  65. url: $.fn.bootstrapTable.defaults.extend.manage_url,
  66. pk: 'id',
  67. sortName: 'id',
  68. search: false,
  69. columns: [
  70. [
  71. {checkbox: true},
  72. {field: 'id', title: __('Book_id')},
  73. {field: 'name', title: __('书籍名称'), operate:'like'},
  74. {field: 'cp_name', title: __('Cp_name')},
  75. {
  76. field: 'operate',
  77. title: __('Operate'),
  78. table: table,
  79. events: Table.api.events.operate,
  80. formatter: function (value, row, index) {
  81. var html = '';
  82. html += '<a href="javascript:void(0);" data-book_id ="' + row.id + '" data-cp_id = "' + row.cp_id + '" data-cpname="' + row.cp_name + '" class="btn btn-xs btn-success btn-danger add-cp-book">添加</a>';
  83. return html;
  84. }
  85. }
  86. ]
  87. ]
  88. });
  89. // 单个添加
  90. $(document).on('click', ".add-cp-book", function(){
  91. $.post(
  92. 'cp/vip/manage/ajaxsavedata',
  93. {
  94. 'row': {
  95. 'book_id': $(this).data('book_id'),
  96. 'cp_id': $(this).data('cp_id'),
  97. 'cp_name': $(this).data('cpname'),
  98. }
  99. },
  100. function (data) {
  101. if (data.code) {
  102. Toastr.success('添加成功');
  103. setTimeout( "Fast.api.close()", 1000 );
  104. } else {
  105. layer.error(data.message);
  106. }
  107. }
  108. );
  109. });
  110. // 为表格绑定事件
  111. Table.api.bindevent(table);
  112. //
  113. $('.btn-add-cp-batch').on('click',function () {
  114. var ids = Table.api.selectedids(table);
  115. Layer.confirm(
  116. '确定要添加选中的'+ids.length+'项么?',
  117. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  118. function () {
  119. $.ajax({
  120. url:'cp/vip/manage/ajaxbatchsave',
  121. type:"post",
  122. data: {
  123. ids:ids,
  124. },
  125. success:function(data){
  126. if(data.code == 0){
  127. Layer.msg(data.msg);
  128. return false;
  129. }else{
  130. layer.msg('操作成功');
  131. Fast.api.close();
  132. }
  133. }
  134. });
  135. }
  136. );
  137. });
  138. },
  139. add: function () {
  140. Controller.api.bindevent();
  141. },
  142. edit: function () {
  143. Controller.api.bindevent();
  144. },
  145. api: {
  146. bindevent: function () {
  147. Form.api.bindevent($("form[role=form]"));
  148. },
  149. }
  150. };
  151. return Controller;
  152. });