index.blade.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. @extends('layouts.app')
  2. @section('title','打印终端')
  3. @section('content')
  4. <div class="container-fluid " id="list">
  5. <div class="card">
  6. {{-- @can('基础设置-快递打印-打印机-添加')--}}
  7. @include('maintenance.expressPrinting.setting.printer._create')
  8. {{-- @endcan--}}
  9. {{-- @can('基础设置-快递打印-打印机-编辑')--}}
  10. @include('maintenance.expressPrinting.setting.printer._edit')
  11. {{-- @endcan--}}
  12. <div class="card-body">
  13. <div class="row pull-left m-1">
  14. {{-- @can('基础设置-快递打印-打印机-添加')--}}
  15. <button class="btn btn-outline-info mb-1 mr-3" @click="showCreatedModel"><span
  16. class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增
  17. </button>
  18. {{-- @endcan--}}
  19. </div>
  20. @include('maintenance.expressPrinting.setting.printer._table')
  21. </div>
  22. </div>
  23. </div>
  24. @endsection
  25. @section('lastScript')
  26. <script>
  27. var list = new Vue({
  28. el: "#list",
  29. data: {
  30. printers: {!! $terminalPrinters->toJson() !!}['data'],
  31. terminals: [
  32. @foreach($terminals as $terminal)
  33. {id:'{{$terminal->id}}',name:'{{$terminal->name}}'},
  34. @endforeach
  35. ],
  36. logistics:[
  37. @foreach($logistics as $logistic)
  38. {id:'{{$logistic->id}}',name:'{{$logistic->name}}'},
  39. @endforeach
  40. ],
  41. printer: {
  42. logistic_ids:[],
  43. },
  44. printerErrors: {},
  45. terminalFilter:null,
  46. filter:{
  47. logistic:null, // 删选 logistic
  48. printer_logistic:null, // 删选 printer->logistic
  49. },
  50. index: null,
  51. selectTr: null,
  52. },
  53. mounted() {
  54. $("#list").removeClass('d-none');
  55. },
  56. computed:{
  57. filterTerminals(){
  58. let terminals = JSON.parse(JSON.stringify(this.terminals));
  59. let self = this;
  60. if(this.terminalFilter === null){
  61. return terminals;
  62. }
  63. let terminalFilter = terminals.filter(item=>{
  64. return item.name.indexOf(self.terminalFilter) >= 0;
  65. });
  66. if (terminalFilter.length < this.terminals.length && terminalFilter.length>0)
  67. this.printer.terminal_id = terminalFilter[0]['id'];
  68. return terminalFilter;
  69. },
  70. },
  71. methods: {
  72. includeLogistics(item){
  73. let bool = !this.printer.logistic_ids.includes(item.id);
  74. if (bool && this.filter.logistic !== null && this.filter.logistic.length > 0)
  75. return item.name.includes(this.filter.logistic)
  76. return bool;
  77. },
  78. includePrintLogistic(item){
  79. if (this.printer.logistic_ids.length === 0) return false;
  80. let bool = this.printer.logistic_ids.includes(item.id);
  81. if (bool && this.filter.printer_logistic !== null && this.filter.printer_logistic.length > 0)
  82. return item.name.includes(this.filter.printer_logistic)
  83. return bool;
  84. },
  85. showCreatedModel() {
  86. this.printer.logistic_ids = [];
  87. this.printerErrors = {};
  88. this.filter.logistic = null;
  89. this.filter.printer_logistic = null;
  90. $('#create-printer').modal('show');
  91. },
  92. showEditModel(printer, index) {
  93. let data = JSON.parse(JSON.stringify(printer));
  94. data.logistics = null;
  95. data.logistic_ids = printer.logistics.map(item=>{
  96. return ""+item.id;
  97. });
  98. this.printer = data;
  99. this.$forceUpdate();
  100. this.index = index;
  101. this.printerErrors = {};
  102. this.filter.logistic = null;
  103. this.filter.printer_logistic = null;
  104. $('#edit-printer').modal('show');
  105. },
  106. createPrinter() {
  107. let url = '{{url('apiLocal/maintenance/expressPrinting/setting/printer')}}';
  108. let data = this.printer;
  109. window.tempTip.setIndex(1999)
  110. window.axios.post(url, data).then(res => {
  111. if (res.data['success']) {
  112. this.printers.unshift(res.data['data']);
  113. this.$forceUpdate();
  114. $('#create-printer').modal('hide');
  115. window.tempTip.showSuccess('添加成功!');
  116. return;
  117. } else if (res.data['errors']) {
  118. this.printerErrors = res.data['errors'];
  119. return;
  120. }
  121. window.tempTip.show(res.data['message']);
  122. }).catch(err => {
  123. window.tempTip.show('网络异常!' + err);
  124. })
  125. },
  126. editPrinter() {
  127. let url = '{{url('apiLocal/maintenance/expressPrinting/setting/printer')}}';
  128. let data = this.printer;
  129. window.tempTip.setIndex(1999)
  130. window.axios.put(url, data).then(res => {
  131. if (res.data['success']) {
  132. this.$set(this.printers, this.index, res.data['data']);
  133. window.tempTip.showSuccess('编辑成功!');
  134. $('#edit-printer').modal('hide');
  135. return;
  136. } else if (res.data['errors']) {
  137. this.printerErrors = res.data['errors'];
  138. return;
  139. }
  140. window.tempTip.show(res.data['message'])
  141. }).catch(err => {
  142. window.tempTip.show('网络异常!' + err)
  143. });
  144. },
  145. destroyPrinter(printer, index) {
  146. let url = '{{url('apiLocal/maintenance/expressPrinting/setting/printer')}}' + '/' + printer['id'];
  147. if (!confirm('是否删除当前终端')) return;
  148. window.axios.delete(url).then(res => {
  149. if (res.data['success']) {
  150. this.$delete(this.printers, index);
  151. window.tempTip.showSuccess('删除成功!');
  152. return;
  153. } else if (res.data['errors']) {
  154. this.printerErrors = res.data['errors'];
  155. return;
  156. }
  157. window.tempTip.show(res.data['message'])
  158. }).catch(err => {
  159. window.tempTip.show('网络异常!' + err)
  160. });
  161. },
  162. addToLogistics(logistic){
  163. this.printer.logistic_ids.push(logistic.id)
  164. },
  165. removeToLogistics(logistic){
  166. this.printer.logistic_ids = this.printer.logistic_ids.filter(item=>{
  167. return item !== logistic.id;
  168. });
  169. }
  170. }
  171. })
  172. </script>
  173. @endsection