index.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. .layui-form{margin-left: initial !important;}
  5. .admin-style-2 .single-filter-box{padding-top: 0;}
  6. </style>
  7. {/block}
  8. {block name="main"}
  9. <!--<div class="layui-collapse tips-wrap">-->
  10. <!-- <div class="layui-colla-item">-->
  11. <!-- <h2 class="layui-colla-title">操作提示</h2>-->
  12. <!-- <ul class="layui-colla-content layui-show">-->
  13. <!-- <li>您可以查看和编辑广告位的宽度和高度</li>-->
  14. <!-- </ul>-->
  15. <!-- </div>-->
  16. <!--</div>-->
  17. <div class="single-filter-box">
  18. <div>
  19. <!-- <button class="layui-btn" onclick="add()">添加广告位</button> -->
  20. </div>
  21. <div class="layui-form">
  22. <div class="layui-input-inline">
  23. <input type="text" name="search_text" placeholder="请输入广告位名称" class="layui-input">
  24. <button type="button" class="layui-btn layui-btn-primary" lay-filter="search" lay-submit>
  25. <i class="layui-icon">&#xe615;</i>
  26. </button>
  27. </div>
  28. </div>
  29. </div>
  30. <!-- 列表 -->
  31. <table id="adv_position" lay-filter="adv_position"></table>
  32. <!-- 广告位宽度 -->
  33. <script type="text/html" id="ap_width">
  34. <input name="ap_width" type="number" onchange="editPosition({{d.ap_id}}, 'ap_width', this)" value="{{d.ap_width}}"
  35. class="layui-input sort-len">
  36. </script>
  37. <!-- 广告位高度 -->
  38. <script type="text/html" id="ap_height">
  39. <input name="ap_height" type="number" onchange="editPosition({{d.ap_id}}, 'ap_height', this)" value="{{d.ap_height}}" class="layui-input sort-len">
  40. </script>
  41. <!-- 操作 -->
  42. <script type="text/html" id="action">
  43. <div class="table-btn">
  44. <a class="layui-btn" lay-event="manager">管理广告</a>
  45. <a class="layui-btn" lay-event="edit">编辑</a>
  46. <!-- <a class="layui-btn" lay-event="delete">删除</a>-->
  47. </div>
  48. </script>
  49. <!-- 批量删除 -->
  50. <script type="text/html" id="toolbarOperation">
  51. <button class="layui-btn layui-btn-primary" lay-event="del">批量删除</button>
  52. </script>
  53. <!-- 批量删除 -->
  54. <script type="text/html" id="batchOperation">
  55. <button class="layui-btn layui-btn-primary" lay-event="del">批量删除</button>
  56. </script>
  57. {/block}
  58. {block name="script"}
  59. <script>
  60. var table, form,
  61. repeat_flag = false; //防重复标识
  62. layui.use('form', function () {
  63. form = layui.form;
  64. form.render();
  65. form.on('switch(state)', function(data){
  66. let state = data.elem.checked ? 1 : 0;
  67. let ap_id = $(data.elem).attr('data-ap-id');
  68. if(repeat_flag) return;
  69. repeat_flag = true;
  70. $.ajax({
  71. url: ns.url("shop/adv/alterAdvPositionState"),
  72. data: {
  73. ap_id : ap_id,
  74. state : state,
  75. },
  76. dataType: 'JSON',
  77. type: 'POST',
  78. success: function(res) {
  79. layer.msg(res.message);
  80. repeat_flag = false;
  81. }
  82. });
  83. })
  84. table = new Table({
  85. elem: '#adv_position',
  86. url: ns.url("shop/adv/index"),
  87. cols: [
  88. [
  89. // {
  90. // width: '3%',
  91. // type: 'checkbox',
  92. // unresize: 'false',
  93. // },
  94. {
  95. field: 'ap_name',
  96. title: '广告位名称',
  97. unresize: 'false',
  98. width: '16%',
  99. }, {
  100. field: 'keyword',
  101. title: '广告关键字',
  102. unresize: 'false',
  103. width: '24%',
  104. }, {
  105. title: '是否是系统',
  106. unresize: 'false',
  107. templet: function(data) {
  108. return data.is_system == 0 ? "否" : "是";
  109. },
  110. width: '10%',
  111. },{
  112. title: '是否启用',
  113. unresize: 'false',
  114. templet: function(data) {
  115. return '<input type="checkbox" name="state" value="1" lay-skin="switch" lay-filter="state" data-ap-id="'+ data.ap_id +'" '+ (data.state == 1 ? 'checked' : '') +' />';
  116. },
  117. width: '10%',
  118. }, {
  119. title: '操作',
  120. toolbar: '#action',
  121. unresize: 'false',
  122. align : 'right'
  123. }]
  124. ],
  125. // toolbar: "#toolbarOperation",
  126. // bottomToolbar: "#batchOperation"
  127. });
  128. /**
  129. * 监听工具栏操作
  130. */
  131. table.tool(function (obj) {
  132. var data = obj.data;
  133. switch (obj.event) {
  134. case 'manager': //管理
  135. location.href = ns.url("shop/adv/lists?ap_id=" + data.ap_id);
  136. break;
  137. case 'edit': //编辑
  138. location.href = ns.url("shop/adv/editPosition?ap_id=" + data.ap_id);
  139. break;
  140. case 'delete': //删除
  141. deletePosition(data.ap_id);
  142. break;
  143. }
  144. });
  145. /**
  146. * 批量操作
  147. */
  148. table.toolbar(function (obj) {
  149. if (obj.data.length < 1) {
  150. layer.msg('请选择要操作的数据');
  151. return;
  152. }
  153. switch (obj.event) {
  154. case "del":
  155. var id_array = new Array();
  156. for (i in obj.data) id_array.push(obj.data[i].ap_id);
  157. deletePosition(id_array.toString());
  158. break;
  159. }
  160. });
  161. table.bottomToolbar(function (obj) {
  162. if (obj.data.length < 1) {
  163. layer.msg('请选择要操作的数据');
  164. return;
  165. }
  166. switch (obj.event) {
  167. case "del":
  168. var id_array = new Array();
  169. for (i in obj.data) id_array.push(obj.data[i].ap_id);
  170. deletePosition(id_array.toString());
  171. break;
  172. }
  173. });
  174. /**
  175. * 删除
  176. */
  177. function deletePosition(ap_ids) {
  178. if (repeat_flag) return false;
  179. repeat_flag = true;
  180. layer.confirm('删除将会影响广告位的使用,确定要删除吗?', function () {
  181. $.ajax({
  182. url: ns.url("shop/adv/deletePosition"),
  183. data: {'ap_ids': ap_ids},
  184. dataType: 'JSON',
  185. type: 'POST',
  186. success: function (res) {
  187. layer.msg(res.message);
  188. repeat_flag = false;
  189. if (res.code == 0) {
  190. table.reload();
  191. }
  192. }
  193. });
  194. }, function () {
  195. layer.close();
  196. repeat_flag = false;
  197. });
  198. }
  199. /**
  200. * 监听搜索
  201. */
  202. form.on('submit(search)', function (data) {
  203. table.reload({
  204. page: {
  205. curr: 1
  206. },
  207. where: data.field
  208. });
  209. });
  210. });
  211. // 监听单元格编辑--编辑宽度
  212. function editPosition(id, type, event) {
  213. var value = $(event).val();
  214. if (!new RegExp("^\\d+$").test(value)) {
  215. layer.msg("广告位宽高必须为大于等于0的整数");
  216. return;
  217. }
  218. $.ajax({
  219. type: 'POST',
  220. url: ns.url("shop/adv/editPositionField"),
  221. data: {
  222. 'type': type,
  223. 'value': value,
  224. 'ap_id': id
  225. },
  226. dataType: 'JSON',
  227. success: function (res) {
  228. layer.msg(res.message);
  229. if (res.code == 0) {
  230. table.reload();
  231. }
  232. }
  233. });
  234. }
  235. function add() {
  236. location.href = ns.url("shop/adv/addPosition");
  237. }
  238. </script>
  239. {/block}