123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数
- Table.api.init({
- extend: {
- index_url: 'inspection/application/index' + location.search,
- detail_url: 'inspection/application/detail',
- audit_url: 'inspection/application/audit',
- del_url: 'inspection/application/del',
- multi_url: 'inspection/application/multi',
- dragsort_url: ''
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- sortOrder: 'desc',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id'), operate: false, sortable: true},
- {field: 'name', title: '姓名', operate: 'LIKE'},
- {field: 'phone', title: '联系电话', operate: 'LIKE'},
- {field: 'user.nickname', title: '用户昵称', operate: false},
- {field: 'user.mobile', title: '用户手机', operate: false},
- {field: 'province_name', title: '省份', operate: false},
- {field: 'city_name', title: '城市', operate: false},
- {field: 'district_name', title: '区县', operate: false},
- {field: 'apply_time_text', title: '申请时间', operate: false, sortable: true},
- {field: 'audit_status', title: '审核状态', searchList: {"1":"审核中","2":"审核通过","3":"审核驳回"}, formatter: Table.api.formatter.status, custom: {"1":"warning","2":"success","3":"danger"}},
- {field: 'audit_time_text', title: '审核时间', operate: false},
- {field: 'reject_reason', title: '驳回原因', operate: false, formatter: function(value, row, index) {
- return value ? '<span class="text-danger">' + value + '</span>' : '-';
- }},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
- buttons: [
- {
- name: 'detail',
- title: '查看详情',
- text: '详情',
- classname: 'btn btn-xs btn-info btn-dialog',
- icon: 'fa fa-eye',
- url: 'inspection/application/detail',
- callback: function (data) {
- Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
- },
- visible: function (row) {
- return true;
- }
- },
- {
- name: 'audit',
- title: '审核',
- text: '审核',
- classname: 'btn btn-xs btn-warning btn-dialog',
- icon: 'fa fa-check',
- url: 'inspection/application/audit',
- callback: function (data) {
- table.bootstrapTable('refresh');
- },
- visible: function (row) {
- return row.audit_status == 1; // 只有审核中状态才显示审核按钮
- }
- }
- ],
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- // 批量通过
- $(document).on("click", ".btn-batch-pass", function () {
- var ids = Table.api.selectedids(table);
- if (ids.length == 0) {
- Toastr.error(__('Please select at least one record'));
- return false;
- }
- Layer.confirm(__('Are you sure you want to batch pass these applications?'), function(index) {
- Fast.api.ajax({
- url: "inspection/application/batchPass",
- data: {ids: ids},
- type: 'post'
- }, function(data, ret) {
- table.bootstrapTable('refresh');
- Layer.close(index);
- });
- });
- });
- // 批量驳回
- $(document).on("click", ".btn-batch-reject", function () {
- var ids = Table.api.selectedids(table);
- if (ids.length == 0) {
- Toastr.error(__('Please select at least one record'));
- return false;
- }
-
- // 弹出驳回原因输入框
- Layer.prompt({
- title: '批量驳回',
- formType: 2,
- value: '',
- area: ['400px', '200px']
- }, function(value, index) {
- if (!value || value.trim() == '') {
- Toastr.error('请输入驳回原因');
- return false;
- }
-
- Layer.confirm(__('Are you sure you want to batch reject these applications?'), function(confirmIndex) {
- Fast.api.ajax({
- url: "inspection/application/batchReject",
- data: {ids: ids, reject_reason: value},
- type: 'post'
- }, function(data, ret) {
- table.bootstrapTable('refresh');
- Layer.close(index);
- Layer.close(confirmIndex);
- });
- });
- });
- });
- // 单独的详情按钮事件
- $(document).on("click", ".btn-detail", function () {
- var ids = Table.api.selectedids(table);
- if (ids.length != 1) {
- Toastr.error(__('Please select one record'));
- return false;
- }
- Fast.api.open("inspection/application/detail/ids/" + ids.join(","), '查看详情', {
- area: ['90%', '90%']
- });
- });
- // 单独的审核按钮事件
- $(document).on("click", ".btn-audit", function () {
- var ids = Table.api.selectedids(table);
- if (ids.length != 1) {
- Toastr.error(__('Please select one record'));
- return false;
- }
- Fast.api.open("inspection/application/audit/ids/" + ids.join(","), '审核申请', {
- area: ['800px', '600px'],
- callback: function(data) {
- table.bootstrapTable('refresh');
- }
- });
- });
- },
-
- detail: function () {
- // 详情页面逻辑
- Controller.api.bindevent();
- },
-
- audit: function () {
- // 审核页面逻辑
- Controller.api.bindevent();
-
- // 监听审核状态变化
- $(document).on('change', 'input[name="audit_status"]', function() {
- var status = $(this).val();
- if (status == '3') {
- $('#reject-reason-group').show();
- $('#reject_reason').attr('data-rule', 'required');
- } else {
- $('#reject-reason-group').hide();
- $('#reject_reason').removeAttr('data-rule').val('');
- }
- });
- },
-
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|