<!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">
                <input hidden type="text" name="performancesId" th:value="${id}">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>订单编号：</label>
                            <input type="text" name="orderCode"/>
                        </li>
                        <li>
                            <label>订单号ID：</label>
                            <input type="text" name="orderTicketsId"/>
                        </li>
                        <li>
                            <label>购买人电话：</label>
                            <input type="text" name="userMobile"/>
                        </li>
                        <li>
                            <label>购买人姓名：</label>
                            <input type="text" name="userName"/>
                        </li>
                        <li>
                            <label>收货人电话：</label>
                            <input type="text" name="expressPhone"/>
                        </li>
                        <li>
                            <label>收货人姓名：</label>
                            <input type="text" name="expressContacts"/>
                        </li>
                        <!--<li>
                            <label>订单状态：</label>
                            <select name="orderStatus" th:with="type=${@dict.getType('zhengzai_order_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>-->
                        <li>
                            <label>订单状态：</label>
                            <select name="orderStatus" th:with="type=${@dict.getType('zhengzai_order_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>快递状态：</label>
                            <select name="expressStatus">
                                <option value="">所有</option>
                                <option value="1">未下单</option>
                                <option value="2">已下单</option>
                                <option value="50">已揽收</option>
                                <option value="80">已签收</option>
                            </select>
                        </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-success multiple disabled"
               onclick="$.operate.removeAll('确定下单吗？', '/kylin/performancesExpress/placeOrder')"
               shiro:hasPermission="kylin:performancesExpress:placeOrder">
                批量下单
            </a>
            <a class="btn btn-danger multiple disabled"
               onclick="$.operate.removeAll('确定取消吗？', '/kylin/performancesExpress/cancelOrder', 'orderExpressId')"
               shiro:hasPermission="kylin:performancesExpress:cancelOrder">
                批量取消
            </a>
            <a class="btn btn-info multiple disabled" onclick="printExpress()"
               shiro:hasPermission="kylin:performancesExpress:printExpress">
                批量打印
            </a>
        </div>

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

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

<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var placeOrderFlag = [[${@permission.hasPermi('kylin:performancesExpress:placeOrder')}]];
    var cancelOrderFlag = [[${@permission.hasPermi('kylin:performancesExpress:cancelOrder')}]];
    var getResultFlag = [[${@permission.hasPermi('kylin:performancesExpress:getResult')}]];
    var getFreightFlag = [[${@permission.hasPermi('kylin:performancesExpress:getFreight')}]];
    var getListFreightFlag = [[${@permission.hasPermi('kylin:performancesExpress:getListFreight')}]];
    var listOrderRouteFlag = [[${@permission.hasPermi('kylin:performancesExpress:listOrderRoute')}]];
    var generateImageFlag = [[${@permission.hasPermi('kylin:performancesExpress:generateImage')}]];
    var printExpressFlag = [[${@permission.hasPermi('kylin:performancesExpress:printExpress')}]];

    var prefix = ctx + "kylin/performancesExpress";

    var orderStatusDic = [[${@dict.getType('zhengzai_order_status')}]];

    function generateImage(orderExpressId) {
        var configPrint = {
            url: prefix + "/generateImage",
            type: "post",
            dataType: "json",
            data: {ids: orderExpressId},
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍后...");
            },
            success: function (result) {
                $.modal.closeLoading();
                var url = "https://img.zhengzai.tv/" + result.data;
                window.location.href = url;
            }
        };
        $.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(orderExpressId) {
        var message = "确定打印吗？";
        $.modal.confirm(message, function () {
            try {
                var LODOP = getLodop();
                if (LODOP == undefined) {
                    return false;
                }
            } catch (err) {
                return false;
            }
            var data = '';
            if (orderExpressId) {
                var ids = [orderExpressId];
                data = {"ids": ids.join()};
            } else {
                var rows = $.table.selectColumns("orderExpressId");
                if (rows.length == 0) {
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }
                data = {"ids": rows.join()};
            }
            var configPrint = {
                url: prefix + "/printExpress",
                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);
                        });
                    }
                    $.modal.closeLoading();
                }
            };
            $.ajax(configPrint)
        });
    }

    $(function () {
        var options = {
            url: prefix + "/performanceOrderList",
            modalName: "演出订单",
            placeOrderUrl: prefix + "/placeOrder",
            cancelOrderUrl: prefix + "/cancelOrder",
            getFreightUrl: prefix + "/getFreight",
            getListFreightUrl: prefix + "/getListFreight",
            getResultUrl: prefix + "/getResult",
            listOrderRouteUrl: prefix + "/listOrderRoute",
            generateImageUrl: prefix + "/generateImage",
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderTicketsId',
                    title: '订单ID'
                },
                {
                    field: 'orderExpressId',
                    title: '快递ID'
                },
                {
                    field: 'orderCode',
                    title: '订单编号'
                },
                {
                    field: 'status',
                    title: '订单状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderStatusDic, value);
                    }
                },
                {
                    field: '',
                    title: '购买用户',
                    formatter: function (value, row, index) {
                        // var userId = row.userId;
                        var userMobile = row.userMobile;
                        var userName = row.userName;
                        // return 'ID：'+userId+'<br>'+'姓名：'+userName+'<br>'+'手机号：'+userMobile;
                        return '昵称：' + userName + '<br>' + '手机号：' + userMobile;
                    }
                },
                {
                    field: '',
                    title: '收货用户',
                    formatter: function (value, row, index) {
                        var expressContacts = row.expressContacts;
                        var expressAddress = row.expressAddress;
                        var expressPhone = row.expressPhone;
                        return '姓名：' + expressContacts + '<br>' + '手机号：' + expressPhone + '<br>' + '地址：' + expressAddress;
                    }
                },
                {
                    field: '',
                    title: '快递方式',
                    formatter: function (value, row, index) {
                        var expressType = '';
                        var freightPrice = row.freightPrice;
                        if (row.expressType == 1) {
                            expressType = "寄付";
                        } else {
                            expressType = "到付";
                        }
                        if (null == freightPrice) {
                            freightPrice = '';
                        }
                        return expressType;
                        // return '快递方式：'+expressType+'<br>'+'已支付快递费：'+row.priceExpress+'<br>'+'预估快递费：'+freightPrice;
                    }
                },
                {
                    field: '',
                    title: '快递信息',
                    formatter: function (value, row, index) {
                        var mailno = row.mailno;
                        var expressStatus = row.expressStatus;
                        var expressStatusName = '';
                        if (null == mailno) {
                            mailno = '';
                        }
                        if (null != expressStatus) {
                            switch (expressStatus) {
                                case 1:
                                    expressStatusName = '下单失败';
                                    break;
                                case 2:
                                    expressStatusName = '下单成功';
                                    break;
                                case 3:
                                    expressStatusName = '下单取消';
                                    break;
                                case 50:
                                    expressStatusName = '已揽收';
                                    break;
                                case 80:
                                    expressStatusName = '已签收';
                                    break;
                                default:
                                    expressStatusName = '运输中';
                                    break;
                            }
                        }
                        return '快递单号：' + mailno + '<br>' + '快递状态：' + expressStatusName;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + placeOrderFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderTicketsId + '\', \'确定下单吗？\', table.options.placeOrderUrl)"></i>下单</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + cancelOrderFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderExpressId + '\', \'确定取消快递单吗？\', table.options.cancelOrderUrl)"></i>取消</a> ');
                        // actions.push('<a class="btn btn-warning btn-xs ' + generateImageFlag + '" href="javascript:void(0)" onclick="generateImage(\'' + row.orderExpressId + '\',)"></i>下载快递单</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + printExpressFlag + '" href="javascript:void(0)" onclick="printExpress(\'' + row.orderExpressId + '\',)"></i>打印快递单</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + getResultFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderExpressId + '\', \'确定获取快递信息吗？\', table.options.getResultUrl)"></i>主动获取下单信息</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + getFreightFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderExpressId + '\', \'确定获取估算运费吗？\', table.options.getFreightUrl)"></i>运费估算</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + getListFreightFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderExpressId + '\', \'确定获取运费信息吗？\', table.options.getListFreightUrl)"></i>主动获取运费</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + listOrderRouteFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderExpressId + '\', \'确定获取路由信息吗？\', table.options.listOrderRouteUrl)"></i>路由主动查询</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

</script>
</body>
</html>