eayUI中常用表单上下移动,表单中的搜索栏,下载excel表单,添加日期表

本文介绍如何在EasyUI中实现表单时间选择插件的集成、表单数据的上下移动功能及Excel数据导出功能的具体实现方式。



eayUI中表单添加时间表:

需要在input里面有2个选择的时间插件

源代码:

//==========================================================通过查询时间过滤数据
	 
	 function systemOutInt() {
	 
		$('#systemOutIn').datagrid("reload", {
			search_startTime : $('#startTimes').val(),
			search_endTime : $('#endTimes').val()
		});
	} 
</script>


<!-- 返回添加图片后的数据 -->
<table id="systemOutIn" class="easyui-datagrid" border="0" fit="true"
	data-options="fitColumns:true,idField:'id',method:'get',pageList:[20,30,50],rownumbers:true,singleSelect:false,url:'${ctx}/pc/after/systemoutincontroller/systemoutinlist',toolbar:'#systemoutin_id',pagination:true">
	<thead>
		<tr>
			<!-- <th data-options="field:'id',checkbox:true">id</th> -->
			<th data-options="field:'inMoney'" width="30" align="center">系统实际进账金额</th>
			<th data-options="field:'outMoney'" width="30" align="center">系统实际出账金额</th>
			<th data-options="field:'Date'" width="30" align="center">时间</th>
			<th data-options="field:'null'" width="20" align='center'
				formatter="operateUser">操作</th>
		</tr>
	</thead>
</table> 
<div id="systemoutin_id" style="padding: 5px; height: auto">
	开始日期:<input  type="text"id="startTimes" value="${search_startTime}" style="width: 120px;margin-right: 20px;" readonly/>
	 结束日期:<input type="text" id="endTimes" value="${search_endTime}" style="width: 120px" readonly/>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-search" plain="true" onclick="systemOutInt();">查询</a>
</div>   
 
<script type="text/javascript">
$(function(){
	try{
		
	$("#startTimes").jeDate({
	    isinitVal:true,
	    festival:false,
	    ishmsVal:false,
	    minDate: '2016-06-16 23:59:59',
	    maxDate: $.nowDate(0),
	    format:"YYYY-MM-DD hh:mm:ss",
	    zIndex:3000,
	})
	$("#endTimes").jeDate({
	    isinitVal:true,
	    festival:false,
	    ishmsVal:false,
	    minDate: '2016-06-16 23:59:59',
	    maxDate:$.nowDate(0),
	    format:"YYYY-MM-DD hh:mm:ss",
	    zIndex:3000,
	})
	}catch(err){
		console.log(err);
	}
})
	
</script>
#################################################################################################

表单中的上下移动

源码:

else if (type=='move'){
				//当前页的所有行
				    var rows=$('#searchTable').datagrid('getRows');
			        console.log(rows);
                    var rowlength=rows.length;  
                    console.log(rowlength);
                   //获取当前行
                   var selectrow=$('#searchTable').datagrid('getSelected'); 
                   console.log(selectrow);
                   var rowIndex=$('#searchTable').datagrid('getRowIndex', selectrow);
                    console.log(rowIndex);
			    
			     if(selectrow == null){
			    	 $.messager.alert('温馨提示', '请选择用户');
			             return;
			     }
			     if (title == 'true') {
			    	    if(rowIndex==0){  
			                $.messager.alert('提示', '顶行无法上移!');  
			            }else{  
			                $('#searchTable').datagrid('deleteRow', rowIndex);//删除一行  
			                rowIndex--;  
			                $('#searchTable').datagrid('insertRow', {  
			                    index:rowIndex,  
			                    row:selectrow  
			                });  
			                $('#searchTable').datagrid('selectRow', rowIndex);  
			            }  
			 } else if(title == 'false'){
				    if(rowIndex==rowlength-1){  
			            $.messager.alert('提示', '底行无法下移!');  
			        }else{  
			            $('#searchTable').datagrid('deleteRow', rowIndex);//删除一行  
			            rowIndex++;  
			            $('#searchTable').datagrid('insertRow', {  
			                index:rowIndex,  
			                row:selectrow  
			            });  
			            $('#searchTable').datagrid('selectRow', rowIndex);  
			        }  
			 } 
		 } 
	}

<security:authorize ifAnyGranted="ROLE_SKW_DOWN">
		<a href="javascript:void(0)"
			onclick="openUserWindow('false','${ctx}/pc/after/searchkeyworddata/searchkeywordadd','move')"
			class="easyui-linkbutton" iconCls="icon-add" plain="true">下移动</a>
	</security:authorize>
	<security:authorize ifAnyGranted="ROLE_SKW_UP">
			<a href="javascript:void(0)"
			onclick="openUserWindow('true','${ctx}/pc/after/searchkeyworddata/searchkeywordadd','move')"
			class="easyui-linkbutton" iconCls="icon-add" plain="true">上移动</a>
	</security:authorize>
	<input type="button" onclick="submiticonForm()" name="" value="确定"/>
	<input type="button" onclick="cleariconForm()" name="" value="重置"/>
#####################################################################################################################

下载excel表中的数据

代码:页面中的代码:

function daoOutData(date){
        console.log("导出数据");
        console.log(date);
        var url = "/pc/after/systemoutincontroller/exportSystemOutOneDay";
        url=url+"?page=0"+"&date="+date;
        location.href=("${ctx}/"+url);    
    }
    function daoInData(date){
        console.log("导入数据");
        console.log(date);
        console.log("导出数据");
        console.log(date);
        var url = "/pc/after/systemoutincontroller/exportSystemInOneDay";
        url=url+"?page=0"+"&date="+date;
        location.href=("${ctx}/"+url);    
    }

Java中的代码:

//===================================================导出excel表格,一天中出账数

据==============================================================
    @Override
    public Result exportSystemOutListOneDay(HttpServletRequest request, HttpServletResponse response,
            HashMap<String, Object> param) {
          Result result = new Result();
            
            int count = systemOutInDao.exportSystemOutListOneDayCount(param);//总记录数
            
            PageModel pm = new PageModel();
            pm.setPageSize(1024);
            pm.setRowCount(count);
            
            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet = wb.createSheet("出账明细表");
            sheet.autoSizeColumn(1, true);
            
            HSSFFont font = wb.createFont();
            font.setFontName("黑体");
            //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
            font.setFontHeightInPoints((short) 12);
            //表头样式
            HSSFCellStyle cellStyle = wb.createCellStyle(); //设置单元格样式
             // 指定单元格垂直居中对齐  
            cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            cellStyle.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
            cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// //居中显示
            cellStyle.setFont(font);
            
            //合并单元格样式
            HSSFCellStyle style = wb.createCellStyle(); // 样式对象    
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直    
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平    
           
            // (2)创建excel的sheet页面
            HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();
            
            // (3)创建第一行标题
            HSSFRow row = sheet.createRow(0);
            
            String[] header={"账号","订单号","金额","状态","时间"};
            int[] clumnWidth={25,25,25,25,25};
            
            int indexHead=0;
            for (String string : header) {
                ++indexHead;
                sheet.setColumnWidth((short)indexHead,(short) ((clumnWidth[indexHead-1])*256));    
                HSSFCell cell_01 = row.createCell((short)indexHead);
                cell_01.setCellValue(new HSSFRichTextString(string));   //VALUE
                cell_01.setCellStyle(cellStyle);
            }
            
            for (int i = 0; i < pm.getPageCount(); i++) {
                param.put("startIndex", i);
                param.put("endIndex",1024);
                List<Map<String,Object>> sList=systemOutInDao.exportSystemOutListOneDayList(param);
                for (int j = 0; j < sList.size(); j++) {
                    
                    Map<String,Object> merchantData = sList.get(j);
                    //插入行数
                    HSSFRow _row = sheet.createRow(i*1024+j+1);
                    
                    //====用户账号======//
                    HSSFCell cell1 = _row.createCell((short) 1);  
                    cell1.setCellValue(new HSSFRichTextString(merchantData.get("NAME")==null?"":merchantData.get("NAME").toString()));//
                    //====订单号======//
                    HSSFCell cell2 = _row.createCell((short) 2);  
                    cell2.setCellValue(new HSSFRichTextString(merchantData.get("waterNum")==null?"":merchantData.get("waterNum").toString()));
                    //====支付金额======//
                    HSSFCell cell3 = _row.createCell((short) 3);
                    cell3.setCellValue(new HSSFRichTextString(merchantData.get("money")==null?"0":merchantData.get("money").toString()));
                    //====状态======//
                    Object status=merchantData.get("type");
                    String type=null;//0 处理中 1处理成功 2处理失败 3回调数据异常(已成功)
                    if (status==null) {
                         type="提现成功";
                    }
                    else if((status.toString()).equals("3")){
                          type="退款成功";
                    }else if((status.toString()).equals("4")){
                         type="退定金成功";
                    }else if((status.toString()).equals("5")){
                         type="退协商价成功";
                    }
                    //String memberMoney2=memberMoney1==null ?"0":memberMoney1.toString();
                    HSSFCell cell4 = _row.createCell((short) 4);  
                    cell4.setCellValue(new HSSFRichTextString(type));
                    
                    //====时间======//
                    HSSFCell cell5 = _row.createCell((short) 5);  
                    cell5.setCellValue(new HSSFRichTextString(merchantData.get("date")==null?"":merchantData.get("date").toString()));
                }
                logger.info("第"+(i+1)+"页数据导出完成");
            }
            // (5)指定写出的流对象
            OutputStream outputStream = null;
            String filedisplay = null;
            try {
                outputStream= new BufferedOutputStream(response.getOutputStream());  
                response.setContentType("application/vnd.ms-excel;charset=utf-8");  
                //outputStream = new FileOutputStream("G:/supplierProductOrder.xls");
                String time=System.currentTimeMillis()+"";
                filedisplay="出账明细"+time+".xls";
                response.setHeader("Content-disposition", "attachment; filename ="+new String((filedisplay).getBytes("utf-8"),"iso8859-1"));
                response.setContentType("application/msexcel");
                // (6)将得到的workbook写入流中
                wb.write(outputStream);
                            
            } catch (FileNotFoundException e) {
                result.setMsg("导出失败");
                logger.info("导出失败"+e.getMessage());
                //e.printStackTrace();
            } catch (IOException e) {
                result.setMsg("导出失败");
                logger.info("导出失败"+e.getMessage());
                //e.printStackTrace();
            } finally {
                IOUtils.closeQuietly(outputStream);
            }
            result.setMsg("导入成功");
        
        return result;
    }

其中的代码PageModel

public class PageModel implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private int pageNo;
    private int pageSize;
    private int rowCount;
    private int pageCount;
    private int startIndex;
    private String search;
    
    private String sEcho;
    private Integer iDisplayStart;
    private Integer iDisplayLength;
    
    public String getSEcho() {
        return sEcho;
    }

    public void setSEcho(String sEcho) {
        this.sEcho = sEcho;
    }

    public Integer getIDisplayStart() {
        return iDisplayStart;
    }

    public void setIDisplayStart(Integer iDisplayStart) {
        this.iDisplayStart = iDisplayStart;
    }

    public Integer getIDisplayLength() {
        return iDisplayLength;
    }

    public void setIDisplayLength(Integer iDisplayLength) {
        this.iDisplayLength = iDisplayLength;
    }
    
    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        if(pageNo!=0){
            startIndex=pageNo*this.pageSize;
        }
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int rowCount) {
        this.rowCount = rowCount;
        // 计算总页数
        this.pageCount = (this.rowCount % this.pageSize == 0) ? (this.rowCount / this.pageSize)
                : (this.rowCount / this.pageSize + 1);
    }

    public int getPageCount() {
        return pageCount;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public int getEndIndex() {
        return pageNo * pageSize;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        this.search = search;
    }
    
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值