lists.html 7.9 KB

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