<!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">
                                    <button id="batch_reset" onclick="reset()" class="btn btn-label btn-primary"><label><i class="mdi mdi-checkbox-marked-circle-outline"></i></label> 重置为待接单</button>
                                    <button id="batch_assign" onclick="modelShow()" class="btn btn-label btn-info"><label><i class="mdi mdi-play-circle-outline"></i></label> 指派派送员处理</button>
                                    <button id="batch_cancel" onclick="chanel()" class="btn btn-label btn-warning"><label><i class="mdi mdi-delete-empty"></i></label> 取消订单</button>
                                    <button id="batch_end" onclick="end()" class="btn btn-label btn-purple"><label><i class="mdi mdi-restore"></i></label> 完结订单</button>
                                    <button id="batch_refund" onclick="refund()" class="btn btn-label btn-danger"><label><i class="mdi mdi-close"></i></label> 退款</button>
                                    <#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">
<!--以下为业务流程处理-->
<!--模态框-->
<!--选择快递员模态框-->
<div>
    <div class="modal fade" id="id_order_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">当前订单：</label>
                        <input id="id_order_model_order" class="form-control" disabled>
                    </div>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="control-label">同时更改状态：</label>
                        <select id="id_order_model_select_status" class="form-control">
                            <option value="待取件" selected="selected">待取件</option>
                            <!--<option value="待支付">待支付</option>-->
                            <option value="取件中">取件中</option>
                            <option value="待派送">待派送</option>
                        </select>
                    </div>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="control-label">选择快递员：</label>
                        <select id="id_order_model_select" class="selectpicker form-control" data-live-search="true">
                            <option value="0" selected="selected">请搜索</option>
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="okZhiPai()">确认提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    /**
     * 指派订单
     */
    function modelShow() {
        let clm=getTableSelectOne();
        $("#id_order_model_order").val("订单编号："+clm.orderNum);
        $("#id_order_model").modal("show");
    }
    /**
     * 重置订单
     **/
    function reset(){
        let clm=getTableSelectOne();
        $.confirm({
            title: '重置订单确认',
            content: '您即将要重置该订单，重置成功后订单将回到待接单队列，同时下单用户将会收到重置通知，确保您已和用户协商确认。如该订单已付款，请先完成退款操作，是否继续？',
            type: 'blue',
            typeAnimated: true,
            buttons: {
                tryAgain: {
                    text: '继续',
                    btnClass: 'btn-blue',
                    action: function(){
                        sendAjax("${ctx}/order/exception/reset","get",{exceptionId:clm.exceptionId,orderId: clm.orderId});
                    }
                },
                close: {
                    text: '放弃'
                }
            }
        });
    }
    /**
     * 取消订单订单
     **/
    function chanel(){
        let clm=getTableSelectOne();
        $.confirm({
            title: '取消订单确认',
            content: '您即将取消该订单，如用户已付款，请先完成退款后，再次取消，未付款直接取消，是否继续？',
            type: 'blue',
            typeAnimated: true,
            buttons: {
                tryAgain: {
                    text: '继续',
                    btnClass: 'btn-blue',
                    action: function(){
                        sendAjax("${ctx}/order/exception/chanel","get",{exceptionId:clm.exceptionId,orderId: clm.orderId});
                    }
                },
                close: {
                    text: '放弃'
                }
            }
        });
    }
    /**
     * 完结单订单
     **/
    function end(){
        let clm=getTableSelectOne();
        $.confirm({
            title: '取消订单确认',
            content: '您即将结束该订单，成功后订单将被置为完成状态，请确保和用户协商一致，如用户未付款请选择取消订单操作，是否继续？',
            type: 'blue',
            typeAnimated: true,
            buttons: {
                tryAgain: {
                    text: '继续',
                    btnClass: 'btn-blue',
                    action: function(){
                        sendAjax("${ctx}/order/exception/end","get",{exceptionId:clm.exceptionId,orderId: clm.orderId});
                    }
                },
                close: {
                    text: '放弃'
                }
            }
        });
    }

    /**
     * 业务退款
     **/
    function refund(){
        let clm=getTableSelectOne();
        $.confirm({
            title: '退款确认',
            content: '您即将为该订单退款，成功后订单将被置为退款状态，请确保和用户协商一致，如用户未付款请选择取消订单操作，是否继续？',
            type: 'blue',
            typeAnimated: true,
            buttons: {
                tryAgain: {
                    text: '继续',
                    btnClass: 'btn-blue',
                    action: function(){
                        sendAjax("${ctx}/tpay/aliAndWinRefund","get",{exceptionId:clm.exceptionId,orderId: clm.orderId});
                    }
                },
                close: {
                    text: '放弃'
                }
            }
        });
    }


    /**
     * 为选择快递员绑定搜索输入事件
     */
    $("#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}/courier/search/key",
                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.courierName+'&nbsp;&nbsp;&nbsp;&nbsp;工号：'+item.courierNumber+'&nbsp;&nbsp;&nbsp;&nbsp;电话：'+item.courierPhone+'</option>';
                            $("#id_order_model_select").append(tempId);
                        });
                    } else{
                        lightyear.notify("没有可选择的派送员，请尽快认证派送员！", 'warning');
                    }
                    $('#id_order_model_select').selectpicker('refresh');
                }
            });
        }
        search_input.keyup(function(){
            $.ajax({
                data:{key:search_input.val()},
                type: 'get',
                url: "${ctx}/courier/search/key",
                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.courierName+'&nbsp;&nbsp;&nbsp;&nbsp;工号：'+item.courierNumber+'&nbsp;&nbsp;&nbsp;&nbsp;电话：'+item.courierPhone+'</option>';
                            $("#id_order_model_select").append(tempId);
                        });
                    }
                    $('#id_order_model_select').selectpicker('refresh');
                }
            });
        });
    });
    /**
     * 指派提交
     */
    function okZhiPai() {
        let clm=getTableSelectOne();
        let data={
            exceptionId:clm.exceptionId,
            orderId:clm.orderId,
            courierId:$("#id_order_model_select").val(),
            status:$("#id_order_model_select_status").val()
        }
        runAjax("${ctx!}/order/exception/assign","GET",data,function (res) {
            $("#id_order_model").modal("hide");
        });
    }
</script>
</body>
</html>