apply.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. 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>');
  75. return html.join(' ');
  76. }}
  77. ]
  78. ]
  79. });
  80. // 为表格绑定事件
  81. Table.api.bindevent(table);
  82. // 批量审核按钮
  83. $(document).on('click', '.btn-approve', function () {
  84. var ids = Table.api.selectedids(table);
  85. if (ids.length === 0) {
  86. Toastr.warning("请至少选择一条记录");
  87. return false;
  88. }
  89. Layer.confirm(__('Are you sure you want to approve %s selected item?', ids.length), {
  90. icon: 3,
  91. title: __('Warning'),
  92. shadeClose: true,
  93. }, function (index) {
  94. Table.api.multi("approve", ids, table, this);
  95. Layer.close(index);
  96. });
  97. });
  98. // 单个审核通过
  99. $(document).on('click', '.btn-approve-one', function () {
  100. var id = $(this).data('id');
  101. Layer.confirm('确定要通过该申请吗?', {title: '提示'}, function(index) {
  102. Fast.api.ajax({
  103. url: 'commission/apply/approve',
  104. data: {ids: id}
  105. }, function(data, ret) {
  106. Layer.close(index);
  107. table.bootstrapTable('refresh');
  108. Toastr.success(ret.msg || '操作成功');
  109. });
  110. });
  111. });
  112. // 单个审核拒绝
  113. $(document).on('click', '.btn-reject-one', function () {
  114. var id = $(this).data('id');
  115. Layer.prompt({
  116. title: '请输入拒绝原因',
  117. formType: 2
  118. }, function(value, index) {
  119. if (!value || !value.trim()) {
  120. Layer.msg('请输入拒绝原因');
  121. return false;
  122. }
  123. Fast.api.ajax({
  124. url: 'commission/apply/reject',
  125. data: {ids: id, reason: value}
  126. }, function(data, ret) {
  127. Layer.close(index);
  128. table.bootstrapTable('refresh');
  129. Toastr.success(ret.msg || '操作成功');
  130. });
  131. });
  132. });
  133. // 单个删除
  134. $(document).on('click', '.btn-delone', function () {
  135. var id = $(this).data('id');
  136. Layer.confirm('确定要删除该申请记录吗?删除后不可恢复!', {
  137. icon: 3,
  138. title: '提示'
  139. }, function(index) {
  140. Fast.api.ajax({
  141. url: 'commission/apply/del',
  142. data: {ids: id}
  143. }, function(data, ret) {
  144. Layer.close(index);
  145. table.bootstrapTable('refresh');
  146. Toastr.success(ret.msg || '删除成功');
  147. });
  148. });
  149. });
  150. },
  151. api: {
  152. bindevent: function () {
  153. Form.api.bindevent($("form[role=form]"));
  154. }
  155. }
  156. };
  157. return Controller;
  158. });