ranking.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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: 'weigh', title: __('Weigh')},
  35. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. },
  42. add: function () {
  43. Controller.api.bindevent();
  44. },
  45. edit: function () {
  46. Controller.api.bindevent();
  47. },
  48. api: {
  49. bindevent: function () {
  50. Form.api.bindevent($("form[role=form]"));
  51. //选择表和渲染字段
  52. var typelist = {};
  53. $(document).on('change', "select[name='row[name]']", function () {
  54. var that = this;
  55. Fast.api.ajax({
  56. url: "customcharts/totalnumber/get_field_list",
  57. data: {table: $(that).val()},
  58. }, function (data, ret) {
  59. let mainfields = data.fieldlist;
  60. let commentlist = data.commentlist;
  61. typelist = data.typelist;//字段类型
  62. Controller.api.renderselect("#c-field_total", mainfields, commentlist, typelist);//渲染数据
  63. Controller.api.renderselect("#c-group_field", mainfields, commentlist, typelist);//渲染数据
  64. Controller.api.renderselect("#c-field_time" , mainfields, commentlist, typelist);//渲染数据
  65. Controller.api.renderselect("#c-foreign_key", mainfields, commentlist, typelist);//渲染数据
  66. return false;
  67. });
  68. return false;
  69. });
  70. $("select[name='row[name]']").change();
  71. //选择时间字段
  72. $(document).on('change', "select[name='row[field_time]']", function () {
  73. $('input[name="row[field_time_type]"]').val(typelist[$(this).val()]);
  74. });
  75. //选择关联表
  76. $(document).on('change', "select[name='row[join_table]']", function () {
  77. var that = this;
  78. if($(that).val() !== '') {
  79. Fast.api.ajax({
  80. url: "customcharts/totalnumber/get_field_list",
  81. data: {table: $(that).val()},
  82. }, function (data, ret) {
  83. let mainfields = data.fieldlist;
  84. let commentlist = data.commentlist;
  85. typelist = data.typelist;//字段类型
  86. Controller.api.renderselect("#c-local_key", mainfields, commentlist, typelist);//渲染数据
  87. Controller.api.renderselect("#c-field_show", mainfields, commentlist, typelist);//渲染数据
  88. $('.join_table').show();
  89. $('.dictionary').hide();
  90. return false;
  91. });
  92. } else {
  93. $('.join_table').hide();
  94. $('.dictionary').show();
  95. }
  96. return false;
  97. });
  98. $("select[name='row[join_table]']").change();
  99. },
  100. renderselect: function(select, data, commentlist, typelist) {
  101. var val = $(select).data('value');
  102. var html = [];
  103. for (var i = 0; i < data.length; i++) {
  104. if ('#c-field_time' == select && typelist[data[i]] != 'int' && typelist[data[i]] != 'datetime' && typelist[data[i]] != 'date' && typelist[data[i]] != 'bigint') {
  105. continue;
  106. }
  107. if (val == data[i]) {
  108. html.push("<option data-subtext='" + commentlist[i] + "' value='" + data[i] + "' selected>" + data[i] + "</option>");
  109. } else {
  110. html.push("<option data-subtext='" + commentlist[i] + "' value='" + data[i] + "'>" + data[i] + "</option>");
  111. }
  112. }
  113. $(select).html(html.join(""));
  114. $(select).selectpicker('refresh');
  115. }
  116. }
  117. };
  118. return Controller;
  119. });