123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- 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 '<span class="label label-' + color + '">' + row.bmi + ' (' + level + ')</span>';
- }
- 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('<a href="javascript:;" class="btn btn-xs btn-success btn-detail" data-id="' + row.id + '" title="' + __('Detail') + '"><i class="fa fa-list"></i></a>');
-
- // 测量数据按钮
- buttons.push('<a href="javascript:;" class="btn btn-xs btn-info btn-measurements" data-id="' + row.id + '" title="' + __('Measurements') + '"><i class="fa fa-bar-chart"></i></a>');
-
- // 体型选择按钮
- buttons.push('<a href="javascript:;" class="btn btn-xs btn-warning btn-body-types" data-id="' + row.id + '" title="' + __('Body Types') + '"><i class="fa fa-user"></i></a>');
-
- // AI测量按钮
- buttons.push('<a href="javascript:;" class="btn btn-xs btn-primary btn-ai-measurement" data-id="' + row.id + '" title="' + __('AI Measurement') + '"><i class="fa fa-camera"></i></a>');
-
- // 生成报告按钮
- buttons.push('<a href="javascript:;" class="btn btn-xs btn-purple btn-generate-report" data-id="' + row.id + '" title="' + __('Generate Report') + '"><i class="fa fa-file-text"></i></a>');
-
- // 标准操作按钮
- 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;
- });
|