unit.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: 'shop/unit/index' + location.search,
  8. add_url: 'shop/unit/add',
  9. edit_url: 'shop/unit/edit',
  10. del_url: 'shop/unit/del',
  11. multi_url: 'shop/unit/multi',
  12. import_url: 'shop/unit/import',
  13. table: 'shop_goods_unit',
  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. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  27. {field: 'weigh', title: __('Weigh'), operate: false},
  28. {field: 'status', title: __('Status'), searchList: Controller.api.parseConfigJson('statusList'), formatter: Table.api.formatter.status},
  29. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  30. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  31. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  32. ]
  33. ]
  34. });
  35. // 为表格绑定事件
  36. Table.api.bindevent(table);
  37. },
  38. recyclebin: function () {
  39. // 初始化表格参数配置
  40. Table.api.init({
  41. extend: {
  42. 'dragsort_url': ''
  43. }
  44. });
  45. var table = $("#table");
  46. // 初始化表格
  47. table.bootstrapTable({
  48. url: 'shop/unit/recyclebin' + location.search,
  49. pk: 'id',
  50. sortName: 'id',
  51. columns: [
  52. [
  53. {checkbox: true},
  54. {field: 'id', title: __('Id')},
  55. {field: 'name', title: __('Name'), align: 'left'},
  56. {
  57. field: 'deletetime',
  58. title: __('Deletetime'),
  59. operate: 'RANGE',
  60. addclass: 'datetimerange',
  61. formatter: Table.api.formatter.datetime
  62. },
  63. {
  64. field: 'operate',
  65. width: '140px',
  66. title: __('Operate'),
  67. table: table,
  68. events: Table.api.events.operate,
  69. buttons: [
  70. {
  71. name: 'Restore',
  72. text: __('Restore'),
  73. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  74. icon: 'fa fa-rotate-left',
  75. url: 'shop/unit/restore',
  76. refresh: true
  77. },
  78. {
  79. name: 'Destroy',
  80. text: __('Destroy'),
  81. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  82. icon: 'fa fa-times',
  83. url: 'shop/unit/destroy',
  84. refresh: true
  85. }
  86. ],
  87. formatter: Table.api.formatter.operate
  88. }
  89. ]
  90. ]
  91. });
  92. // 为表格绑定事件
  93. Table.api.bindevent(table);
  94. },
  95. add: function () {
  96. Controller.api.bindevent();
  97. },
  98. edit: function () {
  99. Controller.api.bindevent();
  100. },
  101. api: {
  102. // 解析Config中的JSON字符串的辅助函数
  103. parseConfigJson: function(configKey, defaultValue) {
  104. var configValue = Config[configKey] || defaultValue || {};
  105. // 如果是字符串,尝试解析JSON
  106. if (typeof configValue === 'string') {
  107. try {
  108. return JSON.parse(configValue);
  109. } catch (e) {
  110. return defaultValue || {};
  111. }
  112. }
  113. return configValue;
  114. },
  115. bindevent: function () {
  116. Form.api.bindevent($("form[role=form]"));
  117. }
  118. }
  119. };
  120. return Controller;
  121. });