123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'shop/comment/index' + location.search,
- add_url: 'shop/comment/add',
- edit_url: 'shop/comment/edit',
- del_url: 'shop/comment/del',
- multi_url: 'shop/comment/multi',
- import_url: 'shop/comment/import',
- table: 'shop_comment',
- }
- });
- var table = $("#table");
- // 绑定评价状态tab事件
- $('.panel-heading .nav-tabs[data-field="evaluate_status"] a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- var value = $(this).data("value");
- var options = table.bootstrapTable('getOptions');
- var queryParams = options.queryParams;
- options.pageNumber = 1;
- options.queryParams = function (params) {
- if (value) {
- params.filter = JSON.stringify({evaluate_status: value});
- params.op = JSON.stringify({evaluate_status: '='});
- }
- params = queryParams.call(this, params);
- return params;
- };
- table.bootstrapTable('refresh', {});
- return false;
- });
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- fixedColumns: true,
- fixedRightNumber: 1,
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search,visible: false},
- {
- field: 'user.username',
- title: __('User_id'),
- operate: 'LIKE',
- formatter: function (value, row, index) {
- // 显示用户头像和用户名
- console.log(row);
- var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png';
- var username = row.user && row.user.username ? row.user.username : '游客';
-
- return '<div style="display:flex;align-items:center;">' +
- '<img src="' + avatar + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />' +
- '<span style="color:#a55bff;">' + username + '</span>' +
- '</div>';
- }
- },
- {field: 'order_id', title: __('Order_id')},
- // {field: 'pid', title: __('Pid')},
- {field: 'goods.title', title: __('Goods')},
- {field: 'star', title: __('Star')},
- {field: 'content', title: __('Content'), formatter: Controller.api.content},
- {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
- // {field: 'subscribe', title: __('Subscribe')},
- {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
- {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, visible: false},
- {field: 'status', title: __('Status'), searchList: Controller.api.parseConfigJson('statusSearchList'), formatter: Table.api.formatter.status},
- {
- field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
- buttons: [
- {
- name: '审核通过',
- title: '审核通过',
- classname: 'btn btn-xs btn-success btn-ajax',
- text: '审核通过',
- icon: 'fa fa-check',
- url: 'shop/comment/audit/evaluate_status/2',
- visible: function (row) {
- //返回true时按钮显示,返回false隐藏
- return row.evaluate_status == 1;
- },
- confirm: '确认审核通过吗',
- success: function (data, ret) {
- Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
- //如果需要阻止成功提示,则必须使用return false;
- //return false;
- },
- error: function (data, ret) {
- console.log(data, ret);
- Layer.alert(ret.msg);
- return false;
- }
- },
- {
- name: '审核拒绝',
- title: '审核拒绝',
- classname: 'btn btn-xs btn-danger btn-ajax',
- text: '审核拒绝',
- icon: 'fa fa-close',
- url: 'shop/comment/audit/evaluate_status/3',
- visible: function (row) {
- //返回true时按钮显示,返回false隐藏
- return row.evaluate_status == 1;
- },
- confirm: '确认审核拒绝吗',
- success: function (data, ret) {
- Layer.alert(ret.msg + ",返回数据:" + JSON.stringify(data));
- //如果需要阻止成功提示,则必须使用return false;
- //return false;
- },
- error: function (data, ret) {
- console.log(data, ret);
- Layer.alert(ret.msg);
- return false;
- }
- },
- // {
- // name: '回复',
- // title: function (row) {
- // return '回复(' + (row.user ? row.user.nickname : '未知') + ')';
- // },
- // classname: 'btn btn-xs btn-primary btn-dialog',
- // text: function (row) {
- // return '回复(' + row.comments + ')';
- // },
- // icon: 'fa fa-comment',
- // url: 'shop/comment/reply/pid/{id}'
- // }
- ]
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- reply: function () {
- let refresh = function () {
- window.location.reload();
- parent.$("#table").bootstrapTable('refresh', {});
- }
- $(document).on('click', '.btn-reply', function () {
- Form.api.submit($("form[role=form]"));
- setTimeout(refresh, 1500)
- })
- $('.btn-delone').data('success', refresh)
- $('.btn-dialog').data('end', refresh)
- Controller.api.bindevent();
- },
- api: {
- // 解析Config中的JSON字符串的辅助函数
- parseConfigJson: function(configKey, defaultValue) {
- var configValue = Config[configKey] || defaultValue || {};
-
- // 如果是字符串,尝试解析JSON
- if (typeof configValue === 'string') {
- try {
- return JSON.parse(configValue);
- } catch (e) {
- return defaultValue || {};
- }
- }
- return configValue;
- },
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- },
- content: function (value, row, index) {
- var width = this.width != undefined ? (this.width.match(/^\d+$/) ? this.width + "px" : this.width) : "250px";
- return "<div style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + ";' title='" + value + "' data-toggle='tooltip' data-placement='right'>" + value + "</div>";
- }
- }
- };
- return Controller;
- });
|