recipe_A5.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <script>
  2. import CLodop from '@/libs/print/CLodop';
  3. import {getDevice} from '@/tools/print.tool';
  4. import {templateA5} from '@/components/print/template';
  5. import {selectOrderDetail} from '@/api/prescription/prescriptionAudit';
  6. export default {
  7. name: 'print_recipe_a5',
  8. props: {
  9. id: {type: [String, Number], required: true},
  10. },
  11. data() {
  12. return {
  13. loaded: false,
  14. preview: false,
  15. total: 1,
  16. tag: `print-preview_${Date.now()}`,
  17. paper: '中药处方笺',
  18. model: null,
  19. device: null,
  20. printing: false,
  21. };
  22. },
  23. computed: {
  24. loading() {
  25. return !this.loaded || !this.preview;
  26. },
  27. },
  28. mounted() {
  29. this.print(true);
  30. },
  31. methods: {
  32. async print(preview = false) {
  33. const instance = await CLodop();
  34. const model = await this.getModel();
  35. templateA5.call(instance, model, `${this.paper}`);
  36. this.device = await getDevice(`paper:${this.paper}`);
  37. if (this.device) instance['SET_PRINT_PAGESIZE'](1, 0, 0, this.paper);
  38. else {
  39. this.device = await getDevice({width: 559, height: 794}, `name:Canon LBP`);
  40. if (this.device) instance['SET_PRINT_PAGESIZE'](1, '148mm', '210mm', 'CreateCustomPage');
  41. }
  42. if (this.device) instance['SET_PRINTER_INDEX'](this.device.index);
  43. instance['SET_PRINT_COPIES'](this.total);
  44. if (preview) {
  45. instance['SET_PREVIEW_WINDOW'](1, 1, 1, 0, 0, `${this.paper}.开始打印`);
  46. instance['SET_SHOW_MODE']('PREVIEW_IN_BROWSE', true);
  47. instance['SET_PRINT_MODE']('AUTO_CLOSE_PREWINDOW', true);
  48. instance['PREVIEW'](this.tag);
  49. } else if (this.device) {
  50. if (instance['PRINT']()) this.complete();
  51. else this.$message.warning(`请检查打印机 (${this.device.name})`);
  52. } else {
  53. if (instance['PRINTA']()) this.complete();
  54. else this.$message.warning(`请检查打印机`);
  55. }
  56. this.printing = false;
  57. this.loaded = true;
  58. },
  59. delay() {
  60. setTimeout(() => {this.preview = true;}, 500);
  61. },
  62. complete() {
  63. this.$message.success(`开始打印`);
  64. this.$emit('close', true);
  65. },
  66. async getModel() {
  67. if (this.model) return this.model;
  68. return selectOrderDetail({id: this.id}).then((res) => {
  69. const data = res.data;
  70. const sign = (index) => { try {return data.operateList[index].operater;} catch (e) {} };
  71. this.model = {
  72. patient: {
  73. name: `${data['name']}`,
  74. gender: `${data['sex']}`,
  75. arg: `${data['args']}岁`,
  76. birthday: `${data['patientBirthday']}`,
  77. phone: `${data['contactNumber']}`,
  78. },
  79. recipe: {
  80. date: `${data['prescriptionTime']}`,
  81. type: {1: '中药处方', 2: '中药制剂'}[data.type] || '',
  82. count: data['number'],
  83. category: data['dosageForm'],
  84. method: data['prescriptionusage'],
  85. volume: data['concentration'] && `每次${data['concentration']}`,
  86. frequency: data['frequency'],
  87. frequencyTime: data['medicationTime'],
  88. decoction: data['isBehalf'] === '1' || +data['daijianNumber'] > 0,
  89. delivery: data['expressExecutor'],
  90. address: [data['province'], data['city'], data['region'], data['address']].filter(Boolean).join(''),
  91. medicineFees: data['prescriptionSum'],
  92. decoctionFees: data['daijianCost'],
  93. deliveryFees: data['distributionCost'],
  94. totalFees: data['prescriptionTotalSum'],
  95. medicines: Array.isArray(data['detailList']) ? data['detailList'].map(item => {
  96. return {
  97. name: item['matName'],
  98. dosage: item['matDose'],
  99. unit: item['matUnitName'],
  100. usage: item['matUsageName'],
  101. };
  102. }) : [],
  103. },
  104. department: [data['department']].filter(Boolean).join(' '),
  105. diagnosis: [data['disName']].filter(Boolean).join(' '),
  106. record: {
  107. title: `${data['yljgName']}(处方笺)`,
  108. date: `${data['printTime']}`,
  109. no: `${data['preNo']}`,
  110. category: data['preMzZy'] === '1' ? '门诊' : '住院',
  111. remark: '1、本处方当日有效;\r\n2、取药时请您当面核对;\r\n3、延长处方用量时间原由:慢性病 其他老年病 外地 其他',
  112. },
  113. recordNo: data['recordNo'],
  114. bedNo: data['bedNo'],
  115. sign: {
  116. field1: sign(1 - 1),
  117. field2: sign(2 - 1),
  118. field3: sign(3 - 1),
  119. field4: sign(4 - 1),
  120. field5: sign(5 - 1),
  121. field6: sign(6 - 1),
  122. field7: sign(7 - 1),
  123. field8: sign(8 - 1),
  124. },
  125. field1: {1: '配药', 2: '煎药', 3: '发药', 4: '配送'}[data.state],
  126. };
  127. if (this.model.field1) this.model.field1 = `当前处方状态:${this.model.field1}`;
  128. return this.model;
  129. });
  130. },
  131. },
  132. };
  133. </script>
  134. <template>
  135. <div class="print-preview" v-loading="loading">
  136. <div class="top" :style="{backgroundColor: preview ? '#f0f0f0' : 'transparent'}"></div>
  137. <iframe :id="tag" @load="delay"></iframe>
  138. <div style="display: flex; align-items: center; justify-content: space-evenly;">
  139. <el-button style="width: 100%;" type="primary" :loading="printing" @click="printing = true;print()">
  140. 打印
  141. </el-button>
  142. </div>
  143. </div>
  144. </template>
  145. <style scoped lang="scss">
  146. .print-preview {
  147. margin: auto;
  148. width: 559px + 100px;
  149. display: flex;
  150. flex-direction: column;
  151. .top {
  152. height: 40px;
  153. }
  154. iframe {
  155. border: none;
  156. width: 100%;
  157. flex: auto;
  158. }
  159. > div {
  160. flex: none;
  161. }
  162. }
  163. </style>