var fieldMark = []
jQuery(document).ready(function () {
tijiaopanduan(); //提交或保存时判断明细行重复
huoqumingxi();//获取明细行数据
qingkongchongfu();//清空明细重复项
});
function tijiaopanduan() {
//提交或保存时触发判断,是否明细行有重复
WfForm.registerCheckEvent(WfForm.OPER_SAVE + "," + WfForm.OPER_SUBMIT, function (callback) {
//获取明细行field14806字段的值
var fieldMark2 = []
var rowArr2 = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
for (var i = 0; i < rowArr2.length; i++) {
var rowIndex2 = rowArr2[i];
if (rowIndex2 !== "") {
fieldMark2[i] = WfForm.getFieldValue("field14806_" + rowIndex2); //遍历明细行字段
//console.log(fieldMark2[i]);
}
}
//判断是否有重复,如有重复值,则赋值给cfx
var cfx = []
var x = 0
var cf = fieldMark2.join(",") + ",";
for (var i = 0; i < fieldMark2.length; i++) {
if (cf.replace(fieldMark2[i] + ",", "").indexOf(fieldMark2[i] + ",") > -1) {
if (fieldMark2[i] != "") {
cfx[x] = "第" + (i + 1) + "行";
x += 1
};
//break;
}
}
//根据cfx长度判断是否有重复,如有重复则提示,无重复则通过提交或保存
//console.log("重复的值", cfx);
if (cfx.length > 0) {
WfForm.showMessage("明细表存在重复行:" + cfx, 2, 3); //错误信息,3s后消失
}
else {
//WfForm.showMessage("提交" + cfx); //错误信息,5s后消失
callback();
};
});
};
function qingkongchongfu() {
//var fieldMark = []
//明细行变动获取变动值
WfForm.bindDetailFieldChangeEvent("field14806", function (id, rowIndex, value) {
//console.log("初始", id, rowIndex, value);
//判断是否重复,如果重复则赋值字段为空
if (fieldMark.includes(value) && value != "") {
//console.log("重复了", fieldMark, id, rowIndex, value);
WfForm.showMessage("发票已存在,请重新选择发票!");
window.setTimeout(function () {
WfForm.changeFieldValue("field14806_" + rowIndex, {
value: "",
specialobj: [{
id: "",
name: ""
},]
});
}, 10);
};
huoqumingxi();
/*
//获取明细行长度和行ID,循环获取字段的ID值
var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
console.log("长度", rowArr.length)
for (var i = 0; i < rowArr.length; i++) {
var row = rowArr[i];
if (row !== "") {
fieldMark[i] = WfForm.getFieldValue("field14806_" + row); //遍历明细行字段
}
};
console.log("展示", fieldMark)
*/
});
//明细行删除时,触发清空数组fieldMark,并且重新循环获取一次字段的ID值,赋值给数组fieldMark
WfForm.registerAction(WfForm.ACTION_DELROW + "1", function (arg) {
fieldMark.splice(0, fieldMark.length);
//console.log("删除", fieldMark);
huoqumingxi();
/*
var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
console.log("长度", rowArr.length)
for (var i = 0; i < rowArr.length; i++) {
var row = rowArr[i];
if (row !== "") {
fieldMark[i] = WfForm.getFieldValue("field14806_" + row); //遍历明细行字段
}
};
*/
});
};
function huoqumingxi() {
//获取明细行长度和行ID,循环获取字段的ID值
var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
//console.log("长度", rowArr.length)
for (var i = 0; i < rowArr.length; i++) {
var row = rowArr[i];
if (row !== "") {
fieldMark[i] = WfForm.getFieldValue("field14806_" + row); //遍历明细行字段
}
};
//console.log("展示", fieldMark)
};
console