客户需求:
在创建交易页面,用户在下拉框中选择阶段,每选择一个阶段,可能性的文本框里自动填写对应的可能性。
当什么阶段都不选,可能性文本框里也不写入内容。
开发功能知识点:
1,可能性的可配置:用户提供配置文件,配置每一个阶段对应一个可能性;
当用户选择阶段时,根据阶段获取可能性,显示到输入框。
1)提供配置文件:由用户提供,保存在后台服务器上。
配置文件:
a)xxxx.properties配置文件:key1=value1
key2=value2
.....
适合配置简单数据,几乎没有冗余数据,效率高
解析相对简单:Properties,BundleResource
b)xxx.xml配置文件:标签语言.
<studentList>
<student email="zs@163.com">
<id>1001</id>
<name>zs</name>
<age>20</age>
</student>
<student email="ls@163.com">
<id>1002</id>
<name>ls</name>
<age>20</age>
</student>
</studentList>
适合配置复杂数据,产生冗余数据,效率低
解析相对复杂:dom4j,jdom
配置可能性:possibility.properties
阶段的名称做key,可能性做value
2)用户每次选择阶段,向后台发送请求。
3)后台提供controller,接收请求,根据选择的阶段,解析配置文件,获取对应的可能性。
4)把可能性返回前台,显示在输入框。
功能实现:
1.在crm\src\main\resources目录下新建possibility.properties文件通过查询语句在tbl_dic_value表中找到关于stage的信息,并按照顺序排列
把text内容选择复制,全部填入possibility.properties文件
2.编写TransactionController代码
@RequestMapping("/workbench/transaction/getPossibilityByStage.do")
@ResponseBody
public Object getPossibilityByStage(String stageValue){
//解析properties配置文件,获取阶段对应的可能性
ResourceBundle possibility = ResourceBundle.getBundle("possibility");
String string = possibility.getString(stageValue);
//返回详细信息
return string;
}
3.transaction目录下的save.jsp页面
//给阶段选择添加改变事件
$("#create-transactionStage").change(function () {
//收集参数
// alert($(this).find("option:selected").text());
var stageValue=$("#create-transactionStage option:selected").text();
//选择验证
if (stageValue=="") {
//清空可能性输入框
$("#create-possibility").val("");
return;
}
//发送请求
$.ajax({
url:'workbench/transaction/getPossibilityByStage.do',
type:'post',
dataType:'json',
data:{
stageValue:stageValue
},
success:function (data) {
$("#create-possibility").val(data);
}
});
});
功能测试:
选择阶段为空时,可能性也填写为空