edit_print_template.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. .design-sketch {
  5. border: 1px solid #ccc;
  6. position: relative;
  7. }
  8. .design-sketch div {
  9. display: inline-block;
  10. border: 1px solid #ccc;
  11. padding: 10px;
  12. margin: 8px;
  13. border-radius: 2px;
  14. color: #555;
  15. white-space: nowrap;
  16. user-select: none;
  17. background-color: #fff;
  18. line-height: 1;
  19. }
  20. .design-sketch div i {
  21. position: absolute;
  22. top: -10px;
  23. right: -10px;
  24. display: none;
  25. width: 20px;
  26. height: 20px;
  27. border-radius: 10px;
  28. background-color: rgba(0, 0, 0, .5);
  29. color: #FFFFFF;
  30. text-align: center;
  31. line-height: 20px;
  32. z-index: 99;
  33. }
  34. .print-option {
  35. display: inline-block;
  36. border: 1px solid;
  37. line-height: 1;
  38. padding: 10px;
  39. margin-left: 5px;
  40. margin-bottom: 8px;
  41. border-radius: 2px;
  42. color: #545454;
  43. cursor: pointer;
  44. }
  45. .bg-color-gray {
  46. background-color: #E5E5E5!important;
  47. }
  48. .form-wrap {margin-top: 0;}
  49. </style>
  50. {/block}
  51. {block name="main"}
  52. <div class="layui-form form-wrap">
  53. <input type="hidden" name="company_id" value="{$company_id}">
  54. <input type="hidden" name="id" value="{$id}">
  55. <div class="layui-form-item">
  56. <label class="layui-form-label">打印字体大小:</label>
  57. <div class="layui-input-block">
  58. {if condition="$info.font_size"}
  59. <input type="number" name="font_size" value="{$info.font_size}" class="layui-input print-size len-short" autocomplete="off">
  60. {else/}
  61. <input type="number" value="14" name="font_size" class="layui-input print-size len-short" autocomplete="off">
  62. {/if}
  63. </div>
  64. <div class="word-aux">
  65. <p>请输入字体大小,字体单位:px,用于控制打印模板的文字大小</p>
  66. </div>
  67. </div>
  68. <div class="layui-form-item">
  69. <label class="layui-form-label">显示尺寸:</label>
  70. <div class="layui-input-block">
  71. <div class="layui-input-inline">
  72. {if condition="$info.width"}
  73. <input name="width" type="number" value="{$info.width}" lay-verify="int" class="layui-input show-width len-short" autocomplete="off">
  74. {else/}
  75. <input name="width" type="number" value="766" lay-verify="int" class="layui-input show-width len-short" autocomplete="off">
  76. {/if}
  77. </div>
  78. <div class="layui-form-mid">-</div>
  79. <div class="layui-input-inline">
  80. {if condition="$info.height"}
  81. <input name="height" type="number" value="{$info.height}" lay-verify="int" class="layui-input show-height len-short" autocomplete="off">
  82. {else/}
  83. <input name="height" type="number" value="510" lay-verify="int" class="layui-input show-height len-short" autocomplete="off">
  84. {/if}
  85. </div>
  86. </div>
  87. <div class="word-aux">
  88. <p>尺寸单位:px,用于控制打印模板的尺寸</p>
  89. </div>
  90. </div>
  91. <div class="layui-form-item">
  92. <label class="layui-form-label">打印选项:</label>
  93. <div class="layui-input-block">
  94. {foreach $print_item_list as $print_k=>$print_v}
  95. <span class="print-option" data-print-name="{$print_v.item_name}">{$print_v.item_title}</span>
  96. {/foreach}
  97. </div>
  98. </div>
  99. <div class="layui-form-item">
  100. <label class="layui-form-label">效果图预览:</label>
  101. <div class="layui-input-block design-sketch"></div>
  102. </div>
  103. <div class="layui-form-item">
  104. <label class="layui-form-label">打印背景图:</label>
  105. <div class="layui-input-block">
  106. <div class="upload-img-block">
  107. <div class="upload-img-box">
  108. {if empty($info.background_image)}
  109. <div class="upload">
  110. <i class="iconfont iconshangchuan"></i>
  111. <p>点击上传</p>
  112. </div>
  113. {else/}
  114. <img layer-src src="{:img($info.background_image)}" alt="">
  115. {/if}
  116. </div>
  117. <p id="printBackground" class=" {if condition="$info.background_image"} replace {else/} no-replace{/if}">替换</p>
  118. <input type="hidden" class="bg-img-pri" name="background_image" value="{$info.background_image}" /> <!-- 预览背景图 -->
  119. <i class="del {if !empty($info.background_image)}show{/if}">x</i>
  120. </div>
  121. </div>
  122. <p class="word-aux">上传打印背景图会在打印时以背景形式显示在打印纸上,可在效果预览图中查看效果</p>
  123. </div>
  124. <div class="form-row">
  125. <button class="layui-btn" lay-submit lay-filter="save">保存</button>
  126. <button type="reset" class="layui-btn layui-btn-primary" onclick="back()">返回</button>
  127. </div>
  128. <input type="hidden" class="print-con" value="{$info.content_json}" /> <!-- 打印内容 -->
  129. </div>
  130. {/block}
  131. {block name="script"}
  132. <script src="STATIC_JS/Tdrag.min.js"></script>
  133. <script>
  134. $(document).ready(function () {
  135. var img = $(".bg-img-pri").val();
  136. $(".design-sketch").css({
  137. "background": "url("+ img +") no-repeat center/ cover",
  138. "width": $("input[name=width]").val(),
  139. "height": $("input[name=height]").val()
  140. });
  141. if ($(".print-con").val() != '') {
  142. var arr = JSON.parse($(".print-con").val());
  143. var fontSize = $("input[name=font_size]").val();
  144. if (fontSize == '') {
  145. fontSize = 14;
  146. }
  147. for (index in arr) {
  148. var class_name = arr[index].item_name,
  149. span_text = arr[index].item_title,
  150. top = arr[index].top,
  151. left = arr[index].left;
  152. $(".print-option").each(function () {
  153. var print_name = $(this).attr("data-print-name");
  154. if (class_name == print_name) {
  155. $(this).addClass("bg-color-gray");
  156. $(this).css("cursor", "not-allowed");
  157. }
  158. });
  159. var html = '<div class="span_' + class_name + '" style="top: '+ top +'px; left: '+ left +'px; font-size: '+ fontSize +'px;">'+
  160. '<span>' + span_text + '</span>'+
  161. '<i class="iconfont iconclose_light" onclick="remove(this)"></i>'+
  162. '</div>';
  163. $(".design-sketch").append(html);
  164. $(".span_" + arr[index].item_name).hover(function () {
  165. $(this).find("i").show();
  166. }, function () {
  167. $(this).find("i").hide();
  168. });
  169. $(".span_" + arr[index].item_name).Tdrag({
  170. scope: ".design-sketch"
  171. });
  172. }
  173. }
  174. });
  175. </script>
  176. <script>
  177. layui.use(['form'],function() {
  178. var form = layui.form,
  179. repeat_flag = false; //防重复标识
  180. form.render();
  181. var upload = new Upload({
  182. elem: '#printBackground',
  183. callback:function (res) {
  184. if (res.code >= 0) {
  185. $(".design-sketch").css("background", "url("+ ns.img(res.data.pic_path) +") no-repeat center/ cover");
  186. }
  187. },
  188. deleteCallback:function () {
  189. $(".design-sketch").css("background", "");
  190. }
  191. });
  192. /**
  193. * 监听提交
  194. */
  195. form.on('submit(save)', function(data) {
  196. var content = [];
  197. $(".design-sketch div").each(function () {
  198. var item = {};
  199. item.item_name = $(this).attr("class").substring(5);
  200. item.item_title = $(this).text();
  201. item.left = $(this).position().left;
  202. item.top = $(this).position().top;
  203. content.push(item);
  204. });
  205. data.field.content_json = JSON.stringify(content);
  206. // 删除图片
  207. if(!data.field.background_image) upload.delete();
  208. if (repeat_flag) return;
  209. repeat_flag = true;
  210. $.ajax({
  211. url: ns.url("shop/express/editprinttemplate"),
  212. data: data.field,
  213. dataType: 'JSON',
  214. type: 'POST',
  215. success: function(res){
  216. repeat_flag = false;
  217. if (res.code == 0) {
  218. layer.confirm('编辑成功', {
  219. title:'操作提示',
  220. btn: ['返回列表', '继续操作'],
  221. yes: function(){
  222. location.href = ns.url("shop/express/expressCompany");
  223. },
  224. btn2: function() {
  225. location.reload();
  226. }
  227. });
  228. }else{
  229. layer.msg(res.message);
  230. }
  231. }
  232. });
  233. });
  234. /**
  235. * 预览内容添加
  236. */
  237. $(".print-option").click(function(){
  238. var dataValue = $(this).text(),
  239. dataId = $(this).attr("data-print-name");
  240. var fontSize = $("input[name=font_size]").val();
  241. if (fontSize == '') {
  242. fontSize = 14;
  243. }
  244. if ($(".span_"+ dataId).length > 0) {
  245. return false;
  246. } else {
  247. $(this).addClass("bg-color-gray");
  248. $(this).css("cursor", "not-allowed");
  249. }
  250. var html = '<div class="span_' + dataId + '" style="font-size: '+ fontSize +'px;">'+
  251. '<span>' + dataValue + '</span>'+
  252. '<i class="iconfont iconclose_light" onclick="remove(this)"></i>'+
  253. '</div>';
  254. $(".design-sketch").append(html);
  255. $(".span_" + dataId).hover(function () {
  256. $(this).find("i").show();
  257. }, function () {
  258. $(this).find("i").hide();
  259. });
  260. $(".span_" + dataId).Tdrag({
  261. scope: ".design-sketch"
  262. });
  263. });
  264. /**
  265. * 改变效果图宽和高
  266. */
  267. $(".show-width").blur(function(){
  268. $(".design-sketch").css("width", $(this).val());
  269. $("#realWidth").text($(this).val() * $(".proportion").val() + "px");
  270. });
  271. $(".show-height").blur(function(){
  272. $(".design-sketch").css("height", $(this).val());
  273. $("#realHeight").text($(this).val() * $(".proportion").val() + "px");
  274. });
  275. /**
  276. * 打印字体大小
  277. */
  278. $(".print-size").blur(function(){
  279. $(".design-sketch span").css("font-size", $(this).val() + "px");
  280. });
  281. });
  282. function remove(e) {
  283. var that = e;
  284. $(that).parent().remove();
  285. var attr_name = $(that).parent().attr("class").substring(5);
  286. $(".print-option").each(function () {
  287. var print_name = $(this).attr("data-print-name");
  288. if (attr_name == print_name) {
  289. $(this).removeClass("bg-color-gray");
  290. $(this).css("cursor", "pointer");
  291. }
  292. });
  293. }
  294. function back(){
  295. location.href = ns.url("shop/express/expressCompany");
  296. }
  297. </script>
  298. {/block}