使用bootbox.js(二级务必提交书面和数字到数字中国)

页面文件

<#-- 页头 -->
<#assign currNav = "deposit">
<#assign title="网校充值">
<#include "/root/commons/header.ftl">

    <div class="container">

        <form id="depositForm" name="depositForm" role="form" action="/root/depositlog/${schoolId}/deposit" method="post">
          <div class="form-group">
            <label for="schoolId">网校ID</label>
            <input type="text" class="form-control" id="schoolId" name="schoolId" placeholder="比如。udemy" value="${school.schoolId!''}" readonly="readonly">
            <p class="help-block">全局唯一,不能和其它网校的ID同样</p>
          </div>
          <div class="form-group">
            <label for="name">网校名称</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="请填写网校名称" value="${school.name!''}" readonly="readonly">
          </div>

          <div class="form-group">
            <label for="duration">充值分钟数  <span id="chinaText" class="text-muted text-sm" style="margin-left:60px;font-size:12px;"> </span></label>
            <input type="number" class="form-control" id="duration" name="duration" placeholder="">
            <p class="help-block">单位:分钟</p>
          </div>
          <div class="form-group">
            <label for="amount">充值金额  <span id="moneyText" class="text-muted text-sm" style="margin-left:60px;font-size:12px;"> </span></label>
            <input type="text" class="form-control" id="amount" name="amount" placeholder="">
            <p class="help-block">单位:元</p>
          </div>
          <div class="form-group">
            <label for="note">备注</label>
            <input type="text" class="form-control" id="note" name="note" placeholder="">
          </div>          

        </form>

          <button  id="submitBtn" class="btn btn-primary">提交充值数据</button>

    </div> <!-- /container -->

<#-- 页脚開始 -->
<#include "/root/commons/footerBegin.ftl">

<script src="/resources/js/bootbox.js"></script>

<script>
    //在输入框内容变化的时候触发change
	  $("#duration").on('input',function(e){
		  var value=$("#duration").val();

		   $.get("/root/depositlog/input/change",{number:value},function(data){
			   $("#chinaText").text(data+" 分钟");
		   });
	  });

	  $("#amount").on('input',function(e){
		  var value=$("#amount").val();

		   $.get("/root/depositlog/input/change",{number:value},function(data){
			   $("#moneyText").text(data+" 元");
		   });
	  });

	  $("#submitBtn").click(function(){
	        var schoolId=$("#schoolId").val();
	        var name=$("#name").val();
	        var duration=$("#duration").val();
	        var amount=$("#amount").val();

	      	bootbox.dialog({
			  message: "<div id='schoolName'>网校名称:<span>"+name+"</span><span style='margin-left:10px'>schoolId-("+schoolId+")</span></div>"+
			           "<div>充值时长:<span>"+duration+" 分钟</span></div>"+
			           "<div>充值金额:<span>"+amount+" 元</span></div>",
			  title: "充值确认",
			  buttons: {
				    success: {
				      label: "确定",
				      className: "btn-success",
				      callback: function() {
				        document.depositForm.submit();
				      }
				    },
				   danger: {
				      label: "取消",
				      className: "btn-danger",
				      callback: function() {
				        return;
				      }
				   }
			  }
			});

	  });
</script>

<#-- 页脚结束 -->
<#include "/root/commons/footerEnd.ftl">

推断仅仅有是数字字符串才发送

$("#duration").on('input',function(e){
	    var value=$("#duration").val();
	    //alert($.isNumeric(value));

	    if($.isNumeric(value)){
	    	$("#mistakeText").html("");
	    	$.get("/springmvc/input/change",{number:value},function(data){
		    	$("#chinaText").html(data+"分钟");
		    });
	    }else{
	    	$("#mistakeText").html("请输入数字!");
	    }

	});

Java类文件

package com.school.web.controller.root;

import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.school.business.DepositLogManager;
import com.school.business.SchoolManager;
import com.school.domain.DepositLog;
import com.school.domain.Root;
import com.school.domain.School;
import com.school.stereotype.YesNoStatus;
import com.school.util.Constants;

/**
 * 充值管理的控制器。
 */
@Controller("rootDepositManagementController")
@RequestMapping("/root/depositlog")
public class DepositManagementController extends AbstractRootController {

    private static final Logger LOG = LoggerFactory.getLogger(DepositManagementController.class);

    @Autowired
    private SchoolManager schoolManager;

    @Autowired
    private DepositLogManager depositLogManager;

    /**
     * 充值表单。
     */
    @RequestMapping(value = "/{schoolId}/deposit", method = RequestMethod.GET)
    public ModelAndView depositForm(@PathVariable String schoolId, HttpServletRequest request) {

        // 网校信息
        School school = schoolManager.getSchool(schoolId);

        ModelAndView mav = this.createModelAndView(request);
        mav.setViewName("root/depositLog/deposit");
        mav.addObject("schoolId", schoolId);
        mav.addObject("school", school);
        return mav;
    }

    /**
     * 处理充值。
     */
    @RequestMapping(value = "/{schoolId}/deposit", method = RequestMethod.POST)
    public @ResponseBody String depositPost(@PathVariable String schoolId, HttpServletRequest request) {

        int duration = ServletRequestUtils.getIntParameter(request, "duration", 0);// 时长分钟数。单位:分钟
        double amount = ServletRequestUtils.getDoubleParameter(request, "amount", 0);// 价格
        String tradingNote = ServletRequestUtils.getStringParameter(request, "note", null); // 备注

        if (duration <= 0) {
            return "invalid duration";
        }

        if (amount < 0) {
            return "invalid amount";
        }

        // 当前管理员信息
        Root root = (Root) (request.getSession().getAttribute(Constants.ROOT_SESSION_NAME));

        // 交易名称
        String tradingName = schoolId + "充值" + duration + "。费用:" + amount + "元";

        // 充值信息
        DepositLog depositLog = new DepositLog();
        depositLog.setSchoolId(schoolId);
        depositLog.setTradingName(tradingName);
        depositLog.setTradingNote(tradingNote);
        depositLog.setDuration(duration);
        depositLog.setAmount(BigDecimal.valueOf(amount));
        depositLog.setOperator(root.getNickname());
        depositLog.setStatus(YesNoStatus.YES.getValue());
        depositLog.setDateAdded(new Date());
        depositLog.setLastModified(new Date());

        int rows = depositLogManager.addDepositLog(depositLog);
        LOG.info(tradingName + "。处理结果:" + rows);

        return "success";
    }

    /**
     * 查看近期100条充值记录。
     */
    @RequestMapping("/list")
    public ModelAndView depositLogs(HttpServletRequest request) {
        // 查询充值记录
        List<DepositLog> depositLogs = depositLogManager.getDepositLogs();

        ModelAndView mav = this.createModelAndView(request);
        mav.setViewName("root/depositLog/list");
        mav.addObject("depositLogs", depositLogs);
        return mav;
    }

    /**
     * 将数字转换成中文数字
     * @author Prosper
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value="/input/change", method = {RequestMethod.POST,RequestMethod.GET})
    public ResponseEntity<String> getCNint(HttpServletRequest request){
        HttpHeaders headers = new HttpHeaders();
        MediaType mediaType = new MediaType("text", "plain", Charset.forName("UTF-8"));
        //MediaType mediaType = new MediaType("application", "json", Charset.forName("UTF-8"));
        headers.setContentType(mediaType);
        //HttpStatus Yes=HttpStatus.OK;

        String str = request.getParameter("number");

        if("".equals(str) && str==null){
            return new ResponseEntity<String>("no",  headers, HttpStatus.OK);
        }else{
            Integer number = Integer.parseInt(str);
            String ri=intToZH(number);
            return new ResponseEntity<String>(ri,  headers, HttpStatus.OK);
        }

    }

    public String intToZH(int i){
        String[] zh = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
        String[] unit = {"", "十", "百", "千", "万", "十", "百", "千", "亿", "十"};

        String str = "";
        StringBuffer sb = new StringBuffer(String.valueOf(i));
        sb = sb.reverse();
        int r = 0;
        int l = 0;
        for (int j = 0; j < sb.length(); j++)
        {
            /**
             * 当前数字
             */
            r = Integer.valueOf(sb.substring(j, j+1));

            if (j != 0)
                /**
                 * 上一个数字
                 */
                l = Integer.valueOf(sb.substring(j-1, j));

            if (j == 0)
            {
                if (r != 0 || sb.length() == 1)
                    str = zh[r];
                continue;
            }

            if (j == 1 || j == 2 || j == 3 || j == 5 || j == 6 || j == 7 || j == 9)
            {
                if (r != 0)
                    str = zh[r] + unit[j] + str;
                else if (l != 0)
                    str = zh[r] + str;
                continue;
            }

            if (j == 4 || j == 8)
            {
                str =  unit[j] + str;
                if ((l != 0 && r == 0) || r != 0)
                    str = zh[r] + str;
                continue;
            }
        }
        return str;
    }

}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

时间: 2024-10-15 01:04:30

使用bootbox.js(二级务必提交书面和数字到数字中国)的相关文章

利用bootbox.js写二次确认提交(以及数字转为中文数字)

页面文件 <#-- 页头 --> <#assign currNav = "deposit"> <#assign title="网校充值"> <#include "/root/commons/header.ftl"> <div class="container"> <form id="depositForm" name="deposi

js表单提交回调函数

在研究表单的时候发现一个有意思的东西——在表单提交的时候如何保证数据全部提交完毕才会清空? 我们常用的<input type="reset" value="重置" />,或者jquery的$('input[name=xxx]')val(''),直接清空input的value值,都是单纯的直接清空,不会等待数据提交完毕后在清空,所以会有数据传输没完成就清空的情况,怎么解决? 搜索的时候发现一个答案——写一个回调函数,感觉不严谨.先记录下来,以后慢慢研究.

js模拟支付宝提交表单

弄过支付宝的程序员可能都知道,里面有很多地方都用到了自提交表单的方式,支付宝的接口通过请求API的形式取得服务器返回的表单字符串,使用out.print("表单字符串")在jsp页面上自提交表单.这种做法虽然很少有人使用,但是它也有着自身的价值,例如有的时候在js内部要提交一个完整的表单但是又不能使用ajax提交,这种时候这种思想就能发挥作用了 封装表单的js如下 var formStart="<form id=\"userForm\" name=\

Jquery/js submit()无法提交问题

有朋友可能会直接利用js或jquery来提交数据而不是使用表单直接提交了,小编来给大家介绍小编碰到的一个问题就是 submit()无法提交,下面我们来看解决办法与原因分析. jquery无法提交  代码如下 复制代码 <form action="register.php" method="post"> <label>邮箱:</label> <input type="text" class="lo

60秒验证码倒计时js代码 js样式代码 方块上下左右随机移动(定时器) js中获取元素的方法 js中表单提交

60秒验证码倒计时js代码 <script type="text/javascript"> var countdown=60; function settime(val) { if (countdown == 0) { //removeAttribute() 方法删除指定的属性. disabled属性规定应该禁用 input 元素. val.removeAttribute("disabled"); val.value="免费获取验证码"

js/jquery回车提交

1.JavaScript 方法: [javascript] <script> document.onkeydown=function(event){ e = event ? event :(window.event ? window.event : null); if(e.keyCode==13){ //执行的方法 alert('回车检测到了'); } } </script> <script> document.onkeydown=function(event){ e

js 禁止表单提交的方法(文件上传)

添加图片上传的表单,在form 添加属性onsubmit,提交之前会执行其中的方法,若返回FALSE,不会提交,返回TRUE,才会提交 <form method="post" enctype="multipart/form-data" action="/UpLoad.ashx" onsubmit="return check()"> <input type="file" name="

bootbox.js [v4.2.0]设置确认框 按钮语言为中文

Bootbox.js (http://bootboxjs.com/)是一个小型的 JavaScript 库用来创建简单的可编程对话框,基于 Twitter 的 Bootstrap 开发. 弹出确认框方法:bootbox.confirm(),此时 默认 语言为英文,弹出对话框 代码及效果如下: bootbox.confirm("确定删除此记录?", function(result) { if (result) { alert("ok"); }else{ alert(&

bootbox.js

bootbox:一个弹出框插件,官网看一下例子就好了:http://bootboxjs.com/examples.html 目前来说应该只要调用bootbox.js就可以了,没有css的问题 1.有最基本的调用就是 bootbox.alert("This is the default alert!"); 就什么都不做,只要alert一下就已经完成了它的使命,要是只要实现这样的话我觉得完全没必要引入这个插件呀,只要自己alert一下不就好了 2.再加一步就是有回调函数了,callback