application.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. {field: 'user.nickname', title: '用户昵称', operate: false, width: 100},
  31. {field: 'user.mobile', title: '用户手机', operate: false, width: 120},
  32. {field: 'supplier.name', title: '绑定供应商', operate: false, width: 120, formatter: function(value, row, index) {
  33. if (row.supplier && row.supplier.name) {
  34. return '<span class="label label-info">' + row.supplier.name + '</span>';
  35. }
  36. return '<span class="text-muted">未绑定</span>';
  37. }},
  38. {field: 'id_card', title: '身份证号', operate: false, width: 150},
  39. {field: 'province_name', title: '省份', operate: false, width: 80},
  40. {field: 'city_name', title: '城市', operate: false, width: 80},
  41. {field: 'district_name', title: '区县', operate: false, width: 80},
  42. {field: 'apply_time_text', title: '申请时间', operate: false, sortable: true, width: 140},
  43. {field: 'audit_status', title: '审核状态', searchList: {"1":"审核中","2":"审核通过","3":"审核驳回"}, formatter: Table.api.formatter.status, custom: {"1":"warning","2":"success","3":"danger"}, width: 100},
  44. {field: 'audit_time_text', title: '审核时间', operate: false, width: 140},
  45. {field: 'reject_reason', title: '驳回原因', operate: false, width: 200, formatter: function(value, row, index) {
  46. return value ? '<span class="text-danger">' + value + '</span>' : '-';
  47. }},
  48. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, width: 150, fixed: 'right',
  49. buttons: [
  50. {
  51. name: 'detail',
  52. title: '查看详情',
  53. text: '详情',
  54. classname: 'btn btn-xs btn-info btn-dialog',
  55. icon: 'fa fa-eye',
  56. url: 'inspection/application/detail',
  57. callback: function (data) {
  58. Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  59. },
  60. visible: function (row) {
  61. return true;
  62. }
  63. },
  64. {
  65. name: 'audit',
  66. title: '审核',
  67. text: '审核',
  68. classname: 'btn btn-xs btn-warning btn-dialog',
  69. icon: 'fa fa-check',
  70. url: 'inspection/application/audit',
  71. callback: function (data) {
  72. table.bootstrapTable('refresh');
  73. },
  74. visible: function (row) {
  75. return row.audit_status == 1; // 只有审核中状态才显示审核按钮
  76. }
  77. }
  78. ],
  79. formatter: Table.api.formatter.operate
  80. }
  81. ]
  82. ]
  83. });
  84. // 为表格绑定事件
  85. Table.api.bindevent(table);
  86. // 批量通过
  87. $(document).on("click", ".btn-batch-pass", function () {
  88. var ids = Table.api.selectedids(table);
  89. if (ids.length == 0) {
  90. Toastr.error(__('Please select at least one record'));
  91. return false;
  92. }
  93. Layer.confirm(__('Are you sure you want to batch pass these applications?'), function(index) {
  94. Fast.api.ajax({
  95. url: "inspection/application/batchPass",
  96. data: {ids: ids},
  97. type: 'post'
  98. }, function(data, ret) {
  99. table.bootstrapTable('refresh');
  100. Layer.close(index);
  101. });
  102. });
  103. });
  104. // 批量驳回
  105. $(document).on("click", ".btn-batch-reject", function () {
  106. var ids = Table.api.selectedids(table);
  107. if (ids.length == 0) {
  108. Toastr.error(__('Please select at least one record'));
  109. return false;
  110. }
  111. // 弹出驳回原因输入框
  112. Layer.prompt({
  113. title: '批量驳回',
  114. formType: 2,
  115. value: '',
  116. area: ['400px', '200px']
  117. }, function(value, index) {
  118. if (!value || value.trim() == '') {
  119. Toastr.error('请输入驳回原因');
  120. return false;
  121. }
  122. Layer.confirm(__('Are you sure you want to batch reject these applications?'), function(confirmIndex) {
  123. Fast.api.ajax({
  124. url: "inspection/application/batchReject",
  125. data: {ids: ids, reject_reason: value},
  126. type: 'post'
  127. }, function(data, ret) {
  128. table.bootstrapTable('refresh');
  129. Layer.close(index);
  130. Layer.close(confirmIndex);
  131. });
  132. });
  133. });
  134. });
  135. // 单独的详情按钮事件
  136. $(document).on("click", ".btn-detail", function () {
  137. var ids = Table.api.selectedids(table);
  138. if (ids.length != 1) {
  139. Toastr.error(__('Please select one record'));
  140. return false;
  141. }
  142. Fast.api.open("inspection/application/detail/ids/" + ids.join(","), '查看详情', {
  143. area: ['90%', '90%']
  144. });
  145. });
  146. // 单独的审核按钮事件
  147. $(document).on("click", ".btn-audit", function () {
  148. var ids = Table.api.selectedids(table);
  149. if (ids.length != 1) {
  150. Toastr.error(__('Please select one record'));
  151. return false;
  152. }
  153. Fast.api.open("inspection/application/audit/ids/" + ids.join(","), '审核申请', {
  154. area: ['800px', '600px'],
  155. callback: function(data) {
  156. table.bootstrapTable('refresh');
  157. }
  158. });
  159. });
  160. },
  161. detail: function () {
  162. // 详情页面逻辑
  163. Controller.api.bindevent();
  164. },
  165. audit: function () {
  166. // 审核页面逻辑
  167. Controller.api.bindevent();
  168. // 监听审核状态变化
  169. $(document).on('change', 'input[name="audit_status"]', function() {
  170. var status = $(this).val();
  171. if (status == '3') {
  172. // 审核驳回
  173. $('#reject-reason-group').show();
  174. $('#reject_reason').attr('data-rule', 'required');
  175. $('#supplier-group').hide();
  176. $('#c-supplier_id').removeAttr('data-rule');
  177. } else {
  178. // 审核通过
  179. $('#reject-reason-group').hide();
  180. $('#reject_reason').removeAttr('data-rule').val('');
  181. $('#supplier-group').show();
  182. $('#c-supplier_id').attr('data-rule', 'required');
  183. }
  184. });
  185. // 初始化状态
  186. $('input[name="audit_status"]:checked').trigger('change');
  187. },
  188. api: {
  189. bindevent: function () {
  190. Form.api.bindevent($("form[role=form]"));
  191. }
  192. }
  193. };
  194. return Controller;
  195. });