<!DOCTYPE html>
<html lang="zh">
<#include "/include/header.html">
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <#include "/include/left.html">
        <!--End 左侧导航-->
        <!--头部信息-->
        <#include "/include/topbar.html">
        <!--End 头部信息-->
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="panel" style="margin-bottom: auto">
                                <div class="panel-heading">
                                    <h3 class="panel-title">
                                        组合条件筛选
                                    </h3>
                                </div>
                                <!--组合条件组件-->
                                <#include "/include/table/table-query.html">

                            </div>
                            <div class="card-toolbar clearfix" style="padding: 0px 24px 0px 24px">
                                <div class="toolbar-btn-action" id="toolBar">
                                    <#include "/include/table/table-batch.html">
                                </div>
                            </div>
                            <!--快速搜索框-->
                            <div class="card-body" style="padding: 10px 15px">
                                <div class="pull-right" id="id_search_column"
                                     style="position: absolute;right: 295px;margin-top: 10px;">
                                    <input type="hidden" name="search_field" id="search-field" value="">
                                    <button class="btn btn-default dropdown-toggle" id="search-btn"
                                            data-toggle="dropdown" type="button" aria-haspopup="true"
                                            aria-expanded="false">
                                        全部 <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu" style="min-width: auto">
                                        <li><a tabindex="-1" href="javascript:void(0)" data-field="">全部</a></li>
                                        <#list pageTemplate.tableSearch as search>
                                            <li><a tabindex="-1" href="javascript:void(0)" data-field="${search.key!}">${search.name}</a></li>
                                        </#list>
                                    </ul>
                                </div>
                                <!--Bootstarp Table插入-->
                                <#include "/include/table/table-data.html">

                            </div>
                        </div>

                    </div>

                </div>
            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
</div>
</div>
<#include "/include/footer.html">
<#include "/include/table/table-event.html">
<#include "/include/table/table-model.html">
<!--<script src="${static!}/plugin/jsPdf-1.5.3/jspdf.min.js"></script>-->
<div>
    <div class="modal fade" id="id_order_batch_model" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" data-backdrop="static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">批量导入订单</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="control-label">选择订单模板<span style="color: red">*</span></label>
                        <select id="id_order_model_select_quite" class="selectpicker form-control"
                                data-live-search="true">
                            <option value="" selected="selected">请选择</option>
                        </select>
                    </div>
                    <!--<div class="form-group">
                        <label class="control-label">选择大客户</label><span style="color: red">*</span></label>
                        <select id="id_order_model_select" class="selectpicker form-control" data-live-search="true">
                            <option value="0" selected="selected">请选择</option>
                        </select>
                    </div>-->
                    <div class="form-group">
                        <label class="control-label">订单备注</label></label>
                        <textarea class="form-control" id="id_order_model_rmk" placeholder="在此输入订单备注……(200字以内)" maxlength="200"></textarea>
                    </div>
                    <div class="form-group">
                        <button id="id_batchOrder_submit_button"  class="btn btn-primary form-control" onclick="easyUpload()" data-loading-text="解析文件中，请耐心等待，不要关闭窗口...">选择文件并导入</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div>
    <div class="modal fade" id="id_order_print_model" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" data-backdrop="static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" >打印电子面单</h4>
                </div>
                <div class="modal-body">
                    <iframe frameborder="0" width="100%"  height="800px" id="printIframe"></iframe>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>

<!--以下为业务流程处理-->
<script>
/**
 * 批量导入
 * **/
function orderBatchImport() {
    $("#id_order_batch_model").modal("show");
}
/**
 * 批量打印
 * **/
function orderBatchPrint() {
    let type = navigator.userAgent;
    if(type.indexOf("Firefox")>0){
        lightyear.notify("您的浏览器不支持打印功能，请使用Chrome或者360安全浏览器极速模式", 'danger');
        return;
    }
    if(type.indexOf("MSIE")>0){
        lightyear.notify("您的浏览器不支持打印功能，请使用Chrome、360安全浏览器极速模式", 'danger');
        return;
    }
    let data={ids:getCheckIds().join(",")};
    $('#id_batchOrder_print_button').button('loading');
    runAjax("${ctx!}/admin/order/batch/print","POST",data,function (res) {
        /*if(res.status!=200){
            $('#id_batchOrder_print_button').button('loading');
            return;
        }*/
        $("#printIframe").attr("src",res.body);
        $("#id_order_print_model").modal("show");
        $('#id_batchOrder_print_button').button('reset');
    });
}
/**
 * 导入文件
 **/
function easyUpload(){
    if(!$("#id_order_model_select_quite").val()){
        lightyear.notify("请先选择订单模板!", 'danger');
        return;
    }

    let input = document.createElement("input");
    input.type = "file";
    input.accept=".xls,.xlsx";
    input.click();
    input.onchange = function(){
        $('#id_batchOrder_submit_button').button('loading');
        let file = input.files[0];
        let form = new FormData();
        form.append("file", file); //第一个参数是后台读取的请求key值
        form.append("fileName", file.name);
        form.append("templateId", $("#id_order_model_select_quite").val()); //实际业务的其他请求参数
        form.append("playerId","-1");
        form.append("rmk",$("#id_order_model_rmk").val())
        let xhr = new XMLHttpRequest();
        let action = "${ctx!}/admin/order/batch/upload/excel"; //上传服务的接口地址
        xhr.open("POST", action);
        xhr.send(form); //发送表单数据
        xhr.onreadystatechange = function(){
            if(xhr.readyState==4 && xhr.status==200){
                let data = JSON.parse(xhr.responseText);
                $('#id_batchOrder_submit_button').button('reset');
                if (data.status != 200) {
                    lightyear.notify(data.message, 'danger');
                    if(data.body.length>0){
                        data.body.forEach(function(item) {
                            console.log(item);
                            lightyear.notify(item, 'danger');
                        });
                    }
                    return;
                }
                lightyear.notify("导入成功", 'success');
                search();
                $("#id_order_model").modal("hide");
                //console.log(data);
                //处理返回的数据......
            }
        }
    }
}
/**
 * 为选择订单模板绑定搜索输入事件
 */
$("#id_order_model_select_quite").on('shown.bs.select', function (e) {
    //获取输入框对象
    let search_input = $(this).next().next().find("input");
    search_input.attr('placeholder', "请输入模板号或模板名称");
    if ($("search_input option").length == 0) {
        $.ajax({
            data: {key: search_input.val()},
            type: 'get',
            url: "${ctx}/admin/order/template/get/list",
            success: function (data) {
                if (data.status != 200) {
                    lightyear.notify(data.message, 'danger');
                    return;
                }
                $("#id_order_model_select_quite").empty();
                if (data.body.length > 0) {
                    console.log(data);
                    $.each(data.body, function (i, item) {
                        let tempId = '<option  value="' + item.id + '">模板名称：' + item.templateName + '&nbsp;&nbsp;&nbsp;&nbsp;模板号：' + item.templateNum + '</option>';
                        $("#id_order_model_select_quite").append(tempId);
                    });
                } else {
                    lightyear.notify("没有可选择的订单模板，请先添加订单模板！", 'warning');
                }
                $('#id_order_model_select_quite').selectpicker('refresh');
            }
        });
    }
    search_input.keyup(function () {
        setTimeout(function () {
            $.ajax({
                data: {key: search_input.val()},
                type: 'get',
                url: "${ctx}/admin/order/template/get/list",
                success: function (data) {
                    if (data.status != 200) {
                        lightyear.notify(data.message, 'danger');
                        return;
                    }
                    $("#id_order_model_select_quite").empty();
                    if (data.body.length > 0) {
                        $.each(data.body, function (i, item) {
                            let tempId = '<option  value="' + item.id + '">模板名称：' + item.templateName + '&nbsp;&nbsp;&nbsp;&nbsp;模板号：' + item.templateNum + '</option>';
                            $("#id_order_model_select_quite").append(tempId);
                        });
                    }
                    $('#id_order_model_select_quite').selectpicker('refresh');
                }
            });
        }, 1500);

    });
});


/**
 * 为选择大客户绑定搜索输入事件
 */
$("#id_order_model_select").on('shown.bs.select',function(e){
    //获取输入框对象
    let search_input=$(this).next().next().find("input");
    search_input.attr('placeholder',"请输入客户号或客户名称");
    if($("search_input option").length==0){
        $.ajax({
            data:{key:search_input.val()},
            type: 'get',
            url: "${ctx}/admin/customer/big/get/list",
            success: function (data) {
                if (data.status!=200){
                    lightyear.notify("系统繁忙，请尝试重新登陆。", 'danger');
                    return;
                }
                $("#id_order_model_select").empty();
                if (data.body.length>0){
                    console.log(data);
                    $.each(data.body, function (i, item) {
                        let tempId = '<option  value="' + item.id + '">客户名称：' +item.bigName+'&nbsp;&nbsp;&nbsp;&nbsp;客户号：'+item.bigNum+'&nbsp;&nbsp;&nbsp;&nbsp;签约价格：'+item.bigPrice+'</option>';
                        $("#id_order_model_select").append(tempId);
                    });
                }
                else{
                    lightyear.notify("没有可选择的大客户，请先添加大客户！", 'warning');
                }
                $('#id_order_model_select').selectpicker('refresh');
            }
        });
    }
    search_input.keyup(function(){
        setTimeout(function () {
            $.ajax({
                data:{key:search_input.val()},
                type: 'get',
                url: "${ctx}/admin/customer/big/get/list",
                success: function (data) {
                    if (data.status!=200){
                        lightyear.notify("系统繁忙，请尝试重新登陆。", 'danger');
                        return;
                    }
                    $("#id_order_model_select").empty();
                    if (data.body.length>0){
                        $.each(data.body, function (i, item) {
                            let tempId = '<option  value="' + item.id + '">客户名称：' +item.bigName+'&nbsp;&nbsp;&nbsp;&nbsp;客户号：'+item.bigNum+'&nbsp;&nbsp;&nbsp;&nbsp;签约价格：'+item.bigPrice+'</option>';
                            $("#id_order_model_select").append(tempId);
                        });
                    }
                    $('#id_order_model_select').selectpicker('refresh');
                }
            });
        },1500);

    });
});
function okZhiPai() {
    let orderIds=getCheckIds("table");
    let courierId=$("#id_order_model_select").val();
    $.ajax({
        type: "post",
        dataType:"json",
        url: "${ctx!}/order/getEditStatus?orderId="+orderIds+"&courierId="+courierId,
        success : function (data) {
            if (data.status==200){
                lightyear.notify('操作成功!', 'success');
                $("#id_order_model").modal("hide");
                search();
                return;
            }
            lightyear.notify(data.message, 'danger');
        }
    });
}
</script>
</body>
</html>