<!-- 模态框（Modal） -->
<div>
    <div class="modal fade" id="id_courier_winthraw_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="id_courier_winthraw_model_title">抽成配置</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <div class="input-group">
                            <ul class="nav nav-tabs nav-justified">
                                <li class="active">
                                    <button type="button" class="btn btn-warning" onclick="showDividedConfigModel('全职')">全职</button>
                                </li>
                                <li class="nav-item">
                                    <button type="button" class="btn btn-warning" onclick="showDividedConfigModel('兼职')">兼职</button>
                                </li>
                                <li class="nav-item">
                                    <button type="button" class="btn btn-warning" onclick="showDividedConfigModel('距离')">距离</button>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">骑手</span>
                            <input type="text" id="id_courier_type" class="form-control" readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">默认距离</span>
                            <input type="text" id="id_dist_model" maxlength="4" class="form-control" value="0" readonly="readonly" onkeyup="clearNoNum(this)">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">平台</span>
                            <input type="text" id="id_sys_model"  maxlength="4"  class="form-control" value="0.00" readonly="readonly" onkeyup="clearNoNum(this)">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">加盟</span>
                            <input type="text" id="id_fran_model" maxlength="4"  class="form-control" value="0.00" readonly="readonly" onkeyup="clearNoNum(this)">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">骑手</span>
                            <input type="text" id="id_rider_model" maxlength="4"  class="form-control" value="0.00" readonly="readonly" onkeyup="clearNoNum(this)">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-warning" onclick="changePrice()">更改比例</button>
                    <button type="button" class="btn btn-primary" onclick="returnBackSubmit()">确认提交</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    /**
     * 在线结算按钮事件
     * */
    function showDividedConfigModel(type){
        document.getElementById("js_load").style.display = "inline";
        let fran=getTableSelectOne();
        $("#id_courier_winthraw_model_title").text("抽成配置");
        runAjax("${ctx!}/fran/divided/get/type","get",{type:type,franId:fran.franId},function (res) {
            console.log("###########",res.body)
            $("#id_courier_type").val(res.body.courType);
            $("#id_dist_model").val(res.body.dist);
            $("#id_sys_model").val(res.body.syst);
            $("#id_fran_model").val(res.body.fran);
            $("#id_rider_model").val(res.body.rider);
            $("#id_courier_winthraw_model").modal("show");
            document.getElementById("js_load").style.display = "none";
        });
    }

    /**
     * 更改金额按钮
     **/
    function changePrice() {
        let fran=getTableSelectOne();
        let data={
            franId:fran.franId,
        }
        runAjax("${ctx}/fran/divided/get/user","get",data,function (res) {
            console.log("###########",res.body)
            if(res.body.franId===1){
                $("#id_dist_model").removeAttr("readonly");
                $("#id_sys_model").removeAttr("readonly");
                $("#id_fran_model").removeAttr("readonly");
                $("#id_rider_model").removeAttr("readonly");
            }else {
                $("#id_dist_model").removeAttr("readonly");
                $("#id_fran_model").removeAttr("readonly");
                $("#id_rider_model").removeAttr("readonly");
            }
        })
    }

    /**
     * 结算提交按钮事件
     */
    function returnBackSubmit() {
        let fran=getTableSelectOne();
       /* if(!blockPrice()){
            return;
        }*/
        let data={
            franId:fran.franId,
            type:$("#id_courier_type").val(),
            dist:$("#id_dist_model").val(),
            sysPrice:$("#id_sys_model").val(),
            franPrice:$("#id_fran_model").val(),
            riderPrice:$("#id_rider_model").val()
        }
        document.getElementById("js_load").style.display = "inline";
        runAjax("${ctx}/fran/divided/post/save","post",data,function (data) {
            $("#id_courier_winthraw_model").modal("hide");
            lightyear.notify('操作成功!', 'success');
            search();
        })
    };

    /**
     * 提现金额输入框，焦点丢失时间
     **/
    function blockPrice() {
        let distNum=$("#id_dist_model").val();
        let price1=$("#id_sys_model").val();
        let price2=$("#id_fran_model").val();
        let price3=$("#id_rider_model").val();
        if(!isDistNumber(distNum)){
            lightyear.notify('当前只允许添加证数!', 'danger');
            return false;
        }
        if(!isPriceNumber(price1)){
            lightyear.notify('抽成比率不正确!', 'danger');
            return false;
        }
        if(!isPriceNumber(price2)){
            lightyear.notify('抽成比率不正确!', 'danger');
            return false;
        }
        if(!isPriceNumber(price3)){
            lightyear.notify('抽成比率不正确!', 'danger');
            return false;
        }
        $("#id_sys_model").attr("readonly","readonly");
        $("#id_fran_model").attr("readonly","readonly");
        $("#id_rider_model").attr("readonly","readonly");
        return true;
    }

    function clearNoNum(obj){
        obj.value = obj.value.replace(/[^\d.]/g,"");//清除"数字"和"."以外的字符
        obj.value = obj.value.replace(/^\./g,"");//验证第一个字符是数字而不是字符
        obj.value = obj.value.replace(/\.{2,}/g,".");//只保留第一个.清除多余的
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
    }
    function isDistNumber(_keyword){
        let rep=/[\.]/;
        if(rep.test(_keyword)){
            return false;
        }else {
            return true;
        }
    }
    function isPriceNumber(_keyword){
        if(_keyword == "0" || _keyword == "0." || _keyword == "0.0" || _keyword == "0.00"){
            return false;
        }else{
            var index = _keyword.indexOf("0");
            var length = _keyword.length;
            if(index == 0 && length>1){/*0开头的数字串*/
                var reg = /^[0]{1}[.]{1}[0-9]{1,2}$/;
                if(!reg.test(_keyword)){
                    return false;
                }else{
                    return true;
                }
            }else{/*非0开头的数字*/
                var reg = /^[1-9]{1}[0-9]{0,10}[.]{0,1}[0-9]{0,2}$/;
                if(!reg.test(_keyword)){
                    return false;
                }else{
                    return true;
                }
            }
            return false;
        }
    }
    /**
     * 获取对象第一个元素key
     * @param obj
     * @returns {*}
     */
    function getOne(obj){
        for(let key in obj){
            return key;
        }
    }

</script>