guidedomain.js 4.7 KB

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