ranking.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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: 'customcharts/ranking/index' + location.search,
  8. add_url: 'customcharts/ranking/add',
  9. edit_url: 'customcharts/ranking/edit',
  10. del_url: 'customcharts/ranking/del',
  11. multi_url: 'customcharts/ranking/multi',
  12. table: 'customcharts_ranking',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'weigh',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'title', title: __('Title')},
  26. {field: 'name', title: __('Name')},
  27. {field: 'field_total', title: __('Field_total')},
  28. {field: 'type_total', title: __('Type_total'), searchList: {"sum":__('Sum'),"count":__('Count')}, formatter: Table.api.formatter.normal},
  29. {field: 'group_field', title: __('Group_field')},
  30. {field: 'field_time', title: __('Field_time')},
  31. {field: 'type_time', title: __('Type_time'), searchList: {"today":__('Today'),"week":__('Week'),"month":__('Month')}, formatter: Table.api.formatter.normal},
  32. {field: 'unit', title: __('Unit')},
  33. {field: 'show_num', title: __('Show_num')},
  34. {field: 'where', title: __('Where')},
  35. {field: 'weigh', title: __('Weigh')},
  36. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  37. ]
  38. ]
  39. });
  40. // 为表格绑定事件
  41. Table.api.bindevent(table);
  42. },
  43. add: function () {
  44. Controller.api.bindevent();
  45. },
  46. edit: function () {
  47. Controller.api.bindevent();
  48. },
  49. api: {
  50. bindevent: function () {
  51. Form.api.bindevent($("form[role=form]"));
  52. //选择表和渲染字段
  53. var typelist = {};
  54. $(document).on('change', "select[name='row[name]']", function () {
  55. var that = this;
  56. Fast.api.ajax({
  57. url: "customcharts/totalnumber/get_field_list",
  58. data: {table: $(that).val()},
  59. }, function (data, ret) {
  60. let mainfields = data.fieldlist;
  61. let commentlist = data.commentlist;
  62. typelist = data.typelist;//字段类型
  63. Controller.api.renderselect("#c-field_total", mainfields, commentlist, typelist);//渲染数据
  64. Controller.api.renderselect("#c-group_field", mainfields, commentlist, typelist);//渲染数据
  65. Controller.api.renderselect("#c-field_time" , mainfields, commentlist, typelist);//渲染数据
  66. Controller.api.renderselect("#c-foreign_key", mainfields, commentlist, typelist);//渲染数据
  67. return false;
  68. });
  69. return false;
  70. });
  71. $("select[name='row[name]']").change();
  72. //选择时间字段
  73. $(document).on('change', "select[name='row[field_time]']", function () {
  74. $('input[name="row[field_time_type]"]').val(typelist[$(this).val()]);
  75. });
  76. //选择关联表
  77. $(document).on('change', "select[name='row[join_table]']", function () {
  78. var that = this;
  79. if($(that).val() !== '') {
  80. Fast.api.ajax({
  81. url: "customcharts/totalnumber/get_field_list",
  82. data: {table: $(that).val()},
  83. }, function (data, ret) {
  84. let mainfields = data.fieldlist;
  85. let commentlist = data.commentlist;
  86. typelist = data.typelist;//字段类型
  87. Controller.api.renderselect("#c-local_key", mainfields, commentlist, typelist);//渲染数据
  88. Controller.api.renderselect("#c-field_show", mainfields, commentlist, typelist);//渲染数据
  89. $('.join_table').show();
  90. return false;
  91. });
  92. } else {
  93. $('.join_table').hide();
  94. }
  95. return false;
  96. });
  97. $("select[name='row[join_table]']").change();
  98. },
  99. renderselect: function(select, data, commentlist, typelist) {
  100. var val = $(select).data('value');
  101. var html = [];
  102. for (var i = 0; i < data.length; i++) {
  103. if ('#c-field_time' == select && typelist[data[i]] != 'int' && typelist[data[i]] != 'datetime' && typelist[data[i]] != 'date') {
  104. continue;
  105. }
  106. if (val == data[i]) {
  107. html.push("<option data-subtext='" + commentlist[i] + "' value='" + data[i] + "' selected>" + data[i] + "</option>");
  108. } else {
  109. html.push("<option data-subtext='" + commentlist[i] + "' value='" + data[i] + "'>" + data[i] + "</option>");
  110. }
  111. }
  112. $(select).html(html.join(""));
  113. $(select).selectpicker('refresh');
  114. }
  115. }
  116. };
  117. return Controller;
  118. });