文件
fenleixinxi/public/assets/js/backend/fc/comment.js

171 行
9.0 KiB
JavaScript

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/comment/index' + location.search,
add_url: 'fc/comment/add',
edit_url: 'fc/comment/edit',
del_url: 'fc/comment/del',
multi_url: 'fc/comment/multi',
import_url: 'fc/comment/import',
table: 'fc_comment',
}
});
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: 'post_id', title: '信息', addClass: 'selectpage', extend: "data-source='fc/post/index' data-field='title'", formatter: function (value, row) {
return row.post_title || '-';
}},
{field: 'user_id', title: '评价人', addClass: 'selectpage', extend: "data-source='user/user/index' data-field='nickname'", formatter: function (value, row) {
return row.user_name || '-';
}},
{field: 'score', title: __('Score'),
searchList: {1: '1', 2: '2', 3: '3', 4: '4', 5: '5'},
formatter: function (value) {
return (value === null || value === '' || value === undefined) ? '-' : value;
}
},
{field: 'content', title: __('Content'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'reply', title: __('Reply'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'top', title: __('Top'),
searchList: {0: __('否'), 1: __('是')},
formatter: Format.statusFormatter({0: __('否'), 1: __('已置顶')}, {0: 'default', 1: 'warning'})
},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'replytime', title: __('Replytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'),
searchList: {1: __('正常'), 0: __('隐藏')},
formatter: Format.statusFormatter({1: __('正常'), 0: __('隐藏')}, {1: 'success', 0: 'default'})
},
{field: 'images', title: __('Images'), visible: false},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, visible: false},
{
field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
formatter: Table.api.formatter.operate,
buttons: [
{
name: 'reply',
text: __('ReplyComment'),
title: __('ReplyComment'),
classname: 'btn btn-xs btn-success btn-click',
click: function (options, row) {
Layer.prompt({title: __('请输入回复内容'), formType: 2, value: row.reply || ''}, function (value, index) {
Fast.api.ajax({
url: 'fc/comment/reply',
data: {ids: row.id, reply: value}
}, function () {
$('#' + options.tableId).bootstrapTable('refresh');
return false;
});
Layer.close(index);
});
}
},
{
name: 'top',
text: __('TopComment'),
title: __('TopComment'),
classname: 'btn btn-xs btn-info btn-click',
visible: function (row) {
return Number(row.top) !== 1;
},
confirm: __('确认置顶该评价?'),
click: function (options, row) {
Fast.api.ajax({
url: 'fc/comment/top',
data: {ids: row.id, top: 1}
}, function () {
$('#' + options.tableId).bootstrapTable('refresh');
return false;
});
}
},
{
name: 'untop',
text: __('UnTopComment'),
title: __('UnTopComment'),
classname: 'btn btn-xs btn-default btn-click',
visible: function (row) {
return Number(row.top) === 1;
},
confirm: __('确认取消置顶该评价?'),
click: function (options, row) {
Fast.api.ajax({
url: 'fc/comment/top',
data: {ids: row.id, top: 0}
}, function () {
$('#' + options.tableId).bootstrapTable('refresh');
return false;
});
}
}
]
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
// 置顶
$(document).on('click', '.btn-top', function () {
var ids = Table.api.selectedids(table);
Layer.confirm(__('确认置顶选中的评价?'), {icon: 3, title: __('提示')}, function (index) {
Fast.api.ajax({
url: 'fc/comment/top',
data: {ids: ids.join(','), top: 1}
}, function (data) {
table.bootstrapTable('refresh');
return false;
});
Layer.close(index);
});
});
// 取消置顶
$(document).on('click', '.btn-untop', function () {
var ids = Table.api.selectedids(table);
Layer.confirm(__('确认取消置顶选中的评价?'), {icon: 3, title: __('提示')}, function (index) {
Fast.api.ajax({
url: 'fc/comment/top',
data: {ids: ids.join(','), top: 0}
}, function (data) {
table.bootstrapTable('refresh');
return false;
});
Layer.close(index);
});
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});