books_level.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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: 'books/books_level/index' + location.search,
  8. add_url: 'books/books_level/add',
  9. edit_url: 'books/books_level/edit',
  10. del_url: 'books/books_level/del',
  11. multi_url: 'books/books_level/multi',
  12. import_url: 'books/books_level/import',
  13. table: 'books_level',
  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')},
  26. {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  27. // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  28. {field: 'is_deleted', title: __('是否已删除'), searchList: {"0":__('是'),"1":__('否')}, formatter: Table.api.formatter.normal},
  29. {field: 'sort', title: __('Sort')},
  30. {field: 'status', title: __('状态'), searchList: {"0":__('正常'),"1":__('禁用')}, formatter: Table.api.formatter.status},
  31. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  32. {
  33. field: 'operate',
  34. title: __('Operate'),
  35. table: table,
  36. events: Table.api.events.operate,
  37. formatter: Table.api.formatter.operate,
  38. buttons: [{
  39. name: 'click',
  40. text:'启用',
  41. title: __('启用'),
  42. classname: 'btn btn-xs btn-info btn-click',
  43. url: 'books.books_level/edit?ids/{id}',
  44. data: {status:0},
  45. // icon: 'fa fa-leaf',
  46. click: function (data,row) {
  47. var temp=table.bootstrapTable('getSelections');
  48. var id = row.id;
  49. console.log(row);
  50. return $.ajax({
  51. // url:'http://up.kuman.cn/settle/cancel',
  52. url:'books.books_level/update_status?ids='+id,
  53. type:'post',
  54. // dataType:'json',
  55. data:{status:0},
  56. success:function(data){
  57. if(data.code === 1){
  58. layer.msg('操作成功');
  59. window.location.reload();
  60. }else{
  61. layer.msg(data.msg);
  62. }
  63. }
  64. });
  65. // Layer.alert("点击按钮执行的事件");
  66. },
  67. visible: function (row) {
  68. console.log(row)
  69. if (row.status === "1"){
  70. return true;
  71. }
  72. return false;
  73. },
  74. refresh:true,
  75. },
  76. {
  77. name: 'click',
  78. text:'禁用',
  79. title: __('禁用'),
  80. classname: 'btn btn-xs btn-danger btn-click',
  81. url: 'books.books_level/edit?ids/{id}',
  82. data: {status:1},
  83. // icon: 'fa fa-leaf',
  84. click: function (data,row) {
  85. var temp=table.bootstrapTable('getSelections');
  86. var id = row.id;
  87. console.log(row);
  88. return $.ajax({
  89. // url:'http://up.kuman.cn/settle/cancel',
  90. url:'books.books_level/update_status?ids='+id,
  91. type:'post',
  92. // dataType:'json',
  93. data:{status:1},
  94. success:function(data){
  95. if(data.code === 1){
  96. layer.msg('操作成功');
  97. window.location.reload();
  98. }else{
  99. layer.alert(data.msg);
  100. }
  101. }
  102. });
  103. // Layer.alert("点击按钮执行的事件");
  104. },
  105. visible: function (row) {
  106. // console.log(row)
  107. if (row.status === "0"){
  108. return true;
  109. }
  110. return false;
  111. },
  112. refresh:true,
  113. },
  114. ],
  115. }
  116. ]
  117. ]
  118. });
  119. // 为表格绑定事件
  120. Table.api.bindevent(table);
  121. },
  122. add: function () {
  123. Controller.api.bindevent();
  124. },
  125. edit: function () {
  126. Controller.api.bindevent();
  127. },
  128. api: {
  129. bindevent: function () {
  130. Form.api.bindevent($("form[role=form]"));
  131. }
  132. }
  133. };
  134. return Controller;
  135. });