anchor.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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: 'user/anchor/index' + location.search,
  8. edit_url: 'user/anchor/edit',
  9. table: 'user_anchor',
  10. }
  11. });
  12. var table = $("#table");
  13. //修改 data-value="0" 和 name="status"
  14. table.on('post-common-search.bs.table', function (event, table) {
  15. $('ul.nav-tabs li a[data-value="0"]').trigger('click');
  16. $('select[name="status"]').val('0');
  17. $(".btn-success").trigger('click');
  18. });
  19. // 初始化表格
  20. table.bootstrapTable({
  21. url: $.fn.bootstrapTable.defaults.extend.index_url,
  22. pk: 'id',
  23. sortName: 'id',
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'user_id', title: __('User_id')},
  29. {field: 'user.u_id', title: __('User.u_id')},
  30. {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
  31. // {field: 'type_id', title: __('Type_id')},
  32. {field: 'useranchortype.name', title: __('Type_id'), operate: 'LIKE'},
  33. {
  34. field: 'desc', title: __('Desc'), operate: 'LIKE',
  35. formatter: function (value, row, index, field) {
  36. return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.desc + "'>" + value + "</span>";
  37. },
  38. cellStyle: function (value, row, index, field) {
  39. return {
  40. css: {
  41. "white-space": "nowrap",
  42. "text-overflow": "ellipsis",
  43. "overflow": "hidden",
  44. "max-width": "250px"
  45. }
  46. };
  47. }
  48. },
  49. {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
  50. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  51. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  52. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  53. ]
  54. ]
  55. });
  56. // 为表格绑定事件
  57. Table.api.bindevent(table);
  58. // 批量审核
  59. $(document).on("click", ".nav-tabs li", function () {
  60. datavalue = $(this).find('a').data('value');
  61. if(datavalue === 0){
  62. $(".btn-anchor-approval").show();
  63. $(".btn-anchor-reject").show();
  64. }else{
  65. $(".btn-anchor-approval").hide();
  66. $(".btn-anchor-reject").hide();
  67. }
  68. });
  69. // 批量审核
  70. $(document).on("click", ".btn-anchor-approval", function () {
  71. var ids = Table.api.selectedids(table);
  72. checkids = ids.join(",");
  73. Layer.confirm(
  74. '确定要一键审批通过吗?',
  75. {icon: 3, title: __('Warning'), offset: '40%', shadeClose: true},
  76. function (index) {
  77. Layer.close(index);
  78. Backend.api.ajax({
  79. url: "user/anchor/batchApproval",
  80. data: {ids:checkids}
  81. }, function(data, ret){//成功的回调
  82. if (ret.code === 1) {
  83. table.bootstrapTable('refresh');
  84. Layer.close(index);
  85. } else {
  86. Layer.close(index);
  87. Toastr.error(ret.msg);
  88. }
  89. }, function(data, ret){//失败的回调
  90. console.log(ret);
  91. // Toastr.error(ret.msg);
  92. Layer.close(index);
  93. });
  94. }
  95. );
  96. });
  97. // 批量审核拒绝
  98. $(document).on("click", ".btn-anchor-reject", function () {
  99. var ids = Table.api.selectedids(table);
  100. checkids = ids.join(",");
  101. Layer.confirm(
  102. '确定要一键审批拒绝吗?',
  103. {icon: 3, title: __('Warning'), offset: '40%', shadeClose: true},
  104. function (index) {
  105. Layer.close(index);
  106. Backend.api.ajax({
  107. url: "user/anchor/batchReject",
  108. data: {ids:checkids}
  109. }, function(data, ret){//成功的回调
  110. if (ret.code === 1) {
  111. table.bootstrapTable('refresh');
  112. Layer.close(index);
  113. } else {
  114. Layer.close(index);
  115. Toastr.error(ret.msg);
  116. }
  117. }, function(data, ret){//失败的回调
  118. console.log(ret);
  119. // Toastr.error(ret.msg);
  120. Layer.close(index);
  121. });
  122. }
  123. );
  124. });
  125. },
  126. add: function () {
  127. Controller.api.bindevent();
  128. },
  129. edit: function () {
  130. Controller.api.bindevent();
  131. },
  132. api: {
  133. bindevent: function () {
  134. Form.api.bindevent($("form[role=form]"));
  135. }
  136. }
  137. };
  138. return Controller;
  139. });