
// 表单数据
const formData = reactive({
  admission: {
    confirmDate: '2023年10月28日',
    dischargeTime: '2023年11月13日 08时14分',
    hospitalDays: '17'
  },
  diagnosis: {
    mainDiagnosis: '腰椎间盘突出症(L4-5)',
    otherDiagnosis: ''
  }
});

// 打印表单
const printForm = () => {
  // 创建一个新的打印窗口
  const printWindow = window.open('', '_blank');
  
  // 构建打印内容
  const printContent = `
    <!DOCTYPE html>
    <html>
    <head>
      <title>住院病案首页</title>
      <style>
        /* ... existing code ... */
        
        .form-row {
          display: flex;
          flex-wrap: wrap;
          margin-bottom: 15px;
          justify-content: space-between;
        }

        .form-item {
          flex: 1;
          min-width: 200px;
          margin-right: 15px;
          margin-bottom: 10px;
        }

        .form-item.full-width {
          flex: 0 0 100%;
          min-width: 100%;
        }

        .barcode {
          width: 240px;
          margin-top: 10px;
        }
      </style>
    </head>
    <body>
      <div class="form-header">
        <div class="form-title">吉林大学第一医院</div>
        <div style="display: flex; justify-content: space-between; align-items: center;">
          <div style="font-size: 12px;text-align: left;">
            <div>组织机构代码：（${formData.hospital.orgCode || ''}）</div>
            <div>医疗付费方式：（${formData.hospital.paymentMethod || ''}）</div>
          </div>
          <div style="font-size: 20px;font-weight: 700;">
            住院病案首页
          </div>
          <div class="barcode" id="barcode"></div>
        </div>
      </div>
      
      <!-- 医院信息、患者基本信息、住院信息、诊断信息等部分保持不变 -->
      
      <!-- 住院信息 -->
      <div class="section">
        <div class="section-title">住院信息</div>
        <div class="form-row">
          <div class="form-item">
            <label>入院时间:</label>
            <div class="form-value">${formData.admission.admitTime || ''}</div>
          </div>
          <div class="form-item">
            <label>入科时间:</label>
            <div class="form-value">${formData.admission.departmentAdmitTime || ''}</div>
          </div>
          <div class="form-item">
            <label>出院时间:</label>
            <div class="form-value">${formData.admission.dischargeTime || ''}</div>
          </div>
        </div>
        <div class="form-row">
          <div class="form-item">
            <label>实际住院天数:</label>
            <div class="form-value">${formData.admission.hospitalDays || ''}</div>
          </div>
        </div>
      </div>

      <!-- 其他部分保持不变 -->

      <script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js"></script>
      <script>
        window.onload = function() {
          JsBarcode("#barcode").init();
          JsBarcode("#barcode").encode("12979667");
          window.print();
          window.onafterprint = function() {
            window.close();
          }
        }
      </script>
    </body>
    </html>
  `;

  // 将内容写入打印窗口并打印
  printWindow.document.write(printContent);
  printWindow.document.close();
};
