sharetitle.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var tag = 0;
  3. $(document).on('click','#submit',function () {
  4. if(tag == 1){
  5. layer.alert('请不要频繁提交');
  6. return false;
  7. }
  8. tag = 1;
  9. if($.trim($("#c-title").val()) == ''){
  10. tag = 0;
  11. layer.alert('标题不能为空');
  12. return false;
  13. }
  14. var datas = {
  15. 'status':$("#status").val(),
  16. 'sex':$("#c-sex").val(),
  17. 'title':$("#c-title").val(),
  18. };
  19. $.ajax({
  20. type: "POST",
  21. dataType: "json",
  22. url: "/admin/manage/sharetitle/addmany",
  23. data: datas,
  24. success: function (result) {
  25. if(typeof result == "string"){
  26. result = JSON.parse(result);
  27. }
  28. if (result.success == '1') {
  29. tag = 0;
  30. $("#c-title").val('');
  31. layer.alert('添加成功');
  32. $('.btn-refresh').click();
  33. }else{
  34. tag = 0;
  35. layer.alert('异常!');
  36. }
  37. },
  38. error : function() {
  39. tag = 0;
  40. layer.alert("异常!");
  41. }
  42. });
  43. });
  44. $(document).on('click', '.btn-pl', function () {
  45. layer.open({
  46. type: 2,
  47. title: '批量添加标题',
  48. maxmin: true,
  49. area: ['60%', '90%'],
  50. shadeClose: true, //点击遮罩关闭层
  51. content: '/admin/manage/sharetitle/addmany',
  52. cancel: function (index,layero) {
  53. $('.btn-refresh').click();
  54. layer.close(index);
  55. },
  56. });
  57. });
  58. var Controller = {
  59. index: function () {
  60. // 初始化表格参数配置
  61. Table.api.init({
  62. extend: {
  63. index_url: 'manage/sharetitle/index',
  64. add_url: 'manage/sharetitle/add',
  65. edit_url: 'manage/sharetitle/edit',
  66. del_url: 'manage/sharetitle/del',
  67. multi_url: 'manage/sharetitle/multi',
  68. table: 'manage_sharetitle',
  69. }
  70. });
  71. var table = $("#table");
  72. // 初始化表格
  73. table.bootstrapTable({
  74. url: $.fn.bootstrapTable.defaults.extend.index_url,
  75. pk: 'id',
  76. sortName: 'id',
  77. columns: [
  78. [
  79. {checkbox: true},
  80. {field: 'id', title: __('Id')},
  81. {field: 'title', title: __('Title')},
  82. {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
  83. {field: 'status_text', title: __('Status'), operate:false},
  84. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  85. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  86. {field: 'sex', title: __('Sex'), visible:false, searchList: {"sex 1":__('Sex 1'),"sex 2":__('Sex 2'),"sex 3":__('Sex 3')}},
  87. {field: 'sex_text', title: __('Sex'), operate:false},
  88. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  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. bindevent: function () {
  103. Form.api.bindevent($("form[role=form]"));
  104. }
  105. }
  106. };
  107. return Controller;
  108. });