define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'shop/address/index' + location.search,
add_url: 'shop/address/add',
edit_url: 'shop/address/edit',
del_url: 'shop/address/del',
multi_url: 'shop/address/multi',
import_url: 'shop/address/import',
table: 'shop_address',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{
field: 'user.username',
title: __('User'),
operate: 'LIKE',
formatter: function (value, row, index) {
// 显示用户头像和用户名
var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png';
var username = row.user && row.user.username ? row.user.username : '游客';
var userId = row.user_id || '';
// 处理头像URL
var avatarUrl = avatar;
if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
}
return '
' +
'

' +
'
' +
'
' + username + '
' +
'
ID: ' + userId + '
' +
'
' +
'
';
}
},
{field: 'province.name', title: __('Province')},
{field: 'city.name', title: __('City')},
{field: 'area.name', title: __('Area')},
{field: 'receiver', title: __('Receiver'), operate: 'LIKE'},
{field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
{field: 'address', title: __('Address'), operate: 'LIKE'},
// {field: 'zipcode', title: __('Zipcode'), operate: 'LIKE', visible: false},
{field: 'used_nums', title: __('Usednums')},
{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},
{
field: 'is_default',
title: __('Isdefault'),
searchList: Controller.api.parseConfigJson('isdefaultList'),
table: table,
formatter: Table.api.formatter.toggle
},
{field: 'status', title: __('Status'), searchList: Controller.api.parseConfigJson('statusList'), formatter: Table.api.formatter.status},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
recyclebin: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
'dragsort_url': ''
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: 'shop/address/recyclebin' + location.search,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'title', title: __('Title'), align: 'left'},
{
field: 'deletetime',
title: __('Deletetime'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
width: '130px',
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: 'shop/address/restore',
refresh: true
},
{
name: 'Destroy',
text: __('Destroy'),
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
icon: 'fa fa-times',
url: 'shop/address/destroy',
refresh: true
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
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]"));
}
}
};
return Controller;
});