Parcourir la source

Merge branch 'feature/print' into develop

cc12458 il y a 1 an
Parent
commit
496eba9766
1 fichiers modifiés avec 175 ajouts et 110 suppressions
  1. 175 110
      src/components/print/template.js

+ 175 - 110
src/components/print/template.js

@@ -19,7 +19,7 @@ export function template60_40(model = {}, title = '') {
   let w = 0, h = 0;
 
   this.SET_PRINT_STYLE('Alignment', 2);
-
+  this.SET_PRINT_STYLE('FontSize', 12);
 
   w = 215;
   h = 20;
@@ -28,6 +28,7 @@ export function template60_40(model = {}, title = '') {
 
   y += h;
   this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.no}}`));
+  this.SET_PRINT_STYLEA(0, 'FontSize', 9);
 
   y += h;
   w = 115;
@@ -72,7 +73,7 @@ export function template60_40(model = {}, title = '') {
 
 
   this.ADD_PRINT_TEXT(86, margin, 170, 44, template(`{{record.remark}}`));
-  this.SET_PRINT_STYLEA(0, 'FontSize', 8);
+  this.SET_PRINT_STYLEA(0, 'FontSize', 9);
   if (model.record.no) this.ADD_PRINT_BARCODE(99, 175, 46, 46, 'QRCode', model.record.no);
 
   y = 130;
@@ -108,6 +109,7 @@ export function template80_50(model = {}, title = '') {
   w = 290;
   h = 20;
   this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.title}}`));
+  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
   this.SET_PRINT_STYLEA(0, 'Bold', 1);
 
   y += h;
@@ -119,14 +121,16 @@ export function template80_50(model = {}, title = '') {
   this.ADD_PRINT_TEXT(y, x, w, h, '病历号');
   x += w - 1;
   w = 100;
-  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.medicalRecordNumber}}`));
+  this.ADD_PRINT_TEXT(y - 4, x, w, h, template(`{{record.recordNo}}`));
+  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
   this.SET_PRINT_STYLEA(0, 'Bold', 1);
   x += w - 3;
   w = 50;
   this.ADD_PRINT_TEXT(y, x, w, h, '处方号');
   x += w - 6;
   w = 94 + 6;
-  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.no}}`));
+  this.ADD_PRINT_TEXT(y - 4, x, w, h, template(`{{record.no}}`));
+  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
   this.SET_PRINT_STYLEA(0, 'Bold', 1);
 
   y += h;
@@ -161,7 +165,7 @@ export function template80_50(model = {}, title = '') {
   this.ADD_PRINT_TEXT(y, x, w, h, '取药:');
   x += w;
   this.ADD_PRINT_TEXT(y, x, 130, h, template(`{{department}}`));
-  this.SET_PRINT_STYLEA(0, 'FontSize', 10);
+  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
   this.SET_PRINT_STYLEA(0, 'Bold', 1);
   y += h;
   x = margin;
@@ -170,7 +174,7 @@ export function template80_50(model = {}, title = '') {
   y += h - 4;
   x = margin;
   this.ADD_PRINT_TEXT(y, x, 180, h, template(`{{recipe.method}}`));
-  this.SET_PRINT_STYLEA(0, 'FontSize', 10);
+  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
   this.SET_PRINT_STYLEA(0, 'Bold', 1);
 
 
@@ -191,7 +195,7 @@ export function template80_50(model = {}, title = '') {
 export function templateA5(model = {}, title = '') {
   const template = renderTemplate.bind(this, model);
 
-  const size = 40;
+  const size = 24;
   const width = 559;
   const height = 794;
   const margin = 12;
@@ -207,149 +211,210 @@ export function templateA5(model = {}, title = '') {
     for (let i = 0; i < array.length; i += size) {result.push(array.slice(i, i + size));}
     return result;
   })(model.recipe['medicines'], size);
+
   if (!chunks.length) chunks.push([]);
   const single = chunks.length === 1;
 
   for (const chunk of chunks) {
     let x = margin, y = margin;
-    let w = 0, h = 0, offset = 0;
+    let w = 0, h = 0, offset = 8;
     // 绘制头部
-    this.ADD_PRINT_TEXT(y, x, 310, 26, template(`{{record.title}}`));
-    this.SET_PRINT_STYLEA(0, 'FontSize', 12);
+    w = 310;
+    h = 20;
+    this.SET_PRINT_STYLE('FontSize', 15);
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.title}}`));
     this.SET_PRINT_STYLEA(0, 'Bold', 1);
 
-    y = 37;
-    this.ADD_PRINT_TEXT(y, 117, 100, 20, template(`{{recipe.type}}`));
+    y += h + 10;
+    x = margin;
+    h = 18;
+    this.SET_PRINT_STYLE('FontSize', 13.5);
+    this.ADD_PRINT_TEXT(y + 1, x, w, h - 2, template(`{{recipe.type}}`));
+    this.SET_PRINT_STYLEA(0, 'FontSize', 12);
     this.SET_PRINT_STYLEA(0, 'Alignment', 2);
 
-    this.ADD_PRINT_TEXT(y, 12, 100, 20, template(`{{recipe.decoction}}`));
-    this.SET_PRINT_STYLEA(0, 'FontSize', 12);
+    this.ADD_PRINT_TEXT(y, x, 100, h, template(`{{recipe.decoction}}`));
     this.SET_PRINT_STYLEA(0, 'Bold', 1);
-    this.ADD_PRINT_TEXT(y, 222, 100, 20, template(`{{record.serialNumber}}`));
+    this.ADD_PRINT_TEXT(y, w - 100 + x, 100, h, template(`{{record.serialNumber}}`));
     this.SET_PRINT_STYLEA(0, 'Alignment', 2);
     this.SET_PRINT_STYLEA(0, 'Bold', 1);
 
-    if (model.record.no) this.ADD_PRINT_BARCODE(12, 331, 216, 50, '128Auto', model.record.no);
+    if (model.record.no) this.ADD_PRINT_BARCODE(margin, width - margin - 216, 216, 50, '128Auto', model.record.no);
 
     // 绘制顶部信息
-    y = 66;
-    h = 20;
-    offset = 2;
-    this.ADD_PRINT_TEXT(y, 12, 45, h, '姓名:');
-    this.ADD_PRINT_TEXT(y, 151, 60, h, template(`性别:{{patient.gender}}`));
-    this.ADD_PRINT_TEXT(y, 211, 80, h, template(`年龄:{{patient.age}}`));
-    this.ADD_PRINT_TEXT(y, 291, 100, h, template(`床号:{{record.bedNo}}`));
-    this.ADD_PRINT_TEXT(y - 6, 56, 96, h + 6, template(`{{patient.name}}`));
-    this.SET_PRINT_STYLEA(0, 'FontSize', 12);
+    y = margin + 50 + offset;
+    x = margin;
+    h = 16;
+    this.SET_PRINT_STYLE('FontSize', 12);
+
+    w = 58;
+    this.ADD_PRINT_TEXT(y, x, w, h, '姓名:');
+    x += w - offset;
+    w = 100;
+    this.ADD_PRINT_TEXT(y, x, w + offset, h, template(`{{patient.name}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    x += w;
+    w = 58;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`性别:`));
+    x += w - offset * 2;
+    w = 16;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`{{patient.gender}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    x += w + offset;
+    w = 58;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`年龄:`));
+    x += w - offset * 2;
+    w = 50;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`{{patient.age}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    x += w - offset;
+    w = 90;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`病历号:`));
+    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    w = 180;
+    x = width - w + offset * 1.5;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.recordNo}}`));
     this.SET_PRINT_STYLEA(0, 'Bold', 1);
+
+
     y += h + offset;
-    this.ADD_PRINT_TEXT(y, 12, 200, h, template(`科室:{{department}}`));
-    this.ADD_PRINT_TEXT(y, 211, 150, h, template(`病历号:{{record.recordNo}}`));
-    this.ADD_PRINT_TEXT(y, 360, 185, h, template(`开方日期:{{record.date}}`));
+    x = margin;
+    w = 58;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`科室:`));
+    x += w - offset;
+    w = 220 - x;
+    this.ADD_PRINT_TEXT(y, x, w + offset, h, template(`{{department}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    x += w + offset;
+    w = 58;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`床号:`));
+    x += w - offset * 2;
+    w = 50;
+    this.ADD_PRINT_TEXT(y, x, w + offset, h, template(`{{record.bedNo}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    x += w - offset;
+    w = 90;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`开方日期:`));
     this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    w = 180;
+    x = width - w + offset * 1.5;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.date}}`));
+    // this.SET_PRINT_STYLEA(0, 'Bold', 1);
+
     y += h + offset;
-    h = 34;
-    this.ADD_PRINT_TEXT(y, 12, 418, h, template(`地址:{{recipe.address}}`));
-    this.ADD_PRINT_TEXT(y, 430, 120, h, template(`电话:{{patient.phone}}`));
+    x = margin;
+    w = 58;
+    h = 16 * 2 + offset;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`地址:`));
+    x += w - offset;
+    this.ADD_PRINT_TEXT(y, x, 348, h, template(`{{recipe.address}}`));
+    w = 150;
+    x = 407;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`电话:{{patient.phone}}`));
     this.SET_PRINT_STYLEA(0, 'Alignment', 3);
     y += h;
-    this.ADD_PRINT_TEXT(y, 12, 418, h, template(`临床诊断:{{diagnosis}}`));
-    this.ADD_PRINT_TEXT(y, 430, 120, h, template(`{{recipe.delivery}}`));
-    this.SET_PRINT_STYLEA(0, 'FontSize', 12);
+    x = margin;
+    w = 90;
+    h = 16 * 2 + offset;
+    this.ADD_PRINT_TEXT(y, x, w, h, template(`临床诊断:`));
+    x += w;
+    this.ADD_PRINT_TEXT(y, x - offset - 2, width - x + offset, h, template(`{{diagnosis}}`));
     this.SET_PRINT_STYLEA(0, 'Bold', 1);
-    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
 
     // 分割线
-    this.ADD_PRINT_SHAPE(4, 178, 12, 535, 1, 0, 1, '#000000');
-
-    y = 188;
-    this.ADD_PRINT_TEXT(y, 48, 120, 20, '药品名');
-    this.SET_PRINT_STYLEA(0, 'Alignment', 2);
-    this.SET_PRINT_STYLEA(0, 'Bold', 1);
-    this.ADD_PRINT_TEXT(y, 168, 50, 20, '单帖量');
-    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
-    this.SET_PRINT_STYLEA(0, 'Bold', 1);
-    this.ADD_PRINT_TEXT(y, 220, 48, 20, '用法');
-    this.SET_PRINT_STYLEA(0, 'Alignment', 2);
-    this.SET_PRINT_STYLEA(0, 'Bold', 1);
-    if (chunk.length > 1) {
-      this.ADD_PRINT_TEXT(y, 291, 120, 20, '药品名');
-      this.SET_PRINT_STYLEA(0, 'Alignment', 2);
-      this.SET_PRINT_STYLEA(0, 'Bold', 1);
-      this.ADD_PRINT_TEXT(y, 411, 50, 20, '单贴量');
+    y += h;
+    this.ADD_PRINT_SHAPE(4, y, margin, width - margin * 2, 1, 0, 1, '#000000');
+
+    y = 200 + offset;
+    h = 26;
+
+    this.SET_PRINT_STYLE('FontSize', 13);
+    this.SET_PRINT_STYLE('Bold', 1);
+    this.SET_PRINT_STYLE('Alignment', 2);
+    if /* 渲染右列表头 */ (chunk.length > 1) {
+      this.ADD_PRINT_TEXT(y, 277, 154, h, '药品名');
+      this.ADD_PRINT_TEXT(y, 429, 72, h, '单帖量');
+      this.ADD_PRINT_TEXT(y, 491, 62, h, '用法');
+      this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    }
+    if /* 渲染左列表头 */ (chunk.length) {
+      this.ADD_PRINT_TEXT(y, 6, 154, h, '药品名');
+      this.ADD_PRINT_TEXT(y, 158, 72, h, '单帖量');
+      this.ADD_PRINT_TEXT(y, 220, 62, h, '用法');
       this.SET_PRINT_STYLEA(0, 'Alignment', 3);
-      this.SET_PRINT_STYLEA(0, 'Bold', 1);
-      this.ADD_PRINT_TEXT(y, 463, 48, 20, '用法');
-      this.SET_PRINT_STYLEA(0, 'Bold', 1);
+      const H = 36;
+      y -= H - h;
+      h = H;
     }
+    this.SET_PRINT_STYLE('FontSize', 12);
+    this.SET_PRINT_STYLE('Bold', 0);
+    this.SET_PRINT_STYLE('Alignment', 0);
+    this.SET_PRINT_STYLE('LineSpacing', -4);
 
-    // 绘制药品
-    chunk.forEach((medicine, i) => {
-      const template = renderTemplate.bind(this, medicine);
+    // 循环输出药品
+    for (let i = 0; i < chunk.length; i++) {
       if (i % 2) {
-        x = 291;
+        x = 277;
       } else {
-        y += 20 + 2;
-        x = 48;
+        x = 6;
+        y += h;
       }
-      this.ADD_PRINT_TEXT(y, x, 120, 20, template(`{{name}}`));
+      const template = renderTemplate.bind(this, chunk[i]);
+      this.ADD_PRINT_TEXT(y, x, 154, h, template(`{{name}}`));
       this.SET_PRINT_STYLEA(0, 'Alignment', 2);
-      x += 120;
-      this.ADD_PRINT_TEXT(y, x, 50, 20, template(`{{dosage}}{{unit}}`));
+      this.ADD_PRINT_TEXT(y, x + 150 - 6, 72, h, template(`{{dosage}}{{unit}}`));
       this.SET_PRINT_STYLEA(0, 'Alignment', 3);
-      x += 50 + 2;
-      this.ADD_PRINT_TEXT(y, x, 48, 16, template(`{{usage}}`));
-      this.SET_PRINT_STYLEA(0, 'FontSize', 6);
-      this.SET_PRINT_STYLEA(0, 'Alignment', 2);
-    });
+      this.ADD_PRINT_TEXT(y, x + 220 - 6, 62, h, template(`{{usage}}`));
+      this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    }
 
-    y += 20 + 2 + 12;
+    y = 666;
+    this.ADD_PRINT_SHAPE(4, y, margin, width - margin * 2, 1, 0, 1, '#000000');
+    this.SET_PRINT_STYLE('LineSpacing', 0);
 
-    this.ADD_PRINT_TEXT(y, 12, 536, 40, template(`{{record.remark}}`));
+    offset = 6;
+    y += offset;
 
-    y += 40;
-    x = margin;
-    h = 20;
-    w = 130;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`用法:{{recipe.method}}`));
-    this.ADD_PRINT_TEXT(y, width - margin - w, w, 40, template(`{{recipe.volume}}`));
-    this.SET_PRINT_STYLEA(0, 'FontSize', 12);
-    this.SET_PRINT_STYLEA(0, 'Alignment', 2);
-    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    h = 16;
+    this.ADD_PRINT_TEXT(y, 6, 74, h, '用法:');
+    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    this.ADD_PRINT_TEXT(y, 80, 192, h, template(`{{recipe.method}}`));
+    this.ADD_PRINT_TEXT(y, 287 - 16, 266 + 16, h, template(`{{recipe.volume}}`));
 
-    y += h;
-    x = margin;
-    h = 20;
-    w = 130;
-    offset = 5;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`金额:{{recipe.totalFees}} 元`));
-    x += w + offset;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`共 {{recipe.count}} 剂`));
-    this.SET_PRINT_STYLEA(0, 'Alignment', 2);
-    x += w + offset;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`煎 {{recipe.count}} 剂`));
-    this.SET_PRINT_STYLEA(0, 'Alignment', 2);
+    y += h + offset;
+    this.ADD_PRINT_TEXT(y, 6, 74, h, '金额:');
+    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    this.ADD_PRINT_TEXT(y, 80, 192, h, template(`{{recipe.totalFees}} 元`));
+    this.ADD_PRINT_TEXT(y, 287 - 16, 266 + 16, h, template(`共 {{recipe.count}} 剂,煎 {{recipe.count}} 剂`));
 
-    y += h;
-    x = margin;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`医生:{{sign.field1}}`));
-    x += w + offset;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`单剂重量:{{recipe.unitWeight}}`));
-    this.SET_PRINT_STYLEA(0, 'Alignment', 2);
-    x += w + offset;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`总重量:{{recipe.totalWeight}}`));
-    this.SET_PRINT_STYLEA(0, 'Alignment', 2);
+    y += h + offset;
+    this.ADD_PRINT_TEXT(y, 6, 74, h, '医生:');
+    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    this.ADD_PRINT_TEXT(y, 80, 192, h, template(`{{sign.field1}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    this.ADD_PRINT_TEXT(y, 287 - 16, 266 + 16, h, template(`单剂重量:{{recipe.unitWeight}},总重量:{{recipe.totalWeight}}`));
 
-    y += h;
-    x = margin;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`审方人:{{sign.field2}}`));
-    x += w + offset;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`配药人:{{sign.field3}}`));
-    x += w + offset;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`复核人:{{sign.field4}}`));
-    x += w + offset;
-    this.ADD_PRINT_TEXT(y, x, w, h, template(`煎药人:{{sign.field6}}`));
+    this.ADD_PRINT_SHAPE(4, y + h + offset, margin, width - margin * 2, 1, 0, 1, '#000000');
 
+    y += h + offset * 2;
+    this.ADD_PRINT_TEXT(y, 6, 74, h, '审方人:');
+    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    this.ADD_PRINT_TEXT(y, 80, 192, h, template(`{{sign.field2}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    this.ADD_PRINT_TEXT(y, 287, 74, h, '配药人:');
+    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    this.ADD_PRINT_TEXT(y, 361, 192, h, template(`{{sign.field3}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+
+    y += h + offset;
+    this.ADD_PRINT_TEXT(y, 6, 74, h, '复核人:');
+    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    this.ADD_PRINT_TEXT(y, 80, 192, h, template(`{{sign.field4}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
+    this.ADD_PRINT_TEXT(y, 287, 74, h, '煎药人:');
+    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
+    this.ADD_PRINT_TEXT(y, 361, 192, h, template(`{{sign.field6}}`));
+    this.SET_PRINT_STYLEA(0, 'Bold', 1);
 
     if (!single) this.NEWPAGEA();
   }