temp_detail.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. @extends('layouts.base')
  2. @section('content')
  3. @section('title', '添加模板')
  4. <link rel="stylesheet" type="text/css" href="{{static_url('yunshop/goods/vue-goods1.css')}}" />
  5. <link rel="stylesheet" href="{{resource_get('plugins/more-printer/assets/css/temp-detail.css?time='.time())}}">
  6. <style>
  7. .top-box {
  8. padding: 0 20px;
  9. }
  10. .el-tag {
  11. font-size: 16px;
  12. cursor: pointer;
  13. }
  14. @media (max-width: 1450px) {
  15. .fixed-pane {
  16. left:70% !important;
  17. }
  18. }
  19. @media (max-height: 960px) {
  20. .fixed-pane {
  21. height: 45% !important;
  22. overflow: auto !important;
  23. }
  24. }
  25. </style>
  26. <div id="app">
  27. <div class="all">
  28. <div class="vue-head">
  29. <div class="vue-main-title">
  30. <div class="vue-main-title-left"></div>
  31. <div class="vue-main-title-content">消息模板信息</div>
  32. </div>
  33. <div style="padding: 10px;">
  34. <div style="color:#333333;margin-bottom:14px">订单商品详情默认打印,按照打印列格式打印。</div>
  35. <div style="background-color: #F6F7F9;width:480px;border-radius: 6px;">
  36. <table style="width:460px;height:120px;align:center;cellspace:0;cellpading:0">
  37. <tr align="center">
  38. <td>名称</td>
  39. <td>单价</td>
  40. <td>数量</td>
  41. <td>金额</td>
  42. </tr>
  43. <tr align="center">
  44. <td>商品名称1</td>
  45. <td>¥100.00</td>
  46. <td>1</td>
  47. <td>¥100.00</td>
  48. </tr>
  49. <tr align="center">
  50. <td>商品名称2</td>
  51. <td>¥100.00</td>
  52. <td>1</td>
  53. <td>¥100.00</td>
  54. </tr>
  55. </table>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="vue-main">
  60. <el-row>
  61. <el-col :span="16">
  62. <div class="top-box">
  63. <div style="padding: 50px 50px;">
  64. <el-form label-position="right" label-width="80px" :model="form">
  65. <el-form-item label="模板名称" label-width="200px">
  66. <el-input placeholder="小票模板名称,例:订单打印小票" v-model="form.title" @focus="focus"></el-input>
  67. </el-form-item>
  68. <el-form-item label="打印头部" label-width="200px">
  69. <el-input v-model="form.print_title" @focus="focus"></el-input>
  70. <span class="help-block">打印头部信息,比如商家名称 建议不超过8个字,会进行加粗处理</span>
  71. </el-form-item>
  72. <el-form-item label="打印列格式" label-width="200px">
  73. <el-input v-model="form.print_style" @focus="focus"></el-input>
  74. <div class="tip">
  75. <span class="help-block">
  76. 例如:
  77. <span style="color: #F30000;">名称:6|单价:6|数量:5|金额:5|折后实付:10</span>
  78. 解释: 名称 占据6位,单价占据6位,数量占据5位,金额占据5位,折后实付占据10位;总共每行是32个字符,每个中文或中文标点占用2字符;请严格按照格式来!
  79. </span>
  80. <br>
  81. <span class="help-block">
  82. 打印列格式顺序与打印顺序需要保持一致,避免发生占据字符错乱
  83. </span>
  84. </div>
  85. </el-form-item>
  86. <el-form-item label="打印顺序" label-width="200px">
  87. <div class="order-pane">
  88. <draggable :list="form.print_style_order_arr">
  89. <div class="order-box" v-for="(item,index) in form.print_style_order_arr" :key="index">
  90. <span class="name">[[item]]</span>
  91. <i class="el-icon-circle-close" @click="removeOrderName(item,index)"></i>
  92. </div>
  93. </draggable>
  94. </div>
  95. <div class="order-name">
  96. <span :class="item.status ? 'name no-drop' : 'name'" v-for="(item,index) in print_order_name" :key="index" @click="sureOrderName(item,index)">[[item.name]]</span>
  97. <span class="tip">不填则默认按名称,单价,数量,金额进行打印</span>
  98. </div>
  99. </el-form-item>
  100. <el-form-item label="字体放大一倍" label-width="200px">
  101. <el-switch v-model="form.print_style_enlarge" active-color="#29BA9C" inactive-color="#DCDFE6" active-value="on" inactive-value="off">
  102. </el-switch>
  103. <span class="help-block" style="color: #F30000;">注:放大一倍,默认关闭</span>
  104. </el-form-item>
  105. <el-form-item label="打印内容" label-width="200px" v-for="(item,index) in form.print_data">
  106. <el-input v-model="form.print_data[index]" @focus="focus">
  107. <template slot="append">
  108. <div style="cursor:pointer" @click="deleteKey(index)">
  109. <i class="el-icon-delete" style="font-size:20px"></i>
  110. </div>
  111. </template>
  112. </el-input>
  113. <span class="help-block">输入要打印的内容</span>
  114. <el-switch v-model="form.is_enlarge[index]" active-color="#29BA9C" inactive-color="#DCDFE6" active-value="on" inactive-value="off">
  115. </el-switch>
  116. <span class="help-block" style="color: #F30000;">注:放大一倍,默认关闭</span>
  117. </el-form-item>
  118. <el-button type="success" style="margin-bottom: 22px; margin-left:100px;background-color:#29BA9C" @click="appendKey"><i class="el-icon-plus">增加一条键</i></el-button>
  119. <el-form-item label="打印二维码" label-width="200px">
  120. <el-input v-model="form.qr_code" @focus="focus"></el-input>
  121. <span class="help-block">为空则不显示</span>
  122. </el-form-item>
  123. </el-form>
  124. </div>
  125. </div>
  126. </el-col>
  127. <el-col :span="8" :push="2" style="margin-top: 35px;;position:fixed;left:75%;top:300px" class="fixed-pane">
  128. <el-select v-model="value" placeholder="请选择">
  129. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  130. </el-option>
  131. </el-select>
  132. <div v-if="value == '1'">
  133. <div style="width: 217px;margin-top:20px" class="help-block">
  134. 点击变量后会自动插入选择的文本框的焦点位置,在打印时系统会自动替换对应变量值
  135. </div>
  136. <span style="color:#f44336">注意:以上模板消息变量只适用于小票打印</span>
  137. </div>
  138. <div v-if="value == '2'" style="width: 340px;">
  139. <div style="color: #353535;line-height: 48px;font-size:16px;margin-left:10px;color:#353535;font-weight:500">订单变量</div>
  140. <el-tag style="border-color: #C8CEDE;margin-bottom: 12px;margin-right: 12px;color:#333333" color="#fff" @click="chose(item)" v-for="(item,index) in order_name" :key="index">[[item]]</el-tag>
  141. <div style="background-color:#F6F7F9;border-radius: 6px;color: #333333;padding:8px;margin-top:12px">
  142. 点击变量后会自动插入选择的文本框的焦点位置,
  143. <div>在打印时系统会自动替换对应变量值</div>
  144. <div style="margin-top: 14px;color:#F30000">注意:以上模板消息变量只适用于小票打印</div>
  145. </div>
  146. </div>
  147. </el-col>
  148. </el-row>
  149. </div>
  150. <div class="vue-page">
  151. <div class="vue-center">
  152. <el-button type="primary" @click="submit">提交</el-button>
  153. <el-button @click="backTo">返回列表</el-button>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <script src="{{resource_get('resources/views/goods/assets/js/vueDraggable/sortable.js')}}"></script>
  159. <script src="{{resource_get('resources/views/goods/assets/js/vueDraggable/vuedraggable.js')}}"></script>
  160. <script language='javascript'>
  161. let id = "{{ request()-> id }}"
  162. //vue
  163. var app = new Vue({
  164. el: "#app",
  165. delimiters: ['[[', ']]'],
  166. data() {
  167. return {
  168. form: {
  169. title: '',
  170. print_title: '',
  171. print_style: '',
  172. print_style_enlarge: 'off',
  173. print_data: [],
  174. is_enlarge: [],
  175. qr_code: '',
  176. print_style_order_arr: [],
  177. },
  178. value: '',
  179. options: [{
  180. value: '1',
  181. label: '选择模板变量类型'
  182. }, {
  183. value: '2',
  184. label: '订单打印'
  185. }, ],
  186. order_name: ['订单编号', '订单金额', '订单时间', '订单状态', '商品条码', '商品编号', '优惠金额', '抵扣金额', '收货地址', '运费', '备注', '姓名', '电话', '订单应付金额', '提货人姓名', '提货人手机号'],
  187. current_input_obj: null,
  188. print_order_name:[{
  189. name:'名称',
  190. status: false
  191. },{
  192. name:'单价',
  193. status: false
  194. },{
  195. name:'数量',
  196. status: false
  197. },{
  198. name:'金额',
  199. status: false
  200. },{
  201. name:'折后实付',
  202. status: false
  203. }]
  204. }
  205. },
  206. computed: {
  207. },
  208. mounted() {
  209. if (id) {
  210. this.getTempDetail()
  211. }
  212. },
  213. methods: {
  214. //选择变量
  215. chose(item) {
  216. if (this.current_input_obj) {
  217. this.current_input_obj.target.value += `[${item}]`
  218. this.current_input_obj.target.dispatchEvent(new Event('input')) //通过触发自定义input事件实现vue中绑定的数据更新
  219. } else {
  220. return
  221. }
  222. },
  223. //聚焦
  224. focus(event) {
  225. this.current_input_obj = event
  226. },
  227. //返回列表
  228. backTo() {
  229. let url = "{!! yzWebUrl('plugin.printer.admin.temp.index') !!}"
  230. window.location.href=url
  231. },
  232. //删除一条键
  233. deleteKey(index) {
  234. this.form.print_data.splice(index, 1)
  235. this.form.is_enlarge.splice(index, 1)
  236. },
  237. //增加一条键
  238. appendKey() {
  239. this.form.print_data.push("")
  240. this.form.is_enlarge.push('off')
  241. },
  242. //提交表单
  243. submit() {
  244. let json = {
  245. title: this.form.title,
  246. print_data: this.form.print_data,
  247. print_style: this.form.print_style,
  248. qr_code: this.form.qr_code,
  249. print_title: this.form.print_title,
  250. print_style_order_arr: this.form.print_style_order_arr
  251. }
  252. if(this.form.print_style_enlarge =='on'){
  253. json.print_style_enlarge = 'on'
  254. }else{
  255. }
  256. json.is_enlarge = []
  257. for (const jsonKey in this.form.is_enlarge) {
  258. if(this.form.is_enlarge[jsonKey] == 'on'){
  259. json.is_enlarge[jsonKey] = this.form.is_enlarge[jsonKey]
  260. }
  261. }
  262. if(json.is_enlarge.length == 0){
  263. delete json.is_enlarge
  264. }
  265. if (id) {
  266. this.$http.post("{!! yzWebFullUrl('plugin.printer.admin.temp.edit') !!}", {
  267. temp: {
  268. id,
  269. ...json
  270. }
  271. }).then((res) => {
  272. if (res.data.result) {
  273. this.$message.success(res.data.msg)
  274. let url = "{!! yzWebUrl('plugin.printer.admin.temp.index') !!}"
  275. window.location.href=url
  276. } else {
  277. this.$message.error(res.data.msg);
  278. }
  279. })
  280. } else {
  281. if (this.form.print_data < 1) {
  282. this.$message.error('请添加一个键')
  283. } else {
  284. this.$http.post("{!! yzWebFullUrl('plugin.printer.admin.temp.add') !!}", {
  285. temp: {
  286. ...json
  287. }
  288. }).then((res) => {
  289. if (res.data.result) {
  290. this.$message.success(res.data.msg)
  291. let url = "{!! yzWebUrl('plugin.printer.admin.temp.index') !!}"
  292. window.location.href=url
  293. } else {
  294. this.$message.error(res.data.msg);
  295. }
  296. })
  297. }
  298. }
  299. },
  300. //获取模板详情
  301. getTempDetail() {
  302. this.$http.post("{!! yzWebFullUrl('plugin.printer.admin.temp.info') !!}", {
  303. id
  304. }).then((res) => {
  305. if (res.data.result) {
  306. let data = res.data.data
  307. this.form.title = data.title
  308. this.form.print_title = data.print_title
  309. this.form.print_style = data.print_style
  310. this.form.print_style_enlarge = data.print_style_enlarge
  311. this.form.print_data = data.print_data?data.print_data:[]
  312. this.form.is_enlarge = data.is_enlarge?data.is_enlarge:[]
  313. this.form.qr_code = data.qr_code;
  314. this.form.print_style_order_arr = Array.isArray(data.print_style_order_arr) ? data.print_style_order_arr : [];
  315. for(let item of this.print_order_name) {
  316. for(let citem of this.form.print_style_order_arr) {
  317. if(citem == item.name) {
  318. item.status = true;
  319. }
  320. }
  321. }
  322. } else {
  323. this.$message.error(res.data.msg);
  324. }
  325. })
  326. },
  327. //选中排序名称
  328. sureOrderName(row,index) {
  329. if(row.status) return
  330. this.print_order_name[index].status = true;
  331. this.form.print_style_order_arr.push(row.name);
  332. },
  333. //移出选中排序名称
  334. removeOrderName(name,index) {
  335. this.form.print_style_order_arr.splice(index,1);
  336. let index_of = this.print_order_name.findIndex(item => item.name == name);
  337. this.print_order_name[index_of].status = false;
  338. }
  339. },
  340. })
  341. </script>
  342. @endsection