const headStr = `<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Document</title>
  <style>
    html, body, p, div, span {
      padding: 0;
      margin: 0;
    }

    .pdfHtml {
      margin: 0 10px;
      padding: 10px 0 10px;
      text-align: center;
      color: #000000;
      font-family: SimSun;
    }
    .title{
      font-weight: bold;
      font-size: 32px;
      font-family: SimSun;
    }
    .top{
      /*display: flex;*/
      /*justify-content: space-between;*/
      /*align-items: center;*/
      padding:40px 0 60px;
      font-size: 20px;
      text-align: left
    }
    table {
      width: 100%;
      font-size: 16px;
      line-height: 1.5;
      border-collapse: collapse;
      table-layout: fixed;
      word-break: break-all;
      word-wrap: break-word;
      text-align: left;
      border: 1px solid #000000;
      line-height: 1.5;
      font-family: SimSun;
    }
    tr > td {
      padding: 8px 8px;
      border: 1px solid #000000;
      border-collapse: collapse;
      text-align: center;
    }

    tr > th {
      padding: 15px 8px;
      border: 1px solid #000000;
      border-collapse: collapse;
      text-align: center;
    }
    .bold{
      font-weight: bold;
    }

  </style>
</head>
<body>`

const html_encode = (str) => {
  var s = ''
  if (str.length === 0) return ''
  s = str.replace(/&/g, '&amp;')
  s = s.replace(/</g, '&lt;')
  // s = s.replace(/≤/g, '&le;')
  s = s.replace(/>/g, '&gt;')
  // s = s.replace(/≥/g, '&ge;')
  // s = s.replace(/ /g, '&nbsp;')
  s = s.replace(/\'/g, '&apos;')
  s = s.replace(/\"/g, '&quot;')
  return s
}
export const getPdfHtmlStr = (projectName, templateTypeName, projectYear, selfAppraisalTotalScore, data1, data2) => {
  let htmlStr = ''
  const listTr1 = data1?.length ? data1.map((item, index) => {
    return `<tr>
    ${index === 0 ? `<td rowspan="${data1.length}">项目维度</td>` : ''}
    ${item.isFirstOne ? `<td rowspan="${item.oneRows}">${html_encode(item.oneName)}</td>` : ''}
     ${item.isFirstTwo ? `<td rowspan="${item.twoRows}">${html_encode(item.twoName)}</td>` : ''}
    <td>${html_encode(item.name)}</td>
    <td style="text-align: left">${html_encode(item.indexDetail)}</td>
    <td style="text-align: left">${html_encode(item.gradeDetail)}</td>
    <td>${item.indexScore}</td>
    <td>${item.appraisalType1List[0].appraisalScore}</td>
    <td>${html_encode(item.supportMaterial)}</td>
  </tr>`
  }).join('') : ''
  const listTr2 = data2?.length ? data2.map((item, index) => {
    return `<tr>
 ${index === 0 ? `<td rowspan="${data2.length}">附加项</td>` : ''}
    ${item.isFirstOne ? `<td rowspan="${item.oneRows}">${html_encode(item.oneName)}</td>` : ''}
     ${item.isFirstTwo ? `<td rowspan="${item.twoRows}">${html_encode(item.twoName)}</td>` : ''}
    <td>${item.name}</td>
    <td style="text-align: left">${html_encode(item.indexDetail)}</td>
    <td style="text-align: left">${html_encode(item.gradeDetail)}</td>
    <td>${item.indexScore}</td>
    <td>${item.appraisalType1List[0].appraisalScore}</td>
    <td>${html_encode(item.supportMaterial)}</td>
  </tr>`
  }).join('') : ''
  htmlStr = `${headStr}<div class="pdfHtml">
  <p class="title">丽水市本级政府投资信息化项目绩效评价指标（${templateTypeName}）${projectYear}版本</p>
  <div class="top">
    <p style="margin-bottom: 20px">项目名称：${projectName}</p>
    <p>单位名称（盖章）：</p>
  </div> <table>
    <thead>
    <tr>
      <th>评价维度</th>
      <th>一级指标</th>
      <th>二级指标</th>
      <th>三级指标</th>
      <th>指标细则</th>
      <th>评价细则</th>
      <th>分值</th>
      <th>自评得分</th>
      <th>佐证材料</th>
    </tr>
    </thead>
    <tbody>
        ${listTr1}
        ${listTr2}
        <tr>
      <td colspan="6" style="text-align: center" class="bold">合计</td>
      <td  class="bold"></td>
      <td  class="bold">${selfAppraisalTotalScore}</td>
      <td></td>
    </tr>
        <tr>
      <td colspan="7" style="text-align: center"  class="bold">星级</td>
      <td  class="bold"></td>
      <td></td>
    </tr>
    </tbody>
  </table>
</div>
</body>
</html>`
  return htmlStr
}
