apply.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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: 'is_reaudit_text', title: __('Audit Type'), searchList: {"首次申请": "首次申请", "重新审核": "重新审核"}, formatter: function(value, row, index) {
  51. if (row.is_reaudit) {
  52. return '<span class="label label-info">' + value + '</span>';
  53. } else {
  54. return '<span class="label label-success">' + value + '</span>';
  55. }
  56. }},
  57. {field: 'status_text', title: __('Status'), searchList: {"pending": "待审核", "approved": "已通过", "rejected": "已拒绝"}, formatter: function(value, row, index) {
  58. var colorMap = {
  59. 'pending': 'warning',
  60. 'approved': 'success',
  61. 'rejected': 'danger'
  62. };
  63. var color = colorMap[row.status] || 'default';
  64. return '<span class="label label-' + color + '">' + value + '</span>';
  65. }},
  66. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  67. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  68. formatter: function (value, row, index) {
  69. var html = [];
  70. // 详情按钮
  71. 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>');
  72. // 审核按钮 - 只在待审核状态显示
  73. if (row.status === 'pending') {
  74. 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>');
  75. 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>');
  76. }
  77. // 删除按钮 - 只允许删除待审核和已拒绝的申请
  78. // if (row.status === 'pending' || row.status === 'rejected') {
  79. // 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>');
  80. // }
  81. 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>');
  82. return html.join(' ');
  83. }}
  84. ]
  85. ]
  86. });
  87. // 为表格绑定事件
  88. Table.api.bindevent(table);
  89. // 批量审核按钮
  90. $(document).on('click', '.btn-approve', function () {
  91. var ids = Table.api.selectedids(table);
  92. if (ids.length === 0) {
  93. Toastr.warning("请至少选择一条记录");
  94. return false;
  95. }
  96. Layer.confirm(__('Are you sure you want to approve %s selected item?', ids.length), {
  97. icon: 3,
  98. title: __('Warning'),
  99. shadeClose: true,
  100. }, function (index) {
  101. Table.api.multi("approve", ids, table, this);
  102. Layer.close(index);
  103. });
  104. });
  105. // 单个审核通过
  106. $(document).on('click', '.btn-approve-one', function () {
  107. var id = $(this).data('id');
  108. // 获取当前行数据
  109. var rowIndex = $(this).closest('tr').data('index');
  110. var rowData = table.bootstrapTable('getData')[rowIndex];
  111. var confirmText = '确定要通过该申请吗?';
  112. if (rowData && rowData.is_reaudit) {
  113. confirmText = '这是一个重新审核申请,确定要通过吗?通过后将更新代理商资料。';
  114. } else {
  115. confirmText = '确定要通过该申请吗?通过后将创建新的代理商。';
  116. }
  117. Layer.confirm(confirmText, {title: '审核确认'}, function(index) {
  118. Fast.api.ajax({
  119. url: 'commission/apply/approve',
  120. data: {ids: id}
  121. }, function(data, ret) {
  122. Layer.close(index);
  123. table.bootstrapTable('refresh');
  124. Toastr.success(ret.msg || '操作成功');
  125. });
  126. });
  127. });
  128. // 单个审核拒绝
  129. $(document).on('click', '.btn-reject-one', function () {
  130. var id = $(this).data('id');
  131. Layer.prompt({
  132. title: '请输入拒绝原因',
  133. formType: 2
  134. }, function(value, index) {
  135. if (!value || !value.trim()) {
  136. Layer.msg('请输入拒绝原因');
  137. return false;
  138. }
  139. Fast.api.ajax({
  140. url: 'commission/apply/reject',
  141. data: {ids: id, reason: value}
  142. }, function(data, ret) {
  143. Layer.close(index);
  144. table.bootstrapTable('refresh');
  145. Toastr.success(ret.msg || '操作成功');
  146. });
  147. });
  148. });
  149. // 单个删除
  150. $(document).on('click', '.btn-delone', function () {
  151. var id = $(this).data('id');
  152. Layer.confirm('确定要删除该申请记录吗?删除后不可恢复!', {
  153. icon: 3,
  154. title: '提示'
  155. }, function(index) {
  156. Fast.api.ajax({
  157. url: 'commission/apply/del',
  158. data: {ids: id}
  159. }, function(data, ret) {
  160. Layer.close(index);
  161. table.bootstrapTable('refresh');
  162. Toastr.success(ret.msg || '删除成功');
  163. });
  164. });
  165. });
  166. },
  167. api: {
  168. bindevent: function () {
  169. Form.api.bindevent($("form[role=form]"));
  170. }
  171. }
  172. };
  173. return Controller;
  174. });