import { changeNumMoneyToChinese, thousands } from '@/utils/util'
export default function (data) {
  // 金额合计
  var je = [
    ...(data.itemList || []).map((item, index) => {
      return item.totalAmount || 0
    }),
    0
  ].reduce((a, b) => {
    return a + b
  })
  return `<style lang="css">
    #new-repair-parts-listing {
      width: 100%;
      height: auto;
      border: 1px solid #000;
      box-sizing: border-box;
      padding: 20px;
    }
    #new-repair-parts-listing table {
      border: 1px solid #aaa;
    }
    #new-repair-parts-listing th,
    #new-repair-parts-listing td {
      height: 30px;
      border: 1px solid #aaa;
    }
    .new-repair-parts-title {
      text-align: center;
      font-weight: bold;
    }
    .new-repair-parts-info {
      width: 100%;
      height: auto;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
    }
  </style>
  <div id="new-repair-parts-listing">
    <h3 class="new-repair-parts-title">维修配件新件申请开单表</h3>
    <div class="new-repair-parts-info">
      <div>
        <p>发货单位：${data.deliveryUnit || ''}</p>
        <p>领入单位：${data.receiveUnit || ''}</p>
      </div>
      <div>
        <p>凭证单号：${data.salesOrderNo || ''}</p>
        <p>经办日期：${data.examineTime || ''}</p>
        <p>打印日期：${new Date().Format('yyyy-MM-dd hh:mm:ss')}</p>
      </div>
    </div>
    <table border="1" cellspacing="0" width="100%">
      <tr>
        <th width="100">序号</th>
        <th width="200">配件编码</th>
        <th width="300">配件名称</th>
        <th width="100">单位</th>
        <th width="150">单价</th>
        <th width="100">数量</th>
        <th width="200">金额</th>
      </tr>
      ${(data.itemList || []).map((item, index) => {
        return `
        <tr>
          <td>${index + 1}</td>
          <td>${item.partsNumber || ''}</td>
          <td>${item.partsName || ''}</td>
          <td>${item.unitName || ''}</td>
          <td>${item.salesPrice || ''}</td>
          <td>${item.quantity || ''}</td>
          <td>${item.totalAmount || ''}</td>
        </tr>`
      })}
      <tr>
        <td colspan="4" align="center">合计(人民币)：${changeNumMoneyToChinese(je)}</td>
        <td colspan="3" align="center">小写：${thousands(je)}</td>
      </tr>
    </table>
    <br />
    <table border="1" cellspacing="0" width="100%">
      <tr>
        <th width="140">配件编码</th>
        <th width="100">是否备用件</th>
        <th width="140">保内/保外</th>
        <th width="140">总部信息编号</th>
        <th width="200">广佛信息编号</th>
        <th width="100">用户姓名</th>
        <th width="140">联系电话</th>
        <th width="100">数量</th>
      </tr>
      ${(data.oldRefundManageRecordBeanList || []).map((item, index) => {
        return `
        <tr>
          <td>${item.partsNumber || ''}</td>
          <td>${item.isBackupName || ''}</td>
          <td>${item.repairFlagName || ''}</td>
          <td>${item.pgId || ''}</td>
          <td>${item.workerOrderNo || ''}</td>
          <td>${item.customerName || ''}</td>
          <td>${item.customerTel || ''}</td>
          <td>${item.qty || ''}</td>
        </tr>`
      })}
    </table>
    <div class="new-repair-parts-info">
      <div style="width:50%">
        <p>开单单位经办人：</p>
        <p>开单单位公章：</p>
      </div>
      <div style="width:50%">
        <p>接收单位经办人：</p>
        <p>接收单位公章：</p>
      </div>
    </div>
  </div>`
}
