import getLodop from "./LodopFuncs.js";
/**
 * 打印交班小票
 */
export default (data) => {
  console.log("data.deviceName===", data.deviceName);
  let LODOP = getLodop();
  LODOP.PRINT_INIT("打印小票");
  // 设置打印纸大小D
  LODOP.SET_PRINT_PAGESIZE(3, "58mm", 20, "");
  //设置默认打印机(这里用的是打印机名称)
  LODOP.SET_PRINTER_INDEX(data.deviceName);
  // 文字内容
  let html = `
        <div style="font-size: 24px;display:flex;justify-content:center;">
        ${data.shopName}
        </div>
        <div style="font-size: 16px;display: flex; justify-content:center;margin-top:6px;">
          交班小票
        </div>
        <div style="font-size: 12px;margin-top:50px;">
          当班时间：${data.loginTime}
        </div>
        <div style="font-size: 12px;">
          交班时间：${data.handoverTime}
        </div>
        <div style="font-size: 12px;">
          收银员：${data.staffName}
        </div>
        <div style="font-size: 12px;margin-top: 4px;">
          当班总收入：${data.handAmount}
        </div>
        <div style="font-size: 12px;margin-top: 4px;">
          现金收入：${data.cashAmount}
        </div>
        <div style="font-size: 12px;margin-top: 4px;">
          微信收入：${data.wechatAmount}
        </div>
        <div style="font-size: 12px;margin-top: 4px;">
          支付宝收入：${data.alipayAmount}
        </div>
        <div style="font-size: 12px;margin-top: 4px;">
          会员支付：${data.vipPay}
        </div>
        <div style="font-size: 12px;margin-top: 4px;">
          会员充值：${data.vipRecharge}
        </div>
  `;

  // let payInfos = "";
  // if (data.payInfos && data.payInfos.length) {
  //   for (let item of data.payInfos) {
  //     payInfos += `
  //         <div style="font-size: 12px;padding-left:20px;">
  //           ${item.payType}：${item.amount}
  //         </div>
  //     `;
  //   }
  // }

  // let memberTitle = `
  //       <div style="font-size: 12px;margin-top: 4px;">
  //         会员数据
  //       </div>
  //       `;

  // let memberData = "";
  // if (data.memberData && data.memberData.length) {
  //   for (let item of data.memberData) {
  //     memberData += `
  //       <div style="font-size: 12px;padding-left:20px;">
  //         ${item.deposit}：${item.amount}
  //       </div>
  //     `;
  //   }
  // }

  let productCategoriesTabHead = `
        <div style="font-size: 12px;margin-top: 4px;">分类数据</div>
        <table class="table" style="width: 100%;">
          <tr>
            <td style="font-size: 12px;width:50%;">名称</td>
            <td style="font-size: 12px;width:25%;">数量</td>
            <td style="font-size: 12px;width:25%;">总计</td>
          </tr>
        `;

  let productCategoriesTableBody = "";
  if (data.categoryDataList && data.categoryDataList.length) {
    for (let item of data.categoryDataList) {
      productCategoriesTableBody += `
          <tr>
            <td style="font-size: 12px;width:50%;">
              <div>${item.categoryName}</div>
            </td>
            <td style="font-size: 12px;width:25%;">${item.num}</td>
            <td style="font-size: 12px;width:25%;">
              ${item.amount}
            </td>
          </tr>
    `;
    }
  }

  let tabHead = `
      </table>
        <div style="font-size: 12px;margin-top: 4px;">商品数据</div>
        <table class="table" style="width: 100%;">
          <tr>
            <td style="font-size: 12px;width:75%;">商品</td>
            <td style="font-size: 12px;width:25%;">数量</td>
          </tr>
      `;

  let tableBody = "";
  if (data.productDataList && data.productDataList.length) {
    for (let item of data.productDataList) {
      tableBody += `
            <tr>
              <td style="font-size: 12px;width:75%;">
                <div>${item.productName}</div>
              </td>
              <td style="font-size: 12px;width:25%;">${item.num}</td>
            </tr>
      `;
    }
  }

  if (!data.printShop) {
    tabHead = "";
    tableBody = "";
  }

  let str = `
        </table>
        <div style="font-size: 12px;margin-top: 4px;">
          <span>快捷收款金额：</span>
          <span>${data.quickInAmount}</span>
        </div>
        <div style="font-size: 12px;">
          <span>退款金额：</span>
          <span>${data.refundAmount}</span>
        </div>
        <div style="font-size: 12px;">
          <span>总收入：</span>
          <span>${data.handAmount}</span>
        </div>
        <div style="font-size: 12px;">
          <span>挂账金额：</span>
          <span>${data.creditAmount}</span>
        </div>
        <div style="margin-top: 20px; font-size: 12px;">
          <span>总订单数：</span>
          <span>${data.orderCount}</span>
        </div>
        <div style="font-size: 12px;">
          打印时间：${data.printTime}
        </div>
        <div>.</div>
        <div>.</div>
        <div>.</div>
        <div>.</div>
  `;

  // let lastHtml = `${html}${payInfos}${memberTitle}${memberData}${productCategoriesTabHead}${productCategoriesTableBody}${tabHead}${tableBody}${str}`;

  let lastHtml = `${html}${productCategoriesTabHead}${productCategoriesTableBody}${tabHead}${tableBody}${str}`;

  setTimeout(() => {
    LODOP.ADD_PRINT_HTM("9mm", "0mm", "RightMargin:0mm", 20, lastHtml);
    LODOP.SET_LICENSES("", "DCFF409304DFCEB3E2C644BF96CD0720", "", "");
    LODOP.PRINT();
  }, 800);
};
