import { str } from "@/utils/mymodelhtml.js";
import { doFetch } from "./doFetch";
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, 800, 600, "");
        // LODOP.PREVIEW();
        LODOP.PRINT();
      }
      return new Promise(
        (resolve, reject) => {
          if (res) {
            resolve(data);
          } else {
            reject();
          }
        },
        (err) => {}
      );
    }
  } catch (err) {
    alert("系统检测当前环境未安装相关插件，请先安装C-Lodop插件！");
  }
}
