<!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_finish" class="btn btn-success m-r-5"
                                            onclick="getEdit('table')"><i class="mdi mdi-check"></i>通过审核
                                    </button>-->
                                    <button class="btn btn-info m-r-5"
                                            onclick="cashModel()"><i class="mdi mdi-check"></i>线下结算审核
                                    </button>
                                    <button class="btn btn-success m-r-5"
                                            onclick="onlineModel()"><i class="mdi mdi-check"></i>支付宝结算审核
                                    </button>
                                    <button class="btn btn-success m-r-5"
                                            onclick="weixinModel()"><i class="mdi mdi-check"></i>微信结算审核
                                    </button>
                                    <button id="batch_returnBack" class="btn btn-warning m-r-5"
                                            onclick="reject()"><i class="mdi mdi-check"></i>结算审核驳回
                                    </button>
                                    <button class="btn btn-danger m-r-5"
                                            onclick="queryAccount()"><i class="mdi mdi-check"></i>账户查询
                                    </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>
<#include "/include/footer.html">
<#include "/include/table/table-event.html">
<#include "/include/table/table-model.html">
<!--提现结算模态框模态框-->
<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">
                        <label class="control-label">当前申请派送员：</label>
                        <input type="text" id="id_courier_winthraw_model_courier"  class="form-control" value="" disabled="disabled">

                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <label class="control-label">提现金额：</label><!--<span style="color: red"> 计算公式： 提现到账金 = 申请金额 - (申请金额 x 提现费率)</span>-->
                        </div>
                        <div class="input-group">
                            <span class="input-group-addon">￥</span>
                            <input type="text" id="id_courier_winthraw_model_money" onblur="blockPrice();" maxlength="4"  class="form-control" value="0.00" readonly="readonly" onkeyup="clearNoNum(this)">
                          <!--  <span class="input-group-addon"> = </span>
                            <input type="text" id="id_courier_winthraw_model_apply_money"  class="form-control" value="0.00" readonly="readonly">
                            <span class="input-group-addon"> - (</span>
                            <input type="text" id="id_courier_winthraw_model_apply2_money"  class="form-control" value="0.00" readonly="readonly">
                            <span class="input-group-addon">x</span>
                            <input type="text" id="id_courier_winthraw_model_rate"  class="form-control" value="0.00" readonly="readonly"  onblur="blockPrice()" size="4">
                            <span class="input-group-addon">% )</span>-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label">选择结算方式：</label>
                        <select id="id_courier_winthraw_model_payWay" class="form-control selectpicker">
                        </select>
                    </div>
                    <div class="form-group">
                        <label class="control-label" id="id_courier_winthraw_model_input">支付单号：</label>
                        <input type="text" id="id_courier_winthraw_model_desc"  class="form-control" placeholder="请填写转账或支付单号">

                    </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 class="modal fade" id="id_courier_returnBack_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 type="text" id="id_courier_returnBack_model_courier"  class="form-control" value="" disabled="disabled">
                        <!--<select id="id_order_model_select" class="selectpicker show-tick form-control" data-live-search="true">
                            <option value="0" selected="selected">请选择</option>
                        </select>-->
                    </div>
                    <div class="form-group">
                        <label class="control-label">驳回描述：</label>
                        <textarea type="text" id="id_courier_returnBack_model_desc"  class="form-control"></textarea>
                        <!--<select id="id_order_model_select" class="selectpicker show-tick 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="rejectSubmit()">确认提交</button>
                </div>
            </div>
        </div>
    </div>
</div>

<!--以下为业务流程处理-->
<script>

    /**
     * 线下结算按钮事件
     * */
    function cashModel() {
        document.getElementById("js_load").style.display = "inline";
        let column=getTableSelectOne();
        $("#id_courier_winthraw_model_title").text("线下结算");
        $("#id_courier_winthraw_model_payWay").empty();
        $("#id_courier_winthraw_model_payWay").append("<option value='银行转账'>银行转账</option>");
        $("#id_courier_winthraw_model_payWay").append("<option value='微信转账'>微信转账</option>");
        $("#id_courier_winthraw_model_payWay").append("<option value='支付转账'>支付转账</option>");
        $("#id_courier_winthraw_model_payWay").append("<option value='其他方式'>其他方式</option>");
        $('#id_courier_winthraw_model_payWay').selectpicker('refresh');
        $("#id_courier_winthraw_model_input").text("支付单号：");
        $("#id_courier_winthraw_model_desc").val("");
        $("#id_courier_winthraw_model_desc").removeAttr("readonly");
        runAjax("${ctx!}/courier/get/id","get",{id:column.courierId},function (res) {
            $("#id_courier_winthraw_model_courier").val(res.body.courierName+"（"+res.body.courierPhone+"）");
            $("#id_courier_winthraw_model_money").val(column.applyAmount);
            $("#id_courier_winthraw_model").modal("show");
            document.getElementById("js_load").style.display = "none";
        });
    }
    /**
     * 在线结算按钮事件
     * */
    function onlineModel(){
        document.getElementById("js_load").style.display = "inline";
        let column=getTableSelectOne();
        $("#id_courier_winthraw_model_title").text("在线结算");
        $("#id_courier_winthraw_model_payWay").empty();
        $("#id_courier_winthraw_model_payWay").append("<option value='支付宝在线转账'>支付宝在线转账</option>");
        $('#id_courier_winthraw_model_payWay').selectpicker('refresh');
        $("#id_courier_winthraw_model_input").text("收款账号：");
        runAjax("${ctx!}/courier/get/id","get",{id:column.courierId},function (res) {
            $("#id_courier_winthraw_model_courier").val(res.body.courierName+"（"+res.body.courierPhone+"）");
            $("#id_courier_winthraw_model_money").val(column.applyAmount);
            runAjax("${ctx!}/courier/get/card/id","get",{id:column.courierId,type:"支付宝"},function (res) {
                $("#id_courier_winthraw_model_desc").val(res.body.cardNum);
                $("#id_courier_winthraw_model_desc").attr("readonly","readonly");
                $("#id_courier_winthraw_model").modal("show");
                document.getElementById("js_load").style.display = "none";
            });
        });
    }

    /**
     * 在线结算按钮事件
     * */
    function weixinModel(){
        document.getElementById("js_load").style.display = "inline";
        let column=getTableSelectOne();
        $("#id_courier_winthraw_model_title").text("在线结算");
        $("#id_courier_winthraw_model_payWay").empty();
        $("#id_courier_winthraw_model_payWay").append("<option value='微信在线转账'>微信在线转账</option>");
        $('#id_courier_winthraw_model_payWay').selectpicker('refresh');
        $("#id_courier_winthraw_model_input").text("收款openId：");
        runAjax("${ctx!}/courier/get/id","get",{id:column.courierId},function (res) {
            $("#id_courier_winthraw_model_courier").val(res.body.courierName+"（"+res.body.courierPhone+"）");
            $("#id_courier_winthraw_model_money").val(column.applyAmount);
            runAjax("${ctx!}/courier/get/card/id","get",{id:column.courierId,type:"微信"},function (res) {
                $("#id_courier_winthraw_model_desc").val(res.body.cardNum);
                $("#id_courier_winthraw_model_desc").attr("readonly","readonly");
                $("#id_courier_winthraw_model").modal("show");
                document.getElementById("js_load").style.display = "none";
            });
        });
    }

    /**
     * 账户查询
     * */
    function queryAccount() {
        document.getElementById("js_load").style.display = "inline";
        runAjax("${ctx!}/courier/pay/query/account","get",{},function (res) {
            document.getElementById("js_load").style.display = "none";
            $.confirm({
                title: '查询结果',
                content: '您当前的支付宝账户可用余额为：'+res.body+' 元',
                type: 'blue',
                typeAnimated: true,
                buttons: {
                    /*tryAgain: {
                        text: '继续',
                        btnClass: 'btn-blue',
                        action: function(){
                            sendAjax("${ctx}/table/model/set/column","post",data);
                        }
                    },*/
                    close: {
                        text: '确定'
                    }
                }
            });
            console.log(res);
        });

    }


    /**
     * 更改金额按钮
     **/
    function changePrice() {
        $("#id_courier_winthraw_model_money").removeAttr("readonly");
    }
    /**
     * 提现金额输入框，焦点丢失时间
     **/
    function blockPrice() {
        let price=$("#id_courier_winthraw_model_money").val();
        if(!isPriceNumber(price)){
            lightyear.notify('提现金额格式不正确!', 'danger');
            return false;
        }
        $("#id_courier_winthraw_model_money").attr("readonly","readonly");
        return true;
    }

    /**
     * 结算提交按钮事件
     */
    function returnBackSubmit() {
        let column=getTableSelectOne();
        let num=$("#id_courier_winthraw_model_desc").val();
        if(!num){
            lightyear.notify('请填写转账或处理单号，以供核查!', 'danger');
            return;
        }
        if(!blockPrice()){
            return;
        }
        let data={
            id:column.id,
            num:num,
            price:$("#id_courier_winthraw_model_money").val(),
            payWay:$("#id_courier_winthraw_model_payWay").val()
        }
        document.getElementById("js_load").style.display = "inline";
        runAjax("${ctx}/courier/withdraw/success","post",data,function (data) {
            $("#id_courier_winthraw_model").modal("hide");
            lightyear.notify('操作成功!', 'success');
            search();
        })
    };
    /**
     * 弹出驳回申请模态框
     */
    function reject() {
        let clm=getTableSelectOne();
        runAjax("${ctx!}/courier/get/id","get",{id:clm.courierId},function (res) {
            $("#id_courier_returnBack_model_courier").val(res.body.courierName+"（"+res.body.courierPhone+"）");
            $("#id_courier_returnBack_model").modal("show");
        });
    }

    /**
     * 驳回审核提交
     */
    function rejectSubmit() {
        let column=getTableSelectOne();
        console.log(column);
        let data={
            withdrawId:column.withdrawId,
            desc:$("#id_courier_returnBack_model_desc").val()
        }
        runAjax("${ctx}/courier/withdraw/getReject","post",data,function (data) {
            $("#id_courier_returnBack_model").modal("hide");
            lightyear.notify('操作成功!', 'success');
            search();
        })
    }

    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 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;
        }
    }
</script>
</body>
</html>