template.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. .tips {margin: 20px 0;border: 1px dashed;padding: 5px 10px;width: 90%;}
  5. .theme-item{display: inline-block;min-width: 140px;height: 60px;line-height: 60px;border: 1px solid #ededed;border-radius: 4px;margin-right: 10px;position: relative;cursor: pointer;margin-bottom: 15px;}
  6. .style{display: flex;-webkit-box-align: center;align-items: center;-webkit-box-pack: center;justify-content: center;padding: 0 10px;}
  7. .style div{width: 50px;height: 16px;}
  8. .style p{margin-left: 10px;font-size: 12px;color: #333;}
  9. .template-list{display: flex;flex-wrap: wrap;}
  10. .template-list li{overflow: hidden;position: relative;padding: 10px;margin-right: 30px;margin-bottom: 30px;width: 270px;height: 410px;border: 1px solid #e9e9e9;border-radius: 4px;box-sizing: border-box;}
  11. .template-list li .item-img{overflow: hidden;width: 200px;height: 300px;margin: 0 auto;}
  12. .template-list li .item-img img{max-width: 100%;}
  13. .template-list li .item-hide{display: none;position: absolute;left: 0;right: 0;top: 0;bottom: 0;background-color: rgba(0,0,0,.6);text-align: center;}
  14. .template-list li .item-name{display: block;padding-top: 7px;line-height: 22px;font-size: 14px;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;}
  15. .template-list li .item-desc{display: block;padding-top: 7px;line-height: 22px;font-size: 12px;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 1;-webkit-box-orient: vertical;color:#999;}
  16. .template-list li .item-hide .item-btn-box{position: absolute;top: 50%;left: 50%;display: flex;flex-wrap: wrap;justify-content: center;align-items: center;transform: translate(-50%, -50%);}
  17. .template-list li .item-hide button{border: 1px solid #fff;display: flex;justify-content: center;align-items: center;height: 33px;width: 100px;color: #fff;background: none;border-radius: 4px;cursor: pointer;}
  18. .template-list li:hover .item-hide{display: block;}
  19. .template-list li .item-hide button ~ button{margin-top: 15px;}
  20. .template-list li .is-default{padding: 6px;font-size: 12px;color:#fff;border-radius: 4px;display: inline-block;margin-top: 5px;line-height: 1;}
  21. </style>
  22. {/block}
  23. {block name="main"}
  24. <div class="theme-wrap">
  25. {foreach $theme_list as $k=>$v}
  26. <div class="theme-item {if $style['name']==$v['name']}border-color{/if}" data-id="{$v['id']}" data-title="{$v['title']}" data-name="{$v['name']}" data-main-color="{$v['main_color']}" data-aux-color="{$v['aux_color']}">
  27. <div class="style">
  28. <div style="background: url('{:img($v['color_img'])}') no-repeat;"></div>
  29. <p>{$v['title']}</p>
  30. </div>
  31. </div>
  32. {/foreach}
  33. </div>
  34. <ul class="template-list">
  35. {foreach name="$template" item="vo"}
  36. <li data-name="{$vo.name}" data-title="{$vo.title}" data-preview="{$vo.preview}" data-desc="{$vo.desc}">
  37. <div class="item-img">
  38. <img src="{:img($vo.cover)}" alt="">
  39. </div>
  40. <span class="item-name">{$vo.title}</span>
  41. <span class="item-desc">{$vo.desc}</span>
  42. {if isset($vo.is_default) && $vo.is_default == 1}
  43. <span class="is-default bg-color">使用中</span>
  44. {/if}
  45. <div class="item-hide">
  46. <div class="item-btn-box">
  47. <button class="use" onclick="createTemplate('{$vo.goods_id}','{$vo.name}')">立即使用</button>
  48. <button class="preview" onclick="$('#{$vo.name}').click()">预览</button>
  49. </div>
  50. </div>
  51. <img id="{$vo.name}" class="layui-hide" src="{:img($vo.preview)}" layer-src>
  52. </li>
  53. {/foreach}
  54. </ul>
  55. {/block}
  56. {block name="script"}
  57. <script>
  58. layui.use('form', function() {
  59. var repeat_flag = false; //防重复标识
  60. $(".theme-item").click(function () {
  61. $(this).addClass("border-color").siblings("div").removeClass("border-color");
  62. var obj = {
  63. id: $(this).attr('data-id'),
  64. title: $(this).attr('data-title'),
  65. name: $(this).attr('data-name'),
  66. main_color: $(this).attr('data-main-color'),
  67. aux_color: $(this).attr('data-aux-color'),
  68. };
  69. if (repeat_flag) return;
  70. repeat_flag = true;
  71. $.ajax({
  72. url: ns.url("shop/diy/style"),
  73. data: obj,
  74. dataType: 'JSON',
  75. type: 'POST',
  76. success: function (res) {
  77. repeat_flag = false;
  78. layer.msg(res.message);
  79. }
  80. });
  81. });
  82. });
  83. // 使用模板
  84. function createTemplate(goods_id,name) {
  85. $.ajax({
  86. type: 'post',
  87. url: ns.url("shop/diy/create"),
  88. data: {
  89. goods_id: goods_id,
  90. name: name
  91. },
  92. dataType: 'JSON',
  93. success: function(res) {
  94. if (res.code >= 0){
  95. location.href = ns.url("shop/diy/index");
  96. }else{
  97. layer.msg(res.message);
  98. }
  99. }
  100. });
  101. // var tips = `切换模版后需要重新<a href="{:addon_url('shop/config/sitedeploy')}" target="_blank" class="text-color">部署</a>H5、小程序`;
  102. // layer.confirm(tips, {
  103. // title: '操作提示',
  104. // btn: ['确定', '取消'],
  105. // yes: function () {
  106. // }
  107. // });
  108. }
  109. </script>
  110. {/block}