import {renderTemplate} from '@/components/print/tools';

export function template60_40(model = {}, title = '') {
  const template = renderTemplate.bind(this, model);

  const width = 227;
  const height = 151;
  const margin = 6;

  this.PRINT_INITA(0, 0, width, height, title);
  // 宽度按纸张的整宽缩放
  this.SET_PRINT_MODE('PRINT_PAGE_PERCENT', 'Full-Width');
  this.SET_PRINT_MODE('FULL_WIDTH_FOR_OVERFLOW', true);
  this.SET_PRINT_MODE('FULL_HEIGHT_OVERFLOW', true);
  // 设置输出位置以纸张边缘为基点
  this.SET_PRINT_MODE('POS_BASEON_PAPER', true);

  let x = margin, y = margin;
  let w = 0, h = 0;

  this.SET_PRINT_STYLE('Alignment', 2);
  this.SET_PRINT_STYLE('FontSize', 12);

  w = 215;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.title}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);

  y += h;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.no}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 9);

  y += h;
  w = 115;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{patient.name}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 30;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.count}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, '帖');
  x += w;
  w = 30;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.total}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, '包');


  this.SET_PRINT_STYLE('Alignment', 1);


  y += h;
  x = margin;
  w = 60;
  this.ADD_PRINT_TEXT(y, x, w, h, '备注：');
  this.SET_PRINT_STYLE('Alignment', 2);
  x += w - 2;
  w = 60;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.volume}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 50;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.method}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.decoction}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  this.SET_PRINT_STYLE('Alignment', 1);


  this.ADD_PRINT_TEXT(86, margin, 170, 44, template(`{{record.remark}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 9);
  if (model.record.orderNo) this.ADD_PRINT_BARCODE(99, 175, 46, 46, 'QRCode', model.record.orderNo);

  y = 130;
  x = margin;
  w = 70;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.delivery}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 100;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.date}}`));
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
}

export function template60_60(model = {}, title = '') {
  const template = renderTemplate.bind(this, model);

  const width = 227;
  const height = 227;
  const margin = 6;

  this.PRINT_INITA(0, 0, width, height, title);
  // 宽度按纸张的整宽缩放
  this.SET_PRINT_MODE('PRINT_PAGE_PERCENT', 'Full-Width');
  this.SET_PRINT_MODE('FULL_WIDTH_FOR_OVERFLOW', true);
  this.SET_PRINT_MODE('FULL_HEIGHT_OVERFLOW', true);
  // 设置输出位置以纸张边缘为基点
  this.SET_PRINT_MODE('POS_BASEON_PAPER', true);

  let x = margin, y = margin;
  let w = 0, h = 0;

  this.SET_PRINT_STYLE('Alignment', 2);
  this.SET_PRINT_STYLE('FontSize', 12);

  w = 215;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.title}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);

  y += h;
  h = 16;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{record.no}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 9);


  y += h;
  w = 115;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{patient.name}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 15);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 30;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.count}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, '帖');

  if (model.recipe.total) {
    x += w;
    w = 30;
    this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.total}}`));
    this.SET_PRINT_STYLEA(0, 'Bold', 1);
    x += w;
    w = 20;
    this.ADD_PRINT_TEXT(y, x, w, h, '包');
  }

  y += h;
  x = margin;
  w = 60;
  this.ADD_PRINT_TEXT(y, x, w, h, '备注：');
  this.SET_PRINT_STYLEA(0, 'Alignment', 1);
  x += w - 2;
  w = 60;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.volume}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 50;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.method}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  this.ADD_PRINT_TEXT(y, x - 3, w, h, template(`{{recipe.decoction}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);

  y += h;
  h = 32;
  this.ADD_PRINT_TEXT(y, margin, width - margin, h, template(`{{record.remark}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  this.SET_PRINT_STYLEA(0, 'Alignment', 1);
  this.SET_PRINT_STYLEA(0, 'LineSpacing', -2);

  y += h;
  x = margin;
  w = 70;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.delivery}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  this.SET_PRINT_STYLEA(0, 'Alignment', 1);
  x += w;
  w = width - margin - x;
  this.ADD_PRINT_TEXT(y + 4, x, w, h, template(`{{record.date}}`));

  y += h;
  x = 0;
  h = 16;
  this.ADD_PRINT_TEXT(y, x, width, h, template(`{{patient.phone}}`));
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  y += h + 2;
  h = 24;
  this.ADD_PRINT_SHAPE(4, y, x, width, h, 0, 1, '#000000');
  this.ADD_PRINT_TEXT(y + (24 - 18) / 2, x, width, 18, template(`{{patient.name}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 13.5);
  this.SET_PRINT_STYLEA(0, 'FontColor', '#ffffff');
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  y += h + margin / 2;
  if (model.record.orderNo) {
    w = 198;
    this.ADD_PRINT_BARCODE(y, (width - w) / 2, w, 44, '128Auto', model.record.orderNo);
    this.SET_PRINT_STYLEA(0, 'AlignJustify', 2);
  }
}

export function template80_50(model = {}, title = '') {
  const template = renderTemplate.bind(this, model);

  const width = 302;
  const height = 189;
  const margin = 12;

  this.PRINT_INITA(0, 0, width, height, title);
  // 宽度按纸张的整宽缩放
  this.SET_PRINT_MODE('PRINT_PAGE_PERCENT', 'Full-Width');
  this.SET_PRINT_MODE('FULL_WIDTH_FOR_OVERFLOW', true);
  this.SET_PRINT_MODE('FULL_HEIGHT_OVERFLOW', true);
  // 设置输出位置以纸张边缘为基点
  this.SET_PRINT_MODE('POS_BASEON_PAPER', true);

  let x = margin, y = margin;
  let w = 0, h = 0;

  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;
  w = 196;
  this.ADD_PRINT_TEXT(y, x, w, h, '中药煎药取药凭证');
  y += h;
  w = 50;

  this.ADD_PRINT_TEXT(y, x, w, h, '病历号');
  x += w - 1;
  w = 100;
  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 - 4, x, w, h, template(`{{record.no}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);

  y += h;
  x = margin;
  w = 50;
  this.ADD_PRINT_TEXT(y, x, w, h, '姓名：');
  x += w;
  w = 146 + 6;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{patient.name}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  w = 44;
  this.ADD_PRINT_TEXT(y, x, w, h, '贴数');
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  x += w;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.count}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);

  y += h;
  x = margin;
  h = 44;
  this.ADD_PRINT_TEXT(y, x, 230, h, template(`地址：{{recipe.address}}`));


  y += h;
  x = margin;
  h = 20;
  w = 50;
  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', 12);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  y += h;
  x = margin;
  this.ADD_PRINT_TEXT(y, x, 180, h, template(`{{record.remark}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 8);
  y += h - 4;
  x = margin;
  this.ADD_PRINT_TEXT(y, x, 180, h, template(`{{recipe.method}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);


  this.ADD_PRINT_TEXT(98, 236, 60, 20, template(`{{recipe.delivery}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);

  if (model.record.orderNo) this.ADD_PRINT_BARCODE(133, 189, 107, 50, '128Auto', model.record.orderNo);
}

/**
 * A5 纸 96 PPI (559px * 794px)
 *
 * @param model
 * @param title
 */
export function templateA5(model = {}, title = '') {
  const template = renderTemplate.bind(this, model);

  const size = 24;
  const width = 559;
  const height = 794;
  const margin = 12;

  this.PRINT_INITA(0, 0, width, height, title);
  // 宽度按纸张的整宽缩放
  this.SET_PRINT_MODE('PRINT_PAGE_PERCENT', 'Full-Width');
  // 设置输出位置以纸张边缘为基点
  this.SET_PRINT_MODE('POS_BASEON_PAPER', true);

  const chunks = (function (array, size = 32) {
    let result = [];
    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 = 8;
    // 绘制头部
    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);
    this.SET_PRINT_STYLEA(0, 'Alignment', 2);

    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 - 2, x, 100, h + 2, template(`{{recipe.decoction}}`));
    this.SET_PRINT_STYLEA(0, 'FontSize', 15);
    this.SET_PRINT_STYLEA(0, 'Bold', 1);
    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.orderNo) this.ADD_PRINT_BARCODE(margin, width - margin - 216, 216, 50, '128Auto', model.record.orderNo);

    // 绘制顶部信息
    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 - 2, x - 2, w + 20, h + 2, template(`{{patient.name}}`));
    this.SET_PRINT_STYLEA(0, 'FontSize', 15);
    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;
    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;
    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;
    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);

    // 分割线
    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);
      const H = 36 - 4;
      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);

    // 循环输出药品
    const max = y + (Math.round(size / 2) + 1) * h;
    for (let i = 0; i < chunk.length; i++) {
      if (i % 2) {
        x = 277;
      } else {
        x = 6;
        y += h;
      }
      const template = renderTemplate.bind(this, chunk[i]);
      this.ADD_PRINT_TEXT(y, x, 154, h, template(`{{name}}`));
      this.SET_PRINT_STYLEA(0, 'Alignment', 2);
      this.ADD_PRINT_TEXT(y, x + 150 - 6, 72, h, template(`{{dosage}}{{unit}}`));
      this.SET_PRINT_STYLEA(0, 'Alignment', 3);
      this.ADD_PRINT_TEXT(y, x + 220 - 6, 62, h, template(`{{usage}}`));
      this.SET_PRINT_STYLEA(0, 'Alignment', 3);
    }

    y = Math.max(y, max);
    this.ADD_PRINT_SHAPE(4, y, margin, width - margin * 2, 1, 0, 1, '#000000');
    this.SET_PRINT_STYLE('LineSpacing', 0);

    offset = 6;
    y += offset;

    h = 16;
    this.ADD_PRINT_TEXT(y, 6, 74, h, '备注：');
    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
    this.ADD_PRINT_TEXT(y, 80, width - margin - 80 + 6, h, template(`{{record.remark}}`));
    this.SET_PRINT_STYLEA(0, 'Bold', 1);

    y += h + 4;
    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.SET_PRINT_STYLEA(0, 'Bold', 1);
    this.ADD_PRINT_TEXT(y, 287 - 16, 266 + 16, h, template(`{{recipe.volume}}`));
    this.SET_PRINT_STYLEA(0, 'Bold', 1);

    y += h + 4;
    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 + 4;
    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}}`));

    this.ADD_PRINT_SHAPE(4, y + h + offset, margin, width - margin * 2, 1, 0, 1, '#000000');

    y += h + offset * 4;
    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 * 3;
    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();
  }

}

/**
 * 药品明细清单
 * @param model
 * @param title
 */
export function template72(model, title) {
  const template = renderTemplate.bind(this, model);

  const width = 272;
  const height = 794;
  const margin = 0;

  this.PRINT_INITA(0, 0, width, height, title);
  // 宽度按纸张的整宽缩放
  this.SET_PRINT_MODE('PRINT_PAGE_PERCENT', 'Full-Width');
  // 设置输出位置以纸张边缘为基点
  this.SET_PRINT_MODE('POS_BASEON_PAPER', true);

  let x = margin, y = margin;
  let w = 0, h = 0;

  w = 60;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`{{recipe.delivery}}`));
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x += w;
  h = 30;
  this.ADD_PRINT_TEXT(y, x, width - x - margin, h, template(`{{record.title}}`));
  this.SET_PRINT_STYLEA(0, 'FontSize', 12);
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  this.SET_PRINT_STYLEA(0, 'Bold', 1);
  x = margin;
  y += h;
  h = 36;
  this.ADD_PRINT_TEXT(y, x, width - x - margin, h, template(`{{recipe.address}}`));
  this.SET_PRINT_STYLEA(0, 'Underline', 1);
  x = margin;
  y += h;
  w = 118;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`序号：{{bedNo}}`));
  x += w;
  this.ADD_PRINT_TEXT(y, x, width - x - margin, h, template(`处方号：{{record.no}}`));

  y += h;
  x = margin;

  this.ADD_PRINT_TEXT(y, x, 118, h, template(`姓名：{{patient.name}}`));
  this.ADD_PRINT_TEXT(y, 118, 75, 20, template(`{{recipe.method}}`));
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  this.SET_PRINT_STYLEA(0, 'Underline', 1);
  this.ADD_PRINT_TEXT(y, 197, 75, 20, template(`{{recipe.decoction}}`));
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  this.SET_PRINT_STYLEA(0, 'Underline', 1);

  y += h;
  x = margin;
  h = 96;
  if (model.record.orderNo) this.ADD_PRINT_BARCODE(y, x, h, h, 'QRCode', model.record.orderNo);

  x = 94;
  h = 45;
  this.ADD_PRINT_TEXT(y, x, 178, h, template(`备注：{{record.remark}}`));
  y += h;
  this.ADD_PRINT_TEXT(y, x, 178, h, template(`另包：`));

  x = margin;
  y += h;

  w = 72;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, `药味：${model.recipe.medicines.length}`);
  x += w;
  w = 100;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`帖重：{{recipe.unitWeight}}`));
  this.SET_PRINT_STYLEA(0, 'Alignment', 3);
  x += w;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`总重：{{recipe.totalWeight}}`));
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);

  x = margin;
  y += h;
  w = 100;
  this.ADD_PRINT_TEXT(y, x, w, h, template(`开单：{{doctor}}`));
  x += w;
  this.ADD_PRINT_TEXT(y, x, width - x - margin, h, template(`共 {{recipe.count}} 帖 煎 {{recipe.total}} 包`));
  this.SET_PRINT_STYLEA(0, 'Alignment', 3);

  y += h;
  this.ADD_PRINT_SHAPE(4, y, 0, 278, 1, 0, 1, '#000000');
  x = margin;
  y += 8;
  w = 178;
  h = 20;
  this.ADD_PRINT_TEXT(y, x, w, h, [
    template(`{{recipe.frequency}}`),
    template(`{{recipe.frequencyTime}}`),
  ].filter(Boolean).join('，'));
  w = 100;
  this.ADD_PRINT_TEXT(y, width - w - margin, w, h, template(`装量：{{recipe.totalVolume}} ML`));
  this.SET_PRINT_STYLEA(0, 'Alignment', 3);

  y += h - 2;
  this.ADD_PRINT_SHAPE(4, y, 0, 278, 1, 0, 1, '#000000');
  y += 10;
  this.ADD_PRINT_TEXT(y, 0, 60, 20, '斗号');
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  this.ADD_PRINT_TEXT(y, 53, 86, 20, '品名');
  this.SET_PRINT_STYLEA(0, 'Alignment', 2);
  this.ADD_PRINT_TEXT(y, 136, 36, 20, '单帖');
  this.SET_PRINT_STYLEA(0, 'Alignment', 3);
  this.ADD_PRINT_TEXT(y, 166, 36, 20, '总量');
  this.SET_PRINT_STYLEA(0, 'Alignment', 3);
  this.ADD_PRINT_TEXT(y, 196, 36, 20, '单位');
  this.SET_PRINT_STYLEA(0, 'Alignment', 3);
  this.ADD_PRINT_TEXT(y, 228, 44, 20, '特煎');
  this.SET_PRINT_STYLEA(0, 'Alignment', 3);
  y += 20;
  this.ADD_PRINT_SHAPE(4, y, 0, 278, 1, 0, 1, '#000000');
  y = 285 + h;

  this.SET_PRINT_STYLE('FontSize', 8);
  model.recipe.medicines.forEach((medicine, i) => {
    const template = renderTemplate.bind(this, medicine);

    x = margin;
    w = 54;
    h = 30;
    this.ADD_PRINT_TEXT(y, x, w, h, template(`{{mark}}`));
    x += w - 1;
    w = 86;
    this.ADD_PRINT_TEXT(y, x, w, h, template(`{{name}}`));
    this.SET_PRINT_STYLEA(0, 'Alignment', 2);
    this.ADD_PRINT_TEXT(y, 132, 40, h, template(`{{dosage}}`));
    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
    this.ADD_PRINT_TEXT(y, 164, 40, h, template(`{{total}}`));
    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
    this.ADD_PRINT_TEXT(y, 200, 22, h, template(`{{unit}}`));
    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
    this.ADD_PRINT_TEXT(y, 222, 50, h, template(`{{usage}}`));
    this.SET_PRINT_STYLEA(0, 'Alignment', 3);
    y += h + 2;
  });
  this.SET_PRINT_STYLE('FontSize', 9);
  // y += 2;
  this.ADD_PRINT_SHAPE(4, y, 0, 278, 1, 0, 1, '#000000');

}
