| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <script>
- import CLodop from '@/libs/print/CLodop';
- import {getDevice} from '@/tools/print.tool';
- import {templateA5} from '@/components/print/template';
- import {selectOrderDetail} from '@/api/prescription/prescriptionAudit';
- export default {
- name: 'print_recipe_a5',
- props: {
- id: {type: [String, Number], required: true},
- },
- data() {
- return {
- loaded: false,
- preview: false,
- total: 1,
- tag: `print-preview_${Date.now()}`,
- paper: '中药处方笺',
- model: null,
- device: null,
- printing: false,
- };
- },
- computed: {
- loading() {
- return !this.loaded || !this.preview;
- },
- },
- mounted() {
- this.print(true);
- },
- methods: {
- async print(preview = false) {
- const instance = await CLodop();
- const model = await this.getModel();
- templateA5.call(instance, model, `${this.paper}`);
- this.device = await getDevice(`paper:${this.paper}`);
- if (this.device) instance['SET_PRINT_PAGESIZE'](1, 0, 0, this.paper);
- else {
- this.device = await getDevice({width: 559, height: 794}, `name:Canon LBP`);
- if (this.device) instance['SET_PRINT_PAGESIZE'](1, '148mm', '210mm', 'CreateCustomPage');
- }
- if (this.device) instance['SET_PRINTER_INDEX'](this.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 (this.device) {
- if (instance['PRINT']()) this.complete();
- else this.$message.warning(`请检查打印机 (${this.device.name})`);
- } 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;
- return selectOrderDetail({id: this.id}).then((res) => {
- const data = res.data;
- const sign = (index) => { try {return data.operateList[index].operater;} catch (e) {} };
- this.model = {
- patient: {
- name: `${data['name']}`,
- gender: `${data['sex']}`,
- arg: `${data['args']}岁`,
- birthday: `${data['patientBirthday']}`,
- phone: `${data['contactNumber']}`,
- },
- recipe: {
- date: `${data['prescriptionTime']}`,
- type: {1: '中药处方', 2: '中药制剂'}[data.type] || '',
- count: data['number'],
- category: data['dosageForm'],
- method: data['prescriptionusage'],
- volume: data['concentration'] && `每次${data['concentration']}`,
- frequency: data['frequency'],
- frequencyTime: data['medicationTime'],
- decoction: data['isBehalf'] === '1' || +data['daijianNumber'] > 0,
- delivery: data['expressExecutor'],
- address: [data['province'], data['city'], data['region'], data['address']].filter(Boolean).join(''),
- medicineFees: data['prescriptionSum'],
- decoctionFees: data['daijianCost'],
- deliveryFees: data['distributionCost'],
- totalFees: data['prescriptionTotalSum'],
- medicines: Array.isArray(data['detailList']) ? data['detailList'].map(item => {
- return {
- name: item['matName'],
- dosage: item['matDose'],
- unit: item['matUnitName'],
- usage: item['matUsageName'],
- };
- }) : [],
- },
- department: [data['department']].filter(Boolean).join(' '),
- diagnosis: [data['disName']].filter(Boolean).join(' '),
- record: {
- title: `${data['yljgName']}(处方笺)`,
- date: `${data['printTime']}`,
- no: `${data['preNo']}`,
- category: data['preMzZy'] === '1' ? '门诊' : '住院',
- remark: '1、本处方当日有效;\r\n2、取药时请您当面核对;\r\n3、延长处方用量时间原由:慢性病 其他老年病 外地 其他',
- },
- recordNo: data['recordNo'],
- bedNo: data['bedNo'],
- sign: {
- field1: sign(1 - 1),
- field2: sign(2 - 1),
- field3: sign(3 - 1),
- field4: sign(4 - 1),
- field5: sign(5 - 1),
- field6: sign(6 - 1),
- field7: sign(7 - 1),
- field8: sign(8 - 1),
- },
- field1: {1: '配药', 2: '煎药', 3: '发药', 4: '配送'}[data.state],
- };
- if (this.model.field1) this.model.field1 = `当前处方状态:${this.model.field1}`;
- return this.model;
- });
- },
- },
- };
- </script>
- <template>
- <div class="print-preview" v-loading="loading">
- <div class="top" :style="{backgroundColor: preview ? '#f0f0f0' : 'transparent'}"></div>
- <iframe :id="tag" @load="delay"></iframe>
- <div style="display: flex; align-items: center; justify-content: space-evenly;">
- <el-button style="width: 100%;" type="primary" :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;
- .top {
- height: 40px;
- }
- iframe {
- border: none;
- width: 100%;
- flex: auto;
- }
- > div {
- flex: none;
- }
- }
- </style>
|