在表单数据维护中F7关联带出其他栏位值的二开方式原创
金蝶云社区-杨天罡
杨天罡
4人赞赏了该文章 136次浏览 未经作者许可,禁止转载编辑于2024年01月24日 17:36:07

背景:产品目前在表单数据维护上,并未设置字段级联的功能,在选择F7时候,需要对表单的其他栏位进行值维护

解决方案:整体方案是对F7的onchange事件进行监听

$("#xxxxxxx01").shrPromptBox("option", {
    onchange: function(e, value) {
         $("#xxxxxx02").shrTextField("setValue", value.xxxxx);
    }
});


方案一、F7的列表出来的数据,已经包含其他栏位需要维护的值,可以直接获取后进行赋值即可

如:行政组织编码界面赋值

$("#adminOrgUnit").shrPromptBox("option", {
			onchange: function(e, value) {
				value && value.current
				&& value.current.number
				&& $("#adminOrgUnit_number").shrTextField("setValue", value.current.number);
				that.getPersonNum(value.current.id);
			}
		});


赋值注意值对象,如果是F7栏位赋值,注意需要拿到对应的id和显示名称,形成对象进行赋值

如:value.xxx.id需要有值,value.xxx.name,显示名称需要有值

$("#xxxxxx01").shrPromptBox("option", {
			onchange: function(e, value) {
				&& $("#xxxxxx02").shrPromptBox("setValue", {"id":value.xxx.id,"name":value.xxx.name});
			}
		});


方案二、F7的列表出来的数据,不包含其他栏位需要维护的值,需要发起后端请求去获取需要的数据,在进行值填充


如:发起ajax请求获取数据,并进行栏位赋值

$("#position"+uuid).shrPromptBox("option", {
							onchange : function(e, value) {
								var info = value.current; 
								var url = shr.getContextPath() + "/dynamic.do?method=getOrgUnitByPosition"+"&uipk="+shr.getUrlRequestParam('uipk');
								 shr.ajax({
										type:"post",
										async:false,  
										url:url,
										data:{positionId: info.id},
										success : function(res)
										{
										 	var info = res;
$("#adminOrgUnit"+uuid).shrPromptBox("setValue",{"id":info.adminOrgUnitId,"name":info.adminOrgUnitName});
										}
							 	});
							}
						});


如:通过remoteCall方式请求赋值

$("#proposer").shrPromptBox("option", {
				onchange: function (e, value) {
					var info = value.current;
					//$("#attendanceNum").val(info.number); //考勤编码==员工编码
					if (info != null) {
						if (info.hasOwnProperty("id")) {

							that.remoteCall({
								type: "post",
								method: "getPersonInfos",
								param: { personId: info.id },
								success: function (res) {
									var info = res;
									$('#name').val(info.personName);
									$('#proposer_number').val(info.personNumber);//@
									$('#attendanceNum').val(info.personNumber);		//员工姓名

									$('#adminOrgUnit_el').val(info.adminOrgUnitId);		//部门ID
									$('#adminOrgUnit').val(info.adminOrgUnitName);	//部门名称  
									$("#position_el").val(info.positionId);		//职位ID
									$("#position").val(info.positionName);    //职位名称
									$("#proposer_employeeType").val(info.employeeType);
									$("#adminOrgUnit_view").val(info.adminOrgUnitName);
									$("#position_view").val(info.positionName);
									if (info.attencePolicy != null) {
										var attencePolicy = $.parseJSON(info.attencePolicy);
										var dataValue = {
											id: attencePolicy.id,
											name: attencePolicy.name
										}
										$('#attencePolicy').shrPromptBox("setValue", dataValue);

									}
									if (info.atsShift != null) {
										var atsShift = $.parseJSON(info.atsShift);
										var dataValue = {
											id: atsShift.id,
											name: atsShift.name
										};
										$('#atsShift').shrPromptBox("setValue", dataValue);

									}
									if (info.holidayPolicySet != null) {
										var holidayPolicySet = $.parseJSON(info.holidayPolicySet);
										var dataValue = {
											id: holidayPolicySet.id,
											name: holidayPolicySet.name
										};
										$('#holidayPolicySet').shrPromptBox("setValue", dataValue);

									}

								}
							}); //remoat call end 
						}

					}

				} // onchange end 
			});

如:通过调用OSF方式进行赋值

$("#" + postName).shrPromptBox("option", {
			onchange : function(e, value) {
				var currentId = value.current.id;
				var selector = 'adminOrgUnit.id,adminOrgUnit.name,adminOrgUnit.displayName,job.id,job.name,jobGrade.id,jobGrade.name,lowJobGrade.id,lowJobGrade.name';
				shr.callService( {
					serviceName : 'getValueByUuid',
					param : {
						id : currentId,
						selector : selector
					},
					async : true,
					success : function(data) {
						self.updateOrgF7Data(orgName,data);
						if(callback)
							callback(currentId);
					}
				});
			}
		});


当然,系统还有很多复杂的逻辑可以进行处理,可以通过notpad++,进行文件查找,去进行参考

路径为:{安装目录}\eas\server\deploy\easweb.ear\shr_web.war,文件类型为 *.js,搜索关键字为 .shrPromptBox("option", {

可以参考下面截图

image.png


赞 4