一套完整的前台頁面增刪改查以及js(easyui)


增加頁面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>表單錄入</title>
</head>
<body>
<script src="<%=request.getContextPath()%>/uiPage/ods/meal/meal.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/js/ajaxfileupload.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-all.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-min.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript">
  function upload(){
      $.ajaxFileUpload({
        url : './meal/upload.action',//用於文件上傳的服務器端請求地址  
        secureuri : false, 
        fileElementId:'file',//必須和<input type="file" name="file" id="file">中的id屬性的值一致,后台才能獲取到文件的名稱
        type:'post',
        dataType : 'text', //返回值類型 一般設置為json 
        success : function(data) {
          $('#picPath').val(data);
          //alert(data);
          //alert(data.substring(data.lastIndexOf("\\")+1));
          data1 = data.substring(data.lastIndexOf("\\")+1);
          //alert(data.substring(0,data.lastIndexOf("\\")));
          data = data.substring(0,data.lastIndexOf("\\"));
          //alert(data.substring(data.lastIndexOf("\\")+1));
          data2 = data.substring(data.lastIndexOf("\\")+1);
          /* alert("/"+data1); */
          $("img[id='imgId']").attr("src","/"+data2+"/"+data1);
        }
      })
}
  (function ($, K) {
        if (!K)
            throw "KindEditor未定義!";
        function create(target) {
            var opts = $.data(target, 'kindeditor').options;
            var editor = K.create(target, opts);
            $.data(target, 'kindeditor').options.editor = editor;
        }

        $.fn.kindeditor = function (options, param) {
            if (typeof options == 'string') {
                var method = $.fn.kindeditor.methods[options];
                if (method) {
                    return method(this, param);
                }
            }
            options = options || {};
            return this.each(function () {
                var state = $.data(this, 'kindeditor');
                if (state) {
                    $.extend(state.options, options);
                } else {
                    state = $.data(this, 'kindeditor', {
                            options : $.extend({}, $.fn.kindeditor.defaults, $.fn.kindeditor.parseOptions(this), options)
                        });
                }
                create(this);
            });
        }
        $.fn.kindeditor.parseOptions = function (target) {
            return $.extend({}, $.parser.parseOptions(target, []));
        };
        $.fn.kindeditor.methods = {
            editor : function (jq) {
                return $.data(jq[0], 'kindeditor').options.editor;
            }
        };
        $.fn.kindeditor.defaults = {
            resizeType : 1,
            allowPreviewEmoticons : false,
            allowImageUpload : false,
            items : [
                'fontname', 'fontsize', 'code','|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
            afterChange:function(){
                this.sync();//這個是必須的,如果你要覆蓋afterChange事件的話,請記得最好把這句加上.
            }
        };
        $.parser.plugins.push("kindeditor");
    })(jQuery, KindEditor);
</script>
        <div  data-options="iconCls:'icon-costom',title:'組織機構信息'" style="padding:10px;" >
            <form method="post" name="addMealForm" id="addMealForm">
            <h1 style="font-weight:bold">基本信息</h1>
            <div style="width:650px;height:5px;border-top:1px dashed #cccccc; margin-left:3px"></div>
            <table id="layoutCentTab" align="center"  class="w600">
            <tr class="lh50">
                <td class="stdfrm-b1">菜品名稱:</td>
                <td><input class="easyui-validatebox stdfrm-b2" type="text" name="meal.mealName" data-options="required:true"></input><span class="redstart">&nbsp;&nbsp;&nbsp;</span></td>
                <td class="stdfrm-b3">菜品分類:</td>
                <td>
                    <input id="type" name="meal.type" type="text" class="easyui-combobox" 
                              data-options="value:'請選擇',
                                              width:'207',height:'24',
                                              valueField:'code',
                                            textField:'name',
                                            panelHeight:'auto',
                                            url:'./meal/queryMealType.action'"/><span class="redstart">&nbsp;&nbsp;&nbsp;</span>                    
                </td>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">單&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;價:</td>
                <td><input class="easyui-validatebox stdfrm-b4" type="text" name="meal.unitPrice" data-options="required:true"></input><span class="redstart">&nbsp;&nbsp;&nbsp;</span></td>
                <td class="stdfrm-b3">菜品圖片:</td>
                <td>
                    <input type="file" name="file" id="file"/>
                    <input type="button" value="上傳" onclick="upload()"></input>
                </td>
            </tr>
            <tr class="lh50">
                <!-- <td class="stdfrm-b1">菜品簡介:</td>
                <td><input class="easyui-validatebox stdfrm-b2" type="text" name="meal.briefIntro" data-options="required:true"></input><span class="redstart">&nbsp;&nbsp;&nbsp;</span></td> -->
                <td class="stdfrm-b1">圖片路徑:</td>
                <td><input id="picPath" readonly="readonly" class="easyui-validatebox stdfrm-b2" type="text" name="picPath" />
            </tr>
            <tr>
                <td class="stdfrm-b1">菜品圖片:&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>
                    <img id="imgId" height="120" width="200" src="${path }"/>
                </td>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">菜品簡介:&nbsp;&nbsp;&nbsp;&nbsp;</td>
               <td colspan="3" ><textarea class="easyui-kindeditor" style=" width:98%;height:200px; margin-top:10px;" name="meal.briefIntro"></textarea></td>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">備&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</td>
               <td colspan="3" ><textarea class="easyui-kindeditor" style=" width:98%;height:200px; margin-top:10px;" name="meal.comment"></textarea></td>
            </tr>
        </table>
        </form>
        </div>
</body>
</html>

查詢頁面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查看</title>
</head>
<body class="easyui-layout" data-options="fit:true">
<script src="<%=request.getContextPath()%>/uiPage/ods/meal/meal.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
      $("#mealName").bind('blur', function(){
        $(this).validatebox('enableValidation').validatebox('validate');
    }); 
})
</script>
<div class="easyui-layout" style="width: 100%; height: 100%;" data-options="fit:true">
<div id="northLayout" data-options="region:'north',maxHeight:500,border:false" style="height: 50px;">
    <table id="layoutCentTab" class="mt10 " style="float: left;">
        <tr class="lh30">
            <td class="w40 tl pl10">菜品名稱:</td>
            <td >
                <input class="easyui-validatebox stdfrm-b2"  type="text" style="width: 150px;" name="meal.mealName" id="mealName" data-options="validType:'minLength[4]',novalidate:true"/>
            </td>
            <td class="w40 tl pl10">菜品分類:</td>
            <td>
                <input id="type" name="meal.type" id="type" type="text" class="easyui-combobox" 
                              data-options="mode:'remote',
                                              valueField:'code',
                                            textField:'name',
                                            panelHeight:'auto',
                                            url:'./meal/queryMealType.action',
                                            delay:1000"/>
            </td>
        </tr>
    </table>
    <span style="float:left;margin-left:80px;margin-top:12px;"><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-fi-search'" style="width:80px" onclick="doQuery();">查詢</a></span>
    </div>
    <div data-options="region:'center'">
    <table id="dg_meal"></table>
    <div id="toolbar_meal">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-fi-add" plain="true" onclick="doAdd()">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-fi-del" plain="true" onclick="deleteMeal()">刪除</a>
    </div>
    <div id="dd_meal"></div>
    </div>
</div>
</body>
</html>

更新或修改頁面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>更新</title>
</head>
<body>
<script src="<%=request.getContextPath()%>/uiPage/ods/meal/meal.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/js/ajaxfileupload.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-all.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-min.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript">
  function upload(){
      $.ajaxFileUpload({
        url : './meal/upload.action',//用於文件上傳的服務器端請求地址  
        secureuri : false, 
        fileElementId:'file',//必須和<input type="file" name="file" id="file">中的id屬性的值一致,后台才能獲取到文件的名稱
        type:'post',
        dataType : 'text', //返回值類型 一般設置為json 
        success : function(data) {
          $('#picPath').val(data);
          //alert(data);
          //alert(data.substring(data.lastIndexOf("\\")+1));
          data1 = data.substring(data.lastIndexOf("\\")+1);
          //alert(data.substring(0,data.lastIndexOf("\\")));
          data = data.substring(0,data.lastIndexOf("\\"));
          //alert(data.substring(data.lastIndexOf("\\")+1));
          data2 = data.substring(data.lastIndexOf("\\")+1);
          //alert("/"+data2+"/"+data1);
          $("img[id='imgId']").attr("src","/"+data2+"/"+data1);
        }
      })
}
  (function ($, K) {
        if (!K)
            throw "KindEditor未定義!";

        function create(target) {
            var opts = $.data(target, 'kindeditor').options;
            var editor = K.create(target, opts);
            $.data(target, 'kindeditor').options.editor = editor;
        }

        $.fn.kindeditor = function (options, param) {
            if (typeof options == 'string') {
                var method = $.fn.kindeditor.methods[options];
                if (method) {
                    return method(this, param);
                }
            }
            options = options || {};
            return this.each(function () {
                var state = $.data(this, 'kindeditor');
                if (state) {
                    $.extend(state.options, options);
                } else {
                    state = $.data(this, 'kindeditor', {
                            options : $.extend({}, $.fn.kindeditor.defaults, $.fn.kindeditor.parseOptions(this), options)
                        });
                }
                create(this);
            });
        }

        $.fn.kindeditor.parseOptions = function (target) {
            return $.extend({}, $.parser.parseOptions(target, []));
        };

        $.fn.kindeditor.methods = {
            editor : function (jq) {
                return $.data(jq[0], 'kindeditor').options.editor;
            }
        };

        $.fn.kindeditor.defaults = {
            resizeType : 1,
            allowPreviewEmoticons : false,
            allowImageUpload : false,
            items : [
                'fontname', 'fontsize', 'code','|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
            afterChange:function(){
                this.sync();//這個是必須的,如果你要覆蓋afterChange事件的話,請記得最好把這句加上.
            }
        };
        $.parser.plugins.push("kindeditor");
    })(jQuery, KindEditor);
</script>
    <!--begin TabsBox-->
        <div  data-options="iconCls:'icon-costom',title:'組織機構信息'" style="padding:10px;" >
            <form method="post" name="editMealForm" id="editMealForm">
            <input type="hidden" name="meal.id" value="${meal.id }"/>
            <h1 style="font-weight:bold">基本信息</h1>
                <div style="width:650px;height:5px;border-top:1px dashed #cccccc; margin-left:3px"></div>
            <table id="layoutCentTab" align="center">
            <tr class="lh50">
                <td class="stdfrm-b1">菜單名稱:</td>
                <td><input class="easyui-validatebox stdfrm-b2" type="text" name="meal.mealName" data-options="required:true"  value="${meal.mealName}"><span class="redstart">&nbsp;&nbsp;&nbsp;</span></td>
                <td class="stdfrm-b3">菜單分類:</td>
                <td>
                    <input type="text" id="type" class="easyui-combobox" name="meal.type" value="${meal.type}" 
                              data-options="required:true,
                                              width:'207',height:'24',
                                              url:'./meal/queryMealType.action',
                                              valueField:'code',
                                            textField:'name',
                                            panelHeight:'auto',
                                            "><span class="redstart">&nbsp;&nbsp;&nbsp;</span></input>
                </td>
            <tr class="lh50">
                <td class="stdfrm-b1">單&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;價:</td>
                <td><input class="easyui-validatebox stdfrm-b2" type="text" name="meal.unitPrice" data-options="required:true" value="${meal.unitPrice}"><span class="redstart">&nbsp;&nbsp;&nbsp;</span></td>
                <td class="stdfrm-b3">菜單圖片:</td>
                <td>
                    <input type="file" id="file" name="file"/>
                    <input type="button" value="上傳" onclick="upload()"/>
                </td>
            </tr>
            <tr class="lh50">
                <%-- <td class="stdfrm-b1">菜單簡介:</td>
                <td><input class="easyui-validatebox stdfrm-b2" type="text" name="meal.briefIntro" value="${meal.briefIntro}"></input></td> --%>
                <td class="stdfrm-b1">圖片路徑:</td>
                <td><input id="picPath" readonly="readonly" class="easyui-validatebox stdfrm-b2" type="text" name="picPath" value="${meal.picPath }"/>
            </tr>
            <tr>
                <td class="stdfrm-b1">菜品圖片:&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>
                    <img id="imgId" height="120" width="207" src="${path }"/>
                </td>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">菜品簡介:</td>
                <td colspan="3"><textarea class="easyui-kindeditor" style=" width:98%;height:200px; margin-top:10px;" name="meal.briefIntro">${meal.briefIntro}</textarea></td>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">備&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</td>
                <td colspan="3"><textarea class="easyui-kindeditor" style=" width:98%;height:200px; margin-top:10px;" name="meal.comment">${meal.comment}</textarea></td>
            </tr>
        </table>
        </form>
        </div>
<!--end TabsBox-->
</body>
</html>

查看頁面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>查看</title>
</head>
<body>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/cascadeEasyUICombox.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/initCascadeEasyUICombox.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-all.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/kindeditor-min.js"></script>
<script src="<%=request.getContextPath()%>/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script language="javascript">
(function ($, K) {
    if (!K)
        throw "KindEditor未定義!";

    function create(target) {
        var opts = $.data(target, 'kindeditor').options;
        var editor = K.create(target, opts);
        $.data(target, 'kindeditor').options.editor = editor;
    }

    $.fn.kindeditor = function (options, param) {
        if (typeof options == 'string') {
            var method = $.fn.kindeditor.methods[options];
            if (method) {
                return method(this, param);
            }
        }
        options = options || {};
        return this.each(function () {
            var state = $.data(this, 'kindeditor');
            if (state) {
                $.extend(state.options, options);
            } else {
                state = $.data(this, 'kindeditor', {
                        options : $.extend({}, $.fn.kindeditor.defaults, $.fn.kindeditor.parseOptions(this), options)
                    });
            }
            create(this);
        });
    }

    $.fn.kindeditor.parseOptions = function (target) {
        return $.extend({}, $.parser.parseOptions(target, []));
    };

    $.fn.kindeditor.methods = {
        editor : function (jq) {
            return $.data(jq[0], 'kindeditor').options.editor;
        }
    };

    $.fn.kindeditor.defaults = {
        resizeType : 1,
        allowPreviewEmoticons : false,
        allowImageUpload : false,
        readonlyMode : true,
        items : [
            'fontname', 'fontsize', 'code','|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
            'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
            'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
        afterChange:function(){
            this.sync();//這個是必須的,如果你要覆蓋afterChange事件的話,請記得最好把這句加上.
        }
    };
    $.parser.plugins.push("kindeditor");
})(jQuery, KindEditor);
</script>
    <!--begin TabsBox-->
        <div  data-options="iconCls:'icon-costom',title:'組織機構信息'" style="padding:10px;" >
            <form method="post" name="editMealForm" id="editMealForm">
            <h1 style="font-weight:bold">基本信息</h1>
            <div style="width:650px;height:5px;border-top:1px dashed #cccccc; margin-left:3px"></div>
            <table id="layoutCentTab" align="center">
            <tr class="lh50">
                <td class="stdfrm-b1">菜單名稱:</td>
                <td><input class="easyui-validatebox stdfrm-b2 bgf1" disabled="disabled" type="text" name="meal.mealName" data-options="required:true" value="${meal.mealName}"></input></td>
                <td class="stdfrm-b3">菜品分類:</td>
                <td><input class="easyui-validatebox stdfrm-b4 bgf1" disabled="disabled" type="text" name="meal.type" data-options="required:true" value="${meal.type}"></input></td>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">單&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;價:</td>
                <td><input class="easyui-validatebox stdfrm-b2 bgf1" disabled="disabled" type="text" name="meal.unitPrice"  value="${meal.unitPrice}"></input></td>
                <%-- <td class="stdfrm-b3">菜品簡介:</td>
                <td><input class="easyui-validatebox stdfrm-b4 bgf1"  disabled="disabled" type="text" name="meal.briefIntro" data-options="required:true" value="${meal.briefIntro}"></input></td> --%>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">菜品圖片:</td>
                <td>
                    <img id="imgId" height="120" width="207" src="${path }"/>
                </td>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">菜品簡介:</td>
                <td colspan="3"><textarea  name="meal.briefIntro" class="bgf1 easyui-kindeditor" rows="8" style="width:98%;height:250px;">${meal.briefIntro}</textarea>
            </tr>
            <tr class="lh50">
                <td class="stdfrm-b1">備&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</td>
                <td colspan="3"><textarea  name="meal.comment" class="bgf1 easyui-kindeditor" rows="8" style="width:98%;height:250px;">${meal.comment}</textarea>
            </tr>
        </table>
        </form>
        </div>
<!--end TabsBox-->
</body>
</html>

js:

$(function(){
    //列表顯示
    $("#dg_meal").datagrid({
        toolbar:'#toolbar_meal',
        url:'./meal/queryMeal.action',
        fit:true,
        striped:true,
        singleSelect:false,
        fitColumns:true,
        nowrap:false,
        pagination:true,
        pageSize:20,
        columns:[[
                  {field:'id',checkbox:true},
                  {field:'mealName',width:5,title:'菜品名稱',align:'left'},
                  {field:'unitPrice',width:5,title:'單價(元)',align:'left'},
                  {field:'type',width:5,title:'菜品分類',align:'left'},
                  {field:'briefIntro',width:20,title:'菜品簡介',align:'left'},
                  {field:'_id_',title:'操作',width:5,align:'center',formatter:function(val,row,index){
                      return '<div class="opreation"><a href="javascript:$(\'#dg_meal\').treegrid(\'select\',\''+row.id+'\');doView(\''+row.id+'\');"><img src="./img/details.gif" style="vertical-align:middle;"/> 查看</a>    <a href="javascript:$(\'#dg_meal\').treegrid(\'select\',\''+row.id+'\');doEdit(\''+row.id+'\');"><img src="./img/edit.gif" style="vertical-align:middle;"/> 修改</a>  <a href="javascript:$(\'#dg_meal\').treegrid(\'select\',\''+row.id+'\');doDelete(\''+row.id+'\');"><img src="./img/del.gif" style="vertical-align:middle;"/> 刪除</a></div>';
                  }}
                  ]],
                  onBeforeLoad:function(){
                      flushCache();
                  },
                  onDblClickRow:function(rowIndex,row){
                      doView(row.id);
                  }
    });
});    

/**
 * 分頁
 */
var p = $('#dg_meal').datagrid('getPager'); 
$(p).pagination({ 
    pageSize: 20,//每頁顯示的記錄條數,默認為20 
    pageList: [10,20,50,100],//可以設置每頁記錄條數的列表 
    beforePageText: '第',//頁數文本框前顯示的漢字 
    afterPageText: '頁    共 {pages} 頁', 
    displayMsg: '當前顯示 {from} - {to} 條記錄   共 {total} 條記錄&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 
});  
    

/**
 * 添加
 */
function doAdd(){
    $('#dd_meal').dialog({
        title: '新增食譜',
        width: 850,
        height: 550,
        closed: false,
        inline: false,
        cache: false,
        href: '/wcs/meal/toAddMeal.action',
        modal: true,
        buttons: [{
            text:'&nbsp;&nbsp;&nbsp;&nbsp;保&nbsp;&nbsp;存&nbsp;&nbsp;&nbsp;',
            iconCls:'icon-fi-save',
            handler:function(){
                if($('#addMealForm').validateForm()){
                    jQuery.ajax({
                        url : "./meal/addMeal.action?seq="+new Date(),
                        dataType : "json",
                        data : $("#addMealForm").serialize(),
                        cache : false,
                        type : 'POST', // 設置請求類型為 ‘POST’,默認為 ‘GET’
                        error : function(XMLHttpRequest, textStatus,
                                errorThrown) {
                            $.messager.alert('信息','錄入失敗,請檢查數據!');
                        },
                        success : function(data) {
                            if (data.result == "success") {
                                $(".panel-tool-close").click();
                                $.messager.alert('信息','新增成功!');
                                $('#dg_meal').datagrid('reload');
                            } else if(data.result == "repeat"){
                                $.messager.alert('信息','錄入重復:'+data.message);
                            } else {
                                $.messager.alert('信息','錄入失敗:'+data.message);
                            }
                        }
                    });
                }
            }
        },
        {
            text:'&nbsp;&nbsp;&nbsp;&nbsp;取&nbsp;&nbsp;消&nbsp;&nbsp;&nbsp;',
            iconCls:'icon-fi-cancel',
            handler:function(){
                $(".panel-tool-close").click();
            }
          }]
    })
}

/**
 * 查看 
 */
function doView(id){
    $('#dd_meal').dialog({
        title: '查看食譜',
        width: 700,
        height: 550,
        closed: false,
        inline: false,
        cache: false,
        href: '/wcs/meal/toViewMeal.action?id='+id,
        modal: true,
        buttons: [{
            text:'&nbsp;&nbsp;&nbsp;&nbsp;取&nbsp;&nbsp;消&nbsp;&nbsp;&nbsp;',
            iconCls:'icon-fi-cancel',
            handler:function(){
                $(".panel-tool-close").click();
            }
              }]
        });
    }

/**
 * 修改
 */
function doEdit(id){
    $('#dd_meal').dialog({
        title: '修改食譜',
        width: 850,
        height: 550,
        closed: false,
        inline: false,
        cache: false,
        href: '/wcs/meal/toUpdateMeal.action?id='+id,
        modal: true,
        buttons: [{
            text:'&nbsp;&nbsp;&nbsp;&nbsp;保&nbsp;&nbsp;存&nbsp;&nbsp;&nbsp;',
            iconCls:'icon-fi-save',
            handler:function(){
                    jQuery.ajax({
                        url : "./meal/updateMeal.action?id="+id+"&seq="+new Date()+"&dictType=MEAL_KIND",
                        dataType : "json",
                        data : $("#editMealForm").serialize(),
                        cache : false,
                        type : 'POST', // 設置請求類型為 ‘POST’,默認為 ‘GET’
                        error : function(XMLHttpRequest, textStatus,
                                errorThrown) {
                            $.messager.alert('信息','更新失敗,請檢查數據!');
                        },
                        success : function(data) {
                            if (data.result == "success") {
                                $(".panel-tool-close").click();
                                $.messager.alert('信息','修改成功!');
                                $('#dg_meal').datagrid('reload');
                            } else {
                                $.messager.alert('信息','更新失敗:'+data.message);
                            }
                        }
                    });
                }
        },
        {
            text:'&nbsp;&nbsp;&nbsp;&nbsp;取&nbsp;&nbsp;消&nbsp;&nbsp;&nbsp;',
            iconCls:'icon-fi-cancel',
            handler:function(){
                $(".panel-tool-close").click();
            }
          }]
    })
}

/**
 * 刪除 
 */
function doDelete(id){
    var rows = $('#dg_meal').datagrid('getChecked');
    var allRows = $('#dg_meal').datagrid('getSelections');
    for(var i in allRows){
        if(allRows[i].id == id){
            rows = new Array();
            rows.push(allRows[i]);
        }
    }
    for(var i=0; i<rows.length; i++){
        if(id == rows[i].id){
            if(rows[i].children != undefined && rows[i].children.length > 0){
                $.messager.alert('信息','不能直接刪除有子節點的對象。','warning');
                return;
            }
        }
    }
    if(rows.length == 0){
        $.messager.alert('信息','請先選擇操作對象。','info');
        return;
    }
    var str_confirm = '即將刪除批量數據,刪除后將無法恢復,確實要這樣做嗎?';
    if(rows.length <= 1){
        str_confirm = '確實要刪除嗎?</font>';
    }
    $.messager.confirm('刪除確認',str_confirm,function(r) {
        if (r) {
            jQuery.ajax({
                url : "./meal/deleteMeal.action?ids="+id,
                dataType : "json",
                cache : false,
                type : 'POST', // 設置請求類型為 ‘POST’,默認為 ‘GET’
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.alert('信息','刪除失敗。<br>錯誤信息:網絡異常或表單數據錯誤。','error');
                },
                success : function(data) {
                    if(data.result == "success"){
                        $.messager.alert('信息','刪除成功。','info');
                        $('#dg_meal').datagrid('reload');
                    }else{
                        if(data.message == 'false'){
                            $.messager.alert('信息','刪除失敗。錯誤信息:不能進行刪除。','error');
                        }else{
                            $.messager.alert('信息','刪除失敗。錯誤信息1:'+data.message,'error');
                        }
                    }
                }
            });
        }
    });
}
function deleteMeal() {
    var rows = $('#dg_meal').datagrid('getSelections');
    var parm = '';
    for(var i=0; i<rows.length; i++){
        if(rows[i].children != undefined && rows[i].children.length > 0){
            $.messager.alert('信息','不能直接刪除有子節點的記錄!','warning');
            return;
        }
        var row = rows[i];
        if(i == 0){
            parm += row.id;
        }else{
            parm += '&ids='+row.id;
        }
    }
    doDelete(parm);
}

/**
 * 查詢
 */
function doQuery(){
    $('#dg_meal').datagrid('reload',{
        'mealName': $('#mealName').val(),
        'code': $('#type').combobox('getValue')
    });
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM