datadictitem.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function ($, undefined, Backend, Table, Form, jstree) {
  2. var Controller = {
  3. index: function () {
  4. var datadict_id = 0;
  5. var table = $("#table");
  6. $(function () {
  7. var autoWidth = $(window).width() - 220;
  8. $('.table-content').css({'width': autoWidth, "position": "absolute", "left": "210px"});
  9. $("#treeview").jstree({
  10. "themes": {"stripes": true},
  11. "core": {
  12. 'multiple': false,
  13. 'check_callback': true,
  14. "data": {
  15. url: "stock/datadict/getjsTree",
  16. }
  17. }
  18. }).on('select_node.jstree', function (node, selected) {
  19. datadict_id = selected.node.data.id;
  20. table.bootstrapTable('refresh', {
  21. query: {
  22. datadict_id: datadict_id
  23. }
  24. });
  25. }).on('ready.jstree',function(){
  26. if($("#treeview ul li:first").length>0){
  27. $('#treeview').jstree('select_node',$("#treeview ul li:first"));
  28. }
  29. });
  30. });
  31. // 初始化表格参数配置
  32. Table.api.init({
  33. extend: {
  34. index_url: 'stock/datadictitem/index',
  35. add_url: 'stock/datadictitem/add',
  36. edit_url: 'stock/datadictitem/edit',
  37. del_url: 'stock/datadictitem/del',
  38. multi_url: 'stock/datadictitem/multi',
  39. table: 'stock_datadictitem',
  40. }
  41. });
  42. // 初始化表格
  43. table.bootstrapTable({
  44. url: $.fn.bootstrapTable.defaults.extend.index_url,
  45. pk: 'id',
  46. sortName: 'weigh',
  47. height: $(window).height() - 137,
  48. columns: [
  49. [
  50. {checkbox: true},
  51. {field: 'id', title: __('Id')},
  52. {field: 'name', title: __('Name')},
  53. {field: 'value', title: __('Value')},
  54. {field: 'weigh', title: __('Weigh')},
  55. {field: 'remark', title: __('Remark')},
  56. {field: 'enabled', title: __('Enabled'), visible: false, searchList: {"1": __('Enabled 1'), "0": __('Enabled 0')}},
  57. {field: 'enabled_text', title: __('Enabled'), operate: false},
  58. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  59. ]
  60. ],
  61. queryParams: function (params) {
  62. params.datadict_id = datadict_id;
  63. return params;
  64. }
  65. });
  66. // 为表格绑定事件
  67. Table.api.bindevent(table);
  68. // 刷新按钮事件
  69. $('.btn-refresh').click(function (event) {
  70. event.stopPropagation();
  71. table.bootstrapTable('refresh', {
  72. query: {
  73. datadict_id: datadict_id
  74. }
  75. });
  76. });
  77. },
  78. add: function () {
  79. Controller.api.bindevent();
  80. },
  81. edit: function () {
  82. Controller.api.bindevent();
  83. },
  84. api: {
  85. bindevent: function () {
  86. Form.api.bindevent($("form[role=form]"));
  87. }
  88. }
  89. };
  90. return Controller;
  91. });