<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-2.1.3.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
function searchSaleChance(){
$("#dg").datagrid('load',{
"customerName":$("#s_customerName").val(),
"overView":$("#s_overView").val(),
"createMan":$("#s_createMan").val(),
"state":$("#s_state").combobox("getValue")
});
}
function formatState(val,row){//区分状态 1为已分配 0未分配
if(val==1){
return "已分配";
}else{
return "未分配";
}
}
</script>
<title>Insert title here</title>
</head>
<body style="margin: 1px">
<table id="dg" title="销售机会信息管理" class="easyui-datagrid"
fitColumns="true" pagination="true" rownumbers="true"
url="${pageContext.request.contextPath}/saleChance/findSaleChance.do" fit="true" toolbar="#tb">
<thead>
<tr>
<th field="cb" checkbox="true" align="center"></th>
<th field="id" width="50" align="center">编号</th>
<th field="chanceSource" width="200" align="center" hidden="true">机会来源</th>
<th field="customerName" width="50" align="center">客户名称</th>
<th field="cgjl" width="50" align="center" hidden="true">成功几率</th>
<th field="overView" width="200" align="center">概要</th>
<th field="linkMan" width="100" align="center">联系人</th>
<th field="linkPhone" width="100" align="center">联系电话</th>
<th field="description" width="200" align="center" hidden="true">机会描述</th>
<th field="createMan" width="100" align="center">创建人</th>
<th field="createTime" width="100" align="center">创建时间</th>
<th field="assignMan" width="200" align="center" hidden="true">指派人</th>
<th field="assignTime" width="200" align="center" hidden="true">指派时间</th>
<th field="state" width="100" align="center" formatter="formatState">状态</th>
<th field="devResult" width="200" align="center" hidden="true">客户开发状态</th>
</tr>
</thead>
</table>
<div id="tb">
<div>
客户名称: <input type="text" id="s_customerName" size="20" οnkeydοwn="if(event.keyCode==13) searchSaleChance()"/>
概要: <input type="text" id="s_overView" size="20" οnkeydοwn="if(event.keyCode==13) searchSaleChance()"/>
创建人: <input type="text" id="s_createMan" size="20" οnkeydοwn="if(event.keyCode==13) searchSaleChance()"/>
分配状态: <select class="easyui-combobox" id="s_state" editable="false" panelHeight="auto" >
<option value="">请选择...</option>
<option value="0">未分配</option>
<option value="1">已分配</option>
</select>
<a href="javascript:searchSaleChance()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
</div>
</div>
</body>
</html>
后台代码
/**
* 查询营销管理数据并分页
*/
@RequestMapping("/findSaleChance")
public String findSaleChance(@RequestParam(value="page")String page,@RequestParam(value="rows")String rows,
SaleChance saleChance,HttpServletResponse response ) throws Exception{
PageBean pageBean =new PageBean(Integer.parseInt(page),Integer.parseInt(rows));
Map<String, Object> map=new HashMap<String,Object>();
map.put("customerName", saleChance.getCustomerName());
map.put("overView", saleChance.getOverView());
map.put("createMan", saleChance.getCreateMan());
map.put("state", saleChance.getState());
map.put("start", pageBean.getStartRow());
map.put("size", pageBean.getEndRow());
List<SaleChance> list=saleChanceService.findSaleChanceList(map);
int total=saleChanceService.getTotalSaleChanceCount(map);
JSONObject result=new JSONObject();
JsonConfig jsonConfig=new JsonConfig();
jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd HH:mm"));//转换时间
JSONArray jsonArray=JSONArray.fromObject(list,jsonConfig);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(response, result);
return null;
}
sql:
<mapper namespace="ssmy.dao.SaleChanceDao">
<resultMap type="ssmy.dto.SaleChance" id="SaleChance">
<!--<resultMap type="User" id="User"> 如果在sprin文件里配置初始化 mybatis里配置了别名就是有-->
<!-- 用id属性来映射主键字段 -->
<id property="id" column="id" jdbcType="INTEGER"/>
<!-- 用result属性来映射非主键字段 -->
<result property="chanceSource" column="chanceSource" jdbcType="VARCHAR"/>
<result property="customerName" column="customerName" jdbcType="VARCHAR"/>
<result property="cgjl" column="cgjl" jdbcType="INTEGER"/>
<result property="overView" column="overView" jdbcType="VARCHAR"/>
<result property="linkMan" column="linkMan" jdbcType="VARCHAR"/>
<result property="linkPhone" column="linkPhone" jdbcType="VARCHAR"/>
<result property="description" column="description" jdbcType="VARCHAR"/>
<result property="createMan" column="createMan" jdbcType="VARCHAR"/>
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
<result property="assignMan" column="assignMan" jdbcType="VARCHAR"/>
<result property="assignTime" column="assignTime" jdbcType="TIMESTAMP"/>
<result property="state" column="state" jdbcType="INTEGER"/>
<result property="devResult" column="devResult" jdbcType="INTEGER"/>
</resultMap>
<!--分页返回类型list 可以使用map User对应的是resultMap size每页的大小-->
<select id="findSaleChanceList" resultMap="SaleChance" parameterType="Map">
select t2.* from
( select t1.*,rownum rn from t_sale_chance t1
<where>
<if test ="customerName !=null and customerName !='' ">
and t1.customerName like '%'||#{customerName,jdbcType=VARCHAR}||'%'
</if>
<if test ="overView !=null and overView !='' ">
and t1.overView like '%'||#{overView,jdbcType=VARCHAR}||'%'
</if>
<if test ="createMan !=null and createMan !='' ">
and t1.createMan like '%'||#{createMan,jdbcType=VARCHAR}||'%'
</if>
<if test ="state !=null ">
and t1.state =#{state,jdbcType=NUMERIC}
</if>
</where>
) t2
<where>
<if test ="start !=null and start !=''">
<![CDATA[and t2.rn >=#{start}]]>
</if>
<if test ="size !=null and size !=''">
<![CDATA[and t2.rn < #{size}]]>
</if>
</where>
</select>
<!--获取总记录数 -->
<select id="getTotalSaleChanceCount" parameterType="Map" resultType="java.lang.Integer">
select count(1) from t_sale_chance t1
<where>
<if test ="customerName !=null and customerName !='' ">
and t1.customerName like '%'||#{customerName,jdbcType=VARCHAR}||'%'
</if>
<if test ="overView !=null and overView !='' ">
and t1.overView like '%'||#{overView,jdbcType=VARCHAR}||'%'
</if>
<if test ="createMan !=null and createMan !='' ">
and t1.createMan like '%'||#{createMan,jdbcType=VARCHAR}||'%'
</if>
<if test ="state !=null ">
and t1.state = #{state,jdbcType=NUMERIC}
</if>
</where>
</select>