index.html 5.7 KB

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