EasyUI的简单使用

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'cmfz_listen.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
      <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
      <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
      <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
      <script type="text/javascript" src="${pageContext.request.contextPath}/js/datagrid-detailview.js"></script>
      <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/css.css">
      <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/easyui.css">
      <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/icon.css">

  </head>
  <body>
  <!-- form表单不能放置,table内部,会导致表单无效 -->
  <form id="queryUserForm"  method="post" enctype="multipart/form-data">
    <table id="showAllcmfz_user">
    		<div id="lele"> 
               <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-add'" onClick="toAdd()">添加</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-edit'"onClick="toUpdate()">修改</a>
                 <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-remove'"onClick="toDelete()">删除</a>
		           <a href="javascript:void(0)" class="easyui-linkbutton" plain="true"  data-options="iconCls:'icon-print'" onClick="exportUser();">导出</a>
		           <input  id="fileName" class="easyui-filebox" name="fileName"  style="width:200px;vertical-align:middle;" />
					<a href="javascript:void(0)" onclick="importUser()" class="easyui-linkbutton">开始导入</a>
            </div> 
    </table>
    </form>
  <div id="adduser" class="easyui-dialog" data-options="closed:true">
      <form id="adduserInformation" enctype="multipart/form-data" method="post">
          用户名:<input name="telphone"><br/>
          密码:<input name="password"><br/>

          用户头像:<input name="uploadFile"  class="easyui-filebox" data-options="
  			buttonText:'选择文件',
  			width:150,
  			height:20
  		"><br/>
          真实名字:<input name="name"><br/>
          法号:<input name="nickname"><br/>
          所在省:<input name="userSheng"><br/>
          所在市:<input name="userShi"><br/>

              <a href="javascript:void(0)" onclick="doAdd()" class="easyui-linkbutton">确认</a>

      </form>
  </div>
  <div id="updateuser"class="easyui-dialog" data-options="closed:true">
      <form id="updateuserInformation" enctype="multipart/form-data" method="post">
          <input id="userId" name="userId" style="display: none">
          用户名:<input id="telphone" name="telphone"><br/><br/>
          密码:<input id="password" name="password"><br/><br/>
          <input id="userImage" name="userImage" style="display: none">
          用户头像:<input name="uploadFile"  class="easyui-filebox"  data-options="
  			buttonText:'选择文件',
  			width:150,
  			height:20
  		"><br/><br/>
          真实名字:<input id="name" name="name"><br/><br/>
          法号:<input id="nickname" name="nickname"><br/><br/>
          所在省:<input id="userSheng" name="userSheng"><br/><br/>
          所在市:<input id="userShi" name="userShi"><br/><br/>

              <a href="javascript:void(0)" onclick="doUpdate()" class="easyui-linkbutton">确认</a>

      </form>
      <p id="guru_picture"></p>
  </div>
 </body>
</html>
<script type="text/javascript">
      $(function(){
          $("#showAllcmfz_user").datagrid({
              url:"${pageContext.request.contextPath}/user/showtAllUser.do",
              pagination:true,
              pageSize:5,
              pageList:[5,10],
              toolbar:"#lele",
              columns:[[
                  {field:"",title:"",checkbox:true},
                  {field:"userId",title:"用户ID",width:40,align:"center",hidden:true},
                  {field:"telphone",title:"用户名",width:100,align:"center"},
                  {field:"password",title:"密码",width:100,align:"center"},
                  {field:"userImage",title:"用户头像",width:100,align:"center",formatter:function(value,row){
                      if(value){
                          return "<image width=50 height=50 src='${pageContext.request.contextPath}/picture"+value+"'/>"
                      }
                  }},
                  {field:"name",title:"真实名字",width:100,align:"center"},
                  {field:"nickname",title:"法号",width:100,align:"center"},
                  {field:"userSheng",title:"所在省",width:100,align:"center"},
                  {field:"userShi",title:"所在市",width:100,align:"center"},

              ]]
          });
          $("#queryUserForm").form({
              url:'${pageContext.request.contextPath}/user/importUser.do',
              success:function(data){
                  $.messager.alert("提示框","导入成功",'info');
                  $("#showAllcmfz_user").datagrid("reload");

              }
          });
      });
      //导入用户
      function importUser(){
          // 输入框的值,用老过滤是否选择文件
          var fileName = $("#fileName").filebox("getValue");
          var fileNameStr = fileName.substr(fileName.indexOf(".")+1).toUpperCase();
          if(fileName==null || fileName==""){
              alert("请选择要导入的excel文件");
          }else if(fileNameStr=="XLS" || fileNameStr=="XLSX"){
              var flag=true;
              if(flag){
                  $.messager.confirm("确定对话框","确认导入吗?",function(n){
                      if(n){
                          $("#queryUserForm").submit();

                      }
                  })
              }
          }else{
              $.messager.alert("提示框","文件类型不一致",'warning');
          }
      }

      function exportUser(){
          var ids = [];
          // 获取勾选用户ID 方便后台查询用户信息
          var users = $("#showAllcmfz_user").datagrid("getChecked");
          if(users.length==0){
              $.messager.alert("提示","请选择要导出的数据");
          }else{
              $.each(users,function(index,value){
                  ids.push(value.userId)
              })
              $.messager.confirm('提示','您确认要导出吗?',function(n){
                  if(n){
                      window.location.href="${pageContext.request.contextPath}/user/exportMessage.do?ids="+ids+"&time="+new Date();
                  }else{
                      alert("取消")
                  }
              });
          }
      }
      function toAdd() {
          $("#adduser").dialog("open");
          //发送ajax请求到后台,执行操作


      }
      //执行添加操作
      function doAdd() {
          //通过form控件,以ajax的方式提交表单
          $("#adduserInformation").form("submit", {
              url : "${pageContext.request.contextPath}/user/insert.do",
              success : function(data) {
                  var i = JSON.parse(data);

                  if (i.insert == "200") {
                      //关闭添加对话框

                      $("#adduser").dialog("close");
                      //刷新datagrid
                      $("#showAllcmfz_user").datagrid("reload");
                  } else {
                      alert("添加失败");
                      //提示
                  }
              }
          });
      }

      //批量删除
      //====================================================================================
      function toDelete() {
          //alert(0)
          //获取到所有选中的内容
          var rows = $("#showAllcmfz_user").datagrid("getSelections");
          if (rows.length == 0) {
              alert("请选中要删除的内容")
          } else {
              var isDelete = confirm("确认是否要删除选中的所有内容;一旦确认删除将无法恢复!");
              if (isDelete) {
                  var ids = new Array(rows.length);
                  for (var i = 0; i < rows.length; i++) {
                      ids[i] = rows[i].userId;
                  }
                  //发送ajax请求到后台,执行操作
                  $.ajax({
                      url : "${pageContext.request.contextPath}/user/deleteMore.do",
                      //data:"ids="+ids,
                      data : {
                          "ids" : ids
                      },
                      traditional : true,
                      success : function(data) {

                          if (data.delete == "200") {
                              //刷新datagrid

                              $("#showAllcmfz_user").datagrid("reload");
                          } else {
                              alert("删除失败");
                          }
                      }
                  });
              }
          }

      }

      //修改对话框的展示
      //==========================================================================================
      function toUpdate() {

          alert("修改操作")
          //-------------------------------
          //通过调用方法getSelected获取选中的行
          var row = $("#showAllcmfz_user").datagrid("getSelected");
          alert("修改操作")

          if (row == null) {
              alert("请选中要修改的内容")
          } else {


              $("#updateuser").dialog("open");
              //2.把要修改的内容在对话框中显示0
              $("#userId").val(row.userId);
              $("#telphone").val(row.telphone);
              $("#password").val(row.password);
              $("#nickname").val(row.nickname);
              $("#name").val(row.name);
              $("#userSheng").val(row.userSheng);
              $("#userShi").val(row.userShi);
              $("#userImage").val(row.userImage);


          }
      }

      //执行修改操作
      //************************************************************************************
      function doUpdate() {
          alert("------------------------")
          //通过form控件,以ajax的方式提交表单updateBannerInformation
          $("#updateuserInformation").form("submit", {
              url : "${pageContext.request.contextPath}/user/update.do",
              success : function(data) {
                  data = JSON.parse(data);

                  if (data.update == "200") {
                      //关闭修改对话框
                      //alert(0);
                      $("#updateuser").dialog("close");
                      //刷新datagrid
                      $("#showAllcmfz_user").datagrid("reload");
                  } else {
                      alert("修改失败");
                      //提示
                  }
              }
          });
      }


  </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值