printContainer.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <script>
  2. import Print_tag_60_40 from '@/components/print/tag_60_40.vue';
  3. import Print_express_75 from '@/components/print/express_75.vue';
  4. import {updatePrintStatus} from '@/api/prescription/prescriptionCore';
  5. export default {
  6. name: 'printContainer',
  7. props: {
  8. id: {type: [String, Number], required: true},
  9. loadExpress: {type: Boolean, default: false},
  10. },
  11. components: {Print_express_75, Print_tag_60_40},
  12. data() {
  13. return {};
  14. },
  15. computed: {
  16. height() { return `${window.innerHeight * 0.8}`; },
  17. style() { return {height: `${this.height}px`}; },
  18. },
  19. watch: {},
  20. mounted() {
  21. this.select(this.loadExpress ? 0 : 1);
  22. },
  23. methods: {
  24. async print() {
  25. const keys = Object.keys(this.$refs).filter(key => key.startsWith('print'));
  26. try {
  27. for (const key of keys) {
  28. const el = this.$refs[key];
  29. await el['print']();
  30. }
  31. this.$message.success(`组合打印成功`);
  32. } catch (e) {
  33. this.$message.error(`出错了,请重试`);
  34. }
  35. },
  36. update(type) {
  37. if (type === 0 || type === 1) {
  38. updatePrintStatus({
  39. isPrint: '1',
  40. id: this.id,
  41. });
  42. }
  43. },
  44. select(index) {
  45. try {
  46. const el = this.$refs[`print${index}`];
  47. el['print'](true);
  48. } catch (e) {}
  49. }
  50. },
  51. };
  52. </script>
  53. <template>
  54. <div>
  55. <el-button class="pin" type="primary" @click="print">组合打印</el-button>
  56. <el-tabs tab-position="left" :style="style" @tab-click="select($event.index)">
  57. <el-tab-pane v-if="loadExpress" label="顺丰面单">
  58. <print_express_75 ref="print0" :id="id" :style="style" @click="$event && update()"></print_express_75>
  59. </el-tab-pane>
  60. <el-tab-pane label="标签">
  61. <print_tag_60_40 ref="print1" :id="id" @click="$event && update(0)"></print_tag_60_40>
  62. </el-tab-pane>
  63. </el-tabs>
  64. </div>
  65. </template>
  66. <style scoped lang="scss">
  67. .pin {
  68. position: absolute;
  69. top: 12px;
  70. right: 60px;
  71. }
  72. </style>