honor.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: 'wwh/honor/index' + location.search,
  8. add_url: 'wwh/honor/add',
  9. edit_url: 'wwh/honor/edit',
  10. del_url: 'wwh/honor/del',
  11. multi_url: 'wwh/honor/multi',
  12. table: 'wwh_honor',
  13. dragsort_url:'',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'weigh',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  29. {field: 'name', title: __('Name')},
  30. {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
  31. {
  32. field: 'weigh',
  33. title: __('Weigh'),
  34. operate: false,
  35. sortable: true,
  36. formatter: function (value, row, index) {
  37. return '<input type="text" class="form-control text-center text-weigh" data-id="' + row.id + '" value="' + value + '" style="width:50px;margin:0 auto;" />';
  38. },
  39. events: {
  40. "dblclick .text-weigh": function (e) {
  41. e.preventDefault();
  42. e.stopPropagation();
  43. return false;
  44. }
  45. }
  46. },
  47. {field: 'zsdate', title: __('Zsdate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  48. {field: 'lang', title: __('Lang'), searchList: {"1":__('Lang 1'),"2":__('Lang 2')}, custom: {1: 'success', 2: 'warning'}, formatter: Table.api.formatter.normal},
  49. // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  50. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  51. ]
  52. ]
  53. });
  54. // 权重修改
  55. $(document).on("change", ".text-weigh", function () {
  56. $(this).data("params", {weigh: $(this).val()});
  57. Table.api.multi('', [$(this).data("id")], table, this);
  58. return false;
  59. });
  60. // 为表格绑定事件
  61. Table.api.bindevent(table);
  62. // 弹窗窗口大小
  63. table.on('post-body.bs.table',function(e, settings, json, xhr){
  64. $(".btn-add").data("area", ['80%','80%']);
  65. $(".btn-editone").data("area", ['80%','80%']);
  66. });
  67. // TAB选项卡默认选中简体中文
  68. $('ul.nav-tabs li a[data-toggle="tab"]').eq(0).trigger("click");
  69. // 获取TAB选项卡值,通过options.extend.add_url传递
  70. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  71. var options = table.bootstrapTable('getOptions');
  72. options.extend.add_url = 'wwh/honor/add?lang=' + $(this).data('value');
  73. });
  74. },
  75. add: function () {
  76. // 将TAB选项卡赋值给lang
  77. $('#c-lang option').each(function(){
  78. if($(this).attr('value') == Fast.api.query('lang'))
  79. {
  80. $(this).attr('selected', 'selected');
  81. }
  82. });
  83. Controller.api.bindevent();
  84. },
  85. edit: function () {
  86. Controller.api.bindevent();
  87. },
  88. api: {
  89. bindevent: function () {
  90. Form.api.bindevent($("form[role=form]"));
  91. }
  92. }
  93. };
  94. return Controller;
  95. });