edit.blade.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. @extends('layouts.app')
  2. @section('title')模板-编辑@endsection
  3. @section('content')
  4. <div class="container-fluid d-none row m-1" id="print-template">
  5. <div class="col-lg-2 col-sm-3 p-0" id="part_panel">
  6. {{-- 组件选择面板 --}}
  7. @include('maintenance.expressPrinting.template._select')
  8. </div>
  9. <div class="col-lg-8 col-sm-6 p-0" id="production_panel">
  10. {{-- 模板制作面板 --}}
  11. @include('maintenance.expressPrinting.template._produce')
  12. </div>
  13. <div class="col-lg-2 col-sm-3 p-0" id="compile_panel">
  14. {{-- 模板编辑页面 --}}
  15. @include('maintenance.expressPrinting.template._compile')
  16. </div>
  17. </div>
  18. @endsection
  19. @section('lastScript')
  20. <script type="text/javascript" src="{{mix('js/utilities/barcode.js')}}"></script>
  21. <script type="text/javascript" src="{{mix('/js/utilities/qrcode.js')}}"></script>
  22. <script>
  23. let vue = new Vue({
  24. el: "#print-template",
  25. data: {
  26. printParts: [
  27. @foreach($printParts as $items)
  28. {
  29. name: '{{ $items['name'] }}', value: {
  30. @foreach($items['value'] as $key=>$value)
  31. '{{$key}}': '{{$value}}',
  32. @endforeach
  33. }
  34. },
  35. @endforeach
  36. ],
  37. imgPrefix:"{{asset("/storage")}}",
  38. images:{!! $printPartImages ?? [] !!},
  39. filterPrintParts: [],
  40. producePanel: {}, // 背景版
  41. selectProducePanel: false, // 是否选中背景版
  42. productionParts: {
  43. bg: null,
  44. printParts: [], // 组件
  45. editPart: null, // 编辑中的组件
  46. editIndex: {}, // 编辑中组件的下标
  47. addPart: {}, // 添加模板
  48. },
  49. partIsSelected: false, // 表示模块被选中
  50. selectPrintPart: {}, // 选中模块
  51. selectPrintPartPoint: {x: '', y: ''}, // 选中模块时模块 point
  52. mousePointStart: {x: '', y: ''}, // 开始拖动时的 point
  53. mousePointEnd: {x: '', y: ''}, // 结束拖动时的 point
  54. selectPrintPartOffset: {left: '', top: ''}, // 选中时的left 和 top
  55. z_index: 10,
  56. },
  57. mounted() {
  58. $('.navbar,.nav1,.nav2').hide();
  59. $('.nav3').on('mouseenter', function () {
  60. $('.navbar,.nav1,.nav2').show();
  61. });
  62. $('.body').on('mouseenter', function () {
  63. $('.navbar,.nav1,.nav2').hide();
  64. });
  65. $("#print-template").removeClass('d-none');
  66. },
  67. methods: {
  68. // 添加组件至面板上
  69. _addPartToProductionPanel(printPart) {
  70. let _clone = JSON.parse(JSON.stringify(printPart));
  71. let print_part = _clone.value
  72. if (!this.productionParts.bg && print_part.type !== 'bg') {
  73. window.tempTip.show('先添加背景组件在进行其他组件的添加');
  74. return
  75. } else if (this.productionParts.bg && print_part.type === 'bg') {
  76. window.tempTip.show('背景组件请勿重复添加');
  77. return
  78. }
  79. if (print_part.type === 'bg') {
  80. this.productionParts.bg = print_part;
  81. return;
  82. }
  83. print_part.index = this.productionParts.printParts.length;
  84. this.z_index+=1
  85. print_part.z_index = this.z_index;
  86. print_part.id = "id" + this.z_index;
  87. print_part.text = null;
  88. this.productionParts.printParts.push(print_part); // 添加入组件列表中
  89. console.log(print_part.type);
  90. if (print_part.type === "stripeCode") {
  91. setTimeout(function () {
  92. console.log(123);
  93. window.setBarcode("0123456789", "#" + print_part.id, 2, 50, true)
  94. }, 100);
  95. } else if (print_part.type === "qRCode") {
  96. setTimeout(function () {
  97. new QRCode(document.getElementById(print_part.id), {
  98. text: "占位二维码",
  99. width: print_part.width,
  100. height: print_part.height,
  101. colorDark : "#000000",
  102. colorLight : "#ffffff",
  103. correctLevel : QRCode.CorrectLevel.H
  104. });
  105. }, 1000)
  106. } else if (print_part.type === "image") {
  107. // TODO 修改为图片
  108. }
  109. },
  110. // 从面板删除组件
  111. _removePartToProductionPanel(editPart) {
  112. this.productionParts.editPart = null;
  113. let index = this.productionParts.printParts.indexOf(editPart);
  114. this.productionParts.printParts.splice(index, 1);
  115. },
  116. //
  117. _alignContentToProductionPanel() {
  118. this.productionParts.printParts.splice(this.productionParts.editIndex, 1);
  119. this.$forceUpdate();
  120. },
  121. // 打开保存modal
  122. showSaveModal() {
  123. $('#saveModal').modal('show');
  124. },
  125. // 保存modal
  126. _savePrintTemplate() {
  127. tempTip.setDuration(3000);
  128. tempTip.setIndex(1999);
  129. let printTemplate = JSON.parse(JSON.stringify(this.productionParts.printParts));
  130. printTemplate.push(this.productionParts.bg);
  131. let data = {
  132. name: this.productionParts.addPart.name,
  133. value: printTemplate
  134. };
  135. window.axios.post("{{url('apiLocal/maintenance/expressPrinting/template/create')}}", data).then(res => {
  136. if (res.data.success) {
  137. tempTip.showSuccess('保存成功!');
  138. $('#saveModal').modal('hide');
  139. return;
  140. }
  141. tempTip.show(res.data.message);
  142. }).catch(err => {
  143. tempTip.show(err);
  144. });
  145. },
  146. // 开始拖动元素时触发
  147. _dragstart(item, $event) {
  148. this.selectPrintPartPoint = {x: parseInt(item.left), y: parseInt(item.top)};
  149. this.mousePointStart = {x: $event.offsetX, y: $event.offsetY};
  150. },
  151. // 结束拖动元素时触发
  152. _dragend(item, $event) {
  153. this.mousePointEnd = {x: $event.offsetX, y: $event.offsetY};
  154. let left = item.left - (this.mousePointStart.x - this.mousePointEnd.x);
  155. let top = item.top - (this.mousePointStart.y - this.mousePointEnd.y);
  156. item.left = left > 0 ? left : 0;
  157. item.top = top > 0 ? top : 0;
  158. },
  159. getProducePanelStyle() {
  160. return {
  161. width: this.producePanel.width + 'px',
  162. height: this.producePanel.height + 'px',
  163. }
  164. },
  165. getStyle(item) {
  166. let style = {
  167. width: item.width + 'px',
  168. height: item.height + 'px',
  169. left: item.left + 'px',
  170. top: item.top + 'px',
  171. 'white-space': 'pre',
  172. 'z-index' : item['z_index'],
  173. };
  174. if (item['border-width']) {
  175. style['border-width'] = item['border-width']+'px';
  176. style['border-color'] = '#000';
  177. style['border-style'] = 'solid';
  178. }
  179. if (item['font-size']) style['font-size'] = item['font-size'];
  180. return style;
  181. },
  182. getImageSrc(image){
  183. return this.imgPrefix+image.file.url+'.'+image.file.type
  184. },
  185. setImageBg(image){
  186. let src = this.getImageSrc(image);
  187. this.productionParts.editPart.value = image.name;
  188. document.getElementById(this.productionParts.editPart.id).setAttribute('src',src) ;
  189. }
  190. }
  191. });
  192. </script>
  193. @endsection