define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var timestamp = new Date().getTime()/1000;
var condition = '';
var nowTime = 0;
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: Config.urlPath,
table: 'user',
},
});
$('#editKandian').click(function(){
Fast.api.open('/admin/auth/user/kandian','批量修改书币');
});
// 初始化表格
var table = $("#table");
if(Config.group>2 && Config.group!=5){
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
showToggle:false,
searchFormVisible:true,
search:false,
columns: [
[
{field: 'avatar', title: __('头像'), formatter: Table.api.formatter.image, operate: false},
{field: 'id', title: __('Id')},
{field: 'nickname', title: __('Nickname'),operate:false,formatter: Controller.api.formatter.nickname},
{field: 'province', title: __('省/市'),operate:false,formatter: Controller.api.formatter.province},
{field: 'is_pay', title: __('充值状态'), searchList: {'0': '未充值', '1':'已充值'}, style: 'min-width:100px;',formatter: Controller.api.formatter.is_pay},
{field: 'vip_endtime', title: __('VIP状态'),operate:false,style: 'min-width:100px;',formatter: Controller.api.formatter.vip_endtime },
{field: 'vip_endtime', title: __('vip结束时间'),formatter: Table.api.formatter.datetime,operate:false},
{field: 'sex', title: __('性别'),searchList: {'0': '未知', '1':'男','2':'女'}, style: 'min-width:100px;', formatter: Controller.api.formatter.sex},
{field: 'is_subscribe', title: __('服务号关注状态'), searchList: {'0': '未关注', '1':'已关注'}, style: 'min-width:100px;',formatter: Controller.api.formatter.is_subscribe},
{field: 'subscription_extend', title: __('导粉号关注状态'),style: 'min-width:100px;',formatter: Controller.api.formatter.subscription_extend},
{field: 'operate_time', title: __('服务号交互时间'),formatter: Table.api.formatter.datetime,operate:false},
{field: 'state_text', title: __('状态'), operate:false},
{field: 'createtime', title: __('注册时间'),formatter: Table.api.formatter.datetime,operate:false},
{field: 'id', title: __('操作'), table: table, buttons: [
{name: 'detail', text: '查看详情', title: '详情', icon: 'fa fa-flash', classname: 'btn btn-xs btn-primary btn-dialog', url: '/admin/auth/user/detail'}
], operate:false, formatter: Table.api.formatter.buttons}
]
]
});
}else{
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
showToggle:false,
searchFormVisible:true,
search:false,
columns: [
[
{field: 'avatar', title: __('头像'), formatter: Table.api.formatter.image, operate: false},
{field: 'id', title: __('Id')},
{field: 'nickname', title: __('Nickname'),operate:false,formatter: Controller.api.formatter.nickname},
{field: 'province', title: __('省/市'),operate:false,formatter: Controller.api.formatter.province},
{field: 'is_pay', title: __('充值状态'), searchList: {'0': '未充值', '1':'已充值'}, style: 'min-width:100px;',formatter: Controller.api.formatter.is_pay},
{field: 'vip_endtime', title: __('VIP状态'),operate:false,style: 'min-width:100px;',formatter: Controller.api.formatter.vip_endtime },
{field: 'vip_endtime', title: __('vip结束时间'),formatter: Table.api.formatter.datetime,operate:false},
{field: 'sex', title: __('性别'),searchList: {'0': '未知', '1':'男','2':'女'}, style: 'min-width:100px;', formatter: Controller.api.formatter.sex},
{field: 'is_subscribe', title: __('服务号关注状态'), searchList: {'0': '未关注', '1':'已关注'}, style: 'min-width:100px;',formatter: Controller.api.formatter.is_subscribe},
{field: 'subscription_extend', title: __('导粉号关注状态'),style: 'min-width:100px;',formatter: Controller.api.formatter.subscription_extend},
{field: 'operate_time', title: __('服务号交互时间'),formatter: Table.api.formatter.datetime,operate:false},
{field: 'kandian', title: __('永久书币'),operate:false},
{field: 'state_text', title: __('状态'), operate:false},
{field: 'createtime', title: __('注册时间'),formatter: Table.api.formatter.datetime,operate:false},
{field: 'id', title: __('操作'), table: table, buttons: [
{name: 'detail', text: '修改书币', title: '修改书币',icon: 'fa fa-list', classname: 'btn btn-xs btn-primary btn-dialog', url: '/admin/auth/user/kandian', callback:function(data){}},
{name: 'detail', text: '查看详情', title: '详情', icon: 'fa fa-flash', classname: 'btn btn-xs btn-primary btn-dialog', url: '/admin/auth/user/detail'}
], operate:false, formatter: Table.api.formatter.buttons}
]
]
});
}
// 为表格绑定事件
Table.api.bindevent(table);
Controller.api.bindevent();
//自定义搜索VIP状态
$(document).on("change", ".selectVipStatus", function () {
var options = table.bootstrapTable('getOptions');
if($(this).val()==0){ //显示全部
condition = '>=';
nowTime = 0;
}else if ($(this).val()==1){ //只显示vip
condition = '>';
nowTime = timestamp;
}else if ($(this).val()==2){ //只显示非vip
condition = '<';
nowTime = timestamp;
}
options.pageNumber = 1;
options.queryParams = function (params) {
return {
search: params.search,
sort: params.sort,
order: params.order,
filter: JSON.stringify({vip_endtime: nowTime}),
op: JSON.stringify({vip_endtime: condition}),
offset: params.offset,
limit: params.limit,
};
};
table.bootstrapTable('refresh', {});
return false;
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
kandian:function () {
Controller.api.bindevent();
},
disable:function(){
Form.api.bindevent($("form[role=form]"), function (data) {
parent.location.reload();
});
},
batchisdisabled:function(){
Form.api.bindevent($("form[role=form]"), function (data) {
parent.location.reload();
},null,function(){
let ids = $("textarea[name='row[id]'").val();
$("textarea[name='row[id]'").val(ids.replace(/[\r\n]/g, ","));
return true;
});
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},formatter:{
sex:function (value,row,index) {
return row.sex_text;
},
is_pay:function (value,row,index) {
return row.is_pay_text;
},
is_subscribe:function (value,row,index) {
return row.is_subscribe_text;
},
subscription_extend:function (value,row,index) {
if(value==1){
return '已关注';
}else{
return '未关注';
}
},
vip_endtime:function(value,row,index){
if (value >= timestamp){
row.vip_endtime_text = 'VIP';
}else{
row.vip_endtime_text = '否';
}
return row.vip_endtime_text;
},
nickname:function(value,row,index){
return row.nickname+' ';
},
province:function(value,row,index){
return row.province+'/'+ row.city;
}
}
}
};
return Controller;
});