<!--##############################指派快递员共享模块####################################-->
<!--选择快递员模态框-->
<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>
                        <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"  id="id_order_model_assign_submit">确认提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    /**
     * 指派订单
     */
    function modelShow(flag) {
        getTableSelectOne();
        $("#id_order_model_assign_submit").click(function () {
            okZhiPai(flag);
        });
        $("#id_order_model").modal("show");
    }
    /**
     * 为选择快递员绑定搜索输入事件
     */
    $("#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+'&nbsp;&nbsp;('+item.courierType+')'+'</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}/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+'&nbsp;&nbsp;('+item.courierType+')'+'</option>';
                                $("#id_order_model_select").append(tempId);
                            });
                        }
                        $('#id_order_model_select').selectpicker('refresh');
                    }
                });
            },1500);

        });
    });
    function okZhiPai(flag) {
        let clm=getTableSelectOne()
        let courierId=$("#id_order_model_select").val();
        runAjax("${ctx!}/order/getEditStatus","GET",{"orderId":clm.orderId,"courierId":courierId,"flag":flag},function (res) {
            if (res.status==200){
                lightyear.notify('操作成功!', 'success');
                $("#id_order_model").modal("hide");
                search();
                return;
            }
            lightyear.notify(res.message, 'danger');
        })
    }
</script>