表單模板程式碼塊如下:
jQuery(document).ready(function(){
var beginTime = {date: "field12937"};
var endTime = {date: "field12938"};
checkCustomize = function (){
var a= new Date($("#" + beginTime.date).val());
var b= new Date($("#" + endTime.date).val());
if(a > b){
window.top.Dialog.alert("盤點開始日期不得大於盤點結束日期,請檢查後重新選擇!");
return false;
}else if(a-b==0){
window.top.Dialog.alert("盤點開始日期時間與盤點結束日期相同,請檢查後重新輸入!");
return false;
}else{
return true;
};
};
ModeForm.bindFieldChangeEvent("field12987",function(obj,id,value){
var bmStr = value;
asset_inventory(bmStr);
console.log(bmStr);
});
});
function asset_inventory (data){
var bmStr = data;
$.ajax({
type:"GET",
url:"/interface/ewqe/PDcycle.jsp",
data:{
"bmStr":bmStr
},
success:function(res){
console.log("res:"+res);
var resultObj = JSON.parse(res);
const departmentNames = Object.keys(resultObj).filter(key => resultObj[key] === "Exists");
if(departmentNames.length > 0){
const resultString = `您所選擇的部門:${departmentNames.join("、")}在本月盤點中已存在盤點週期`;
ModeList.showMessage(resultString, 1,3);
}
},
error:function(xhr, status, error){
// console.error("AJAX 請求失敗:", status, error);
ModeList.showMessage(xhr.responseText || "AJAX 請求失敗,請稍後再試", 2);
}
});
}
jsp檔案如下:
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="net.sf.json.JSONArray" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.Objects" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.conn.RecordSet,weaver.conn.RecordSetDataSource" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="net.sf.json.JSONObject"%>
<%@ page import="weaver.hrm.*"%>
<%@ page import="javax.servlet.http.HttpServletRequest;" %>
<%@ page import="javax.servlet.http.HttpServletResponse;" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<%
String bmStr = request.getParameter("bmStr");
String[] bmarrArray = bmStr.split(",");
JSONObject resultObj = new JSONObject();
String sqlString = "SELECT CASE WHEN FIND_IN_SET(?, bcpdbm) > 0 THEN 'Exists' ELSE 'NoExist' END AS result FROM uf_zcpdzq WHERE pdny = DATE_FORMAT(NOW(), '%Y-%m') ";
String sqlString1 = "SELECT DEPARTMENTMARK FROM hrmdepartment WHERE id = ? ";
RecordSet rs1=new RecordSet();
for (String element : bmarrArray) {
String trimmedElement = element.trim();
rs.executeQuery(sqlString,trimmedElement);
boolean exists = false;
while(rs.next()){
String result = rs.getString("result");
if ("Exists".equals(result)) {
exists = true;
}
}
String departmentMark = "";
rs1.executeQuery(sqlString1,trimmedElement);
if(rs1.next()){
departmentMark = rs1.getString("DEPARTMENTMARK");
}
resultObj.put(departmentMark, exists ? "Exists" : "NoExist"); // 儲存最終狀態
}
out.print(resultObj.toString());
%>