123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- 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',
- fixedColumns: true,
- fixedRightNumber: 1,
- columns: [
- [
- {checkbox: true, width: 50},
- {field: 'id', title: __('Id'), operate: false, sortable: true, width: 80},
- {field: 'name', title: '姓名', operate: 'LIKE', width: 100},
- {field: 'phone', title: '申请手机号', operate: 'LIKE', width: 120},
- {
- field: 'user.username',
- title: __('User'),
- operate: 'LIKE',
- formatter: function (value, row, index) {
- // 显示用户头像和用户名
- var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png';
- var username = row.user && row.user.username ? row.user.username : '游客';
- var userId = row.user_id || '';
-
- // 处理头像URL
- var avatarUrl = avatar;
- if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
- avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
- }
-
- return '<div style="display:flex;align-items:center;">' +
- '<img src="' + avatarUrl + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />' +
- '<div>' +
- '<div style="color:#337ab7;font-weight:bold;">' + username + '</div>' +
- '<div style="color:#999;font-size:12px;">ID: ' + userId + '</div>' +
- '</div>' +
- '</div>';
- }
- },
- {field: 'supplier.name', title: '绑定供应商', operate: false, width: 120, formatter: function(value, row, index) {
- if (row.supplier && row.supplier.name) {
- return '<span class="label label-info">' + row.supplier.name + '</span>';
- }
- return '<span class="text-muted">未绑定</span>';
- }},
- {field: 'id_card', title: '身份证号', operate: false, width: 150},
- {field: 'province_name', title: '省份', operate: false, width: 80},
- {field: 'city_name', title: '城市', operate: false, width: 80},
- {field: 'district_name', title: '区县', operate: false, width: 80},
- {field: 'apply_time_text', title: '申请时间', operate: false, sortable: true, width: 140},
- {field: 'audit_status', title: '审核状态', searchList: {"1":"审核中","2":"审核通过","3":"审核驳回"}, formatter: Table.api.formatter.status, custom: {"1":"warning","2":"success","3":"danger"}, width: 100},
- {field: 'status', title: '状态', searchList: {"0":"禁用","1":"启用"}, table: table, formatter: Table.api.formatter.toggle, width: 80},
- {field: 'audit_time_text', title: '审核时间', operate: false, width: 140},
- {field: 'reject_reason', title: '驳回原因', operate: false, width: 200, formatter: function(value, row, index) {
- return value ? '<span class="text-danger">' + value + '</span>' : '-';
- }},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, width: 150, fixed: 'right',
- 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');
- $('#supplier-group').hide();
- $('#c-supplier_id').removeAttr('data-rule');
- } else {
- // 审核通过
- $('#reject-reason-group').hide();
- $('#reject_reason').removeAttr('data-rule').val('');
- $('#supplier-group').show();
- $('#c-supplier_id').attr('data-rule', 'required');
- }
- });
-
- // 初始化状态
- $('input[name="audit_status"]:checked').trigger('change');
- },
-
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|