You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
3.4 KiB

  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: 'unishop/config/index',
  8. add_url: 'unishop/config/add',
  9. edit_url: 'unishop/config/edit',
  10. del_url: 'unishop/config/del',
  11. multi_url: 'unishop/config/multi',
  12. table: 'mixconfig',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {field: 'state', checkbox: true},
  24. {field: 'id', title: __('Id')},
  25. {field: 'name', title: __('Name')},
  26. {field: 'intro', title: __('Intro')},
  27. {field: 'group', title: __('Group')},
  28. {field: 'type', title: __('Type')},
  29. {
  30. field: 'operate',
  31. title: __('Operate'),
  32. table: table,
  33. events: Table.api.events.operate,
  34. formatter: Table.api.formatter.operate
  35. }
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. $("form.edit-form").data("validator-options", {
  42. display: function (elem) {
  43. return $(elem).closest('tr').find("td:first").text();
  44. }
  45. });
  46. Form.api.bindevent($("form.edit-form"));
  47. //不可见的元素不验证
  48. $("form#add-form").data("validator-options", {ignore: ':hidden'});
  49. Form.api.bindevent($("form#add-form"), null, function (ret) {
  50. location.reload();
  51. });
  52. //切换显示隐藏变量字典列表
  53. $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
  54. $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
  55. });
  56. //删除配置
  57. $(document).on("click", ".btn-delcfg", function () {
  58. var that = this;
  59. Layer.confirm(__('Are you sure you want to delete this item?'), {icon: 3, title:'提示'}, function (index) {
  60. Backend.api.ajax({
  61. url: "unishop/config/del?receiver=" + value,
  62. data: {name: $(that).data("name")}
  63. }, function () {
  64. $(that).closest("tr").remove();
  65. Layer.close(index);
  66. });
  67. });
  68. });
  69. },
  70. add: function () {
  71. Controller.api.bindevent();
  72. },
  73. edit: function () {
  74. Controller.api.bindevent();
  75. },
  76. api: {
  77. bindevent: function () {
  78. Form.api.bindevent($("form[role=form]"));
  79. }
  80. }
  81. };
  82. return Controller;
  83. });