apply.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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: 'commission/apply/index',
  8. detail_url: 'commission/apply/detail',
  9. approve_url: 'commission/apply/approve',
  10. reject_url: 'commission/apply/reject',
  11. del_url: 'commission/apply/del',
  12. table: 'shop_commission_apply',
  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. sortOrder: 'desc',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id'), sortable: true},
  26. {field: 'user.nickname', title: __('User'), operate: 'LIKE', formatter: Table.api.formatter.search},
  27. {field: 'apply_type_text', title: __('Apply type'), searchList: {"personal": "个人申请", "company": "企业申请"}, formatter: function(value, row, index) {
  28. if (row.apply_type === 'personal') {
  29. return '<span class="label label-primary">' + value + '</span>';
  30. } else {
  31. return '<span class="label label-info">' + value + '</span>';
  32. }
  33. }},
  34. {field: 'agent_type_text', title: __('Agent type'), searchList: {"normal": "普通代理商", "province": "省级代理商", "city": "市级代理商", "district": "区域代理商"}, formatter: function(value, row, index) {
  35. var colorMap = {
  36. 'province': 'danger', // 省级-红色
  37. 'city': 'warning', // 市级-橙色
  38. 'district': 'info', // 区域-蓝色
  39. 'normal': 'default' // 普通-默认
  40. };
  41. var color = colorMap[row.agent_type] || 'default';
  42. return '<span class="label label-' + color + '">' + value + '</span>';
  43. }},
  44. {field: 'identity.name', title: __('Identity'), operate: false},
  45. {field: 'real_name', title: __('Real name'), visible: false},
  46. {field: 'company_name', title: __('Company name'), visible: false},
  47. {field: 'province_name', title: __('Area'), operate: false, formatter: function(value, row, index) {
  48. return (row.province_name || '') + '-' + (row.city_name || '') + '-' + (row.district_name || '');
  49. }},
  50. {field: 'status_text', title: __('Status'), searchList: {"pending": "待审核", "approved": "已通过", "rejected": "已拒绝"}, formatter: function(value, row, index) {
  51. var colorMap = {
  52. 'pending': 'warning',
  53. 'approved': 'success',
  54. 'rejected': 'danger'
  55. };
  56. var color = colorMap[row.status] || 'default';
  57. return '<span class="label label-' + color + '">' + value + '</span>';
  58. }},
  59. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  60. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  61. formatter: function (value, row, index) {
  62. var html = [];
  63. // 详情按钮
  64. html.push('<a href="' + Fast.api.fixurl("commission/apply/detail/ids/" + row.id) + '" class="btn btn-xs btn-info btn-dialog" data-area=\'["80%","80%"]\' title="' + __('Detail') + '"><i class="fa fa-list"></i></a>');
  65. // 审核按钮 - 只在待审核状态显示
  66. if (row.status === 'pending') {
  67. html.push('<a href="javascript:;" class="btn btn-xs btn-success btn-approve-one" data-id="' + row.id + '" title="' + __('Approve') + '"><i class="fa fa-check"></i></a>');
  68. html.push('<a href="javascript:;" class="btn btn-xs btn-danger btn-reject-one" data-id="' + row.id + '" title="' + __('Reject') + '"><i class="fa fa-times"></i></a>');
  69. }
  70. // 删除按钮 - 只允许删除待审核和已拒绝的申请
  71. if (row.status === 'pending' || row.status === 'rejected') {
  72. html.push('<a href="javascript:;" class="btn btn-xs btn-warning btn-delone" data-id="' + row.id + '" title="' + __('Del') + '"><i class="fa fa-trash"></i></a>');
  73. }
  74. return html.join(' ');
  75. }}
  76. ]
  77. ]
  78. });
  79. // 为表格绑定事件
  80. Table.api.bindevent(table);
  81. // 批量审核按钮
  82. $(document).on('click', '.btn-approve', function () {
  83. var ids = Table.api.selectedids(table);
  84. if (ids.length === 0) {
  85. Toastr.warning("请至少选择一条记录");
  86. return false;
  87. }
  88. Layer.confirm(__('Are you sure you want to approve %s selected item?', ids.length), {
  89. icon: 3,
  90. title: __('Warning'),
  91. shadeClose: true,
  92. }, function (index) {
  93. Table.api.multi("approve", ids, table, this);
  94. Layer.close(index);
  95. });
  96. });
  97. // 单个审核通过
  98. $(document).on('click', '.btn-approve-one', function () {
  99. var id = $(this).data('id');
  100. Layer.confirm('确定要通过该申请吗?', {title: '提示'}, function(index) {
  101. Fast.api.ajax({
  102. url: 'commission/apply/approve',
  103. data: {ids: id}
  104. }, function(data, ret) {
  105. Layer.close(index);
  106. table.bootstrapTable('refresh');
  107. Toastr.success(ret.msg || '操作成功');
  108. });
  109. });
  110. });
  111. // 单个审核拒绝
  112. $(document).on('click', '.btn-reject-one', function () {
  113. var id = $(this).data('id');
  114. Layer.prompt({
  115. title: '请输入拒绝原因',
  116. formType: 2
  117. }, function(value, index) {
  118. if (!value || !value.trim()) {
  119. Layer.msg('请输入拒绝原因');
  120. return false;
  121. }
  122. Fast.api.ajax({
  123. url: 'commission/apply/reject',
  124. data: {ids: id, reason: value}
  125. }, function(data, ret) {
  126. Layer.close(index);
  127. table.bootstrapTable('refresh');
  128. Toastr.success(ret.msg || '操作成功');
  129. });
  130. });
  131. });
  132. // 单个删除
  133. $(document).on('click', '.btn-delone', function () {
  134. var id = $(this).data('id');
  135. Layer.confirm('确定要删除该申请记录吗?删除后不可恢复!', {
  136. icon: 3,
  137. title: '提示'
  138. }, function(index) {
  139. Fast.api.ajax({
  140. url: 'commission/apply/del',
  141. data: {ids: id}
  142. }, function(data, ret) {
  143. Layer.close(index);
  144. table.bootstrapTable('refresh');
  145. Toastr.success(ret.msg || '删除成功');
  146. });
  147. });
  148. });
  149. },
  150. api: {
  151. bindevent: function () {
  152. Form.api.bindevent($("form[role=form]"));
  153. }
  154. }
  155. };
  156. return Controller;
  157. });