<!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 = {
        id:'[[${printData.id}]]',
        xm:'[[${printData.xm}]]',
        photo:'[[${printData.photo}]]',
        address:'[[${printData.address}]]',
        idnum:'[[${printData.idnum}]]',
        fzrq:'[[${printData.fzrq}]]',
        zsbh:'[[${printData.zsbh}]]',
        securityPic:'[[${printData.securityPic}]]',
        qrcode:'[[${printData.qrcode}]]'
    };
    $(function () {
        LODOP = getLodop();
        if (LODOP != null) {
            setTimeout("lodopPrint()", 500);
        }
    });

    function lodopPrint() {
        document.body.innerText = "打印中...";
        //打印前变量赋值为0 add start yyx 2020-01-16
        printState = 0;
        LODOP.PRINT_INITA("0mm", 0, "210mm", "148.51mm", "广西保安员证书打印");
        LODOP.SET_PRINT_MODE("BKIMG_IN_PREVIEW", 1);
        LODOP.ADD_PRINT_TEXT(266, 459, 133, 20, printData.xm);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(325, 459, 171, 56, printData.address == null ? '' : printData.address.substring(0, 9) + "\r\n" + printData.address.substring(9, printData.address.length));
        LODOP.SET_PRINT_STYLEA(2, "ReadOnly", 0);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.SET_PRINT_STYLEA(0, "LineSpacing", 3);
        LODOP.ADD_PRINT_TEXT(294, 459, 163, 20, changeBirthFormat(getBirthdayFromIDNo(printData.idnum)));
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", -1);
        LODOP.ADD_PRINT_TEXT(379, 501, 239, 20, printData.idnum);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", -1);
        LODOP.ADD_PRINT_TEXT(304, 180, 200, 20, (printData.fzrq == null ? "" : changeBirthFormatFZRQ(printData.fzrq.substring(0, 10))));
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", -1);
        LODOP.ADD_PRINT_TEXT(359, 186, 186, 20, printData.zsbh.replace("桂", ""));
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", -2);
        LODOP.ADD_PRINT_TEXT(105, 112, 111, 20, printData.xm);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);
        //照片
        LODOP.ADD_PRINT_IMAGE(45, 454, "26.00mm", "32.00mm", printData.photo);//+1
        LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
        //二维码50
        LODOP.ADD_PRINT_IMAGE(142, 212, 99, 99, printData.qrcode);
        LODOP.SET_PRINT_STYLEA(0, "Stretch", 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_SETUP();
        //非谷歌
        if (!LODOP.CVERSION) {
            if(printState >= 1) {
                document.body.innerText="打印完成";
                recordsGenerated(true);
            }else{
                document.body.innerText="已取消打印";
                recordsGenerated(false);
            }
        }
    }
    /***
     * 出生日期
     * @param birthday
     * @returns {string}
     */
    function changeBirthFormat(birthday) {

        var birthdayArr = birthday.split("-");
        if (birthdayArr[1].substring(0, 1) == "0") {
            birthdayArr[1] = birthdayArr[1].substring(1, birthdayArr[1].length);
        }
        if (birthdayArr[2].substring(0, 1) == "0") {
            birthdayArr[2] = birthdayArr[2].substring(1, birthdayArr[2].length);
        }
        return birthdayArr[0] + "年" + birthdayArr[1] + "月" + birthdayArr[2] + "日";
    }
    //根据身份证获取出生日期，格式YYYY-MM-DD
    function getBirthdayFromIDNo(IDNo) {
        var tmpStr="";
        if(IDNo!=null && IDNo!=undefined) {
            if (IDNo.length == 15) {
                tmpStr = IDNo.substring(6, 12);
                tmpStr = "19" + tmpStr;
            } else if (IDNo.length == 18) {
                tmpStr = IDNo.substring(6, 14);
            }

            tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6);
        }
        return tmpStr;
    }

    /***
     * 发证日期
     * @param birthday
     * @returns {string}
     */
    function changeBirthFormatFZRQ(birthday) {

        var birthdayArr = birthday.split("-");
        if (birthdayArr[1].substring(0, 1) == "0") {
            birthdayArr[1] = birthdayArr[1].substring(1, birthdayArr[1].length);
        }
        if (birthdayArr[2].substring(0, 1) == "0") {
            birthdayArr[2] = birthdayArr[2].substring(1, birthdayArr[2].length);
        }
        return birthdayArr[0] + "    " + birthdayArr[1] + "    " + birthdayArr[2];

    }
    function recordsGenerated(isprint) {
        $.ajax({
            type: 'POST',
            url: host + "/manage/cer/recordsPerGenerated",
            dataType: "json",
            data: {
                "id":printData.id,
                "isPrint":isprint
            },
            success: function (json) {
                if (json == true || json == "true") {
                    console.log("更新打印状态成功！");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console && console.log(errorThrown);
            }
        });
    }


</script>
</html>
