subscription.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. layui.use(['layer', 'table', 'element', 'form'], function () {
  2. var $ = layui.jquery
  3. , layer = layui.layer //弹层
  4. , table = layui.table //表格
  5. , form = layui.form
  6. var tableIns = table.render({
  7. elem: '#subscriptionlist',
  8. url: '/zt/subscriptionform',
  9. method: 'get',
  10. page: false,
  11. id: 'tablerReload',
  12. cols: [[
  13. {type: 'numbers', title: '序号'},
  14. {field: 'subject', title: '资讯标题', width: 400, align: "center"},
  15. {field: 'subhead', title: '副标题', width: 400, align: "center"},
  16. {
  17. field: 'sort',
  18. title: '排序',
  19. width: 100,
  20. event: 'sortData',
  21. edit: 'text',
  22. align: 'center',
  23. sort: true,
  24. templet: "#sortBox"
  25. },
  26. {
  27. field: 'state', title: '状态', align: 'center', templet: function (d) {
  28. if (d.state == 1) {
  29. return '<input type="checkbox" checked value="' + d.id + '" data-state="2" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  30. } else {
  31. return '<input type="checkbox" value="' + d.id + '" data-state="1" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  32. }
  33. }
  34. },
  35. {title: '操作', templet: '#subscriptionfunc', fixed: "right", align: "center"}
  36. ]]
  37. });
  38. table.reload('tablerReload'); //重新加载
  39. //表格头部操作菜单
  40. var $ = layui.$, active = {
  41. addData: function () {
  42. var index = layui.layer.open({
  43. title: "添加湾区导航",
  44. type: 2,
  45. area: ['70%', '50%'],
  46. content: '/zt/subscriptionadd',
  47. })
  48. },
  49. };
  50. $('.demoTable .layui-btn').on('click', function () {
  51. var type = $(this).data('type');
  52. active[type] ? active[type].call(this) : '';
  53. });
  54. //监听指定开关
  55. form.on('switch(switchTest)', function (data) {
  56. var id = $(this).val();
  57. var state = $(this).data('state');
  58. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  59. $.post('/zt/subscriptionstate', {id: id, state: state}, function (data) {
  60. if (data.code == 200) {
  61. layer.msg(data.msg);
  62. table.reload('tablerReload');
  63. } else if (data.code == 300) {
  64. layer.msg(data.msg);
  65. }
  66. })
  67. }, function (aa) {
  68. table.reload('tablerReload'); //重新加载
  69. })
  70. });
  71. //排序
  72. table.on('edit(subscriptionlist)', function (obj) {
  73. var data = obj.data;
  74. $.post('/zt/subscriptionsort', {id: data.id, sort: data.sort}, function (data) {
  75. if (data.code == 200) {
  76. layer.msg(data.msg);
  77. } else if (data.code == 300) {
  78. layer.msg(data.msg);
  79. }
  80. })
  81. })
  82. //表格右边操作栏目
  83. table.on('tool(subscriptionlist)', function (obj) {
  84. var data = obj.data;
  85. var id = data.id;
  86. var title = data.title;
  87. if (obj.event === 'del') { //删除操作
  88. layer.confirm('确定要删除吗?', {btn: ['确定', '取消']}, function () {
  89. $.post('/zt/subscriptiondel', {id: id}, function (data) {
  90. if (data.code == 200) {
  91. layer.msg(data.msg);
  92. table.reload('tablerReload');
  93. } else if (data.code == 300) {
  94. layer.msg(data.msg);
  95. }
  96. })
  97. })
  98. }
  99. })
  100. $('.The_house').focus(function(){
  101. indexOpen = parent.layui.layer.open({
  102. type: 2,
  103. title: '选择需要添加的区域',
  104. area: ['','100%'],
  105. content: '/publicuse/cnnews?type=1',
  106. success:function (layero, index) {
  107. },
  108. end:function(){
  109. }
  110. });
  111. parent.layui.layer.full(indexOpen);
  112. //改变窗口大小时,重置弹窗的宽高,防止超出可视区域(如F12调出debug的操作)
  113. $(window).on("resize",function(){
  114. parent.layui.layer.full(indexOpen);
  115. })
  116. })
  117. form.on('submit(add_hainanville)', function (data) {
  118. $.post('/zt/subscriptionaddto', {'data': data.field}, function (data) {
  119. if (data.code == 200) {
  120. layer.msg(data.msg);
  121. var index = parent.layer.getFrameIndex(window.name);
  122. parent.layer.close(index);
  123. window.parent.location.reload();
  124. }
  125. })
  126. return false;
  127. });
  128. })