import { str } from "@/utils/mymodelhtml.js";
import { doFetch } from "./doFetch";
import { Button, Modal, Space } from "antd";

const { confirm } = Modal;
export async function start(url, params) {
  try {
    var LODOP = window.getLodop();
    // if (LODOP.VERSION) {
    //   if (LODOP.CVERSION)
    //     alert(
    //       "当前有WEB打印服务C-Lodop可用!\n C-Lodop版本:" +
    //         LODOP.CVERSION +
    //         "(内含Lodop" +
    //         LODOP.VERSION +
    //         ")"
    //     );
    //   else alert("本机已成功安装了Lodop控件！\n 版本号:" + LODOP.VERSION);
    // }
    if (LODOP.VERSION) {
      const res = await doFetch({ url, params });
      const data = JSON.parse(JSON.stringify(res?.data?.dataList));
      for (let i = 0; i < data.length; i++) {
        const template = str(data[i]);
        console.log(template);
        let LODOP = getLodop();
        LODOP.PRINT_INIT("task1");
        LODOP.ADD_PRINT_HTM(0, 0, "100%", "100%", template);
        LODOP.SET_PRINT_PAGESIZE(0, 1000, 500, "");
        // LODOP.PREVIEW();
        LODOP.PRINT();
      }
      return new Promise(
        (resolve, reject) => {
          if (res) {
            resolve(data);
          } else {
            reject();
          }
        },
        (err) => {}
      );
    }
  } catch (err) {
    // alert("系统检测当前环境未安装相关插件，请先安装C-Lodop插件！");
    // var message =
    //   '系统检测当前环境未安装相关插件，请先安装C-Lodop插件！<a href="/staticfile/download/CLodop_Setup_for_Win32NT.exe">点击此处下载插件</a>';
    // var tempElement = document.createElement("div");
    // tempElement.innerHTML = message;
    // var alertText = tempElement.textContent || tempElement.innerText || "";

    const showDeleteConfirm = () => {
      confirm({
        title: "提示",
        content: (
          <div>
            系统检测当前环境未安装C-Lodop相关插件！
            {/* <br /> */}
            {/* <a href="/staticfile/download/CLodop_Setup_for_Win32NT.exe">
              点击此处下载插件
            </a> */}
          </div>
        ),
        okText: "下载插件",
        onOk() {
          location.href = "http://10.110.84.250/staticfile/group1/M00/00/00/CLodop_Setup_for_Win32NT1111111.exe";   // 郑州思锐生产环境
          // http://192.168.40.18/staticfile/download/CLodop_Setup_for_Win32NT.exe  测试环境
        },
      });
    };
    showDeleteConfirm();
  }
}
