easyui简易提交订单,前台页面

![主界面,上下布局,


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <jsp:include page="${pageContext.request.contextPath}../../common/base.jsp"></jsp:include>
</head>
<body>
<div class="easyui-layout" style="width:1000px;height: 700px ">
        <div id="north" data-options="title:'新增订单',region:'north',split:true" style="height:250px">
            <form id="orderAdd" method="post">
            <table>
                <tr>
                    <td>客户:</td>
                    <td><input type="text" class="easyui-combogrid" id="tabuser-combobox" name="userId" style="width: 200px"><span style="color:red">*</span></td>
                </tr>
                <tr>
                    <td>成交时间:</td>
                    <td><input type="text" class="easyui-datebox" name="createTime"><span style="color:red">*</span></td>
                    <td>订单金额:</td>
                    <td><input type="text" class="easyui-numberbox" name="orderMoney" id="dinprice" data-options="readonly:true"><span style="color:red">*</span></td>
                </tr>
                <tr>
                    <td>订单状态:</td>
                    <td>
                        <select name="orderStatus" class="easyui-combobox" style="width:50%" name="orderStatus">
                            <option value="0">请选择</option>
                            <option value="1"  >已付款</option>
                            <option value="2" >预付款</option>
                        </select><span style="color:red">*</span>
                    </td>
                    <td>优惠金额:</td>
                    <td><input type="text" class="easyui-numberbox" name="discountMount" id="youhui"><span style="color:red">*</span></td>
                </tr>
                <tr>
                    <td>支付方式:</td>
                    <td>
                        <select name="playType" class="easyui-combobox" style="width:50%">
                            <option value="0">请选择</option>
                            <option value="1"  >支付宝支付</option>
                            <option value="2" >网银支付</option>
                        </select><span style="color:red">*</span>
                       </td>
                    <td>金额总计:</td>
                    <td><input type="text" class="easyui-numberbox" name="totalMoney" id="totalPrice" data-options="readonly:true"><span style="color:red">*</span></td>
                </tr>
                <tr>
                    <td>备注:</td>
                    <td><textarea name="remarks" rows="4" cols="50"></textarea></td>
                </tr>
            </table>
                <div id="product-info"></div>
            </form>
            <div id="orderkk">
                客户:<input type="text" name="username" class="easyui-textbox">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" id="userlook">查询</a>
            </div>
        </div>


        <div data-options="region:'center',title:'产品明细'" style="background:#eee;">
            <div id="order-goods-btn"></div>
            <div id="order-goods-tb">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" id="tianjia">添加</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" id="dele-btn">删除</a>
            </div>
        </div>
        <div data-options="region:'south'" style="height:100px">
            <a href="#" class="easyui-linkbutton" date-options="icon:'save'" id="ordersave">保存</a>
            <a href="#" class="easyui-linkbutton" date-options="icon:'clear'" id="orderclose">关闭</a>
        </div>
</div>
    <script>
        //优惠金额
        //属性对应的框要一直
        $("#youhui").numberbox({
            onChange:function(newValue,oldValue){

                var old=$("#totalPrice").textbox("getValue");
                $("#totalPrice").textbox("setValue",old-newValue);
                $("#totalPrice").textbox("setText",old-newValue);
            }
        })
        //订单添加
        $("#ordersave").click(function(){
            $("#orderAdd").form('submit',{
                url:'${pageContext.request.contextPath}/order/orderAdd',
                onSubmit:function(){
                    return $("#orderAdd").form("validate");
                },
                success:function (data) {
                        data=JSON.parse(data)
                    if(data.status ==200){
                        $.messager.alert("消息提醒","操作成功");
                        location.reload();

                    }else{
                        $.messager.alert("消息提醒","操作失败");
                        location.reload();

                    }
                }
            })
        })
        //下拉框客户查询
        $("#userlook").click(function(){
            $("#tabuser-combobox").combogrid("grid").datagrid("reload",{///grid是 一个方法文档中有些,
                username:$("input[name='username']").val()
            })
        })
        //客户下拉表
        $("#tabuser-combobox").combogrid({
            title:'选择客户',
            panelWidth:500,
            url:'${pageContext.request.contextPath}/user/list',
            idField:'id',
            textField:'userName',
            fit:true,
            fitColumns:true,
            toolbar:'#orderkk',
            striped:true,//斑马线
            rownumbers:true,//显示号码
            pagination:true,//在DataGrid控件底部显示分页栏工具
            pageSize:3,
            pageList:[3,6,9,12],
            columns:[[
                {field:'id',title:'编号',width:70},
                {field:'userName',title:'姓名',width:70},
                {field:'userTel',title:'手机号',width:70},
            ]]
        })

        //添加
        $("#tianjia").click(function(){
            $("body").append("<div id='type-dialog'></div>");
            $("#type-dialog").dialog({
                href:'${pageContext.request.contextPath}/good/togood',
                width:800,
                height:500,
                modal:true,
                buttons:[{//底部按钮
                    text:'保存',
                    iconCls:'icon-sava',
                    handler:function(){
                        //getData:返回数据加载完后的数据
                        //datagrid的数据格式,{“total”:11,“rows':[]}
                        var data=$("#order-goods-btn").datagrid("getData");
                          //商品选择的datagrid
                        //商品训中的商品
                        var rows=$("#good-list").datagrid("getSelections");

                        if(rows.length>0){//若选择商品
                           for(var i=0;i<rows.length;i++){
                               var row=rows[i];//选择商品
                               var flag=false;//默认商品明细没有这个选择商品的信息
                               //查看是否选择过该商品
                               for(var j=0;j<data.rows.length;j++){
                                   if(data.rows[j].id==row.id){ //悬着过该商品
                                       flag=true;//说明已经加过
                                       data.rows[j].goodsCount=data.rows[j].goodsCount+1;
                                       data.rows[j].total=data.rows[j].total+row.goodsPrice;
                                       break;
                                   }
                               }if(!flag){//若没有选择过就添加进图
                                   row.goodsCount=1;//总数量
                                   row.total=row.goodsPrice;//总金额
                                   data.rows.push(row);//将数据放入集合中
                                   data.total=data.total+1;//总条数+1
                               }
                           }
                        }
                        var total=0;
                        $("#product-info").html("");
                        for(var i=0;i<data.rows.length;i++){
                            var obj=data.rows[i];
                            total+=obj.total;
                            //把商品的id和数量放入隐藏域中, 
                            /此处我把商品的id抓住,数量我 是用总价钱除以单价算出来在service,也可以同时传入后台
                            、//注意,如果是按照我的方法,数据类型我给 是BigDecmal做除法运算divle,会有余数出现,
                            《BigDecimal divide = order.getTotalMoney().divide(type.getGoodsPrice(),2,BigDecimal.ROUND_HALF_DOWN); 2,表示保留两位小数》
                            var input=$("<input type='hidden' name='goodIds'>")
                            //input.val(obj.id+";"+obj.goodsCount);
                            input.val(obj.id);
                            $("#product-info").append(input);
                        }
                        //将订单总金额加到文本框中
                        $("#dinprice").textbox("setText",total);
                        $("#dinprice").textbox("setValue",total);
                        $("#totalPrice").textbox("setText",total);
                        $("#totalPrice").textbox("setValue",total);

                       $("#order-goods-btn").datagrid("loadData",data);
                       $("#type-dialog").dialog("destroy");

                    }
                },{
                    text:'关闭',
                    iconCls:'icon-cancel',
                    handler:function(){
                        alert("关闭操作窗口");
                        $("#type-dialog").dialog("destroy");
                    }
                }]

            })
        })

        //添加商品列表
      $("#order-goods-btn").datagrid({//此处不需要发送ur因为是本地添加,不是加入到数据库中,
            fit:true,
            fitColumns:true,
            toolbar:'#order-goods-tb',
            striped:true,//斑马线
            rownumbers:true,//显示号码
            columns:[[
                {field:'orderId',title:'编号',width:'70',checkbox:true},
                {field:'goodName',title:'产品',width:'70'},
                {field:'goodsUnit',title:'单位',width:'70'},
                {field:'goodsSpec',title:'规格',width:'70'},
                {field:'goodsPrice',title:'销售价',width:'70'},
                {field:'goodsCount',title:'数量',width:'70',},
                {field:'total',title:'总价',width:'70', }
            ]]
        })
    </script>
</body>
</html>

``

serviced层代码
public int insert(Order order, String goodIds) {
int i=orderMapper.insert(order);
if(goodIds!=null&&!"".equals(goodIds)){
String[] split = goodIds.split(",");
for (String id : split) {

            Type type = typeMapper.selectByPrimaryKey(new BigDecimal(id));
            if(type.getGoodsPrice().compareTo(order.getTotalMoney())==1){
                return 0;
            }
            OrderGoodsExample example = new OrderGoodsExample();
            example.createCriteria().andGoodNameEqualTo(type.getGoodName());
            List<OrderGoods> list =orderGoodsMapper.selectByExample(example);
            if(list.isEmpty()){
                BigDecimal divide = order.getTotalMoney().divide(type.getGoodsPrice(),2,BigDecimal.ROUND_HALF_DOWN);
                OrderGoods orderGoods = new OrderGoods();
                orderGoods.setOrderId(order.getId());
                orderGoods.setGoodName(type.getGoodName());
                orderGoods.setGoodsPrice(type.getGoodsPrice());
                orderGoods.setGoodsSpec(type.getGoodsSpec());
                orderGoods.setGoodsUnit(type.getGoodsUnit());
                orderGoods.setGoodsCount(divide);
                orderGoodsMapper.insert(orderGoods);
            }else{

                BigDecimal divide = order.getTotalMoney().divide(type.getGoodsPrice(),2,BigDecimal.ROUND_HALF_DOWN);
                OrderGoods orderGoods=list.get(0);
                orderGoods.setGoodsCount(divide.add(orderGoods.getGoodsCount()));
                orderGoodsMapper.updateByPrimaryKeySelective(orderGoods);
            }
        }
        return 1;
    }return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值