body_profile.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. table: 'body_profile',
  9. }
  10. });
  11. var table = $("#table");
  12. // 初始化表格
  13. table.bootstrapTable({
  14. url: $.fn.bootstrapTable.defaults.extend.index_url,
  15. pk: 'id',
  16. sortName: 'id',
  17. fixedColumns: true,
  18. fixedRightNumber: 1,
  19. columns: [
  20. [
  21. {checkbox: true},
  22. {field: 'id', title: __('Id'), sortable: true},
  23. {
  24. field: 'profile_name',
  25. title: __('Profile name'),
  26. operate: 'LIKE',
  27. table: table,
  28. class: 'autocontent',
  29. formatter: Table.api.formatter.content
  30. },
  31. {
  32. field: 'user.username',
  33. title: __('User'),
  34. operate: false,
  35. formatter: function(value, row, index) {
  36. return row.user ? row.user.username : '-';
  37. }
  38. },
  39. {
  40. field: 'gender',
  41. title: __('Gender'),
  42. searchList: {"1": __("Male"), "2": __("Female")},
  43. formatter: Table.api.formatter.normal
  44. },
  45. {
  46. field: 'is_own',
  47. title: __('Is own'),
  48. searchList: {"1": __("Yes"), "0": __("No")},
  49. formatter: Table.api.formatter.normal
  50. },
  51. // {
  52. // field: 'relation',
  53. // title: __('Relation'),
  54. // operate: 'LIKE'
  55. // },
  56. {
  57. field: 'age',
  58. title: __('Age'),
  59. operate: 'BETWEEN'
  60. },
  61. {
  62. field: 'height',
  63. title: __('Height'),
  64. operate: 'BETWEEN',
  65. formatter: function(value, row, index) {
  66. return value ? value + 'cm' : '-';
  67. }
  68. },
  69. {
  70. field: 'weight',
  71. title: __('Weight'),
  72. operate: 'BETWEEN',
  73. formatter: function(value, row, index) {
  74. return value ? value + 'kg' : '-';
  75. }
  76. },
  77. // {
  78. // field: 'bmi',
  79. // title: __('BMI'),
  80. // operate: false,
  81. // formatter: function(value, row, index) {
  82. // if (row.bmi && row.bmi > 0) {
  83. // var level = row.bmi_level || '';
  84. // var color = 'success';
  85. // if (level === '偏瘦') color = 'info';
  86. // else if (level === '超重') color = 'warning';
  87. // else if (level === '肥胖') color = 'danger';
  88. // return '<span class="label label-' + color + '">' + row.bmi + ' (' + level + ')</span>';
  89. // }
  90. // return '-';
  91. // }
  92. // },
  93. {
  94. field: 'createtime',
  95. title: __('Createtime'),
  96. operate: 'RANGE',
  97. addclass: 'datetimerange',
  98. autocomplete: false,
  99. formatter: Table.api.formatter.datetime
  100. },
  101. {
  102. field: 'operate',
  103. title: __('Operate'),
  104. table: table,
  105. events: Table.api.events.operate,
  106. formatter: function(value, row, index) {
  107. var that = this;
  108. var buttons = [];
  109. // 详情按钮
  110. 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>');
  111. return buttons.join(' ');
  112. },
  113. events: $.extend({}, Table.api.events.operate, {
  114. 'click .btn-detail': function (e, value, row, index) {
  115. e.stopPropagation();
  116. e.preventDefault();
  117. Fast.api.open('body_profile/detail?ids=' + row.id, __('Detail'), {
  118. area: ['90%', '90%']
  119. });
  120. }
  121. })
  122. }
  123. ]
  124. ]
  125. });
  126. // 为表格绑定事件
  127. Table.api.bindevent(table);
  128. },
  129. detail: function () {
  130. // 详情页面初始化
  131. }
  132. };
  133. return Controller;
  134. });