<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('服务公司许可打印')"/>
    <th:block th:include="include :: footer"/>
    <th:block th:include="include :: lodop"/>
</head>
<body style="text-align: center;padding-top: 20px;font-weight: bold;font-size: 20px">
</body>

<script>
    var LODOP = null;
    var printState=0;
    var host="http://"+window.location.host;
    var printData = {
        gsmc: '[[${printData.gsmc}]]',
        gsdz: '[[${printData.gsdz}]]',
        frmc: '[[${printData.frmc}]]',
        management: '[[${printData.management}]]',
        pzwh: '[[${printData.pzwh}]]',
        fzrq: '[[${printData.fzrq}]]',
        xkzh: '[[${printData.xkzh}]]',
        clrq: '[[${printData.clrq}]]',
        zczb: '[[${printData.zczb}]]',
        id:'[[${printData.id}]]',
        companyPic_1_2:'[[${printData.companyPic_1_2}]]',
        companyPic_2_1:'[[${printData.companyPic_2_1}]]',
        zf: '[[${printData.zf}]]',
        qrcode: '[[${printData.qrcode}]]'
    };
    $(function () {
        LODOP = getLodop();
        if (LODOP != null) {
            setTimeout("lodopPrint()", 1500);
            var zf = "[[${printData.zf}]]";
            if (zf == "f") {//副本
                lodopPrint2();
            } else {//正本
                lodopPrint1();
            }

        }
    });

    function lodopPrint1() {
        document.body.innerText = "打印中...";
        printState=0;
        LODOP.PRINT_INITA("0mm", "0mm", "359.99mm", "260.01mm", "保安服务许可证正本-多行");

        LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE", 1);

        LODOP.ADD_PRINT_SETUP_BKIMG("<img border='0'  src='"+host+printData.companyPic_1_2+ "'>");

        LODOP.SET_SHOW_MODE("BKIMG_LEFT", 0);

        LODOP.SET_SHOW_MODE("BKIMG_TOP", 0);

        LODOP.SET_SHOW_MODE("BKIMG_WIDTH", "360.1mm");

        LODOP.SET_SHOW_MODE("BKIMG_HEIGHT", "260mm");

        LODOP.ADD_PRINT_TEXTA("gsmc", "31.75mm", "91.55mm", "174.63mm", "12.96mm", printData.gsmc || '');

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 25);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("gsdz", "48.45mm", "92.08mm", "261.14mm", "13.76mm", printData.gsdz || '');

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 25);

        LODOP.SET_PRINT_STYLEA(0, "LineSpacing", 15);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("frmc", "64.56mm", "92.08mm", "93.13mm", "11.64mm", printData.frmc || '');

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 25);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("fwfw", "81.23mm", "92.34mm", "260.51mm", "25.93mm", (printData.management == null || printData.management == "" || printData.management.length < 25) ? (printData.management || '') : printData.management.substring(0, 24) + '\r\n' + printData.management.substring(24));

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 25);

        LODOP.SET_PRINT_STYLEA(0, "LineSpacing", 13);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", -2);

        LODOP.ADD_PRINT_TEXTA("zczb", "113.77mm", "92.34mm", "81.23mm", "11.64mm", (printData.zczb == null ? "" : (Arabia_to_Chinese(parseFloat(printData.zczb) * 10000))));

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 25);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("pzwh", "131.5mm", "92.6mm", "181.48mm", "12.17mm", (printData.pzwh == null ? "" : (printData.pzwh.replace("【", "[").replace("】", "]"))));

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 25);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("year", "165.1mm", "222.51mm", "19.58mm", "9mm", (printData.fzrq == null ? "" : (printData.fzrq).substring(0, 4)));

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 20);

        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("month", "165.63mm", "260.88mm", "12.44mm", "9mm", (printData.fzrq == null ? "" : (printData.fzrq).substring(5, 7)));

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 20);

        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("day", "165.63mm", "287.07mm", "12.17mm", "9mm", (printData.fzrq == null ? "" : (printData.fzrq).substring(8, 10)));

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 20);

        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("xkzh", "19.26mm", "279.85mm", "49.48mm", "9.26mm", (printData.xkzh == null ? "" : printData.xkzh.replace("桂公保服", "")));

        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");

        LODOP.SET_PRINT_STYLEA(0, "FontSize", 23);

        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);


        //谷歌浏览器
        if (LODOP.CVERSION) {
            CLODOP.On_Return = function (TaskID, Value) {
                //打印状态
                printState = Value;
                if (printState >= 1) {
                    document.body.innerText = "打印完成";
                    recordsGenerated(true);
                } else {
                    document.body.innerText = "已取消打印";
                    recordsGenerated(false);
                }
            };
        }

        printState = LODOP.PRINT_DESIGN();
        //非谷歌
        if (!LODOP.CVERSION) {
            if (printState >= 1) {
                document.body.innerText = "打印完成";
                recordsGenerated(true);
            } else {
                document.body.innerText = "已取消打印";
                recordsGenerated(false);
            }
        }
    }

    function lodopPrint2() {
        document.body.innerText = "打印中...";
        printState=0;
        LODOP.PRINT_INITA("-3mm", "0mm", "250mm", "230mm", "保安服务许可证副本单行");
        LODOP.SET_SHOW_MODE('BKIMG_IN_PREVIEW', 1);
        LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE", 1);
        LODOP.ADD_PRINT_SETUP_BKIMG("<img border='0'  src='" + host + printData.companyPic_2_1 + "'>");
        LODOP.SET_SHOW_MODE("BKIMG_WIDTH", "250mm");
        LODOP.SET_SHOW_MODE("BKIMG_HEIGHT", "215mm");
        LODOP.SET_SHOW_MODE("BKIMG_IN_PREVIEW", true);
        LODOP.ADD_PRINT_TEXTA("gsmc", "63.18mm", "55.03mm", "76.46mm", "6.61mm", printData.gsmc || '');
        LODOP.SET_PRINT_STYLEA(0, "FontName", "宋体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);
        LODOP.ADD_PRINT_TEXTA("gsdz", "74.03mm", "55.03mm", "76.2mm", "7.14mm", printData.gsdz || '');
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);
        LODOP.ADD_PRINT_TEXTA("frmc", "85.1mm", "55.03mm", "57.15mm", "6.88mm", printData.frmc || '');
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("fwfw", "95.71mm", "54.77mm", "85.73mm", "28.31mm", (printData.management == null || printData.management == "" || printData.management.length < 17) ? (printData.management || '') : printData.management.substring(0, 16) + '\r\n' + printData.management.substring(16));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "LineSpacing", 5);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 1);

        LODOP.ADD_PRINT_TEXTA("zczb", "123.08mm", "55.03mm", "69.85mm", "6.61mm", (printData.zczb == null ? "" : (Arabia_to_Chinese(parseFloat(printData.zczb) * 10000))));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("pzwh", "133.75mm", "55.03mm", "169.31mm", "6.61mm", (printData.pzwh == null ? "" : (printData.pzwh.replace("【", "[").replace("】", "]"))));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        LODOP.ADD_PRINT_TEXTA("year", "160.6mm", "69.59mm", "14.02mm", "7.41mm", (printData.fzrq == null ? "" : (printData.fzrq).substring(0, 4)));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

        LODOP.ADD_PRINT_TEXTA("month", "160.6mm", "86.52mm", "7.94mm", "7.41mm", (printData.fzrq == null ? "" : (printData.fzrq).substring(5, 7)));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

        LODOP.ADD_PRINT_TEXTA("day", "160.6mm", "95.25mm", "9mm", "7.41mm", (printData.fzrq == null ? "" : (printData.fzrq).substring(8, 10)));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

        LODOP.ADD_PRINT_TEXTA("xkzh", "49mm", "68.87mm", "43.39mm", "6.09mm", (printData.xkzh == null ? "" : printData.xkzh.replace("桂公保服", "")));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "仿宋_GB2312");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 2);

        //谷歌浏览器
        if (LODOP.CVERSION) {
            CLODOP.On_Return = function (TaskID, Value) {
                //打印状态
                printState = Value;
                if (printState >= 1) {
                    document.body.innerText = "打印完成";
                    recordsGenerated(true);
                } else {
                    document.body.innerText = "已取消打印";
                    recordsGenerated(false);
                }
            };
        }

        printState = LODOP.PRINT_DESIGN();
        //非谷歌
        if (!LODOP.CVERSION) {
            if (printState >= 1) {
                document.body.innerText = "打印完成";
                recordsGenerated(true);
            } else {
                document.body.innerText = "已取消打印";
                recordsGenerated(false);
            }
        }
    }

    //小写数字转换为大写
    function Arabia_to_Chinese(Num) {
//      for (i = Num.length - 1; i >= 0; i--) {
//       Num = Num.replace(",", "")//替换tomoney()中的“,”
//       Num = Num.replace(" ", "")//替换tomoney()中的空格
//      }
//      Num = Num.replace("￥", "")//替换掉可能出现的￥字符
        if (isNaN(Num)) { //验证输入的字符是否为数字
            alert("请检查小写金额是否正确");
            return;
        }
        //---字符处理完毕，开始转换，转换采用前后两部分分别转换---//
        part = String(Num).split(".");
        newchar = "";
        //小数点前进行转化
        for (i = part[0].length - 1; i >= 0; i--) {
            if (part[0].length > 10) {
                alert("位数过大，无法计算");
                return "";
            }//若数量超过拾亿单位，提示
            tmpnewchar = "";
            perchar = part[0].charAt(i);
            switch (perchar) {
                case "0":
                    tmpnewchar = "零" + tmpnewchar;
                    break;
                case "1":
                    tmpnewchar = "壹" + tmpnewchar;
                    break;
                case "2":
                    tmpnewchar = "贰" + tmpnewchar;
                    break;
                case "3":
                    tmpnewchar = "叁" + tmpnewchar;
                    break;
                case "4":
                    tmpnewchar = "肆" + tmpnewchar;
                    break;
                case "5":
                    tmpnewchar = "伍" + tmpnewchar;
                    break;
                case "6":
                    tmpnewchar = "陆" + tmpnewchar;
                    break;
                case "7":
                    tmpnewchar = "柒" + tmpnewchar;
                    break;
                case "8":
                    tmpnewchar = "捌" + tmpnewchar;
                    break;
                case "9":
                    tmpnewchar = "玖" + tmpnewchar;
                    break;
            }
            switch (part[0].length - i - 1) {
                case 0:
                    tmpnewchar = tmpnewchar + "元";
                    break;
                case 1:
                    if (perchar != 0)
                        tmpnewchar = tmpnewchar + "拾";
                    break;
                case 2:
                    if (perchar != 0)
                        tmpnewchar = tmpnewchar + "佰";
                    break;
                case 3:
                    if (perchar != 0)
                        tmpnewchar = tmpnewchar + "仟";
                    break;
                case 4:
                    tmpnewchar = tmpnewchar + "万";
                    break;
                case 5:
                    if (perchar != 0)
                        tmpnewchar = tmpnewchar + "拾";
                    break;
                case 6:
                    if (perchar != 0)
                        tmpnewchar = tmpnewchar + "佰";
                    break;
                case 7:
                    if (perchar != 0)
                        tmpnewchar = tmpnewchar + "仟";
                    break;
                case 8:
                    tmpnewchar = tmpnewchar + "亿";
                    break;
                case 9:
                    tmpnewchar = tmpnewchar + "拾";
                    break;
            }
            newchar = tmpnewchar + newchar;
        }
        //替换所有无用汉字
        while (newchar.search("零零") != -1)
            newchar = newchar.replace("零零", "零");
        newchar = newchar.replace("零亿", "亿");
        newchar = newchar.replace("亿万", "亿");
        newchar = newchar.replace("零万", "万");
        newchar = newchar.replace("零元", "元");
        return newchar;
    }
    function recordsGenerated(isPrint) {
        $.ajax({
            type: 'POST',
            url: host + "/manage/cer/recordsComGenerated",
            dataType: "json",
            data: {
                "id":printData.id,
                "isPrint":isPrint
            },
            success: function (json) {
                if (json.successful == true || json.successful == "true") {
                    console.log("更新打印状态成功！");
                } else {
                    console.log("更新打印状态失败！");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console && console.log(errorThrown);
            }
        });
    }
</script>
</html>
