guidemanage.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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: 'guidemanage/index',
  8. add_url: 'guidemanage/add',
  9. edit_url: 'guidemanage/edit',
  10. del_url: 'guidemanage/del',
  11. multi_url: 'guidemanage/multi',
  12. table: 'guidemanage',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'state desc, updatetime desc,id',
  21. sortOrder:'',
  22. search: false,
  23. searchFormVisible: true,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id'), operate: 'LIKE %...%'},
  28. {field: 'channel_id', title: __('channel_id'), operate: 'LIKE %...%'},
  29. {
  30. field: 'state',
  31. title: __('state'),
  32. visible: false,
  33. searchList: {"0": __('关闭'), "1": __('启用')}
  34. },
  35. {
  36. field: 'state_text',
  37. title: __('state'),
  38. operate: false,
  39. formatter: function (value, row, index) {
  40. if (row.state == "0") {
  41. return '<span style="color:red">关闭</span>';
  42. } else {
  43. return '<span style="color:green">启用</span>';
  44. }
  45. }
  46. },
  47. {
  48. field: 'createtime',
  49. title: __('Createtime'),
  50. formatter: Table.api.formatter.datetime,
  51. type: 'datetime',
  52. operate:false,
  53. addclass: 'datetimerange'
  54. },
  55. {
  56. field: 'updatetime',
  57. title: __('Updatetime'),
  58. formatter: Table.api.formatter.datetime,
  59. type: 'datetime',
  60. operate:false,
  61. addclass: 'datetimerange'
  62. },
  63. {
  64. field: 'operate',
  65. title: __('Operate'),
  66. table: table,
  67. events: Table.api.events.operate,
  68. formatter: Table.api.formatter.operate
  69. }
  70. ]
  71. ]
  72. });
  73. // 为表格绑定事件
  74. Table.api.bindevent(table);
  75. Controller.api.bindevent();
  76. },
  77. add: function () {
  78. $("#c-host").on("blur", function () {
  79. var len = $(this).val().split("\n").length;
  80. $("#host_length").find("span").text(len);
  81. $("#host_length").css("color", len > 50 ? "red" : "");
  82. });
  83. Controller.api.bindevent();
  84. },
  85. edit: function () {
  86. Controller.api.bindevent();
  87. },
  88. open: function () {
  89. var that = this;
  90. var table = $("#table");
  91. var ids = Table.api.selectedids(table);
  92. Layer.confirm(
  93. "确定启用选中的"+ ids.length +"项?",
  94. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  95. function (index) {
  96. Fast.api.ajax({
  97. url: 'guidedomain/open',
  98. dataType: 'json',
  99. data: {ids: ids}
  100. }, function (data, ret) {
  101. table.bootstrapTable('refresh');
  102. });
  103. Layer.close(index);
  104. }
  105. );
  106. },
  107. close: function () {
  108. var that = this;
  109. var table = $("#table");
  110. var ids = Table.api.selectedids(table);
  111. Layer.confirm(
  112. "确定关闭选中的"+ ids.length +"项?<small class='text-info help-block'>关闭后将解除对应的渠道商/代理商关联关系</small>",
  113. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  114. function (index) {
  115. Fast.api.ajax({
  116. url: 'guidedomain/close',
  117. dataType: 'json',
  118. data: {ids: ids}
  119. }, function (data, ret) {
  120. table.bootstrapTable('refresh');
  121. });
  122. Layer.close(index);
  123. }
  124. );
  125. },
  126. api: {
  127. bindevent: function () {
  128. $("#toolbar>a.btn-open").on("click", Controller.open);
  129. $("#toolbar>a.btn-close").on("click", Controller.close);
  130. Form.api.bindevent($("form[role=form]"));
  131. }
  132. }
  133. };
  134. return Controller;
  135. });