lists.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. .layui-table-view td:last-child>div{overflow: inherit;}
  5. .operation-wrap{position: relative;}
  6. .layui-table-box{overflow: inherit;}
  7. .layui-table-body{overflow: inherit;}
  8. .set-home{display:inline-block;margin-left: 5px;padding: 3px;font-size: 12px;line-height: 1;color: #fff;}
  9. .popup-qrcode-wrap{text-align: center;background: #fff;border-radius: 2px;box-shadow: 0 2px 8px 0 rgba(200,201,204,.5);padding: 10px;position: absolute;z-index: 1;top: -73px;left: -180px;display: none;width: 170px;height: 230px;}
  10. .popup-qrcode-wrap:before, .popup-qrcode-wrap:after {left: 100%;top: 50%;border: solid transparent;content: " ";height: 0;width: 0;position: absolute;pointer-events: none;}
  11. .popup-qrcode-wrap:before {border-color: transparent;border-left-color: #e5e5e5;border-width: 8px;margin-top: -29px;}
  12. .popup-qrcode-wrap:after {border-color: transparent;border-left-color: #ffffff;border-width: 7px;margin-top: -31px;}
  13. .popup-qrcode-wrap img{width: 150px;height: 150px;max-width: initial;}
  14. .popup-qrcode-wrap p{font-size: 12px;margin: 5px 0;line-height: 1.8!important;}
  15. .popup-qrcode-wrap a{font-size: 12px;}
  16. .popup-qrcode-wrap input{opacity: 0;position: absolute;}
  17. .popup-qrcode-wrap .popup-qrcode-loadimg {width: 16px!important; height: 16px!important; margin-top: 107px;}
  18. .edit-sort.len-short{width: 100px !important;}
  19. .use{
  20. display: inline-block;
  21. /*padding: 2px 8px;*/
  22. line-height: 20px;
  23. /*color: #fff;*/
  24. /*border-radius: 2px;*/
  25. }
  26. .unused{
  27. display: inline-block;
  28. /*padding: 2px 8px;*/
  29. line-height: 20px;
  30. /*color: #999;*/
  31. /*background: #EFF0F4;*/
  32. /*border-radius: 2px;*/
  33. }
  34. .custom-tag{
  35. display: inline-block;
  36. /*padding: 2px 8px;*/
  37. line-height: 20px;
  38. }
  39. .select-page{
  40. display: flex;
  41. flex-wrap: nowrap;
  42. justify-content: center;
  43. text-align: center;
  44. /*overflow: hidden;*/
  45. }
  46. .select-page .item {position: relative;margin-right: 30px;padding: 10px;width: 200px;height: 390px;cursor: pointer;overflow: hidden;box-sizing: border-box;border: 1px solid #e9edef;}
  47. .select-page .item:last-child{margin-right: 0;}
  48. .select-page .item .checked {position: absolute;bottom: -1px;right: -1px;z-index: 101;font-size: 30px;display: none;}
  49. .select-page .item .mask{position: absolute;background: -webkit-gradient(linear, left top, left bottom, color-stop(52.65%, rgba(255,255,255,0)), color-stop(83.57%, #fff));background: linear-gradient(180deg, rgba(255,255,255,0) 52.65%, #fff 83.57%);height: 100%;width: 100%;z-index: 99;left:0;}
  50. .select-page .item img{width: 180px;}
  51. .select-page .item .info{position: absolute;bottom: 12px;z-index: 100;background-color: #ffffff;display: flex;flex-direction: column;width: 100%;text-align: center;color: #333;left: 0;}
  52. .select-page .item .info i {margin-bottom: 10px;font-size: 24px;color: #333;}
  53. .select-page .item .info span{font-size: 16px;font-weight: bold;}
  54. .select-page .item.selected .checked{display: block;}
  55. .select-btn{padding-top: 10px;margin-top:20px;padding-right:10px;height:40px;line-height:40px;text-align:right;border-top:1px solid #e9edef;}
  56. </style>
  57. {/block}
  58. {block name="main"}
  59. <!-- 搜索框 -->
  60. <div class="single-filter-box">
  61. <button class="layui-btn" onclick="createPage()">新建页面</button>
  62. <div class="layui-form">
  63. <div class="layui-input-inline">
  64. <input type="text" name="search_text" placeholder="请输入页面名称" autocomplete="off" class="layui-input">
  65. <button type="button" class="layui-btn layui-btn-primary" lay-filter="search" lay-submit>
  66. <i class="layui-icon">&#xe615;</i>
  67. </button>
  68. </div>
  69. </div>
  70. </div>
  71. <!-- 筛选面板 -->
  72. <!--<div class="screen layui-collapse" lay-filter="selection_panel">-->
  73. <!-- <div class="layui-colla-item">-->
  74. <!-- <form class="layui-colla-content layui-form layui-show">-->
  75. <!-- <div class="layui-form-item">-->
  76. <!-- <div class="layui-inline">-->
  77. <!-- <label class="layui-form-label">页面名称</label>-->
  78. <!-- <div class="layui-input-inline">-->
  79. <!-- <input type="text" name="search_text" placeholder="请输入页面名称" autocomplete="off" class="layui-input">-->
  80. <!-- </div>-->
  81. <!-- </div>-->
  82. <!-- <div class="layui-inline">-->
  83. <!-- <label class="layui-form-label">店铺模板</label>-->
  84. <!-- <div class="layui-input-inline">-->
  85. <!-- <select name="template_id" lay-filter="template_id">-->
  86. <!-- {foreach name="$template_goods_list" item="vo"}-->
  87. <!-- <option value="{$vo.goods_id}">{$vo.title}</option>-->
  88. <!-- {/foreach}-->
  89. <!-- </select>-->
  90. <!-- </div>-->
  91. <!-- </div>-->
  92. <!-- <div class="layui-inline">-->
  93. <!-- <label class="layui-form-label">页面类型</label>-->
  94. <!-- <div class="layui-input-inline">-->
  95. <!-- <select name="type" lay-filter="type">-->
  96. <!-- <option value="">全部</option>-->
  97. <!-- <option value="DIY_PAGE">自定义页面</option>-->
  98. <!-- {foreach name="$template_list" item="vo"}-->
  99. <!-- <option value="{$vo.name}">{$vo.title}</option>-->
  100. <!-- {/foreach}-->
  101. <!-- </select>-->
  102. <!-- </div>-->
  103. <!-- </div>-->
  104. <!-- </div>-->
  105. <!-- <div class="form-row">-->
  106. <!-- <button class="layui-btn" lay-submit lay-filter="search">筛选</button>-->
  107. <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
  108. <!-- </div>-->
  109. <!-- </form>-->
  110. <!-- </div>-->
  111. <!--</div>-->
  112. <div class="layui-tab table-tab" lay-filter="diy_list_tab">
  113. <ul class="layui-tab-title js-diy-tab">
  114. {foreach name="$template_list" item="vo"}
  115. <li {if $vo.name==$type }class="layui-this"{/if} lay-id="{$vo.name}">{$vo.title}({$vo.count})</li>
  116. {/foreach}
  117. </ul>
  118. <div class="layui-tab-content">
  119. <table id="diy_list" lay-filter="diy_list"></table>
  120. </div>
  121. </div>
  122. <script type="text/html" id="action">
  123. <div class="operation-wrap" data-id="{{d.id}}">
  124. <div class="table-btn">
  125. <div class="popup-qrcode-wrap"><img class="popup-qrcode-loadimg" src="__STATIC__/loading/loading.gif" /></div>
  126. {{# if(d.type != 'DIY_PAGE' && d.is_default == 0){ }}
  127. <a class="layui-btn" lay-event="setUse">使用</a>
  128. {{# } }}
  129. <a class="layui-btn text-color" lay-event="promote">推广</a>
  130. <a class="layui-btn" lay-event="edit">编辑</a>
  131. <a class="layui-btn" lay-event="copy">复制页面</a>
  132. {{# if(d.type == 'DIY_PAGE' || d.is_default == 0){ }}
  133. <a class="layui-btn" lay-event="delete">删除</a>
  134. {{# } }}
  135. </div>
  136. </div>
  137. </script>
  138. <!-- 编辑排序 -->
  139. <script type="text/html" id="editSort">
  140. <input name="sort" type="number" onchange="editSort({{d.id}}, this)" value="{{d.sort}}" class="layui-input edit-sort len-short">
  141. </script>
  142. <script type="text/html" id="toolbarOperation">
  143. <button class="layui-btn layui-btn-primary" lay-event="delete">批量删除</button>
  144. </script>
  145. <script type="text/html" id="batchOperation">
  146. <button class="layui-btn layui-btn-primary" lay-event="delete">批量删除</button>
  147. </script>
  148. <script type="text/html" id="createPageHtml">
  149. <div class="layui-form">
  150. <div class="layui-form-item">
  151. <label class="layui-form-label sm"><span class="required">*</span>所属模板</label>
  152. <div class="layui-input-inline len-mid">
  153. <select name="template_id" lay-filter="template_id" lay-verify="required">
  154. {foreach name="$template_goods_list" item="vo"}
  155. <option value="{$vo.goods_id}">{$vo.title}</option>
  156. {/foreach}
  157. </select>
  158. </div>
  159. </div>
  160. <div class="layui-form-item">
  161. <label class="layui-form-label sm"><span class="required">*</span>页面名称</label>
  162. <div class="layui-input-inline len-mid">
  163. <input type="text" name="title" placeholder="请输入页面名称" lay-verify="required" autocomplete="off" maxlength="15" class="layui-input">
  164. </div>
  165. </div>
  166. <div class="form-row sm">
  167. <button class="layui-btn" lay-submit lay-filter="createPage">确定</button>
  168. <button class="layui-btn layui-btn-primary" onclick="layer.close(createPageIndex)">取消</button>
  169. </div>
  170. </div>
  171. </script>
  172. <script type="text/html" id="selectPageHtml">
  173. <div class="layui-form select-page">
  174. {foreach name="$page_type_list" item="vo" key="k"}
  175. <div class="item{if $k==0} selected border-color{/if}" data-page-type="{$vo.name}">
  176. <i class="iconfont iconxuanzhong text-color checked"></i>
  177. <div class="mask"></div>
  178. <img src="{:img($vo.preview)}" alt="">
  179. <div class="info">
  180. <i class="{$vo.icon}{if $k==0} text-color{/if}"></i>
  181. <span {if $k==0}class="text-color"{/if}>{$vo.title}</span>
  182. </div>
  183. </div>
  184. {/foreach}
  185. </div>
  186. <div class="select-btn">
  187. <button class="layui-btn select-save" onclick="selectPage()">确定</button>
  188. <button class="layui-btn select-cancel layui-btn-primary" onclick="layer.close(createPageIndex)">取消</button>
  189. </div>
  190. </script>
  191. {/block}
  192. {block name="script"}
  193. <script>
  194. var form,laytpl,element,table,repeat_flag = false,createPageIndex;
  195. layui.use([ 'laytpl', 'form','element'], function () {
  196. laytpl = layui.laytpl;
  197. form = layui.form;
  198. element = layui.element;
  199. table = new Table({
  200. id: 'diy_list',
  201. elem: '#diy_list',
  202. url: ns.url("shop/diy/lists"),
  203. cols: [[{
  204. type: 'checkbox',
  205. width: '3%'
  206. }, {
  207. width: '20%',
  208. title: '页面名称',
  209. templet: function (res) {
  210. var html = '';
  211. html += `<span>${res.title}</span>`;
  212. return html;
  213. }
  214. }, {
  215. field: 'type_name',
  216. width: '16%',
  217. title: '页面类型',
  218. }, {
  219. width: '16%',
  220. title: '状态',
  221. templet: function (res) {
  222. var html = '';
  223. if (res.type == 'DIY_PAGE'){
  224. html = '<span class="custom-tag">-</span>';
  225. }else{
  226. if(res.is_default == 1) html = `<span class="use text-color">使用中</span>`;
  227. else html = `<span class="unused">未使用</span>`;
  228. }
  229. return html;
  230. }
  231. },
  232. // {
  233. // field: 'click_num',
  234. // width: '13%',
  235. // title: '浏览量',
  236. // sort: true
  237. // },
  238. {
  239. width: '20%',
  240. title: '创建时间',
  241. templet: function (d) {
  242. return ns.time_to_date(d.create_time);
  243. }
  244. },
  245. // {
  246. // field: 'sort',
  247. // width: '12%',
  248. // title: '排序',
  249. // templet: '#editSort',
  250. // sort: true
  251. // },
  252. {
  253. title: '操作',
  254. toolbar: '#action',
  255. width: '25%',
  256. align: 'right'
  257. }]],
  258. where: {
  259. template_id: $("select[name='template_id']").val()
  260. },
  261. toolbar: '#toolbarOperation',
  262. bottomToolbar: "#batchOperation"
  263. });
  264. //监听工具条
  265. table.tool(function (obj) {
  266. var data = obj.data;
  267. if (obj.event === 'promote') {
  268. // 推广
  269. window.open(ns.url('index/index/h5preview', {id: data.id, type: 'page'}));
  270. } else if (obj.event === 'edit') {
  271. window.open(ns.url("shop/diy/edit", {id: data.id}));
  272. } else if (obj.event === "delete") {
  273. deleteSiteDiyView(data.id);
  274. } else if (obj.event === "copy") {
  275. layer.confirm('确定要复制该页面吗?', function (index) {
  276. $.ajax({
  277. type: "post",
  278. url: ns.url("shop/diy/copySiteDiyView"),
  279. data: {'id': data.id},
  280. dataType: "JSON",
  281. success: function (res) {
  282. layer.msg(res.message);
  283. if (res.code >= 0) {
  284. table.reload();
  285. getPageCount();
  286. }
  287. }
  288. });
  289. layer.close(index);
  290. });
  291. }else if(obj.event === 'setUse') {
  292. $.ajax({
  293. type: "post",
  294. url: ns.url("shop/diy/setUse"),
  295. data: {id: data.id, name: data.name},
  296. dataType: "JSON",
  297. success: function (res) {
  298. layer.msg(res.message);
  299. if (res.code >= 0) {
  300. table.reload();
  301. }
  302. }
  303. });
  304. }
  305. });
  306. //批量操作
  307. table.bottomToolbar(function (obj) {
  308. if (obj.data.length < 1) {
  309. layer.msg('请选择要操作的数据');
  310. return;
  311. }
  312. switch (obj.event) {
  313. case "delete":
  314. var id_array = [];
  315. for (var i in obj.data) id_array.push(obj.data[i].id);
  316. deleteSiteDiyView(id_array.toString());
  317. break;
  318. }
  319. });
  320. //批量操作
  321. table.toolbar(function (obj) {
  322. if (obj.data.length < 1) {
  323. layer.msg('请选择要操作的数据');
  324. return;
  325. }
  326. switch (obj.event) {
  327. case "delete":
  328. var id_array = [];
  329. for (var i in obj.data) id_array.push(obj.data[i].id);
  330. deleteSiteDiyView(id_array.toString());
  331. break;
  332. }
  333. });
  334. // 搜索功能
  335. form.on('submit(search)', function (data) {
  336. table.reload({
  337. page: {
  338. curr: 1
  339. },
  340. where: data.field
  341. });
  342. return false;
  343. });
  344. form.on('submit(createPage)', function (data) {
  345. location.href = ns.url('shop/diy/edit',data.field);
  346. });
  347. //监听Tab切换,以改变地址hash值
  348. element.on('tab(diy_list_tab)', function () {
  349. var type = this.getAttribute('lay-id');
  350. table.reload({
  351. page: {
  352. curr: 1
  353. },
  354. where: {
  355. search_text : $('input[name="search_text"]').val(),
  356. type : type
  357. }
  358. });
  359. });
  360. });
  361. // 监听单元格编辑
  362. function editSort(id, event){
  363. var data = $(event).val();
  364. if (data == '') {
  365. $(event).val(0);
  366. data = 0;
  367. }
  368. if(!new RegExp("^-?[0-9]\\d*$").test(data)){
  369. layer.msg("排序号只能是整数");
  370. return ;
  371. }
  372. if(data<0){
  373. layer.msg("排序号必须大于0");
  374. return ;
  375. }
  376. $.ajax({
  377. type: 'POST',
  378. url: ns.url("shop/diy/modifySort"),
  379. data: {
  380. id: id,
  381. sort: data
  382. },
  383. dataType: 'JSON',
  384. success: function(res) {
  385. layer.msg(res.message);
  386. if(res.code==0){
  387. table.reload();
  388. }
  389. }
  390. });
  391. }
  392. function createPage() {
  393. // location.href = ns.url('shop/diy/edit');
  394. createPageIndex = layer.open({
  395. type: 1,
  396. title: '选择页面类型',
  397. content: $('#selectPageHtml').html(),
  398. offset: 'auto',
  399. area: ['auto','auto'],
  400. success: function (layero, index) {
  401. form.render();
  402. $('.select-page .item').click(function () {
  403. $(this).addClass('selected border-color').siblings().removeClass('selected border-color');
  404. $('.select-page .item').find('.info>*').removeClass('text-color');
  405. $(this).find('.info>*').addClass('text-color');
  406. });
  407. }
  408. });
  409. }
  410. function selectPage() {
  411. var selected = $('.select-page .item.selected');
  412. var params = {};
  413. // 排除自定义页面类型
  414. if (selected.attr('data-page-type') !== 'DIY_PAGE') {
  415. params.page_type = selected.attr('data-page-type');
  416. }
  417. location.href = ns.url('shop/diy/edit', params);
  418. }
  419. // 删除店铺微页面
  420. function deleteSiteDiyView(id_array) {
  421. layer.confirm('确定要删除这些微页面模板吗', function (index) {
  422. $.ajax({
  423. url: ns.url("shop/diy/deleteSiteDiyView"),
  424. data: {'id': id_array},
  425. dataType: "JSON",
  426. success: function (res) {
  427. layer.msg(res.message);
  428. if (res.code == 0) {
  429. getPageCount();
  430. table.reload();
  431. }
  432. }
  433. });
  434. layer.close(index);
  435. });
  436. }
  437. // 查询页面数量
  438. function getPageCount() {
  439. $.ajax({
  440. type: "post",
  441. url: ns.url("shop/diy/getPageCount"),
  442. data: {},
  443. dataType: "JSON",
  444. success: function (res) {
  445. if (res.code >= 0) {
  446. var str = '';
  447. for (var i = 0; i < res.data.length; i++) {
  448. var item = res.data[i];
  449. var type = $('.js-diy-tab li.layui-this').attr('lay-id');
  450. str += `<li`;
  451. if(item.name == type){
  452. str += ` class="layui-this"`;
  453. }
  454. str += ` lay-id="${item.name}">`;
  455. str += `${item.title}(${item.count})</li>`;
  456. }
  457. $('.js-diy-tab').html(str);
  458. }
  459. }
  460. });
  461. }
  462. </script>
  463. {/block}