【泛微E9】移动应用页面字段的自动赋值计算
目前此代码块有点丑陋,但能用。
$load(function() {
setTimeout(function() {
var ygid = $p("ygid");
$f("dcyg").val(ygid);
$f("btbz").hide(); /* 隐藏字段 */
Mobile_NS.SQL("SELECT departmentid FROM hrmresource WHERE id = ?",[ygid], function(result) {
$f("dcbm").val(result[0].departmentid);
function executeTimeBasedLogic() {
// 获取当前时间
const now = new Date();
const currentHour = now.getHours();
const currentMinute = now.getMinutes();
// 将时间转换为总分钟数(便于比较)
const totalMinutes = currentHour * 60 + currentMinute;
// 定义时间边界
const cutoff14 = 14 * 60; // 14:00 → 840 分钟
const cutoff17 = 17 * 60; // 17:00 → 1020 分钟
// 逻辑分支
if (totalMinutes <= cutoff14) {
$f("dclb").val('0');
$f("jw").val('0')
console.log("当前时间在 14:00 前,执行逻辑A");
} else if (totalMinutes >= cutoff17) {
console.log("当前时间在 17:00 后,执行逻辑B");
$f("dclb").val('1');
$f("jw").val('2');
} else {
$f("dclb").val('1');
$f("jw").val('2');
console.log("当前时间在 14:00 到 17:00 之间");
}
}
// 测试执行
executeTimeBasedLogic();
console.log($f("jw").val()); // 确保输出不为 null 或 undefined
console.log($f("fs").val()); // 确保输出不为 null 或 undefined
// 初始化存储三个字段的值
var lastDclb = +$f("dclb").val();
var lastJw = +$f("jw").val();
var lastFs = +$f("fs").val();
// 重新计算btbz
if(lastJw === 0){
$f("btbz").val(lastFs*12);
console.log($f("btbz").val()); // 确保输出不为 null 或 undefined
}
if(lastJw === 1){
$f("btbz").val(lastFs*15);
console.log($f("btbz").val()); // 确保输出不为 null 或 undefined
}
if(lastJw === 2){
$f("btbz").val(lastFs*10);
console.log($f("btbz").val()); // 确保输出不为 null 或 undefined
}
// 统一处理字段变化的函数
function handleFieldChange() {
const currentDclb = +$f("dclb").val();
const currentJw = +$f("jw").val();
const currentFs = +$f("fs").val();
// 检查dclb, jw, fs三者值是否发生变化
if (currentDclb !== lastDclb || currentJw !== lastJw || currentFs !== lastFs) {
console.log("字段值发生变化");
console.log("dclb:", currentDclb, "jw:", currentJw, "fs:", currentFs);
// 更新最后一次的值
lastDclb = currentDclb;
lastJw = currentJw;
lastFs = currentFs;
// 重新计算btbz
if(lastJw === 0){
$f("btbz").val(lastFs*12);
console.log($f("btbz").val()); // 确保输出不为 null 或 undefined
}
if(lastJw === 1){
$f("btbz").val(lastFs*15);
console.log($f("btbz").val()); // 确保输出不为 null 或 undefined
}
if(lastJw === 2){
$f("btbz").val(lastFs*10);
console.log($f("btbz").val()); // 确保输出不为 null 或 undefined
}
}
}
// 为dclb, jw, fs三个字段绑定change事件
$f("dclb").on("change", handleFieldChange);
$f("jw").on("change", handleFieldChange);
$f("fs").on("change", handleFieldChange);
});
}, 150);
});
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架