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

348 行
18 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/post/index' + location.search,
add_url: 'fc/post/add',
edit_url: 'fc/post/edit',
del_url: 'fc/post/del',
multi_url: 'fc/post/multi',
import_url: 'fc/post/import',
table: 'fc_post',
}
});
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: 'title', title: __('Title'), operate: 'LIKE'},
{field: 'category_id', title: '分类', addClass: 'selectpage', extend: "data-source='fc/category/index' data-field='name'", formatter: function (value, row) {
return row.category_name || '-';
}},
{field: 'price', title: __('Price'), operate: 'BETWEEN',
formatter: function (value) {
return (value === null || value === '' || value === undefined) ? '-' : '¥' + value;
}
},
{field: 'price_unit', title: __('Price_unit'), operate: 'LIKE'},
{field: 'area', title: __('Area'), operate: 'LIKE'},
{field: 'audit_status', title: __('Audit_status'),
searchList: {0: __('待审核'), 1: __('已通过'), 2: __('已驳回')},
formatter: Format.statusFormatter({0: __('待审核'), 1: __('已通过'), 2: __('已驳回')}, {0: 'warning', 1: 'success', 2: 'danger'})
},
{field: 'views', title: __('Views')},
{field: 'is_paid', title: __('Is_paid'),
searchList: {0: __('否'), 1: __('是')},
formatter: Format.statusFormatter({0: __('未付费'), 1: __('已付费')}, {0: 'default', 1: 'success'})
},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'content', title: __('Content'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'cover', title: __('Cover'), operate: 'LIKE'},
{field: 'media', title: __('Media'), visible: false},
{field: 'user_id', title: '发布用户', addClass: 'selectpage', extend: "data-source='user/user/index' data-field='nickname'", formatter: function (value, row) {
return row.user_name || '-';
}},
{field: 'address', title: __('Address'), operate: 'LIKE'},
{field: 'contact', title: __('Contact'), operate: 'LIKE'},
{field: 'phone', title: __('Phone'), operate: 'LIKE'},
{field: 'wechat', title: __('Wechat'), operate: 'LIKE'},
{field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
{field: 'amount', title: __('Amount'), operate: 'BETWEEN',
formatter: function (value) {
return (value === null || value === '' || value === undefined) ? '-' : '¥' + value;
}
},
{field: 'pay_type', title: __('Pay_type'),
searchList: {wxpay: __('微信支付'), balance: __('余额支付')},
formatter: function (value) {
var m = {wxpay: __('微信支付'), balance: __('余额支付')};
return m[value] !== undefined ? m[value] : '-';
}
},
{field: 'audit_reason', title: __('Audit_reason'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'likes', title: __('Likes')},
{field: 'comment_count', title: __('Comment_count')},
{field: 'status', title: __('Status'),
searchList: {1: __('正常'), 0: __('已下架')},
formatter: Format.statusFormatter({1: __('正常'), 0: __('已下架')}, {1: 'success', 0: 'default'})
},
{field: 'is_top', title: __('Is_top'),
searchList: {0: __('否'), 1: __('是')},
formatter: Format.statusFormatter({0: __('未置顶'), 1: __('已置顶')}, {0: 'default', 1: 'warning'})
},
{field: 'distance', title: __('Distance')},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, visible: false},
{field: 'deletetime', title: __('Deletetime'), visible: false},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons: [
{
name: 'auditpass',
text: __('AuditPass'),
title: __('AuditPass'),
classname: 'btn btn-xs btn-success btn-click',
visible: function (row) {
return Number(row.audit_status) !== 1;
},
confirm: __('确认审核通过该信息?'),
click: function (options, row) {
Fast.api.ajax({
url: 'fc/post/audit',
data: {ids: row.id, auditStatus: 1}
}, function () {
$('#' + options.tableId).bootstrapTable('refresh');
return false;
});
}
},
{
name: 'auditreject',
text: __('AuditReject'),
title: __('AuditReject'),
classname: 'btn btn-xs btn-danger btn-click',
visible: function (row) {
return Number(row.audit_status) !== 2;
},
click: function (options, row) {
Layer.prompt({title: __('请输入驳回原因'), formType: 2}, function (value, index) {
Fast.api.ajax({
url: 'fc/post/audit',
data: {ids: row.id, auditStatus: 2, reason: value}
}, function () {
$('#' + options.tableId).bootstrapTable('refresh');
return false;
});
Layer.close(index);
});
}
},
{
name: 'offline',
text: __('OfflinePost'),
title: __('OfflinePost'),
classname: 'btn btn-xs btn-warning btn-click',
visible: function (row) {
return Number(row.status) === 1;
},
confirm: __('确认下架该信息?'),
click: function (options, row) {
Fast.api.ajax({
url: 'fc/post/offline',
data: {ids: row.id}
}, function () {
$('#' + options.tableId).bootstrapTable('refresh');
return false;
});
}
},
{
name: 'top',
text: __('TopPost'),
title: __('TopPost'),
classname: 'btn btn-xs btn-info btn-click',
visible: function (row) {
return Number(row.is_top) !== 1;
},
confirm: __('确认置顶该信息?'),
click: function (options, row) {
Fast.api.ajax({
url: 'fc/post/top',
data: {ids: row.id, isTop: 1}
}, function () {
$('#' + options.tableId).bootstrapTable('refresh');
return false;
});
}
},
{
name: 'untop',
text: __('CancelTopPost'),
title: __('CancelTopPost'),
classname: 'btn btn-xs btn-default btn-click',
visible: function (row) {
return Number(row.is_top) === 1;
},
confirm: __('确认取消置顶该信息?'),
click: function (options, row) {
Fast.api.ajax({
url: 'fc/post/top',
data: {ids: row.id, isTop: 0}
}, function () {
$('#' + options.tableId).bootstrapTable('refresh');
return false;
});
}
}
]
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
// 审核通过
$(document).on('click', '.btn-audit-pass', function () {
var ids = Table.api.selectedids(table);
Layer.confirm(__('确认审核通过选中的信息?'), {icon: 3, title: __('提示')}, function (index) {
Fast.api.ajax({
url: 'fc/post/audit',
data: {ids: ids.join(','), auditStatus: 1}
}, function (data) {
table.bootstrapTable('refresh');
return false;
});
Layer.close(index);
});
});
// 审核驳回
$(document).on('click', '.btn-audit-reject', function () {
var ids = Table.api.selectedids(table);
Layer.prompt({title: __('请输入驳回原因'), formType: 2}, function (value, index) {
Fast.api.ajax({
url: 'fc/post/audit',
data: {ids: ids.join(','), auditStatus: 2, reason: value}
}, function (data) {
table.bootstrapTable('refresh');
return false;
});
Layer.close(index);
});
});
// 下架
$(document).on('click', '.btn-offline', function () {
var ids = Table.api.selectedids(table);
Layer.confirm(__('确认下架选中的信息?'), {icon: 3, title: __('提示')}, function (index) {
Fast.api.ajax({
url: 'fc/post/offline',
data: {ids: ids.join(',')}
}, function (data) {
table.bootstrapTable('refresh');
return false;
});
Layer.close(index);
});
});
// 置顶(选中项在用户端首页优先展示)
$(document).on('click', '.btn-top', function () {
var ids = Table.api.selectedids(table);
Layer.confirm(__('确认置顶选中的信息?'), {icon: 3, title: __('提示')}, function (index) {
Fast.api.ajax({
url: 'fc/post/top',
data: {ids: ids.join(','), isTop: 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/post/top',
data: {ids: ids.join(','), isTop: 0}
}, function (data) {
table.bootstrapTable('refresh');
return false;
});
Layer.close(index);
});
});
},
recyclebin: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
'dragsort_url': ''
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: 'fc/post/recyclebin' + location.search,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('SerialNo'), operate: false, sortable: false, align: 'center', width: '70px', class: 'fc-serial', table: table, formatter: Format.serial},
{field: 'title', title: __('Title'), align: 'left'},
{
field: 'deletetime',
title: __('Deletetime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
width: '140px',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'Restore',
text: __('Restore'),
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
icon: 'fa fa-rotate-left',
url: 'fc/post/restore',
refresh: true
},
{
name: 'Destroy',
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
icon: 'fa fa-times',
url: 'fc/post/destroy',
refresh: true
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});