application.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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: 'inspection/application/index' + location.search,
  8. detail_url: 'inspection/application/detail',
  9. audit_url: 'inspection/application/audit',
  10. del_url: 'inspection/application/del',
  11. multi_url: 'inspection/application/multi',
  12. dragsort_url: ''
  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. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true, width: 50},
  27. {field: 'id', title: __('Id'), operate: false, sortable: true, width: 80},
  28. {field: 'name', title: '姓名', operate: 'LIKE', width: 100},
  29. {field: 'phone', title: '申请手机号', operate: 'LIKE', width: 120},
  30. {
  31. field: 'user.username',
  32. title: __('User'),
  33. operate: 'LIKE',
  34. formatter: function (value, row, index) {
  35. // 显示用户头像和用户名
  36. var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png';
  37. var username = row.user && row.user.username ? row.user.username : '游客';
  38. var userId = row.user_id || '';
  39. // 处理头像URL
  40. var avatarUrl = avatar;
  41. if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
  42. avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
  43. }
  44. return '<div style="display:flex;align-items:center;">' +
  45. '<img src="' + avatarUrl + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />' +
  46. '<div>' +
  47. '<div style="color:#337ab7;font-weight:bold;">' + username + '</div>' +
  48. '<div style="color:#999;font-size:12px;">ID: ' + userId + '</div>' +
  49. '</div>' +
  50. '</div>';
  51. }
  52. },
  53. {field: 'supplier.name', title: '绑定供应商', operate: false, width: 120, formatter: function(value, row, index) {
  54. if (row.supplier && row.supplier.name) {
  55. return '<span class="label label-info">' + row.supplier.name + '</span>';
  56. }
  57. return '<span class="text-muted">未绑定</span>';
  58. }},
  59. {field: 'id_card', title: '身份证号', operate: false, width: 150},
  60. {field: 'province_name', title: '省份', operate: false, width: 80},
  61. {field: 'city_name', title: '城市', operate: false, width: 80},
  62. {field: 'district_name', title: '区县', operate: false, width: 80},
  63. {field: 'apply_time_text', title: '申请时间', operate: false, sortable: true, width: 140},
  64. {field: 'audit_status', title: '审核状态', searchList: {"1":"审核中","2":"审核通过","3":"审核驳回"}, formatter: Table.api.formatter.status, custom: {"1":"warning","2":"success","3":"danger"}, width: 100},
  65. {field: 'status', title: '状态', searchList: {"0":"禁用","1":"启用"}, table: table, formatter: Table.api.formatter.toggle, width: 80},
  66. {field: 'audit_time_text', title: '审核时间', operate: false, width: 140},
  67. {field: 'reject_reason', title: '驳回原因', operate: false, width: 200, formatter: function(value, row, index) {
  68. return value ? '<span class="text-danger">' + value + '</span>' : '-';
  69. }},
  70. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, width: 150, fixed: 'right',
  71. buttons: [
  72. {
  73. name: 'detail',
  74. title: '查看详情',
  75. text: '详情',
  76. classname: 'btn btn-xs btn-info btn-dialog',
  77. icon: 'fa fa-eye',
  78. url: 'inspection/application/detail',
  79. callback: function (data) {
  80. Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  81. },
  82. visible: function (row) {
  83. return true;
  84. }
  85. },
  86. {
  87. name: 'audit',
  88. title: '审核',
  89. text: '审核',
  90. classname: 'btn btn-xs btn-warning btn-dialog',
  91. icon: 'fa fa-check',
  92. url: 'inspection/application/audit',
  93. callback: function (data) {
  94. table.bootstrapTable('refresh');
  95. },
  96. visible: function (row) {
  97. return row.audit_status == 1; // 只有审核中状态才显示审核按钮
  98. }
  99. }
  100. ],
  101. formatter: Table.api.formatter.operate
  102. }
  103. ]
  104. ]
  105. });
  106. // 为表格绑定事件
  107. Table.api.bindevent(table);
  108. // 批量通过
  109. $(document).on("click", ".btn-batch-pass", function () {
  110. var ids = Table.api.selectedids(table);
  111. if (ids.length == 0) {
  112. Toastr.error(__('Please select at least one record'));
  113. return false;
  114. }
  115. Layer.confirm(__('Are you sure you want to batch pass these applications?'), function(index) {
  116. Fast.api.ajax({
  117. url: "inspection/application/batchPass",
  118. data: {ids: ids},
  119. type: 'post'
  120. }, function(data, ret) {
  121. table.bootstrapTable('refresh');
  122. Layer.close(index);
  123. });
  124. });
  125. });
  126. // 批量驳回
  127. $(document).on("click", ".btn-batch-reject", function () {
  128. var ids = Table.api.selectedids(table);
  129. if (ids.length == 0) {
  130. Toastr.error(__('Please select at least one record'));
  131. return false;
  132. }
  133. // 弹出驳回原因输入框
  134. Layer.prompt({
  135. title: '批量驳回',
  136. formType: 2,
  137. value: '',
  138. area: ['400px', '200px']
  139. }, function(value, index) {
  140. if (!value || value.trim() == '') {
  141. Toastr.error('请输入驳回原因');
  142. return false;
  143. }
  144. Layer.confirm(__('Are you sure you want to batch reject these applications?'), function(confirmIndex) {
  145. Fast.api.ajax({
  146. url: "inspection/application/batchReject",
  147. data: {ids: ids, reject_reason: value},
  148. type: 'post'
  149. }, function(data, ret) {
  150. table.bootstrapTable('refresh');
  151. Layer.close(index);
  152. Layer.close(confirmIndex);
  153. });
  154. });
  155. });
  156. });
  157. // 单独的详情按钮事件
  158. $(document).on("click", ".btn-detail", function () {
  159. var ids = Table.api.selectedids(table);
  160. if (ids.length != 1) {
  161. Toastr.error(__('Please select one record'));
  162. return false;
  163. }
  164. Fast.api.open("inspection/application/detail/ids/" + ids.join(","), '查看详情', {
  165. area: ['90%', '90%']
  166. });
  167. });
  168. // 单独的审核按钮事件
  169. $(document).on("click", ".btn-audit", function () {
  170. var ids = Table.api.selectedids(table);
  171. if (ids.length != 1) {
  172. Toastr.error(__('Please select one record'));
  173. return false;
  174. }
  175. Fast.api.open("inspection/application/audit/ids/" + ids.join(","), '审核申请', {
  176. area: ['800px', '600px'],
  177. callback: function(data) {
  178. table.bootstrapTable('refresh');
  179. }
  180. });
  181. });
  182. },
  183. detail: function () {
  184. // 详情页面逻辑
  185. Controller.api.bindevent();
  186. },
  187. audit: function () {
  188. // 审核页面逻辑
  189. Controller.api.bindevent();
  190. // 监听审核状态变化
  191. $(document).on('change', 'input[name="audit_status"]', function() {
  192. var status = $(this).val();
  193. if (status == '3') {
  194. // 审核驳回
  195. $('#reject-reason-group').show();
  196. $('#reject_reason').attr('data-rule', 'required');
  197. $('#supplier-group').hide();
  198. $('#c-supplier_id').removeAttr('data-rule');
  199. } else {
  200. // 审核通过
  201. $('#reject-reason-group').hide();
  202. $('#reject_reason').removeAttr('data-rule').val('');
  203. $('#supplier-group').show();
  204. $('#c-supplier_id').attr('data-rule', 'required');
  205. }
  206. });
  207. // 初始化状态
  208. $('input[name="audit_status"]:checked').trigger('change');
  209. },
  210. api: {
  211. bindevent: function () {
  212. Form.api.bindevent($("form[role=form]"));
  213. }
  214. }
  215. };
  216. return Controller;
  217. });