ebu_ecology_dev1/javascript/youhong.ai/taibao/建模打包带数据到指定明细.js

228 lines
7.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/* ******************* youhong.ai 建模部分 start ******************* */
$(() => {
let config = {
workflowUrl: '',
table: '',
detailTable: 'detail_1',
fieldMap: {
fkgs: 'fkgs',
zw: 'zw',
fj: 'fj'
}
}
function jumpToWorkflow() {
let ids = ModeList.getCheckedID();
let url = `${config.workflowUrl}&table=${config.table}&ids=${ids}&detail=${config.detailTable}&field_map=${JSON.stringify(config.fieldMap)}`
window.open(url, "_blank")
}
window.jumpToWorkflow = jumpToWorkflow
})
/* ******************* youhong.ai 建模部分 end ******************* */
/* ******************* youhong.ai 流程部分 start ******************* */
$(() => {
function getQueryString(name) {
let reg = new RegExp("(^|&|\/?)" + name + "=([^&]*)(&|$)", "i");
let searchStr = window.location.href
if (searchStr.startsWith('&')) {
searchStr = searchStr.substr(1)
}
let search = searchStr.match(reg)
if (search != null) {
return unescape(search[2]);
}
return null;
}
function getConfig() {
let tableName = getQueryString("table")
let ids = getQueryString("ids")
let mapping = getQueryString("field_map")
let detail = getQueryString("detail")
let fieldMap = JSON.parse(mapping)
return {
table: tableName,
ids,
fieldMap,
detailTable: detail
}
}
function runJs(config) {
console.log("config", config)
let {WeaLoadingGlobal} = ecCom
WeaLoadingGlobal.start();
$.ajax(`/aiyh/taibao/packing2model/packing?table=${config.table}&ids=${config.ids}`, {
success: (res) => {
WeaLoadingGlobal.destroy();
if (res && res.code === 200) {
console.log("获取到的数据", res.data)
let modelData = res.data
let fieldMap = config.fieldMap
let workflowDetailList = []
modelData.forEach(item => {
let obj = {}
Object.keys(fieldMap).forEach(key => {
obj[key] = item[fieldMap[key]]
})
workflowDetailList.push(obj)
})
console.log("收集整理的数据:", workflowDetailList)
addDetailValue(workflowDetailList, config.detailTable)
} else {
WfForm.showMessage("打包数据错误,无法带出数据!", 2, 5);
}
},
error: (err) => {
WeaLoadingGlobal.destroy();
WfForm.showMessage("网路异常,打包失败!", 2, 5);
console.log(err)
},
complete: () => {
WeaLoadingGlobal.destroy();
}
})
}
function addDetailValue(workflowDetailList, detail) {
workflowDetailList.forEach(item => {
let valueMap = {}
Object.keys(item).forEach(key => {
valueMap[WfForm.convertFieldNameToId(key, detail)] = {
value: item[key]
}
})
console.log("添加明细行数据", valueMap)
WfForm.addDetailRow(detail, valueMap);
})
}
runJs(getConfig())
})
/* ******************* youhong.ai 流程部分 end ******************* */
/* ******************* youhong.ai 编号验证是否存在 start ******************* */
$(() => {
const config = {
ecId: '',
tableName: '',
field: 'fwbh',
}
/**
* @author youhong.ai
* @desc 发起请求
*/
function api(requestOptions = {
url: "",
type: "GET",
data: "",
isAsync: true,
success: () => {
},
error: () => {
},
complete: () => {
},
contentType: 'application/json',
beforeSend: () => {
}
}) {
let options = Object.assign({
url: "",
type: "GET",
data: "",
isAsync: true,
success: () => {
},
error: () => {
},
complete: () => {
},
contentType: 'application/json',
beforeSend: () => {
}
}, requestOptions)
return $.ajax(options)
}
function findReact(dom, traverseUp = 0) {
const key = Object.keys(dom).find(key => {
return key.startsWith("__reactFiber$") // react 17+
|| key.startsWith("__reactInternalInstance$")
|| key.startsWith("__reactEventHandlers$"); // react <17
});
const domFiber = dom[key];
if (domFiber == null) return null;
// react <16
if (domFiber._currentElement) {
let compFiber = domFiber._currentElement._owner;
for (let i = 0; i < traverseUp; i++) {
compFiber = compFiber._currentElement._owner;
}
return compFiber._instance;
}
// react 16+
const GetCompFiber = fiber => {
let parentFiber = fiber.return;
while (typeof parentFiber.type == "string") {
parentFiber = parentFiber.return;
}
return parentFiber;
};
let compFiber = GetCompFiber(domFiber);
for (let i = 0; i < traverseUp; i++) {
compFiber = GetCompFiber(compFiber);
}
return compFiber.stateNode;
}
function runJs() {
let node = findReact($(`button[ecid='${config.ecId}']`)[0])
let baseInfo = WfForm.getBaseInfo();
baseInfo.workflowid
if (baseInfo.requestid == -1) {
return
}
if (node) {
let click = node.props.onClick;
node.props.onClick = (e) => {
api({
url: `/api/aiyh/taibao/bh/check-number?tableName=${config.tableName}&field=${config.field}&requestId=${baseInfo.requestid}`,
success(res) {
if (res && res.code == 200) {
if (res.data) {
// 存在编号,提示是否需要编号
WfForm.showConfirm("编号一存在,是否重新编号?", function () {
click(e)
}, function () {
// 不重新编号,刷新
window.location.reload()
}, {
title: "编号确认", //弹确认框的title仅PC端有效
okText: "确认", //自定义确认按钮名称
cancelText: "取消" //自定义取消按钮名称
});
} else {
click(e)
}
}
}
})
};
}
}
runJs()
})
/* ******************* youhong.ai 编号验证是否存在 end ******************* */