define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], function ($, undefined, Backend, Table, Form, Format) { var Controller = { index: function () { // 初始化表格参数配置(举报工单为用户上报材料,关闭后台直接新增与编辑,防止数据篡改) Table.api.init({ extend: { index_url: 'fc/report/index' + location.search, add_url: '', edit_url: '', del_url: '', multi_url: 'fc/report/multi', table: 'fc_report', } }); var table = $("#table"); // 初始化表格,固定操作列在右侧,只展示核心关键内容 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', fixedColumns: true, fixedRightNumber: 1, columns: [ [ {checkbox: true}, {field: 'id', title: __('SerialNo'), operate: false, sortable: false, align: 'center', width: '70px', class: 'fc-serial', table: table, formatter: Format.serial}, { field: 'target_type', title: '举报类型', width: '90px', align: 'center', searchList: {post: __('信息'), comment: __('评价')}, formatter: function (value) { if (value === 'post') { return '信息举报'; } if (value === 'comment') { return '评价举报'; } return '-'; } }, { field: 'target_title', title: '举报对象', operate: false, sortable: false, formatter: function (value, row) { var title = value ? value : ('目标ID: ' + row.target_id); return '' + title + ''; }, events: { 'click .btn-detail-link': function (e, value, row, index) { e.stopPropagation(); Fast.api.open('fc/report/detail?ids=' + row.id, (row.status === 'handled' ? '举报详情' : '审核处理举报') + ' - #' + row.id, { area: ['880px', '820px'] }); } } }, { field: 'reason', title: __('Reason'), operate: 'LIKE', table: table, width: '120px', formatter: function (value) { return '' + (value || '-') + ''; } }, { field: 'reporter_id', title: '举报人', width: '110px', addClass: 'selectpage', extend: "data-source='user/user/index' data-field='nickname'", formatter: function (value, row) { return row.reporter_name || ('UID:' + value); } }, { field: 'status', title: __('Status'), width: '90px', align: 'center', searchList: {pending: __('待处理'), handled: __('已处理')}, formatter: Format.statusFormatter({pending: __('待处理'), handled: __('已处理')}, {pending: 'warning', handled: 'success'}) }, { field: 'createtime', title: __('Createtime'), width: '150px', operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime }, {field: 'updatetime', title: __('Updatetime'), operate: false, visible: false}, { field: 'operate', title: __('Operate'), table: table, align: 'center', width: '140px', events: Table.api.events.operate, formatter: Table.api.formatter.buttons, buttons: [ { name: 'handle', text: '审核处理', title: function (row) { return '审核处理举报 - #' + row.id; }, icon: 'fa fa-gavel', classname: 'btn btn-xs btn-success btn-dialog', url: 'fc/report/detail', extend: 'data-area=\'["920px", "860px"]\'', visible: function (row) { return row.status !== 'handled'; } }, { name: 'detail', text: '详情', title: function (row) { return '举报详情 - #' + row.id; }, classname: 'btn btn-xs btn-info btn-dialog', icon: 'fa fa-eye', url: 'fc/report/detail', extend: 'data-area=\'["920px", "860px"]\'' } ] } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); // 批量处理 $(document).on('click', '.btn-handle', function () { var ids = Table.api.selectedids(table); if (!ids.length) { Toastr.warning(__('Please select item')); return; } Layer.prompt({title: __('请输入处理备注(可选,将通知举报人)'), formType: 2}, function (value, index) { Fast.api.ajax({ url: 'fc/report/handle', data: {ids: ids.join(','), remark: value, action: 'none'} }, function (data) { table.bootstrapTable('refresh'); return false; }); Layer.close(index); }); }); }, detail: function () { Controller.api.bindevent(); var Layer = window.Layer || (window.parent && window.parent.Layer) || window.layer || (window.parent && window.parent.layer); var Fast = window.Fast || (window.parent && window.parent.Fast) || Backend.api; var Toastr = window.Toastr || (window.parent && window.parent.Toastr); // 1. 动态切换处置话术 $(document).off('change', 'input[name="action"]').on('change', 'input[name="action"]', function () { if ($(this).val() === 'offline') { $('#remark').val('经平台核实情况属实,已予以处置。感谢您的监督与支持!'); } else { $('#remark').val('经平台核实该内容暂未构成违规。感谢您的反馈与对平台的关注!'); } }); // 2. 确认处理并通知用户 $(document).off('click', '#btn-submit-handle').on('click', '#btn-submit-handle', function () { var $btn = $(this); if ($btn.prop('disabled')) return; var form = $('#handle-form'); var data = form.serialize(); var doSubmit = function () { $btn.prop('disabled', true).html(' 正在提交处理...'); Fast.api.ajax({ url: 'fc/report/handle', data: data }, function (res, ret) { if (Toastr) Toastr.success(ret && ret.msg ? ret.msg : '处理成功'); // 1. 立即刷新父级页面或Tab中的列表表格 try { if (window.parent && window.parent.$ && window.parent.$("#table").length) { window.parent.$("#table").bootstrapTable('refresh'); } } catch (e) {} try { if (window.top && window.top.$) { window.top.$('.tab-pane.active iframe').each(function () { if (this.contentWindow && this.contentWindow.$ && this.contentWindow.$("#table").length) { this.contentWindow.$("#table").bootstrapTable('refresh'); } }); } } catch (e) {} // 2. 立即关闭当前弹窗 setTimeout(function () { if (Fast.api && Fast.api.close) { Fast.api.close(); } else if (window.parent && window.parent.layer) { var idx = window.parent.layer.getFrameIndex(window.name); window.parent.layer.close(idx); } }, 350); return false; }, function () { $btn.prop('disabled', false).html(' 确认处理并通知用户'); }); }; if (Layer && Layer.confirm) { Layer.confirm('确定要执行该处置操作吗?系统将自动下发通知给举报人。', { title: '审核处置确认', icon: 3 }, function (index) { Layer.close(index); doSubmit(); }); } else { if (confirm('确定要执行该处置操作吗?系统将自动下发通知给举报人。')) { doSubmit(); } } }); // 3. 取消关闭 $(document).off('click', '#btn-close-handle').on('click', '#btn-close-handle', function () { if (Fast && Fast.api && Fast.api.close) { Fast.api.close(); } else if (parent && parent.layer) { var idx = parent.layer.getFrameIndex(window.name); parent.layer.close(idx); } else { window.close(); } }); // 4. 图片点击大图预览 $(document).off('click', '.fc-evidence-img').on('click', '.fc-evidence-img', function (e) { e.preventDefault(); var src = $(this).attr('src'); if (!src) return; var l = (window.parent && window.parent.Layer) || window.Layer || window.layer || (window.parent && window.parent.layer); if (l && l.open) { l.open({ type: 1, title: false, closeBtn: 1, area: ['auto', 'auto'], skin: 'layui-layer-nobg', shadeClose: true, content: '