apply.js 7.5 KB

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