index.html 3.7 KB

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