body_profile.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'body_profile/index' + location.search,
  8. add_url: 'body_profile/add',
  9. edit_url: 'body_profile/edit',
  10. del_url: 'body_profile/del',
  11. multi_url: 'body_profile/multi',
  12. import_url: 'body_profile/import',
  13. table: 'body_profile',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id'), sortable: true},
  28. {
  29. field: 'profile_name',
  30. title: __('Profile name'),
  31. operate: 'LIKE',
  32. table: table,
  33. class: 'autocontent',
  34. formatter: Table.api.formatter.content
  35. },
  36. {
  37. field: 'user.username',
  38. title: __('User'),
  39. operate: false,
  40. formatter: function(value, row, index) {
  41. return row.user ? row.user.username : '-';
  42. }
  43. },
  44. {
  45. field: 'gender',
  46. title: __('Gender'),
  47. searchList: {"1": __("Male"), "2": __("Female")},
  48. formatter: Table.api.formatter.normal
  49. },
  50. {
  51. field: 'is_own',
  52. title: __('Is own'),
  53. searchList: {"1": __("Yes"), "0": __("No")},
  54. formatter: Table.api.formatter.normal
  55. },
  56. {
  57. field: 'relation',
  58. title: __('Relation'),
  59. operate: 'LIKE'
  60. },
  61. {
  62. field: 'age',
  63. title: __('Age'),
  64. operate: 'BETWEEN'
  65. },
  66. {
  67. field: 'height',
  68. title: __('Height'),
  69. operate: 'BETWEEN',
  70. formatter: function(value, row, index) {
  71. return value ? value + 'cm' : '-';
  72. }
  73. },
  74. {
  75. field: 'weight',
  76. title: __('Weight'),
  77. operate: 'BETWEEN',
  78. formatter: function(value, row, index) {
  79. return value ? value + 'kg' : '-';
  80. }
  81. },
  82. {
  83. field: 'bmi',
  84. title: __('BMI'),
  85. operate: false,
  86. formatter: function(value, row, index) {
  87. if (row.bmi && row.bmi > 0) {
  88. var level = row.bmi_level || '';
  89. var color = 'success';
  90. if (level === '偏瘦') color = 'info';
  91. else if (level === '超重') color = 'warning';
  92. else if (level === '肥胖') color = 'danger';
  93. return '<span class="label label-' + color + '">' + row.bmi + ' (' + level + ')</span>';
  94. }
  95. return '-';
  96. }
  97. },
  98. {
  99. field: 'createtime',
  100. title: __('Createtime'),
  101. operate: 'RANGE',
  102. addclass: 'datetimerange',
  103. autocomplete: false,
  104. formatter: Table.api.formatter.datetime
  105. },
  106. {
  107. field: 'operate',
  108. title: __('Operate'),
  109. table: table,
  110. events: Table.api.events.operate,
  111. formatter: function(value, row, index) {
  112. var that = this;
  113. var buttons = [];
  114. // 详情按钮
  115. 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>');
  116. // 测量数据按钮
  117. 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>');
  118. // 体型选择按钮
  119. 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>');
  120. // AI测量按钮
  121. 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>');
  122. // 生成报告按钮
  123. 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>');
  124. // 标准操作按钮
  125. buttons.push(Table.api.formatter.operate.call(that, value, row, index));
  126. return buttons.join(' ');
  127. },
  128. events: $.extend({}, Table.api.events.operate, {
  129. 'click .btn-detail': function (e, value, row, index) {
  130. e.stopPropagation();
  131. e.preventDefault();
  132. Fast.api.open('body_profile/detail?ids=' + row.id, __('Detail'), {
  133. area: ['90%', '90%']
  134. });
  135. },
  136. 'click .btn-measurements': function (e, value, row, index) {
  137. e.stopPropagation();
  138. e.preventDefault();
  139. Fast.api.open('body_profile/measurements?profile_id=' + row.id, __('Measurements'), {
  140. area: ['90%', '90%']
  141. });
  142. },
  143. 'click .btn-body-types': function (e, value, row, index) {
  144. e.stopPropagation();
  145. e.preventDefault();
  146. Fast.api.open('body_profile/bodyTypes?profile_id=' + row.id, __('Body Types'), {
  147. area: ['90%', '90%']
  148. });
  149. },
  150. 'click .btn-ai-measurement': function (e, value, row, index) {
  151. e.stopPropagation();
  152. e.preventDefault();
  153. Fast.api.open('body_profile/aiMeasurement?profile_id=' + row.id, __('AI Measurement'), {
  154. area: ['90%', '90%']
  155. });
  156. },
  157. 'click .btn-generate-report': function (e, value, row, index) {
  158. e.stopPropagation();
  159. e.preventDefault();
  160. Layer.confirm(__('Are you sure you want to generate AI report?'), function(index) {
  161. Fast.api.ajax({
  162. url: 'body_profile/generateReport',
  163. data: {profile_id: row.id}
  164. }, function(data, ret) {
  165. Layer.close(index);
  166. if (ret.data && ret.data.report_id) {
  167. Fast.api.open('body_profile/viewReport?report_id=' + ret.data.report_id, __('AI Report'), {
  168. area: ['90%', '90%']
  169. });
  170. }
  171. });
  172. });
  173. }
  174. })
  175. }
  176. ]
  177. ]
  178. });
  179. // 为表格绑定事件
  180. Table.api.bindevent(table);
  181. // 绑定统计按钮事件
  182. $(document).on('click', '.btn-statistics', function() {
  183. Fast.api.open('body_profile/statistics', __('Statistics'), {
  184. area: ['90%', '90%']
  185. });
  186. });
  187. },
  188. add: function () {
  189. Controller.api.bindevent();
  190. },
  191. edit: function () {
  192. Controller.api.bindevent();
  193. },
  194. detail: function () {
  195. // 详情页面初始化
  196. },
  197. measurements: function () {
  198. // 测量数据管理页面初始化
  199. Table.api.init({
  200. extend: {
  201. index_url: 'body_profile/measurements' + location.search,
  202. add_url: 'body_profile/addMeasurement' + location.search,
  203. edit_url: 'body_profile/editMeasurement',
  204. del_url: 'body_profile/delMeasurement',
  205. table: 'body_measurements',
  206. }
  207. });
  208. var table = $("#table");
  209. table.bootstrapTable({
  210. url: $.fn.bootstrapTable.defaults.extend.index_url,
  211. pk: 'id',
  212. sortName: 'measurement_date',
  213. sortOrder: 'desc',
  214. columns: [
  215. [
  216. {checkbox: true},
  217. {field: 'id', title: __('Id')},
  218. {
  219. field: 'measurement_date',
  220. title: __('Measurement Date'),
  221. operate: 'RANGE',
  222. addclass: 'datetimerange',
  223. formatter: Table.api.formatter.datetime
  224. },
  225. {field: 'height', title: __('Height'), formatter: function(value) { return value ? value + 'cm' : '-'; }},
  226. {field: 'weight', title: __('Weight'), formatter: function(value) { return value ? value + 'kg' : '-'; }},
  227. {field: 'chest', title: __('Chest'), formatter: function(value) { return value ? value + 'cm' : '-'; }},
  228. {field: 'waist', title: __('Waist'), formatter: function(value) { return value ? value + 'cm' : '-'; }},
  229. {field: 'hip', title: __('Hip'), formatter: function(value) { return value ? value + 'cm' : '-'; }},
  230. {
  231. field: 'operate',
  232. title: __('Operate'),
  233. table: table,
  234. events: Table.api.events.operate,
  235. formatter: Table.api.formatter.operate
  236. }
  237. ]
  238. ]
  239. });
  240. Table.api.bindevent(table);
  241. },
  242. bodyTypes: function () {
  243. // 体型选择页面初始化
  244. Form.api.bindevent($("form[role=form]"));
  245. },
  246. aiMeasurement: function () {
  247. // AI测量页面初始化
  248. },
  249. statistics: function () {
  250. // 统计页面初始化
  251. },
  252. api: {
  253. bindevent: function () {
  254. Form.api.bindevent($("form[role=form]"));
  255. // 身体照片上传
  256. $(document).on('change', 'input[name="row[body_photos][]"]', function() {
  257. // 处理多图片上传预览
  258. });
  259. // 档案照片上传
  260. $(document).on('change', 'input[name="row[profile_photo]"]', function() {
  261. // 处理单图片上传预览
  262. });
  263. }
  264. }
  265. };
  266. return Controller;
  267. });