define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'body_profile/index' + location.search,
add_url: 'body_profile/add',
edit_url: 'body_profile/edit',
del_url: 'body_profile/del',
multi_url: 'body_profile/multi',
import_url: 'body_profile/import',
table: 'body_profile',
}
});
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: __('Id'), sortable: true},
{
field: 'profile_name',
title: __('Profile name'),
operate: 'LIKE',
table: table,
class: 'autocontent',
formatter: Table.api.formatter.content
},
{
field: 'user.username',
title: __('User'),
operate: false,
formatter: function(value, row, index) {
return row.user ? row.user.username : '-';
}
},
{
field: 'gender',
title: __('Gender'),
searchList: {"1": __("Male"), "2": __("Female")},
formatter: Table.api.formatter.normal
},
{
field: 'is_own',
title: __('Is own'),
searchList: {"1": __("Yes"), "0": __("No")},
formatter: Table.api.formatter.normal
},
{
field: 'relation',
title: __('Relation'),
operate: 'LIKE'
},
{
field: 'age',
title: __('Age'),
operate: 'BETWEEN'
},
{
field: 'height',
title: __('Height'),
operate: 'BETWEEN',
formatter: function(value, row, index) {
return value ? value + 'cm' : '-';
}
},
{
field: 'weight',
title: __('Weight'),
operate: 'BETWEEN',
formatter: function(value, row, index) {
return value ? value + 'kg' : '-';
}
},
{
field: 'bmi',
title: __('BMI'),
operate: false,
formatter: function(value, row, index) {
if (row.bmi && row.bmi > 0) {
var level = row.bmi_level || '';
var color = 'success';
if (level === '偏瘦') color = 'info';
else if (level === '超重') color = 'warning';
else if (level === '肥胖') color = 'danger';
return '' + row.bmi + ' (' + level + ')';
}
return '-';
}
},
{
field: 'createtime',
title: __('Createtime'),
operate: 'RANGE',
addclass: 'datetimerange',
autocomplete: false,
formatter: Table.api.formatter.datetime
},
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: function(value, row, index) {
var that = this;
var buttons = [];
// 详情按钮
buttons.push('');
// 测量数据按钮
buttons.push('');
// 体型选择按钮
buttons.push('');
// AI测量按钮
buttons.push('');
// 生成报告按钮
buttons.push('');
// 标准操作按钮
buttons.push(Table.api.formatter.operate.call(that, value, row, index));
return buttons.join(' ');
},
events: $.extend({}, Table.api.events.operate, {
'click .btn-detail': function (e, value, row, index) {
e.stopPropagation();
e.preventDefault();
Fast.api.open('body_profile/detail?ids=' + row.id, __('Detail'), {
area: ['90%', '90%']
});
},
'click .btn-measurements': function (e, value, row, index) {
e.stopPropagation();
e.preventDefault();
Fast.api.open('body_profile/measurements?profile_id=' + row.id, __('Measurements'), {
area: ['90%', '90%']
});
},
'click .btn-body-types': function (e, value, row, index) {
e.stopPropagation();
e.preventDefault();
Fast.api.open('body_profile/bodyTypes?profile_id=' + row.id, __('Body Types'), {
area: ['90%', '90%']
});
},
'click .btn-ai-measurement': function (e, value, row, index) {
e.stopPropagation();
e.preventDefault();
Fast.api.open('body_profile/aiMeasurement?profile_id=' + row.id, __('AI Measurement'), {
area: ['90%', '90%']
});
},
'click .btn-generate-report': function (e, value, row, index) {
e.stopPropagation();
e.preventDefault();
Layer.confirm(__('Are you sure you want to generate AI report?'), function(index) {
Fast.api.ajax({
url: 'body_profile/generateReport',
data: {profile_id: row.id}
}, function(data, ret) {
Layer.close(index);
if (ret.data && ret.data.report_id) {
Fast.api.open('body_profile/viewReport?report_id=' + ret.data.report_id, __('AI Report'), {
area: ['90%', '90%']
});
}
});
});
}
})
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
// 绑定统计按钮事件
$(document).on('click', '.btn-statistics', function() {
Fast.api.open('body_profile/statistics', __('Statistics'), {
area: ['90%', '90%']
});
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
detail: function () {
// 详情页面初始化
},
measurements: function () {
// 测量数据管理页面初始化
Table.api.init({
extend: {
index_url: 'body_profile/measurements' + location.search,
add_url: 'body_profile/addMeasurement' + location.search,
edit_url: 'body_profile/editMeasurement',
del_url: 'body_profile/delMeasurement',
table: 'body_measurements',
}
});
var table = $("#table");
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'measurement_date',
sortOrder: 'desc',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{
field: 'measurement_date',
title: __('Measurement Date'),
operate: 'RANGE',
addclass: 'datetimerange',
formatter: Table.api.formatter.datetime
},
{field: 'height', title: __('Height'), formatter: function(value) { return value ? value + 'cm' : '-'; }},
{field: 'weight', title: __('Weight'), formatter: function(value) { return value ? value + 'kg' : '-'; }},
{field: 'chest', title: __('Chest'), formatter: function(value) { return value ? value + 'cm' : '-'; }},
{field: 'waist', title: __('Waist'), formatter: function(value) { return value ? value + 'cm' : '-'; }},
{field: 'hip', title: __('Hip'), formatter: function(value) { return value ? value + 'cm' : '-'; }},
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
formatter: Table.api.formatter.operate
}
]
]
});
Table.api.bindevent(table);
},
bodyTypes: function () {
// 体型选择页面初始化
Form.api.bindevent($("form[role=form]"));
},
aiMeasurement: function () {
// AI测量页面初始化
},
statistics: function () {
// 统计页面初始化
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
// 身体照片上传
$(document).on('change', 'input[name="row[body_photos][]"]', function() {
// 处理多图片上传预览
});
// 档案照片上传
$(document).on('change', 'input[name="row[profile_photo]"]', function() {
// 处理单图片上传预览
});
}
}
};
return Controller;
});