index.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. {extend name="base"/}
  2. {block name="resources"}
  3. {/block}
  4. {block name="main"}
  5. <div class="layui-collapse ns-tips">
  6. <div class="layui-colla-item">
  7. <h2 class="layui-colla-title">操作提示</h2>
  8. <ul class="layui-colla-content layui-show">
  9. <li>您可以查看和编辑广告位的宽度和高度</li>
  10. </ul>
  11. </div>
  12. </div>
  13. <div class="ns-single-filter-box">
  14. <button class="layui-btn ns-bg-color" onclick="add()">添加轮播图</button>
  15. </div>
  16. <!-- 列表 -->
  17. <table id="adv_position" lay-filter="adv_position"></table>
  18. <!-- 广告图片 -->
  19. <script type="text/html" id="imgae">
  20. <div class="ns-img-box">
  21. <img layer-src src="{{ns.img(d.imgae)}}" />
  22. </div>
  23. </script>
  24. <!-- 操作 -->
  25. <script type="text/html" id="operation">
  26. <div class="ns-table-btn">
  27. <a class="layui-btn" lay-event="edit">编辑</a>
  28. </div>
  29. </script>
  30. <!-- 批量删除 -->
  31. <script type="text/html" id="batchOperation">
  32. <button class="layui-btn layui-btn-primary" lay-event="del">批量删除</button>
  33. </script>
  34. {/block}
  35. {block name="script"}
  36. <script>
  37. var table, form,
  38. repeat_flag = false; //防重复标识
  39. layui.use('form', function() {
  40. form = layui.form;
  41. form.render();
  42. table = new Table({
  43. elem: '#adv_position',
  44. url: ns.url("admin/SideAdv/index"), cols: [
  45. [{
  46. width: '3%',
  47. type: 'checkbox',
  48. unresize: 'false',
  49. }, {
  50. field: 'title',
  51. title: '标题',
  52. unresize: 'false',
  53. templet: '#title',
  54. width: '20%'
  55. },{
  56. title: '图片',
  57. unresize: 'false',
  58. templet: '#imgae',
  59. width: '15%'
  60. }, {
  61. title: '操作',
  62. toolbar: '#operation',
  63. unresize: 'false',
  64. templet: '#operation',
  65. width: '17%'
  66. }]
  67. ],
  68. bottomToolbar: "#batchOperation"
  69. });
  70. /**
  71. * 监听工具栏操作
  72. */
  73. table.tool(function(obj) {
  74. var data = obj.data;
  75. switch (obj.event) {
  76. case 'manager': //管理
  77. location.href = ns.url("admin/banner/lists?ap_id=" + data.ap_id);
  78. break;
  79. case 'edit': //编辑
  80. location.href = ns.url("admin/SideAdv/editAdv?ap_id=" + data.id);
  81. break;
  82. case 'delete': //删除
  83. deletePosition(data.id);
  84. break;
  85. }
  86. });
  87. /**
  88. * 批量操作
  89. */
  90. table.bottomToolbar(function(obj) {
  91. if (obj.data.length < 1) {
  92. layer.msg('请选择要操作的数据');
  93. return;
  94. }
  95. switch (obj.event) {
  96. case "del":
  97. var id_array = new Array();
  98. for (i in obj.data) id_array.push(obj.data[i].ap_id);
  99. deletePosition(id_array.toString());
  100. break;
  101. }
  102. });
  103. /**
  104. * 删除
  105. */
  106. function deletePosition(ap_ids) {
  107. if (repeat_flag) return false;
  108. repeat_flag = true;
  109. layer.confirm('确定要删除该广告位吗?', function() {
  110. $.ajax({
  111. url: ns.url("admin/banner/deleteBanner"),
  112. data: {ap_ids},
  113. dataType: 'JSON',
  114. type: 'POST',
  115. success: function(res) {
  116. layer.msg(res.message);
  117. repeat_flag = false;
  118. if (res.code == 0) {
  119. table.reload();
  120. }
  121. }
  122. });
  123. }, function() {
  124. layer.close();
  125. repeat_flag = false;
  126. });
  127. }
  128. /**
  129. * 监听搜索
  130. */
  131. form.on('submit(search)', function(data) {
  132. table.reload({
  133. page: {
  134. curr: 1
  135. },
  136. where: data.field
  137. });
  138. });
  139. });
  140. // 监听单元格编辑--编辑宽度
  141. function editPosition(id, type, event) {
  142. var value = $(event).val();
  143. if (!new RegExp("^\\d+$").test(value)) {
  144. layer.msg("广告位宽高必须为大于等于0的整数");
  145. return;
  146. }
  147. $.ajax({
  148. type: 'POST',
  149. url: ns.url("admin/banner/editPositionField"),
  150. data: {
  151. 'type': type,
  152. 'value': value,
  153. 'ap_id': id
  154. },
  155. dataType: 'JSON',
  156. success: function(res) {
  157. layer.msg(res.message);
  158. if (res.code == 0) {
  159. table.reload();
  160. }
  161. }
  162. });
  163. }
  164. function add() {
  165. location.href = ns.url("admin/SideAdv/addSide");
  166. }
  167. </script>
  168. {/block}