未完全适配,待更新
function getDetailObj(detailListId) {
const TABLE_DL_ID = "TABLE_DL_" + detailListId;
const table = window[TABLE_DL_ID];// 明细表<table></table>
const table_selector = "#" + TABLE_DL_ID + " ";
const tbody_selector = table_selector + " > tbody ";
if (isEmpty(table)){// 明细表未加载完,或不存在该表
console.error(detailListId + ":明细表未加载完或不存在该表;请检查表id");
return null;
}
// √
function hasStatisticRow() {
const statisticRow = $(tbody_selector).find("[statistic-celltr-title=true]");
return statisticRow.length > 0;
}
// √
function getDetailListId() {
return detailListId;
}
function getDetailListLabel() {
let label = "";
const properties = Xform_ObjectInfo.properties;
for (const property of properties) {
if (property.name === detailListId) {
label = property.label;
break;
}
}
return label;
}
function getDetailListStatus() {
const addBtn = _getDetailBtnObj("bottom_add");
return isEmpty(addBtn) ? "onlyRead" : "edit"
}
// √
function getFieldIds(rowIndex) {
let isAddRow = getRowLength() === 0 && typeof rowIndex === "undefined";
if (isAddRow) {// 一行控件都没有是无法获取控件id的,故需添加一行并隐藏之;最后再将该行删除
addRow(null);
}
let idArr = [];
const fieldObjs = getRowFieldObjs(rowIndex);// undefined相当于不传入rowIndex
for (const obj of fieldObjs) {
let id = $(obj).attr("id");
let flagid = id.substring(id.lastIndexOf(".") + 1, id.lastIndexOf(")"));
if (typeof rowIndex !== "undefined") {
flagid = detailListId + "." + rowIndex + "." + flagid;
}
idArr.push(flagid);
}
// if (isAddRow) {
// setTimeout(function () {
// // 当存在图片上传控件时,在该控件未加载完就调用该函数删除的话会引起swf_attachment.js报错
// // Uncaught TypeError: a.connectRuntime is not a function
// // 解决办法:延迟500ms执行删除行,并在addRow之后将添加的行隐藏
// deleteAllRows();
// }, 500)
// }
return idArr;
}
function getFieldLabels() {
const labelArr = [];
const tdArr = $(tbody_selector +" > tr.tr_normal_title > td");
for(const td of tdArr) {
const label = $(td).find(".xform_label");
if (label.length > 0) {
labelArr.push(label[0].innerText);
}
}
return labelArr;
}
// √ (onReady 里执行拿不到)
function getRowLength() {
return $(tbody_selector).find("[kmss_iscontentrow]").length;
}
function getColumnLength(isAll) {
isAll = isAll || false;
let length = 0;
const td = $(tbody_selector + " > tr:nth-child(1) > td")// 明细表标题行
if (isAll){
length = td.length;
return length;
}
td.each(function(){
if ($(this).find(".xform_label").length > 0) length++;
})
return length;
}
// √
function getRowFieldObjs(rowIndex) {
const rows = $(tbody_selector).find("[kmss_iscontentrow]");
const row = rows[rowIndex || 0];
const objs = [];
const dataCells = $(row).find("[data-celltr='true']");// 第rowIndex行数据行
for (let i = 0; i < dataCells.length; i++) {
const xform = $(dataCells[i]).find("td:nth-child(2) > xformflag:nth-child(1)")[0];
objs.push(xform);
}
return objs;
}
function getRowObj(rowIndex) {
let rows = $(tbody_selector + " > tr");// 全部行
rows = rows.slice(1, getRowLength() + 1);// 只取数据行
let rtn = null;
const isArr = typeof rowIndex === "object" && rowIndex instanceof Array;
if (isArr) {// 参数是数组类型
rtn = rows.slice(rowIndex[0], rowIndex[1] + 1);
}
else if (typeof rowIndex === "number") {// 参数是数字类型
rtn = rows.slice(rowIndex, rowIndex + 1);
}
return rtn;
}
function getColumnFieldObjs(columnId) {
const objs = [];
for (let i = 0; i < getRowLength(); i++) {
const obj = $("[flagid='"+ getFlagidInDetailList(i, columnId) +"']")[0];
objs.push(obj);
}
return objs;
}
function _getColumnIndexByColumnId(columnId) {
const idArr = getFieldIds();
return idArr.indexOf(getFlagidInDetailList(0, columnId));
}
// √
function getFlagidInDetailList(rowIndex, columnId) {
return detailListId + "." + rowIndex +"." + columnId;
}
// √
function getDataSingle(rowIndex, columnId) {
const flagid = getFlagidInDetailList(rowIndex, columnId);
return getValueById(flagid);
}
// √
function getData() {
let dataArr = [];
for (let i = 0; i < getRowLength(); i++) {
dataArr.push(getDataByRowIndex(i));
}
return dataArr;
}
function getData2Json() {
}
// √
function getDataByRowIndex(rowIndex) {
const fieldIds = getFieldIds(rowIndex);
const dataArr = [];
for (const id of fieldIds) {
dataArr.push(getValueById(id));
}
return dataArr;
}
function getDataByRowIndex2Json(rowIndex) {
}
// √
function getDataByColumnId(columnId) {
const dataArr = [];
for (let i = 0; i < getRowLength(); i++) {
dataArr.push(getDataSingle(i, columnId));
}
return dataArr;
}
function getDataSameRow(domElemt, columnId) {
const rowIndex = getRowIndexByDom(domElemt);
return getDataSingle(rowIndex, columnId);
}
function setData(dataArr) {
// × 不使用删除策略,避免明细表重加载时的闪烁效果
// deleteAllRows();// 首先删除全部行
// for (let i = 0; i < dataArr.length; i++) {
// addRow(dataArr[i]);
// }
// √ 重新赋值已存在的行,若超过已存在的行数则添加行再设置剩余数据
let i = 0;
for (; i < getRowLength(); i++) {
setDataByRowIndex(i, dataArr[i]);
}
while (i < dataArr.length) {// 设置剩余数据
addRow(dataArr[i++]);
}
}
function setDataByRowIndex(rowIndex, dataArr) {
const fieldIds = getFieldIds();
for (let i = 0; i < fieldIds.length; i++) {
setDataSingle(rowIndex, fieldIds[i], dataArr[i]);
}
}
function setDataByColumnId(columnId, dataArr) {
for (let i = 0; i < getRowLength(); i++) {
setDataSingle(i, columnId, dataArr[i]);
}
}
function setColumnDataByDom(columnId, dom) {
}
function setColumnNextDataByDom(columnIds, dom) {
}
function addRow(dataArr) {
let addedRowIndex = getRowLength();
const interval = setInterval(() =>{
if (typeof window["detail_" + detailListId + "_add"] !== "undefined") {
clearInterval(interval);
eval("detail_" + detailListId + "_add()");
if (typeof dataArr !== "undefined" && dataArr !== null) {
setDataByRowIndex(getRowLength() - 1, dataArr);// 设置最后一行的数据
}
}
}, 200);
setTimeout(() =>{
clearInterval(interval);
}, 5 * 1000);
return addedRowIndex;
}
function setDataSingle(rowIndex, columnId, value) {
const flagid = getFlagidInDetailList(rowIndex, columnId);
setValueById(flagid, value);
}
function clearSingle(rowIndex, columnId) {
const flagid = getFlagidInDetailList(rowIndex, columnId);
clearField(flagid);
}
function clearRow(rowIndex) {
for (const columnId of getFieldIds()) {
clearSingle(rowIndex, columnId);
}
}
function clearColumn(columnId) {
for (let i = 0; i < getRowLength(); i++) {
clearSingle(i, columnId);
}
}
function clearAll() {
for (let i = 0; i < getRowLength(); i++) {
clearRow(i);
}
}
function deleteRow(rowIndex) {
DocList_DeleteRow(getRowObj(rowIndex)[0]);
}
function deleteAllRows() {
const rows = getRowObj([0, getRowLength()]);
for (const row of rows) {
DocList_DeleteRow(row);
}
}
function hideRow(rowIndex) {
_showOrHideRow(getRowObj(rowIndex), true );
}
function hideAllRows() {
const rows = getRowObj([0, getRowLength()]);
_showOrHideRow(rows, true);
}
function showRow(rowIndex) {
_showOrHideRow(getRowObj(rowIndex), false);
}
function showAllRows() {
const rows = getRowObj([0, getRowLength()]);
_showOrHideRow(rows, false)
}
function _showOrHideRow(rowObjArr, isHide) {
for (const row of rowObjArr) {
if (isHide) $(row).hide();
else $(row).show();
}
_resetFrontRowNum();
}
function _resetFrontRowNum() {
const orderDom = $(tbody_selector + " > tr.tr_normal_title > td:nth-child(2)")[0];
if (!orderDom || !("序号;Seq".includes(orderDom.innerText))) {// 不存在序号列,不执行序号刷新
return;
}
let count = 1;
const rows = getRowObj([0, getRowLength() -1]);
for (const row of rows) {
if ($(row).css("display") !== "none"){
$(row).find("td:nth-child(2)")[0].innerText = count++;
}
}
}
function lbpm_hideRowInNodes(rowIndexArr, nodeIdArr) {
if (nodeIdArr.indexOf(lbpm.nowNodeId) > -1) {//
for (let i = 0; i < rowIndexArr.length; i++) {
hideRow(rowIndexArr[i]);
}
}
}
function _getDetailBtnObj(icon, rowIndex) {
let obj = null;
switch (icon) {
case "bottom_add": {
obj = $(tbody_selector +" > tr.tr_normal_opt > td > div > div.tr_normal_opt_c > span:nth-child(1)")[0];
}break;
case "bottom_delete": {
obj = $(tbody_selector +" > tr.tr_normal_opt > td > div > div.tr_normal_opt_l > span")[0];
}break;
case "right_copy": {
if (typeof rowIndex !== "undefined") {// 返回某行的复制按钮
return $(tbody_selector + " > tr:nth-child(" + (rowIndex + 2) +
") > td:nth-child("+ getColumnLength(true) +
") > nobr > span.optStyle.opt_copy_style")[0];
}
else {// 返回当前已存在的全部复制按钮
obj = [];
for (let i = 0; i < getRowLength(); i++) {
obj.push(_getDetailBtnObj("right_copy", i));
}
}
}break;
case "right_delete": {
if (typeof rowIndex !== "undefined") {
return $(tbody_selector +" > tr:nth-child(" + (rowIndex + 2) +
") > td:nth-child("+ getColumnLength(true) +
") > nobr > span.optStyle.opt_del_style")[0];
}
else {
obj = [];
for (let i = 0; i < getRowLength(); i++) {
obj.push(_getDetailBtnObj("right_delete", i));
}
}
}break;
}
// console.log("_getDetailBtnObj: ", {obj});
return obj;
}
function _transformFlagid2Index(flagid) {
return flagid.replace(/\.\d{1,10}\./, ".!{index}.");// 返回未渲染完成前的id格式:id.!{index}.id
}
function listenChange(fd_id, func) {
removeCopy();
if (getRowLength() > 0) {// 将初始行全部添加触发事件
for (let i = 0; i < getRowLength(); i++) {
const id_index_id = getFlagidInDetailList(i, fd_id);
AttachChangeEventById(id_index_id, func);
}
}
listenAddRowEvent(function () {// 新增行 → 给最后一行添加触发事件
const id_index_id = getFlagidInDetailList(getRowLength() - 1, fd_id);
// 先移除上一个事件(因为当行数为0时点击添加行会将之前的func也clone出来 → 导致触发两次)
$(document).off("change", "[flagid='"+ id_index_id +"']", func);
AttachChangeEventById(id_index_id, func);
})
}
// √ 无需适配
function removeCopy() {}
function removeAdd() {
}
function removeDelete() {}
function removeLastColumn() {
}
function listenAddRowEvent(func) {
const addBtnSelector = _getDetailBtnObj("bottom_add");
$(addBtnSelector).bind("click", func);
}
function setValidateByColumnId(columnId, validate) {
// 给初始行设置(非)必填
for (let i = 0; i < getRowLength(); i++) {
const id_index_id = getFlagidInDetailList(i, columnId);
setValidateById(id_index_id, validate);
}
// 添加行时需要给最后一行设置(非)必填
listenAddRowEvent(function () {
const id_index_id = getFlagidInDetailList(getRowLength() - 1, columnId);
setValidateById(id_index_id, validate);
})
}
function getRowIndexByDom(domElemt) {
return $(domElemt).closest("tr").index() - 1;
}
function setValidateSameRow(domElemt, columnId, validate) {
const rowIndex = getRowIndexByDom(domElemt);
const id_index_id = getFlagidInDetailList(rowIndex, columnId);
setValidateById(id_index_id, validate);
}
function setAddressScopeSameRow(scopeColumnId, targetColumnIds, index) {
}
function setAddressScopeAllAndChange(scopeColumnId, targetColumnIds) {
}
function detailOpenWin(dbTableName, target, width, height, callback) {
}
function detailOpenWin_reSetData(data, target) {
}
function exeValidationByColumnId(columnId) {
}
function setEditLevelSingle(rowIndex, columnId, editLevel) {
}
function setEditLevelByColumnId(columnId, editLevel) {
}
return {
createdTime: new Date().getTime(),
hasStatisticRow: hasStatisticRow,
getDetailListId: getDetailListId, getDetailListLabel: getDetailListLabel,
getDetailListStatus: getDetailListStatus,
getFieldIds: getFieldIds, getFieldLabels: getFieldLabels,
getRowLength: getRowLength, getColumnLength: getColumnLength,
getRowFieldObjs: getRowFieldObjs, getRowObj: getRowObj,getColumnFieldObjs: getColumnFieldObjs,
getFlagidInDetailList: getFlagidInDetailList,
getDataSingle: getDataSingle,
getData: getData, getData2Json: getData2Json,
getDataByRowIndex: getDataByRowIndex, getDataByRowIndex2Json: getDataByRowIndex2Json, getDataByColumnId: getDataByColumnId, getDataSameRow: getDataSameRow,
setData: setData,
setDataByRowIndex: setDataByRowIndex, setDataByColumnId: setDataByColumnId, setColumnDataByDom: setColumnDataByDom, setColumnNextDataByDom: setColumnNextDataByDom,
addRow: addRow,
setDataSingle: setDataSingle,
clearSingle: clearSingle,
clearRow: clearRow, clearColumn: clearColumn,
clearAll: clearAll,
deleteRow: deleteRow, deleteAllRows: deleteAllRows,
hideRow: hideRow, hideAllRows: hideAllRows, showRow: showRow, showAllRows: showAllRows,
lbpm_hideRowInNodes: lbpm_hideRowInNodes,
listenChange: listenChange, removeCopy: removeCopy, removeAdd: removeAdd, removeDelete:removeDelete, removeLastColumn:removeLastColumn,
listenAddRowEvent: listenAddRowEvent,
setValidateByColumnId: setValidateByColumnId,
getRowIndexByDom: getRowIndexByDom,
setValidateSameRow: setValidateSameRow,
setAddressScopeSameRow:setAddressScopeSameRow, setAddressScopeAllAndChange: setAddressScopeAllAndChange,
detailOpenWin: detailOpenWin, detailOpenWin_reSetData: detailOpenWin_reSetData,
exeValidationByColumnId: exeValidationByColumnId,
setEditLevelSingle: setEditLevelSingle, setEditLevelByColumnId: setEditLevelByColumnId,
}
}
function simplifyImgUpload(ids) {}// 无需适配移动端
function simplifyImgUpload_detailList(detailListId, columnId) {}// 无需适配移动端
// function addOpenRow2DetailList(outerDivId, detailListId, hasOrderNo) {}// 无需适配移动端
// function _addOpenRow2DetailList(outerDivId, detailListId, hasOrderNo) {}// 无需适配移动端
// function openDetailListRow(outerDivId, detailListId, hasOrderNo, rowIndex, operation) {}// 无需适配移动端