<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('演出快递列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>演出名称：</label>
                            <input type="text" name="title"/>
                        </li>
                        <li>
                            <label>演出ID：</label>
                            <input type="text" name="performancesId"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-info" onclick="$.table.importExcel()"
               shiro:hasPermission="kylin:performancesExpress:import">
                <i class="fa fa-upload"></i> 导入快递信息
            </a>
        </div>

        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>

<div id="selectTicketDiv" hidden>
    <form class="mt20 mb10">
        <div class="col-xs-offset-1">
            <div class="form-group">
                <div class="col-sm-12">
                    <select class="form-control m-b" name="ticketId" id="openTicketListTplSelect">
                        <option>选项 1</option>
                        <option>选项 2</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-12 control-label">mid(特殊情况使用)：</label>
                <div class="col-sm-12">
                    <input class="form-control" type="number" name="printNum" id="printNum">
                </div>
            </div>
        </div>
    </form>
</div>

<script th:src="@{/lodop6226/LodopFuncs.js}"></script>

<th:block th:include="include :: footer"/>

<script th:inline="javascript">
    var performanceOrderListFlag = [[${@permission.hasPermi('kylin:performancesExpress:performanceOrderList')}]];
    var batchPlaceOrderFlag = [[${@permission.hasPermi('kylin:performancesExpress:batchPlaceOrder')}]];
    var batchCancelOrderFlag = [[${@permission.hasPermi('kylin:performancesExpress:batchCancelOrder')}]];
    var prefix = ctx + "kylin/performancesExpress";
    var batchGenerateImageFlag = [[${@permission.hasPermi('kylin:performancesExpress:batchGenerateImage')}]];
    var batchPrintExpressFlag = [[${@permission.hasPermi('kylin:performancesExpress:batchPrintExpress')}]];
    var exportExcelFlag = [[${@permission.hasPermi('kylin:performancesExpress:exportExcel')}]];

    function generateImage(performanceId) {
        var configPrint = {
            url: prefix + "/batchGenerateImage",
            type: "post",
            dataType: "json",
            data: {ids: performanceId},
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                if (result.data != '' && result.data != null) {
                    var url = "https://img.zhengzai.tv/" + result.data;
                    window.location.href = url;
                } else {
                    $.modal.msg("暂无需打印单");
                }

            }
        };
        $.ajax(configPrint)
    }

    /**
     * 打印
     * @returns {string}
     */
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
        return currentdate;
    }

    function substrMailno(str) {
        if (str != null && str != "" && str.length == 15) {
            var newStr1 = (str.slice(0, 2) + "\xa0" + str.slice(2))
            var newStr2 = (newStr1.slice(0, 6) + "\xa0" + newStr1.slice(6));
            var newStr3 = (newStr2.slice(0, 10) + "\xa0" + newStr2.slice(10));
            var newStr4 = (newStr3.slice(0, 14) + "\xa0" + newStr3.slice(14));
            return newStr4
        }
        return str
    }

    function printExpressData(dataInfo, jContact, jAddress, jTel, index, listLen) {
        var LODOP = getLodop();
        LODOP.PRINT_INIT("运单打印");
        // LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "100mm*148mm");
        LODOP.ADD_PRINT_TEXT(22, 115, 200, 20, "打印时间：" + getNowFormatDate());
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 5);
        // LODOP.ADD_PRINT_TEXT(32, 115, 200, 20, "第1次打印");
        // LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        // LODOP.SET_PRINT_STYLEA(0, "FontSize", 5);
        // LODOP.ADD_PRINT_TEXT(98, 55, 42, 20, index + "/" + listLen); //子母单
        LODOP.ADD_PRINT_TEXT(60, 20, 100, 20, "FQ");
        LODOP.ADD_PRINT_TEXT(32, 190, 200, 20, "第" + index + "/" + listLen + "个");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 5);
        LODOP.ADD_PRINT_BARCODE(45, 55, "80mm", "13mm", "128Auto", dataInfo.mailno);
        LODOP.SET_PRINT_STYLEA(0, "ShowBarText", 0);
        LODOP.ADD_PRINT_TEXT(98, 95, 500, 15, "运单号 " + substrMailno(dataInfo.mailno));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 9);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(9, 290, 100, 40, dataInfo.proCode);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 26);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(125, 10, 500, 45, dataInfo.destRouteLabel);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 33);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_ELLIPSE(175, 18, 41, 39, 0, 1);
        LODOP.ADD_PRINT_TEXT(183, 27, 31, 31, "收");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 17);
        LODOP.ADD_PRINT_TEXT(181, 76, 200, 20, dataInfo.expressContacts);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(181, 230, 296, 20, dataInfo.expressPhone.substr(0, 3) + "****" + dataInfo.expressPhone.substr(8, 11));
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(195, 74, 296, 39, dataInfo.expressAddress);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        if (dataInfo.freightPrice > 0) {
            LODOP.ADD_PRINT_TEXT(233, 26, 105, 20, "到付 " + dataInfo.freightPrice + "元");
        } else {
            LODOP.ADD_PRINT_TEXT(233, 26, 105, 20, "到付");
        }
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1)
        LODOP.ADD_PRINT_TEXT(263, 21, 120, 50, dataInfo.cargoTypeCode);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 30);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_BARCODE(228, 150, 115, 99, "QRCode", dataInfo.twoDimensionCode);
        LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 7);
        LODOP.SET_PRINT_STYLEA(0, "DataCharset", "UTF-8");
        LODOP.ADD_PRINT_TEXT("61.94mm", "67.47mm", "7.41mm", "21.17mm", "已\r\n验\r\n视");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 15);
        LODOP.ADD_PRINT_TEXT(235, 300, 80, 50, dataInfo.proName);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "宋体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(295, 300, 80, 20, dataInfo.expressTypeCode);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "宋体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

        LODOP.ADD_PRINT_ELLIPSE(329, 18, 41, 38, 0, 1);
        LODOP.ADD_PRINT_TEXT(336, 27, 31, 31, "寄");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 17);
        LODOP.ADD_PRINT_TEXT(335, 76, 200, 15, jContact);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(335, 230, 200, 15, jTel);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(350, 74, 296, 30, jAddress);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(388, 10, 57, 15, "托寄物：");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "宋体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
        LODOP.ADD_PRINT_TEXT(400, 10, 180, 70, "演出票");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);

        //  LODOP.SET_PRINT_STYLEA(0, "Bold", 1)

        LODOP.ADD_PRINT_TEXT(388, 200, 70, 15, "增值服务：");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "宋体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
        LODOP.ADD_PRINT_TEXT(433, 200, 57, 15, "重量：");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "宋体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
        LODOP.ADD_PRINT_TEXT(433, 225, 80, 15, "1kg");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(483, 10, 55, 15, "备注：");
        LODOP.SET_PRINT_STYLEA(0, "FontName", "宋体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
        LODOP.ADD_PRINT_TEXT(494, 10, 180, 55, dataInfo.timeTitle + " " + dataInfo.ticketsTitle + "\r\n数量 " + dataInfo.number);
        LODOP.SET_PRINT_STYLEA(0, "FontName", "黑体");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.SET_SHOW_MODE("BKIMG_PRINT", 1);
        LODOP.ADD_PRINT_LINE("0mm", "0mm", "0mm", "100mm", 0, 1);
        LODOP.ADD_PRINT_LINE("147mm", "0mm", "0mm", "0mm", 0, 1);
        LODOP.ADD_PRINT_LINE("33.13mm", "0mm", "33.13mm", "100mm", 0, 1);

        //   LODOP.ADD_PRINT_LINE("43.13mm", "0mm", "43.13mm", "100mm", 0, 1);

        LODOP.ADD_PRINT_LINE("60mm", "0mm", "60mm", "100mm", 0, 1);
        LODOP.ADD_PRINT_LINE("69.35mm", "0mm", "69.35mm", "38.36mm", 0, 1);
        LODOP.ADD_PRINT_LINE("0mm", "100mm", "147mm", "100mm", 0, 1);
        LODOP.ADD_PRINT_LINE("60.1mm", "38.36mm", "84.5mm", "38.36mm", 0, 1);
        LODOP.ADD_PRINT_LINE("60.1mm", "64.29mm", "84.5mm", "64.29mm", 0, 1);
        LODOP.ADD_PRINT_LINE("60.1mm", "75.67mm", "84.5mm", "75.67mm", 0, 1);

        //  LODOP.ADD_PRINT_LINE("77.87mm", "0mm", "77.87mm", "38.36mm", 0, 1);

        LODOP.ADD_PRINT_LINE("75.87mm", "75.67mm", "75.87mm", "100mm", 0, 1);
        LODOP.ADD_PRINT_LINE("84.5mm", "0mm", "84.5mm", "100mm", 0, 1);
        LODOP.ADD_PRINT_LINE("101mm", "0mm", "101mm", "100mm", 0, 1);
        LODOP.ADD_PRINT_LINE("101mm", "50.00mm", "147mm", "50.00mm", 0, 1);
        LODOP.ADD_PRINT_LINE("113mm", "50mm", "113mm", "100mm", 0, 1);
        LODOP.ADD_PRINT_LINE("126.3mm", "0mm", "126.3mm", "100mm", 0, 1);
        LODOP.ADD_PRINT_LINE("147mm", "0mm", "147mm", "100mm", 0, 1);
        LODOP.PRINT();
    }

    function printExpress(performanceId, ticketId, printNum) {
        var message = "确定打印吗？";
        $.modal.confirm(message, function () {
            try {
                var LODOP = getLodop();
                if (LODOP == undefined) {
                    return false;
                }
            } catch (err) {
                return false;
            }
            var data = '';
            var ids = [performanceId];
            data = {"ids": ids.join(), "ticketId": ticketId, "printNum": printNum};
            var configPrint = {
                url: prefix + "/batchPrintExpress",
                type: "post",
                dataType: "json",
                data: data,
                beforeSend: function () {
                    $.modal.loading("正在获取数据中，请稍后...");
                },
                success: function (result) {
                    $.modal.closeLoading();
                    $.modal.loading("正在打印中，请稍后...");
                    var expressList = result.data.expressList;
                    var listLen = expressList.length;
                    var jContact = result.data.jcontact;
                    var jAddress = result.data.jaddress;
                    var jTel = result.data.jtel;
                    if (listLen > 0) {
                        $.each(expressList, function (index, value) {
                            printExpressData(value, jContact, jAddress, jTel, index + 1, listLen);
                        });
                    } else {
                        $.modal.msg("暂无需要打印的订单");
                    }
                    $.modal.closeLoading();
                }
            };
            $.ajax(configPrint)
        });
    }

    function getPerformancesTicketList(performanceId) {
        var data = {"ids": performanceId};
        var configPrint = {
            url: prefix + "/getPerformancesTicketList",
            type: "post",
            dataType: "json",
            data: data,
            beforeSend: function () {
                $.modal.loading("正在获取数据中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                var rows = result.rows;
                var html = '<option value="">全部</option>';
                $.each(rows, function (index, value) {
                    html += '<option value="' + value.ticketsId + '">' + value.title + '/' + value.timeTitle + '</option>'
                });
                $('#selectTicketDiv').find('#openTicketListTplSelect').html(html);
                openTicketList("openTicketListTpl", performanceId);
            }
        };
        $.ajax(configPrint)
    }

    function openTicketList(formId, performanceId, width, height) {
        table.set();
        var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
        var _width = $.common.isEmpty(width) ? "400" : width;
        var _height = $.common.isEmpty(height) ? "230" : height;
        let selectTicketDiv = $('#selectTicketDiv').html();
        $('#' + currentId).html(selectTicketDiv);
        layer.open({
            type: 1,
            area: [_width + 'px', _height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '选择票种打印',
            content: $('#' + currentId).html(),
            btn: ['<i class="fa fa-check"></i> 打印', '<i class="fa fa-remove"></i> 取消'],
            // 弹层外区域关闭
            shadeClose: true,
            btn1: function (index, layero) {
                var ticketId = layero.find('#openTicketListTplSelect').val();
                var printNum = layero.find('#printNum').val();
                printExpress(performanceId, ticketId, printNum);
            }
        });
    }

    function exportExcel(performancesId) {
        var data = {"ids": performancesId};
        $.table.exportExcel("", data)
    }

    $(function () {
        var options = {
            url: prefix + "/performancesList",
            detailUrl: prefix + "/performanceOrderList/{id}",
            batchPlaceOrderUrl: prefix + "/batchPlaceOrder",
            batchCancelOrderUrl: prefix + "/batchCancelOrder",
            batchGenerateImageUrl: prefix + "/batchGenerateImage",
            batchPrintExpressUrl: prefix + "/batchPrintExpress",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            modalName: "演出快递",
            columns: [
                {
                    field: 'performancesId',
                    title: '演出id'
                },
                {
                    field: 'title',
                    title: '演出名称'
                },
                {
                    field: 'timeStart',
                    title: '开演时间'
                },
                {
                    field: 'totalNumber',
                    title: '快递票总数'
                },
                {
                    field: 'total1',
                    title: '已下单'
                },
                {
                    field: 'total2',
                    title: '运输中'
                },
                {
                    field: 'total3',
                    title: '已签收'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + performanceOrderListFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.performancesId + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + batchPlaceOrderFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.performancesId + '\', \'确定批量下单吗？\', table.options.batchPlaceOrderUrl)"></i>下单</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + batchCancelOrderFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.performancesId + '\', \'确定批量取消吗？\', table.options.batchCancelOrderUrl)"></i>取消</a> ');
                        // actions.push('<a class="btn btn-warning btn-xs ' + batchGenerateImageFlag + '" href="javascript:void(0)" onclick="generateImage(\'' + row.performancesId + '\',)"></i>下载快递单</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + batchPrintExpressFlag + '" href="javascript:void(0)" onclick="getPerformancesTicketList(\'' + row.performancesId + '\',)"></i>打印快递单</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + exportExcelFlag + '" href="javascript:void(0)" onclick="exportExcel(\'' + row.performancesId + '\')"></i>导出快递票订单</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

<!-- 票种选择区域 -->
<script id="openTicketListTpl" type="text/template">

</script>

</html>