style.html 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. .exchange-type{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;}
  5. .style{display: flex;-webkit-box-align: center;align-items: center;-webkit-box-pack: center;justify-content: center;padding: 0 10px;}
  6. .style div{width: 50px;height: 16px;}
  7. .style p{margin-left: 10px;font-size: 12px;color: #333;}
  8. .preview-style img{margin-right: 64px; margin-bottom: 50px; height: 595px;width: 275px;-webkit-box-shadow: 5px 5px 20px #f5f5f5;box-shadow: 5px 5px 20px #f5f5f5;}
  9. </style>
  10. {/block}
  11. {block name="main"}
  12. {notempty name="$theme_list"}
  13. <div class="layui-form form-wrap">
  14. <div class="layui-form-item">
  15. <div class="layui-input-block">
  16. {foreach $theme_list as $k=>$v}
  17. <div class="exchange-type" data-id="{$v['id']}" data-title="{$v['title']}" data-name="{$v['name']}" data-main-color="{$v['main_color']}" data-aux-color="{$v['aux_color']}">
  18. <div class="style">
  19. <div style="background: url('{:img($v['color_img'])}') no-repeat;"></div>
  20. <p>{$v['title']}</p>
  21. </div>
  22. </div>
  23. {/foreach}
  24. </div>
  25. </div>
  26. <div class="layui-input-block">
  27. <div class="preview-style">
  28. {foreach $theme_list as $k=>$v}
  29. {foreach $v['preview'] as $ck=>$cv}
  30. <img src="{:img($cv)}" data-name="{$v['name']}" {if $k!=0}style="display:none;"{/if}>
  31. {/foreach}
  32. {/foreach}
  33. </div>
  34. </div>
  35. <div class="form-row">
  36. <input type="hidden" name="style_theme" value="{$style|json_encode}">
  37. <button class="layui-btn" lay-submit lay-filter="save">保存</button>
  38. </div>
  39. </div>
  40. {/notempty}
  41. {/block}
  42. {block name="script"}
  43. <script>
  44. var theme = JSON.parse($("input[name='style_theme']").val());
  45. $(".exchange-type").click(function() {
  46. $(this).addClass("border-color").siblings("div").removeClass("border-color");
  47. var obj = {
  48. id: $(this).attr('data-id'),
  49. title: $(this).attr('data-title'),
  50. name: $(this).attr('data-name'),
  51. main_color: $(this).attr('data-main-color'),
  52. aux_color: $(this).attr('data-aux-color'),
  53. };
  54. $("input[name='style_theme']").val(JSON.stringify(obj));
  55. $('.preview-style img').hide();
  56. $('.preview-style img[data-name="' + obj.name + '"]').show();
  57. });
  58. $('.exchange-type[data-name="' + theme.name + '"]').click();
  59. layui.use('form', function() {
  60. var form = layui.form, repeat_flag = false; //防重复标识
  61. form.on('submit(save)', function(data) {
  62. if (repeat_flag) return;
  63. repeat_flag = true;
  64. data.field = JSON.parse(data.field.style_theme);
  65. $.ajax({
  66. url: ns.url("shop/diy/style"),
  67. data: data.field,
  68. dataType: 'JSON',
  69. type: 'POST',
  70. success: function(res) {
  71. repeat_flag = false;
  72. layer.msg(res.message);
  73. }
  74. });
  75. });
  76. });
  77. </script>
  78. {/block}