zoukankan      html  css  js  c++  java
  • 投资

    ;(function(){
        //标的标题
        var investitle = '';
        //标的Id
        var loanId = MS.getQueryStringArgs()["loanId"];
        //每份金额
        var minInvestUnit =0;
        //最小限购份额   多少份起投
        var minInvestorNum = 0;
        //账户余额
        var cash = 0;
        //用户最大可投资份数
        var investUnitMax = 0;
        //可投金额显示
        var investableAmountShow = "";
        //将显示的金额转换成数字
        function showToNum(showStr){
            var str = "",num = "";
            str = showStr.substr(0,showStr.length-1);
            var nums = str.split(",");
            for(var i = 0; i< nums.length;i++){
                num += nums[i];
            }
            return num;
        }
        //投资份数加减和输入
        function investMP(){
            $(".plus").click(function(){
                var investNum = parseInt($("input[name='num']").val());
                var im = 0;
                if(!isNaN(investNum)){
                    if(investNum >= investUnitMax){
                        return;
                    }
                    investNum = investNum + 1;
                    $("input[name='num']").val(investNum);
                    im = investNum*minInvestUnit;
                    $(".invest-total-money span").text(im +"元");
                }else{
                    MS.messShow("请输入数字","","");
                    $("input[name='num']").val(minInvestorNum);
                    if(minInvestorNum){
                        im = minInvestorNum*minInvestUnit;
                        $("input[name='num']").val(im+"元");
                    }else{
                        $("input[name='num']").val(minInvestUnit+"元");
                    }
                }
            });
            $(".minus").click(function(){
                var investNum = parseInt($("input[name='num']").val());

                if(!isNaN(investNum)){
                    if( investNum > 1){
                        investNum = investNum - 1;
                        $("input[name='num']").val(investNum);
                        im = investNum*minInvestUnit;
                        $(".invest-total-money span").text(im +"元");
                    }else{
                        MS.messShow("份额不能小于1","","");
                    }
                }else{
                    MS.messShow("请输入数字","","");
                    $("input[name='num']").val(minInvestorNum);
                    if(minInvestorNum){
                        im = minInvestorNum*minInvestUnit;
                        $("input[name='num']").val(im+"元");
                    }else{
                        $("input[name='num']").val(minInvestUnit+"元");
                    }
                }
            });
            $("input[name='num']").keypress(function(event){
                if(!(event.which == 8 || event.which == 13)){
                    if (event.which < 48 || event.which > 57) {
                        event.preventDefault();
                        return;
                     }
                }
            });
            $("input[name='num']").keyup(function(event){

                var investNum = $("input[name='num']").val();
                if(isNaN(investNum)){
                        $("input[name='num']").val(investUnitMax);
                        return;
                }
                if(!isNaN(investNum)){
                    if(investNum >= investUnitMax){
                        im = investUnitMax*minInvestUnit;
                        $("input[name='num']").val(investUnitMax);
                    }else{
                        im = investNum*minInvestUnit;
                    }

                    $(".invest-total-money span").text(im +"元");

                }else{
                    MS.messShow("请输入数字","","");
                    $("input[name='num']").val(minInvestorNum);
                    if(minInvestorNum){
                        im = minInvestorNum*minInvestUnit;
                        $("input[name='num']").val(im+"元");
                    }else{
                        $("input[name='num']").val(minInvestUnit+"元");
                    }
                }
            });
        }
        //复选按钮选择
        function checkBoxToggle(){
            $("label").click(function(){
                var index = $("label").index($(this));
                var text = $(this).text();
                if(text){
                    $(this).text("");
                }else{
                    $(this).text("√");
                }
            });
            $("label[for='agreeCheck']").click(function(){
                var agreeCheck =$("#agreeCheck").prop("checked");
                if(!agreeCheck){
                    //投资可点击
                    $(".invest-btn").off("click",invest).on("click",invest);
                    $(".invest-btn").css("background","#FF634F");
                }else{
                    //投资不可点击
                    $(".invest-btn").on("click",invest).off("click",invest);
                    $(".invest-btn").css("background","#DAD8D9");
                }
            });
        }
        //投资
        function invest(){
            var requeatAjax = null;
            var payPwd = $("#patpass").val();
            if(!payPwd){
                MS.messShow("支付密码不能为空,请填写支付密码","","");
                return;
            }
            //投资份数
            var investUnit = $("input[name='num']").val();
            if(!investUnit){
                MS.messShow("投资份数不能为空或者零,请填写投资份数","","");
                return;
            }
            //有多少卖多少
            var bugLeftAll = $("#numCheck").prop("checked");
            if(bugLeftAll){
                bugLeftAll = 1;
            }else{
                bugLeftAll = 0;
            }
            //推荐码
            var recommendCode = "";
            //二维码id
            var mobileQrCodeId = "";
            //同意 《民生易贷投融资协议》
            var agreeCheck =$("#agreeCheck").prop("checked");
            if(!agreeCheck){
                MS.messShow("需同意 《民生易贷投融资协议》,请勾选后在投资","","");
                return;
            }
            var $url = '', $data = {
                loanId : loanId,
                payPwd : payPwd,
                bugLeftAll : bugLeftAll,
                investUnit : investUnit
            };
            requeatAjax = MS.requeat( $url, $data, function(resp){
                var succ = resp.isSuccess;
                var code = resp.code;
                var msg = resp.msg;
                var respData = resp.data || {};
                if( succ == true ){
                    //实际购买份数
                    var investAmount = respData.investAmount;
                    if(investAmount){
                        location.href = '/view/page/investmentSuc.jsp?loanId=' + loanId + '&investAmount=' + investAmount + '&investitle=' + investitle;
                    }else{
                        MS.messShow("投资失败,请重新选择投资份数","","");
                    }
                }else if( code == "M00009" ){
                    //支付密码失败次数
                    var errorCount = respData.errorCount;
                    //总失败次数
                    var payNum = respData.payNum;
                    if(errorCount >= 5){
                        MS.messShow("您输入支付密码错误次数超过"+ payNum + "次,请20分钟后尝试","","");
                        return;
                    }else if(errorCount>=1 && errorCount<5){
                        MS.messShow("支付密码输入错误,您还有"+ (payNum-errorCount) + "次机会","","");
                        return;
                    }
                }else{
                    if( msg == "用户未登录" ){
                        MS.messShow( msg,"/view/page/regist/login.jsp","确定");
                    }else{
                        MS.messShow( msg, "", "");
                    }
                }
            } );
        }
        $(function(){
            //显示详细信息
            ;(function(){
                MS.requeat( '', { loanId : loanId }, function(resp){
                    var succ = resp.isSuccess;
                    var code = resp.code;
                    var msg = resp.msg;
                    var respData = resp.data || {};
                    if( succ == true ){
                        //标题
                        investitle = respData.title;
                        //可投金额显示
                        investableAmountShow = respData.investableAmountShow;
                        //每份金额
                        minInvestUnit = respData.minInvestUnit;
                        //最小限购份额   多少份起投
                        minInvestorNum = respData.minInvestorNum;
                        //限购份数
                        var shareBuyLimitation = respData.shareBuyLimitation;
                        //用户最大可投资份数
                        investUnitMax = respData.investUnitMax;
                        //账户余额
                        cash = respData.cash;
                        var cashNum = showToNum(cash);
                        var investableAmountNum = showToNum(investableAmountShow);
                        var useNum = "";
                        ( parseFloat(cashNum) < parseFloat(investableAmountNum) ) ? useNum=cashNum : useNum=investableAmountNum;
                        $(".sub-title p").text(investitle);
                        $(".sub-may-vote span").text(investableAmountShow + "元");
                        $(".sub-every .money").text(minInvestUnit + "元");
                        if(minInvestorNum){
                            $(".sub-every .start-num").text("(" + minInvestorNum + "份起投)");
                        }
                        if(cashNum/minInvestUnit>1){//investableAmount   可投金额
                            if(shareBuyLimitation != 0 && shareBuyLimitation < useNum/minInvestUnit){
                                if(investUnitMax < shareBuyLimitation){
                                    $("input[name='num']").val(Math.floor(investUnitMax));
                                }else{
                                    $("input[name='num']").val(Math.floor(shareBuyLimitation));
                                }
                            }else{
                                $("input[name='num']").val(Math.floor(useNum/minInvestUnit));
                            }
                        }else{
                            $("input[name='num']").val(1);
                        }
                        if(shareBuyLimitation){
                            $(".sub-limite span").text(shareBuyLimitation+"份");
                        }else{
                            $(".sub-limite span").text("不限投");
                        }
                        var investNumInit = parseInt($("input[name='num']").val());
                        if(!isNaN(investNumInit)){
                            var itm = investNumInit * minInvestUnit;
                            $(".invest-total-money span").text(itm +"元");
                        }else{
                            $(".invest-total-money span").text(0 +"元");
                        }
                        $(".user-balance span").text(cash + "元");
                    }else{
                        $(".mess-btn li.cancel").hide();
                        $(".mess-btn li.sure").css("width","100%");
                        $(".mess-btn li.sure span").text("");
                        MS.messShow( msg, "/view/page/investmentDetail.jsp?loanId=" + loanId, "确定" );
                    }
                }, { isLoading : false } );
                //协议初始化链接
                $(".invest-agree span a").attr( "href", "/view/page/agreement/agreement.jsp?loanId=" + loanId );
            })();
            //投资份数加减
            investMP();
            //复选按钮选择
            checkBoxToggle();
            $( '#js_invest_btn' )off( 'click', invest ).on( 'click', invest );
        });
    })();

  • 相关阅读:
    linux下shell显示-bash-4.1#不显示路径解决方法
    update chnroute
    An error "Host key verification failed" when you connect to other computer by OSX SSH
    使用dig查询dns解析
    DNS被污染后
    TunnelBroker for EdgeRouter 后记
    mdadm详细使用手册
    关于尼康黄的原因
    Panda3d code in github
    Python实例浅谈之三Python与C/C++相互调用
  • 原文地址:https://www.cnblogs.com/sunhw360/p/4624122.html
Copyright © 2011-2022 走看看