channelfanstransfer.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: 'auth/channelfanstransfer/index',
  8. add_url: 'auth/channelfanstransfer/add',
  9. edit_url: 'auth/channelfanstransfer/edit',
  10. del_url: 'auth/channelfanstransfer/del',
  11. multi_url: 'auth/channelfanstransfer/multi',
  12. table: 'channel_fans_transfer',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id'),operate: false},
  25. {field: 'send_channel_id', title: __('Send_channel_id')},
  26. {field: 'receive_channel_id', title: __('Receive_channel_id')},
  27. {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate: false},
  28. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate: false},
  29. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate: false},
  30. {
  31. field: 'status',
  32. title: __('Status'),
  33. searchList: {
  34. "1":__('生效'),
  35. "2":__('失效'),
  36. },
  37. formatter: function (value, row, index) {
  38. if (value == 2) {
  39. return "失效";
  40. }else{
  41. return "生效";
  42. }
  43. }
  44. },
  45. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,formatter:function (value,row) {
  46. var html = '';
  47. if(row.status == 1){
  48. html += '<a href="javascript:;" data-id="'+row.id+'" data-status="'+row.status+'" class="btn btn-xs btn-danger btn-switchstatus" >失效 </a> ';
  49. }else{
  50. html += '<a href="javascript:;" data-id="'+row.id+'" data-status="'+row.status+'" class="btn btn-xs btn-success btn-switchstatus" >生效 </a> ';
  51. }
  52. return html;
  53. }
  54. }
  55. ]
  56. ]
  57. });
  58. //批量更换状态
  59. $(document).on('click','.btn-batch-switchstatus',function () {
  60. var ids = Table.api.selectedids(table).join(",");
  61. var status = $(this).data("status") == 2 ? 1 :2;
  62. var status_text = $(this).data("status") == 2 ? '生效' : '失效';
  63. Layer.confirm(
  64. '确定要将选中的'+ Table.api.selectedids(table).length +'项改为' + status_text + '吗?',
  65. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  66. function (index) {
  67. $.ajax({
  68. type: 'post',
  69. data: {ids:ids,status:status},
  70. url:'/admin/auth/channelfanstransfer/switchstatus',
  71. success:function () {
  72. Toastr.success('操作成功');
  73. table.bootstrapTable('refresh');
  74. },
  75. error: function(){
  76. Toastr.error('操作失败');
  77. }
  78. });
  79. Layer.close(index);
  80. }
  81. );
  82. });
  83. //更换状态
  84. $(document).on('click','.btn-switchstatus',function () {
  85. var ids = $(this).data("id");
  86. var status = $(this).data("status") == 2 ? 1 :2;
  87. var status_text = $(this).data("status") == 2 ? '生效' : '失效';
  88. Layer.confirm(
  89. '确定要将选中项改为' + status_text + '吗?',
  90. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  91. function (index) {
  92. $.ajax({
  93. type: 'post',
  94. data: {ids:ids,status:status},
  95. url:'/admin/auth/channelfanstransfer/switchstatus',
  96. success:function () {
  97. Toastr.success('操作成功');
  98. table.bootstrapTable('refresh');
  99. },
  100. error: function(){
  101. Toastr.error('操作失败');
  102. }
  103. });
  104. Layer.close(index);
  105. }
  106. );
  107. });
  108. // 为表格绑定事件
  109. Table.api.bindevent(table);
  110. },
  111. add: function () {
  112. Controller.api.bindevent();
  113. },
  114. edit: function () {
  115. Controller.api.bindevent();
  116. },
  117. api: {
  118. bindevent: function () {
  119. Form.api.bindevent($("form[role=form]"));
  120. }
  121. }
  122. };
  123. return Controller;
  124. });