index.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. .layui-layout-admin.admin-style-2 .layui-body .layui-tab + .body-content{padding-top: 65px !important;}
  5. .promote-flex {display:flex;margin-top:15px;padding:0 10px 0;}
  6. .promote-img {background-color:#f8f8f8;display:flex;justify-content:center;align-items:center;width:160px;height:160px;}
  7. .promote-img img {width:140px;height:140px;}
  8. .label-width {width:100px;}
  9. .block-left {margin-left:100px !important;display:flex;}
  10. .promote-download {margin-left:20px;}
  11. .path-wrap {margin-left:20px;}
  12. .path-wrap .copy {width:1px;height:0px;border:0px;}
  13. .path-wrap span {display:block;margin-bottom:10px;}
  14. .path-wrap p input {height:30px;line-height:30px;border:1px solid #e6e6e5;width:260px;padding:0px 5px;border-radius:5px;margin-right:10px;}
  15. </style>
  16. {/block}
  17. {block name="main"}
  18. <!-- 筛选面板 -->
  19. <!-- <div class="screen layui-collapse">
  20. <div class="layui-colla-item">
  21. <form class="layui-colla-content layui-form layui-show">
  22. <div class="layui-form-item">
  23. <div class="layui-inline">
  24. <label class="layui-form-label">接收范围:</label>
  25. <div class="layui-input-inline">
  26. <select name="receiving_type">
  27. <option value="">全部</option>
  28. <option value="mobile">手机端</option>
  29. </select>
  30. </div>
  31. </div>
  32. <button class="layui-btn" lay-submit lay-filter="search">筛选</button>
  33. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  34. </div>
  35. </form>
  36. </div>
  37. </div> -->
  38. <!-- 搜索框 -->
  39. <div class="single-filter-box">
  40. <button class="layui-btn" onclick="add()">添加公告</button>
  41. <div class="layui-form">
  42. <div class="layui-input-inline">
  43. <input type="text" name="search_text" placeholder="请输入公告名称" autocomplete="off" class="layui-input">
  44. <button type="button" class="layui-btn layui-btn-primary" lay-filter="search" lay-submit>
  45. <i class="layui-icon">&#xe615;</i>
  46. </button>
  47. </div>
  48. </div>
  49. </div>
  50. <!-- 列表 -->
  51. <table id="notice_list" lay-filter="notice_list"></table>
  52. <!-- 操作 -->
  53. <script type="text/html" id="operation">
  54. <div class="table-btn">
  55. <a class="layui-btn" lay-event="promote">推广</a>
  56. <a class="layui-btn" lay-event="basic">查看</a>
  57. <a class="layui-btn" lay-event="edit">编辑</a>
  58. {{# if(!d.is_top){ }}
  59. <a class="layui-btn" lay-event="setTop">置顶</a>
  60. {{# } }}
  61. <a class="layui-btn" lay-event="del">删除</a>
  62. </div>
  63. </script>
  64. <!-- 编辑排序 -->
  65. <script type="text/html" id="editSort">
  66. <input name="sort" type="number" onchange="editSort({{d.id}}, this)" value="{{d.sort}}" class="layui-input edit-sort len-short">
  67. </script>
  68. <!-- 推广 -->
  69. <script type="text/html" id="promote">
  70. <div class="promote-flex">
  71. <div class="promote-img">
  72. <img src="{{ ns.img(d.h5.path) }}" alt="推广二维码">
  73. </div>
  74. <div class="layui-form">
  75. <div class="layui-form-item">
  76. <label class="layui-form-label label-width">选择端口:</label>
  77. <div class="layui-input-block block-left">
  78. <input type="radio" name="promote_type" value="h5" title="H5" checked lay-filter="promote_type" >
  79. <input type="radio" name="promote_type" value="weapp" title="小程序" lay-filter="promote_type">
  80. {if $pc_is_exit == 1}
  81. <input type="radio" name="promote_type" value="pc" title="PC" lay-filter="promote_type">
  82. {/if}
  83. </div>
  84. </div>
  85. <div class="path-wrap">
  86. <span>推广链接</span>
  87. <p class="tips text-color">
  88. <input type="text" value="{{d.h5.url}}" readonly />
  89. <a class="layui-btn" href="javascript:ns.copy('article_url_{{ d.id }}');">复制</a>
  90. </p>
  91. <input type="text" id="article_url_{{ d.id }}" value="{{d.h5.url}}" readonly class="copy"/>
  92. </div>
  93. <div class="promote-download">
  94. <a class="text-color" href="{{ ns.img(d.h5.path) }}" download>下载二维码</a>
  95. </div>
  96. </div>
  97. </div>
  98. </script>
  99. {/block}
  100. {block name="script"}
  101. <script type="text/javascript">
  102. var form,laytpl,table,repeat_flag = false; //防重复标识
  103. layui.use(['form','laytpl'], function() {
  104. form = layui.form;
  105. laytpl = layui.laytpl;
  106. form.render();
  107. table = new Table({
  108. elem: '#notice_list',
  109. url: ns.url("shop/notice/index"),
  110. cols: [
  111. [{
  112. width: '35%',
  113. title: '公告标题',
  114. unresize: 'false',
  115. templet: function(data) {
  116. var html = data.is_top ? '<span class="required">[ 置顶 ] </span>' : '';
  117. html += data.title;
  118. return html;
  119. }
  120. },
  121. // {
  122. // field:'receiving_name',
  123. // width: '20%',
  124. // title: '接收范围',
  125. // unresize: 'false',
  126. // },
  127. {
  128. width: '25%',
  129. title: '创建时间',
  130. unresize: 'false',
  131. templet: function(data) {
  132. return ns.time_to_date(data.create_time);
  133. }
  134. }, {
  135. field: 'sort',
  136. unresize:'false',
  137. title: '排序',
  138. sort : true,
  139. width: '20%',
  140. templet: '#editSort'
  141. }, {
  142. title: '操作',
  143. unresize: 'false',
  144. templet: '#operation',
  145. align : 'right'
  146. }
  147. ]]
  148. });
  149. table.tool(function(obj) {
  150. var data = obj.data;
  151. var event = obj.event;
  152. switch (obj.event) {
  153. case 'promote': // 推广
  154. promote(data);
  155. break;
  156. case 'edit': //编辑
  157. location.href = ns.url("shop/notice/editNotice?id=" + data.id);
  158. break;
  159. case 'delete': //删除
  160. deleteNotice(data.id);
  161. break;
  162. case 'setTop': // 置顶
  163. modifySiteNoticeTop(data.id);
  164. break;
  165. case 'basic':
  166. location.href = ns.url("shop/notice/detail?id=" + data.id);
  167. break;
  168. }
  169. });
  170. /**
  171. * 搜索功能
  172. */
  173. form.on('submit(search)', function(data) {
  174. table.reload({
  175. page: {
  176. curr: 1
  177. },
  178. where: data.field
  179. });
  180. });
  181. function deleteNotice(id) {
  182. if (repeat_flag) return;
  183. repeat_flag = true;
  184. layer.confirm('确定要删除该公告吗?', function() {
  185. $.ajax({
  186. type: "post",
  187. async: false,
  188. url: ns.url("shop/notice/deleteNotice"),
  189. data: {
  190. 'id': id
  191. },
  192. dataType: "JSON",
  193. success: function(res) {
  194. layer.msg(res.message);
  195. repeat_flag = false;
  196. if (res.code == 0) {
  197. table.reload();
  198. }
  199. }
  200. });
  201. }, function() {
  202. repeat_flag = false;
  203. layer.close();
  204. }
  205. );
  206. }
  207. table.on("sort",function (obj) {
  208. table.reload({
  209. page: {
  210. curr: 1
  211. },
  212. where: {
  213. order:obj.field,
  214. sort:obj.type
  215. }
  216. });
  217. });
  218. function modifySiteNoticeTop(id) {
  219. if (repeat_flag) return;
  220. repeat_flag = true;
  221. $.ajax({
  222. type: "POST",
  223. dataType: "JSON",
  224. async: false,
  225. url: ns.url("shop/notice/modifyNoticeTop"),
  226. data: {id},
  227. success: function(res) {
  228. layer.msg(res.message);
  229. repeat_flag = false;
  230. if (res.code == 0) {
  231. table.reload();
  232. }
  233. }
  234. });
  235. }
  236. });
  237. function add() {
  238. location.href = ns.url("shop/notice/addNotice");
  239. }
  240. // 监听单元格编辑
  241. function editSort(id, event){
  242. var data = $(event).val();
  243. if (data == '') {
  244. $(event).val(0);
  245. data = 0;
  246. }
  247. if(!new RegExp("^-?[0-9]\\d*$").test(data)){
  248. layer.msg("排序号只能是整数");
  249. return ;
  250. }
  251. if(data<0){
  252. layer.msg("排序号必须大于0");
  253. return ;
  254. }
  255. $.ajax({
  256. type: 'POST',
  257. url: ns.url("shop/notice/modifySort"),
  258. data: {
  259. sort: data,
  260. id: id
  261. },
  262. dataType: 'JSON',
  263. success: function(res) {
  264. layer.msg(res.message);
  265. if(res.code==0){
  266. table.reload();
  267. }
  268. }
  269. });
  270. }
  271. function promote(data) {
  272. $.ajax({
  273. type: "POST",
  274. url: ns.url("shop/notice/promote"),
  275. data: {
  276. notice_id: data.id
  277. },
  278. dataType: 'JSON',
  279. success: function (res) {
  280. if(res.code==0){
  281. res.data.id = data.id;
  282. laytpl($("#promote").html()).render(res.data, function (html) {
  283. layer.open({
  284. type: 1,
  285. area: ['600px', '280px'],
  286. offset: '155px',
  287. title: ['推广'],
  288. content: html,
  289. success: function(){
  290. // 推广渠道监听
  291. form.on('radio(promote_type)', function(radio){
  292. if(radio.value == 'h5') {
  293. var content = "";
  294. content += '<img src="'+ res.data.h5.path +'"/>';
  295. $('.promote-img').html(content);
  296. $('.path-wrap p input').val(res.data.h5.url);
  297. $('.path-wrap .copy').val(res.data.h5.url);
  298. $('.promote-download a').attr('href',res.data.h5.path).show();
  299. $(".path-wrap").show();
  300. }else if(radio.value == 'weapp') {
  301. if(res.data.weapp.path == ""){
  302. var content = "";
  303. content += '<span>小程序配置错误</span>';
  304. $('.promote-img').html(content);
  305. $('.promote-download a').attr('href','').hide();
  306. }else{
  307. $('.promote-img img').attr('src',res.data.weapp.path);
  308. $('.promote-download a').attr('href',res.data.weapp.path).show();
  309. }
  310. $(".path-wrap").hide();
  311. }else if(radio.value == 'pc') {
  312. var content = "";
  313. content += '<img src="'+ res.data.pc.path +'"/>';
  314. $('.promote-img').html(content);
  315. $('.path-wrap p input').val(res.data.pc.url);
  316. $('.path-wrap .copy').val(res.data.pc.url);
  317. $('.promote-download a').attr('href',res.data.pc.path).show();
  318. $(".path-wrap").show();
  319. }
  320. });
  321. }
  322. });
  323. form.render();
  324. });
  325. }else{
  326. layer.msg('加载失败,请重试');
  327. }
  328. }
  329. });
  330. }
  331. </script>
  332. {/block}