apply.js 7.5 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: '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": "普通代理商", "regional": "区域代理商"}, formatter: function(value, row, index) {
  34. if (row.agent_type === 'regional') {
  35. return '<span class="label label-warning">' + value + '</span>';
  36. } else {
  37. return '<span class="label label-default">' + value + '</span>';
  38. }
  39. }},
  40. {field: 'identity.name', title: __('Identity'), operate: false},
  41. {field: 'real_name', title: __('Real name'), visible: false},
  42. {field: 'company_name', title: __('Company name'), visible: false},
  43. {field: 'province_name', title: __('Area'), operate: false, formatter: function(value, row, index) {
  44. return (row.province_name || '') + '-' + (row.city_name || '') + '-' + (row.district_name || '');
  45. }},
  46. {field: 'status_text', title: __('Status'), searchList: {"pending": "待审核", "approved": "已通过", "rejected": "已拒绝"}, formatter: function(value, row, index) {
  47. var colorMap = {
  48. 'pending': 'warning',
  49. 'approved': 'success',
  50. 'rejected': 'danger'
  51. };
  52. var color = colorMap[row.status] || 'default';
  53. return '<span class="label label-' + color + '">' + value + '</span>';
  54. }},
  55. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  56. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  57. formatter: function (value, row, index) {
  58. var html = [];
  59. // 详情按钮
  60. if (Table.api.checkAuth('detail')) {
  61. 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>');
  62. }
  63. // 审核按钮
  64. if (row.status === 'pending') {
  65. if (Table.api.checkAuth('approve')) {
  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. }
  68. if (Table.api.checkAuth('reject')) {
  69. 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>');
  70. }
  71. }
  72. return html.join(' ');
  73. }}
  74. ]
  75. ]
  76. });
  77. // 为表格绑定事件
  78. Table.api.bindevent(table);
  79. // 批量审核按钮
  80. $(document).on('click', '.btn-approve', function () {
  81. var ids = Table.api.selectedids(table);
  82. if (ids.length === 0) {
  83. Toastr.warning("请至少选择一条记录");
  84. return false;
  85. }
  86. Layer.confirm(__('Are you sure you want to approve %s selected item?', ids.length), {
  87. icon: 3,
  88. title: __('Warning'),
  89. shadeClose: true,
  90. }, function (index) {
  91. Table.api.multi("approve", ids, table, this);
  92. Layer.close(index);
  93. });
  94. });
  95. // 单个审核通过
  96. $(document).on('click', '.btn-approve-one', function () {
  97. var id = $(this).data('id');
  98. Layer.confirm('确定要通过该申请吗?', {title: '提示'}, function(index) {
  99. Fast.api.ajax({
  100. url: 'commission/apply/approve',
  101. data: {ids: id}
  102. }, function(data, ret) {
  103. Layer.close(index);
  104. table.bootstrapTable('refresh');
  105. Toastr.success(ret.msg || '操作成功');
  106. });
  107. });
  108. });
  109. // 单个审核拒绝
  110. $(document).on('click', '.btn-reject-one', function () {
  111. var id = $(this).data('id');
  112. Layer.prompt({
  113. title: '请输入拒绝原因',
  114. formType: 2
  115. }, function(value, index) {
  116. if (!value || !value.trim()) {
  117. Layer.msg('请输入拒绝原因');
  118. return false;
  119. }
  120. Fast.api.ajax({
  121. url: 'commission/apply/reject',
  122. data: {ids: id, reason: value}
  123. }, function(data, ret) {
  124. Layer.close(index);
  125. table.bootstrapTable('refresh');
  126. Toastr.success(ret.msg || '操作成功');
  127. });
  128. });
  129. });
  130. },
  131. api: {
  132. bindevent: function () {
  133. Form.api.bindevent($("form[role=form]"));
  134. }
  135. }
  136. };
  137. return Controller;
  138. });