| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <script>
- import CLodop from '@/libs/print/CLodop';
- import {getDevice, getDevices} from '@/tools/print.tool';
- import {templateA5} from '@/components/print/template';
- import {selectOrderDetail, selectOrderDetail2} from '@/api/prescription/prescriptionAudit';
- import {bignumber, chain, multiply} from 'mathjs';
- export default {
- name: 'print_recipe_a5',
- props: {
- id: {type: [String, Number], required: true},
- selectable: Boolean,
- },
- data() {
- return {
- loaded: false,
- preview: false,
- total: 1,
- tag: `print-preview_${Date.now()}`,
- paper: '中药处方笺',
- paperWidth: 1485,
- paperHeight: 2100,
- model: null,
- device: null,
- devices: [],
- printing: false,
- };
- },
- computed: {
- loading() {
- return !this.loaded || !this.preview;
- },
- deviceId() {
- return this.device ? this.device.index : '';
- },
- },
- mounted() {
- if (this.selectable) getDevices().then(devices => this.devices = devices);
- this.loaded = true;
- },
- methods: {
- async print(preview = false) {
- if (preview) this.loaded = false;
- const instance = await CLodop();
- const model = await this.getModel();
- templateA5.call(instance, model, `${this.paper}`);
- const device = await this.getDevice();
- if (device) {
- if (device.papers.includes(this.paper)) instance['SET_PRINT_PAGESIZE'](1, 0, 0, this.paper);
- else instance['SET_PRINT_PAGESIZE'](1, this.paperWidth, this.paperHeight, 'CreateCustomPage');
- instance['SET_PRINTER_INDEX'](device.index);
- instance['SET_PRINT_COPIES'](this.total);
- if (preview) {
- instance['SET_PREVIEW_WINDOW'](1, 1, 1, 0, 0, `${this.paper}.开始打印`);
- instance['SET_SHOW_MODE']('PREVIEW_IN_BROWSE', true);
- instance['SET_PRINT_MODE']('AUTO_CLOSE_PREWINDOW', true);
- instance['PREVIEW'](this.tag);
- } else {
- if (instance['PRINT']()) this.complete();
- else this.$message.warning(`请检查打印机 (${this.device.name})`);
- }
- } else if (preview) {
- this.devices = await getDevices();
- } else {
- if (instance['PRINTA']()) this.complete();
- else this.$message.warning(`请检查打印机`);
- }
- this.printing = false;
- this.loaded = true;
- },
- delay() {
- setTimeout(() => {this.preview = true;}, 500);
- },
- complete() {
- this.$message.success(`开始打印`);
- this.$emit('close', true);
- },
- async getModel() {
- if (this.model) return this.model;
- this.model = await selectOrderDetail2({id: this.id});
- const count = bignumber(this.model.recipe.count || 0);
- let unitWeight = chain(bignumber(0));
- for (const medicine of this.model.recipe.medicines) {
- unitWeight = unitWeight.add(bignumber(medicine.dosage));
- }
- this.model.recipe.unitWeight = +unitWeight.valueOf().toFixed(2);
- this.model.recipe.totalWeight = +unitWeight.multiply(count).valueOf().toFixed(2);
- return this.model;
- },
- async getDevice() {
- if (!this.device) this.device = await getDevice(
- `name: Six:${this.paper}`,
- `name: Six:${this.paperWidth}*${this.paperHeight}`,
- `driver: Canon LBP6030/6040/6018L; paper: ${this.paper}`,
- `driver: Canon LBP6030/6040/6018L; form: A5`,
- `driver: Canon LBP6030/6040/6018L;`,
- {width: this.paperWidth, height: this.paperHeight},
- `paper:${this.paper}`,
- `form: A5`,
- );
- console.log(this.device);
- return this.device;
- },
- selected(value) {
- this.device = this.devices.find(device => device.index === value);
- this.print(true);
- },
- },
- };
- </script>
- <template>
- <div class="print-preview">
- <div class="content" v-loading="loading">
- <div class="top" :style="{backgroundColor: preview ? '#f0f0f0' : 'transparent'}">
- {{ device && device.name }}
- </div>
- <iframe :id="tag" @load="delay"></iframe>
- </div>
- <div style="display: flex; align-items: center; justify-content: space-evenly;">
- <el-select v-if="devices.length" placeholder="打印机" :value="deviceId" @change="selected">
- <el-option v-for="item in devices" :key="item.index" :label="item.name" :value="item.index"></el-option>
- </el-select>
- <el-button style="width: 100%;" type="primary" :disabled="loading" :loading="printing"
- @click="printing = true;print()">打印
- </el-button>
- </div>
- </div>
- </template>
- <style scoped lang="scss">
- .print-preview {
- margin: auto;
- width: 559px + 100px;
- display: flex;
- flex-direction: column;
- .content {
- flex: auto;
- display: flex;
- flex-direction: column;
- }
- .top {
- height: 40px;
- font-size: 12px;
- color: rgba(0, 0, 0, 0.5);
- }
- iframe {
- border: none;
- width: 100%;
- flex: auto;
- }
- > div {
- flex: none;
- }
- .el-select {
- margin-right: 12px;
- }
- }
- </style>
|