ebu_ecology_dev1/javascript/youhong.ai/pcn/workflow_code_block.js

1160 lines
38 KiB
JavaScript
Raw Normal View History

/* ******************* 保时捷target setting流程提交控制 start ******************* */
import React from "react";
import ReactDOM from "react-dom"
window.workflowCus = Object.assign(window.workflowCus ? window.workflowCus : {}, {
/**
* @author youhong.ai
* @desc 禁止点击提交按钮
*/
doNotClickSubmit: function () {
let submitButton = $('.ant-btn.ant-btn-primary[ecid="_Route@vmt0lk_Comp@upn4fo_Button@2oxqe7@0_button@xq1ea3"][title="Submit "]')
if (submitButton.length === 0) {
submitButton = $('.ant-btn.ant-btn-primary[ecid="_Route@vmt0lk_Comp@upn4fo_Button@2oxqe7@0_button@xq1ea3"][title="提交"]')
}
if (submitButton.length === 0) {
submitButton = $("#weareqtop_9v5e5i_1670481049632 div.ant-row.wea-new-top-req div.ant-col-xs-18.ant-col-sm-18.ant-col-md-16.ant-col-lg-14 button[title='提交'],[title='Submit '],[title='Submit']")
}
if (submitButton.length !== 0) {
let buttonReact = window.Utils.findReact(submitButton[0])
let rightBtn = Utils.findReact($(".ant-menu-item.text-elli[ecid='_Route@vmt0lk_Comp@upn4fo_WeaRightMenu@1ok9r0_Item@eu37n0_li@zyccqn']")[0])
setTimeout(() => {
buttonReact.props.disabled = true
buttonReact.setState({})
rightBtn.props.disabled = true
rightBtn.setState({})
}, 100)
}
},
/**
* @author youhong.ai
* @desc 允许点击按钮
*/
allowClickSubmit: function () {
let submitButton = $('.ant-btn.ant-btn-primary[ecid="_Route@vmt0lk_Comp@upn4fo_Button@2oxqe7@0_button@xq1ea3"][title="Submit "]')
if (submitButton.length === 0) {
submitButton = $('.ant-btn.ant-btn-primary[ecid="_Route@vmt0lk_Comp@upn4fo_Button@2oxqe7@0_button@xq1ea3"][title="提交"]')
}
if (submitButton.length === 0) {
submitButton = $("#weareqtop_9v5e5i_1670481049632 div.ant-row.wea-new-top-req div.ant-col-xs-18.ant-col-sm-18.ant-col-md-16.ant-col-lg-14 button[title='提交'],[title='Submit '],[title='Submit']")
}
if (submitButton.length !== 0) {
WfForm.controlBtnDisabled(false)
let buttonReact = window.Utils.findReact(submitButton[0])
buttonReact.props.disabled = false
buttonReact.setState({})
}
},
/**
* 监听qzhj字段值改变
* @author youhong.ai
* @param id 字段id
* @param value 字段值
* @param obj 字段值对象
*/
onQzhjFieldChangeValue: function (obj, id, value) {
if (value != '100') {
window.workflowCus.doNotClickSubmit()
} else {
window.workflowCus.allowClickSubmit()
}
},
/**
* 检查qzhj字段值
* @author youhong.ai
* @param fieldId qzhj字段id
*/
checkOnQzhJfiedlChangeValue: function (fieldId) {
let value = WfForm.getFieldValue(fieldId);
window.workflowCus.onQzhjFieldChangeValue(null, null, value)
},
/**
* 检查提交按钮是否符合条件
* @author youhong.ai
* @param fieldId 字段id
* @returns {(function(function()=): void)|*}
*/
checkClickSubmit: function (fieldId) {
return (callback = () => {
}) => {
let value = WfForm.getFieldValue(fieldId);
if (value != 100) {
WfForm.showMessage("~`~`7 目标设定的总值必须是100%,请检查并修改后提交。 " + "`~`8 The total value of target setting must be 100%,please check to submit after modification! " + "`~`9 目标设定的总值必须是100%,请检查并修改后提交。`~`~", 2, 5);
} else {
callback()
}
}
},
/**
* 保存按钮触发流程转数据
* @author youhong.ai
*/
saveTriggerWorkflowToModel: async function () {
let baseInfo = WfForm.getBaseInfo()
if (baseInfo && baseInfo.requestid != '-1') {
let result = await Utils.api({
url: "/api/aiyh/workflow/target-setting/save-trigger",
type: "POST",
contentType: "application/json",
data: JSON.stringify({
requestId: baseInfo.requestid,
nodeId: baseInfo.nodeid,
isBill: baseInfo.isbill,
formId: baseInfo.formid,
workflowId: baseInfo.workflowid
})
})
if (result && result.code === 200) {
localStorage.setItem("saveTriggerWorkflowToModel", "false")
}
}
},
saveAfterCallback: function (callback) {
localStorage.setItem("saveTriggerWorkflowToModel", "true")
callback()
}
})
/* ******************* 保时捷target setting流程提交控制 end ******************* */
/* ******************* 保时捷target setting流程提交控制 start ******************* */
$(() => {
let qzhjFieldId = WfForm.convertFieldNameToId("qzhj")
window.workflowCus.checkOnQzhJfiedlChangeValue(qzhjFieldId)
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, window.workflowCus.checkClickSubmit(qzhjFieldId))
WfForm.registerCheckEvent(WfForm.OPER_SAVECOMPLETE, window.workflowCus.saveAfterCallback)
WfForm.bindFieldChangeEvent(qzhjFieldId, window.workflowCus.onQzhjFieldChangeValue)
let flag = localStorage.getItem("saveTriggerWorkflowToModel")
if (flag === "true") {
window.workflowCus.saveTriggerWorkflowToModel()
}
})
/* ******************* 保时捷target setting流程提交控制 end ******************* */
/* ******************* 保时捷个人目标台账查询target setting按钮默认置灰色 ******************* */
window.workflowCus = Object.assign(window.workflowCus ? window.workflowCus : {}, {
notAllowedTargetSetting: function () {
window.workflowCus.changeBtnDisabledValue(true)
},
changeBtnDisabledValue: function (disable) {
if ($(".ant-btn.ant-btn-primary[ecid='_Route@9uoqid_Com@knmejd_ButtonNew@813let@0_Button@tegwjx_button@xq1ea3']").length === 0) {
return
}
let button = Utils.findReact($(".ant-btn.ant-btn-primary[ecid='_Route@9uoqid_Com@knmejd_ButtonNew@813let@0_Button@tegwjx_button@xq1ea3']")[0])
if (button) {
button.props.disabled = disable
button.setState({})
}
},
allowedTargetSettingBtnClick: function () {
window.workflowCus.changeBtnDisabledValue(false)
},
queryTotalWeight: function () {
Utils.api({
url: "/api/ayh/target-setting/btn/can-allowed"
}).then(res => {
if (res && res.code === 200) {
if (res.data) {
window.workflowCus.allowedTargetSettingBtnClick()
} else {
window.workflowCus.notAllowedTargetSetting()
}
}
}).catch(error => {
console.log(err)
})
},
reRender: function () {
const dataHandle = function (datas, displayType) {
window.workflowCus.notAllowedTargetSetting()
//Changes to 'datas' do not directly modify the real database data, but modify the data received at the front end.
$(() => {
window.workflowCus.queryTotalWeight()
})
return datas
}
ModeList.dataLoadAfter(dataHandle)
}
})
$(() => {
window.workflowCus.notAllowedTargetSetting()
setTimeout(() => {
window.workflowCus.notAllowedTargetSetting()
}, 10)
window.workflowCus.reRender()
})
/* ******************* 保时捷个人目标台账查询target setting按钮默认置灰色 END ******************* */
/* ******************* apa流程通过apa分数字段带出level字段 ******************* */
window.workflowCus = Object.assign(window.workflowCus ? window.workflowCus : {}, {
getLevelByScore: async function (config) {
let scoreFiled = config.scoreFiled
let score = Utils.getFiledValueByName(scoreFiled);
if (score == 0 || score == '') {
return
}
let result = await Utils.api({
url: "/api/ayh/workflow/apa/level",
data: {
score
}
})
if (result && result.code === 200) {
Utils.changeFieldValueByName(config.levelField, result.data)
}
}
})
2022-12-13 15:30:18 +08:00
/* ******************* apa流程通过apa分数字段带出level字段eng ******************* */
2022-12-13 15:30:18 +08:00
/* ******************* apa流程通过apa分数字段带出level字段 ******************* */
$(() => {
let config = {
scoreFiled: "apafsptyg",
levelField: "level1"
}
try {
setTimeout(() => {
WfForm.bindFieldChangeEvent(Utils.convertNameObjToId(config.scoreFiled), () => {
window.workflowCus.getLevelByScore(config)
})
window.workflowCus.getLevelByScore(config)
}, 100)
} catch (err) {
console.log(err)
}
})
/* ******************* apa流程通过apa分数字段带出level字段eng ******************* */
/* ******************* apa(employee)流程明细分数控制 ******************* */
function addChangeEventListener(configItem) {
let fieldIds = Utils.convertNameToIdUtil([{
fieldName: configItem.selfEvaluationScore,
table: configItem.table
}, {
fieldName: configItem.leaderScore,
table: configItem.table
}])
WfForm.bindDetailFieldChangeEvent(fieldIds, (id, rowIndex, value) => {
if (value == '') {
return
}
if (value >= 1 && value <= 5) {
if (value % 0.5 !== 0) {
showHint(id + "_" + rowIndex)
}
} else {
showHint(id + "_" + rowIndex)
}
})
}
function showHint(id) {
WfForm.showMessage(`Evaluate your target completion by selecting a score.
The scores are of 0.5 break-down.
5 - Outstanding
4 - Exceeds Expectations
3 - Meets Expectations
2 - Needs Improvement
1 - Unsatisfactory`, 2, 10)
setTimeout(() => {
WfForm.changeFieldValue(id, {value: ""})
}, 100)
}
$(() => {
let employeeDetailConfig = [{
table: 'detail_1',
selfEvaluationScore: 'zp',
leaderScore: 'ldpf'
}, {
table: 'detail_2',
selfEvaluationScore: 'zp',
leaderScore: 'ldpf'
}]
employeeDetailConfig.forEach(item => {
addChangeEventListener(item)
})
})
/* ******************* apa(employee)流程明细分数控制end ******************* */
2023-02-13 10:40:45 +08:00
/* ******************* 流程明细数据整合插入start ******************* */
$(() => {
const workflowInsertValueConfig = [
{
2023-02-16 19:00:32 +08:00
table: 'detail_1',
targetTable: 'detail_3',
2023-02-13 10:40:45 +08:00
filedMapping: [{
2023-02-16 19:00:32 +08:00
source: 'mbmc',
target: 'name'
}, {
source: 'mbms',
target: 'description'
}, {
source: 'zp',
target: 'score'
}, {
source: 'zwpj',
target: 'grpj'
}, {
source: 'mbmc',
target: 'ldpf'
}, {
source: 'ldpj',
target: 'ldpj'
2023-02-13 10:40:45 +08:00
}]
}, {
2023-02-16 19:00:32 +08:00
table: 'detail_2',
targetTable: 'detail_3',
filedMapping: [{
source: 'xx',
target: 'name'
}, {
source: 'ms',
target: 'description'
}, {
source: 'zp',
target: 'score'
}, {
source: 'zwpj',
target: 'grpj'
}, {
source: 'mbmc',
target: 'ldpf'
}, {
source: 'ldpj',
target: 'ldpj'
}]
2023-02-13 10:40:45 +08:00
}
]
2023-02-16 19:00:32 +08:00
/**
* 执行提交时将配置中的明细表数据合并到指定的明细表中
*/
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, (continueRun) => {
start()
continueRun()
})
/**
* 开始执行合并操作
*/
function start() {
2023-02-13 10:40:45 +08:00
let mappingResult = []
workflowInsertValueConfig.forEach(item => {
let valueMapping = getDetailValueMapping(item)
mappingResult = [...mappingResult, ...valueMapping]
})
2023-02-16 19:00:32 +08:00
setValue(mappingResult)
}
2023-02-13 10:40:45 +08:00
2023-02-16 19:00:32 +08:00
/**
* 设置表数据到指定的明细表中
* @param valueMapping 值映射数组
*/
2023-02-13 11:24:46 +08:00
function setValue(valueMapping) {
2023-02-16 19:00:32 +08:00
valueMapping.forEach(row => {
let rowData = {}
row.forEach(item => {
if (!rowData[item.targetTable]) {
rowData[item.targetTable] = {}
}
rowData[item.targetTable][Utils.convertNameToIdUtil({
fieldName: item.targetField,
table: item.targetTable
})] = {
value: item.value
}
})
Object.keys(rowData).forEach(key => {
WfForm.addDetailRow(key, rowData[key]);
})
})
}
2023-02-16 19:00:32 +08:00
/**
* 获取明细值和对应字段的映射数组
* @param configItem 配置项
* @returns {*[]} 明细字段和对应值的映射数组
*/
2023-02-13 10:40:45 +08:00
function getDetailValueMapping(configItem) {
let detailIdsStr = WfForm.getDetailAllRowIndexStr(configItem.table);
let detailIdArr = detailIdsStr.split(",")
let result = []
for (let i = 0; i < detailIdArr.length; i++) {
2023-02-16 19:00:32 +08:00
let fieldValueMapping = getValueByConfig(configItem.filedMapping, configItem.table, detailIdArr[i], configItem.targetTable)
2023-02-13 10:40:45 +08:00
result.push(fieldValueMapping)
}
return result
}
2023-02-16 19:00:32 +08:00
/**
* 通过配置数据获取值
* @param fieldMapping 字段映射规则数组
* @param tableName 表名称
* @param detailIndex 明细表下标
* @param targetTable 目标表
* @returns {*[]} 对应明细行的值数组
*/
function getValueByConfig(fieldMapping, tableName, detailIndex, targetTable) {
2023-02-13 10:40:45 +08:00
let result = []
fieldMapping.forEach(item => {
let fieldValue = Utils.getFiledValueByName({
fieldName: item.source,
2023-02-16 19:00:32 +08:00
table: tableName
2023-02-13 10:40:45 +08:00
}, detailIndex)
result.push({
targetField: item.target,
2023-02-16 19:00:32 +08:00
value: fieldValue,
targetTable: targetTable
2023-02-13 10:40:45 +08:00
})
})
return result
}
2023-02-13 10:40:45 +08:00
})
/* ******************* 流程明细数据整合插入end ******************* */
2023-02-16 19:00:32 +08:00
/* ******************* 当明细数据未加载完成时 控制流程提交 start ******************* */
$(() => {
const config = {
table: 'detail_1',
field: ['qswj']
2023-02-16 19:00:32 +08:00
}
function check() {
let detailRowIndexStr = WfForm.getDetailAllRowIndexStr(config.table);
let rowIndexArr = detailRowIndexStr.split(",");
try {
rowIndexArr.forEach(item => {
config.field.forEach(field => {
let value = WfForm.getFieldValue(WfForm.convertFieldNameToId(field, config.table) + "_" + item)
2023-02-16 19:00:32 +08:00
if (value == '' || value == null) {
throw field + " is can not be null!";
}
})
})
} catch (err) {
return false
}
return true
}
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, callback => {
if (check()) {
callback()
} else {
WfForm.showConfirm("~`~` " + "7 模版文件生成中,请稍后在提交! " + " `~`8 Template file generation, please submit later! " + "`~`~", function () {
}, function () {
}, {
title: "~`~` " + "7 提交检查提示 " + "`~` 8 Submit check prompt " + "`~`~", //弹确认框的title仅PC端有效
okText: "OK", //自定义确认按钮名称
cancelText: "Cancel" //自定义取消按钮名称
});
}
})
})
2023-02-24 15:28:54 +08:00
/* ******************* 当明细数据未加载完成时 控制流程提交 end ******************* */
/* ******************* 流程明细字段包含某个字符串时给某个字段赋值为某个东西start ******************* */
$(() => {
let config = [{
table: 'detail_1',
mapping: [{
sourceField: '',
targetField: '',
sourceIncludes: '',
targetSet: ''
}]
}]
function runJs() {
config.forEach(item => {
let tableName = item.table
let mapping = item.mapping
if (tableName === "main") {
mapping.forEach(row => {
let sourceValue = WfForm.getFieldValue(WfForm.convertFieldNameToId(row.sourceField, tableName));
if (sourceValue.indexOf(row.sourceIncludes) !== -1) {
WfForm.changeFieldValue(WfForm.convertFieldNameToId(row.targetField, tableName, {
value: row.targetSet
}))
}
})
} else {
let rowIndexArr = WfForm.getDetailAllRowIndexStr(tableName).split(",");
rowIndexArr.forEach(rowIndex => {
mapping.forEach(row => {
let sourceValue = WfForm.getFieldValue(WfForm.convertFieldNameToId(row.sourceField, tableName));
if (sourceValue.indexOf(row.sourceIncludes) !== -1) {
WfForm.changeFieldValue(WfForm.convertFieldNameToId(row.targetField, tableName) + "_" + rowIndex, {
value: row.targetSet
})
}
})
})
}
})
}
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, callback => {
runJs()
callback()
})
})
2023-03-14 15:12:53 +08:00
/* ******************* 流程明细字段包含某个字符串时给某个字段赋值为某个东西end ******************* */
/* ******************* 流程提交按钮触发流程抄送start ******************* */
$(() => {
let config = {
// 抄送人所在明细表编号1-明细1 2-明细2
detailNo: '1',
// 抄送人所在字段字段名
ccResourceField: '',
// 一级部门负责人字段名
firstLevelDepResponsibleField: ''
}
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, function (callback) {
$.ajax("/api/aiyh/pcn/cc-workflow/trigger", {
type: "POST",
data: JSON.stringify({
detailNo: config.detailNo,
requestId: WfForm.getBaseInfo().requestid,
ccResourceField: config.ccResourceField,
firstLevelDepResponsibleField: config.firstLevelDepResponsibleField
}),
headers: {
"Content-Type": "application/json"
},
complete: (res) => {
res.then(r => {
if (r && r.code === 200) {
callback();
}
})
2023-03-14 15:12:53 +08:00
}
})
});
})
/* ******************* 流程提交按钮触发流程抄送end ******************* */
/* ******************* 提交外出流程 ******************* */
(function start() {
function fillNum(n) {
if (n < 10) {
return "0" + n;
} else {
return n;
}
}
2023-03-20 14:40:59 +08:00
let date = new Date();
let month = date.getMonth() + 1;
let year = date.getFullYear();
2023-03-20 14:40:59 +08:00
let n = window.prompt("请输入日期:", date.getDate().toString());
let workDate = year + "-" + fillNum(month) + "-" + fillNum(n);
n = fillNum(n);
WfForm.changeFieldValue("field607", {value: workDate});
let workflowTitle = WfForm.getFieldValue("field-1");
2023-03-20 14:40:59 +08:00
WfForm.changeFieldValue("field-1", {value: workflowTitle.substring(0, workflowTitle.length - 2) + n});
WfForm.changeFieldValue("field609", {value: workDate});
WfForm.changeFieldValue("field608", {value: "00:00"});
WfForm.changeFieldValue("field610", {value: "23:59"});
WfForm.changeFieldValue("field30038", {value: 0});
WfForm.changeFieldValue("field611", {value: "出差"});
WfForm.changeFieldValue("field8715", {value: "2"});
$("button[ecid='_Route@vmt0lk_Comp@upn4fo_FormContent@g9f33k_MainLayout@kdmfyn_LayoutTr@ds2cqb@main_0_CellType@27chqt@main_17_10_FieldContent@r045n3_BrowserElement@2mq6lm_WeaBrowser@j1zg9h_WrappedComponent@i9q2c5_Component@iiw91q_Associative@zt8qgk_Button@ztqsd2_button@xq1ea3']").trigger("click");
2023-03-04 16:04:39 +08:00
WfForm.registerCheckEvent(WfForm.OPER_CLOSE, function (callback) {
setTimeout(() => {
2023-03-20 14:40:59 +08:00
window.location.href = "/spa/workflow/static4form/index.html#/main/workflow/req?iscreate=1&workflowid=746";
2023-03-04 16:04:39 +08:00
}, 500)
});
})()
/* ******************* 提交外出流程 ******************* */
/* ******************* 明细数据统计数量添加 ******************* */
$(() => {
let config = {
// 数据来源表配置
sourceConfig: {
key: '',
table: '',
type: ''
},
// 需要修改的表配置
targetConfig: {
key: '',
table: '',
type: [{
type: '',
changeField: ''
}, {
type: '',
changeField: ''
}]
}
}
function changeTargetFieldValue() {
let sourceConfig = config.sourceConfig;
let targetConfig = config.targetConfig;
let targetDetailRowArr = WfForm.getDetailAllRowIndexStr(targetConfig.table).split(",");
let targetMap = new Map()
// 组装明细数据
targetDetailRowArr.forEach(item => {
let fieldMark = WfForm.convertFieldNameToId(targetConfig.key, targetConfig.table)
let fieldId = fieldMark + "_" + item
let fieldValue = WfForm.getFieldValue(fieldId);
targetMap.set(fieldValue, item)
})
let sourceDetailRowArr = WfForm.getDetailAllRowIndexStr(sourceConfig.table).split(",");
sourceDetailRowArr.forEach(item => {
let fieldMark = WfForm.convertFieldNameToId(sourceConfig.key, sourceConfig.table)
let fieldId = fieldMark + "_" + item
let fieldValue = WfForm.getFieldValue(fieldId);
let typeFieldMark = WfForm.convertFieldNameToId(sourceConfig.type, sourceConfig.table)
let typeFieldId = typeFieldMark + "_" + item
let typeFieldValue = WfForm.getFieldValue(typeFieldId);
targetConfig.type.forEach(typeItem => {
if (typeItem.type == typeFieldValue) {
// 需要修改对应行的字段
let targetRowIndex = targetMap.get(fieldValue);
let fieldMark = WfForm.convertFieldNameToId(typeItem.changeField, targetConfig.table)
let fieldId = fieldMark + "_" + targetRowIndex
let targetRowValue = WfForm.getFieldValue(fieldId);
let result = +targetRowValue + 1
WfForm.changeFieldValue(fieldId, {
value: result
})
}
})
})
}
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, callback => {
changeTargetFieldValue()
callback()
})
})
/* ******************* 明细数据数量统计添加 end ******************* */
/* ******************* 计算年月日 start ******************* */
$(() => {
const config = [{
// 源字段
2023-05-23 14:45:23 +08:00
sourceField: 'htksrq',
// 目标字段
2023-05-23 14:45:23 +08:00
targetField: 'htjsrq',
// 日期加月份字段
2023-05-30 11:50:41 +08:00
numberField: 'contractperiod',
monthBase: 12
}, {
2023-05-23 14:45:23 +08:00
sourceField: 'syqksrq',
targetField: 'syqjsrq',
2023-05-30 11:50:41 +08:00
numberField: 'probationperiod',
monthBase: 1
}]
runJs();
function runJs() {
config.forEach(item => {
bindAction(item)
})
}
function bindAction(configItem) {
let fieldId = WfForm.convertFieldNameToId(configItem.numberField)
WfForm.bindFieldChangeEvent(fieldId, (obj, id, value) => {
if ("" == value) {
2023-05-23 14:45:23 +08:00
WfForm.changeFieldValue(WfForm.convertFieldNameToId(configItem.targetField), {value: ""})
return
}
let sourceValue = WfForm.getFieldValue(WfForm.convertFieldNameToId(configItem.sourceField));
2023-05-23 14:45:23 +08:00
if ("" == sourceValue) {
setTimeout(() => {
WfForm.changeFieldValue(fieldId, {value: ""})
}, 10)
}
let date = new Date(sourceValue)
2023-05-30 11:50:41 +08:00
date.setMonth(date.getMonth() + +value * configItem.monthBase)
date.setDate(date.getDate() - 1)
2023-05-23 14:45:23 +08:00
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
WfForm.changeFieldValue(WfForm.convertFieldNameToId(configItem.targetField), {
value: `${year}-${fullNum(month)}-${fullNum(day)}`
2023-05-23 14:45:23 +08:00
})
})
2023-05-23 14:45:23 +08:00
}
function fullNum(i) {
if (i <= 9) {
return '0' + i
} else {
return i
}
}
})
2023-05-30 11:50:41 +08:00
/* ******************* 计算年月日 end ******************* */
/* ******************* 年假计算 start ******************* */
$(() => {
let config = {
// 基础年假
base: 20,
2023-05-30 11:50:41 +08:00
// 入职日期
dateField: 'jrbsjjtsj',
// 年假
targetField: 'nj'
}
runJs()
function runJs() {
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId(config.dateField), (obj, id, value) => {
let date = new Date(value)
let nowDate = new Date()
let njValue = calculateBonus(date, nowDate, config)
if (value !== 0) {
WfForm.changeFieldValue(WfForm.convertFieldNameToId(config.targetField), {value: njValue})
}
})
}
function calculateBonus(startDate, endDate, config) {
const diffInMs = endDate.getTime() - startDate.getTime();
const diffInYears = diffInMs / (1000 * 60 * 60 * 24 * 365);
if (diffInYears < 3) {
return config.base;
} else if (diffInYears >= 3 && diffInYears < 6) {
return config.base + 1;
2023-05-30 11:50:41 +08:00
} else {
const extraYears = Math.floor((diffInYears - 3) / 3);
let resultDay = config.base + extraYears * 2
if (resultDay >= 25) {
return 25;
}
return resultDay;
2023-05-30 11:50:41 +08:00
}
}
})
/* ******************* 年假计算 end ******************* */
/* ******************* youhong.ai 明细字段合并主表,序号内容换行展示 start ******************* */
$(() => {
const config = {
// 明细表
detail: 'detail_3',
// 明细字段
detailField: 'jbxxnr',
// 主表字段
mainField: 'jbxxnr'
}
function runJs() {
let rowIndexStr = WfForm.getDetailAllRowIndexStr(config.detail);
let rowIndexArr = rowIndexStr.split(",");
let value = ""
rowIndexArr.forEach(item => {
let fieldId = WfForm.convertFieldNameToId(config.detailField, config.detail) + "_" + item
let fieldValue = WfForm.getFieldValue(fieldId);
value += (+item + 1) + "、" + fieldValue + "\n";
})
WfForm.changeFieldValue(WfForm.convertFieldNameToId(config.mainField), {value})
}
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, (callback) => {
runJs()
callback()
})
})
/* ******************* youhong.ai 明细字段合并主表,序号内容换行展示 end ******************* */
/* ******************* youhong.ai 取明细行中最早时间的一行,将数据放到主表 start ******************* */
$(() => {
const config = {
// 明细表
detail: 'detail_1',
// 映射关系
mapping: [{
// 明细表字段
detailField: 'jbsj',
// 主表字段
mainField: 'zzjsrq',
}, {
// 明细表字段
detailField: 'jbtd',
// 主表字段
mainField: 'jbqd',
}],
dateSort: 'jbsj'
}
function runJs() {
let rowIndexStr = WfForm.getDetailAllRowIndexStr(config.detail);
let rowIndexArray = rowIndexStr.split(",");
const detailData = []
rowIndexArray.forEach(item => {
let obj = {}
config.mapping.forEach(mapping => {
obj[mapping.detailField] = WfForm.getFieldValue(WfForm.convertFieldNameToId(mapping.detailField, config.detail) + "_" + item)
})
detailData.push(obj)
})
console.log(detailData)
let minDateObj = filterByMinDate(detailData, config.dateSort);
console.log(minDateObj)
config.mapping.forEach(item => {
WfForm.changeFieldValue(WfForm.convertFieldNameToId(item.mainField), {
value: minDateObj[item.detailField]
})
})
}
function filterByMinDate(arr, key) {
return arr.reduce((min, obj) => {
if (!min || new Date(obj[key]) <= new Date(min[key])) {
return obj;
}
return min;
}, null);
}
WfForm.registerCheckEvent(WfForm.OPER_SUBMIT, (callback) => {
runJs()
callback()
})
})
/* ******************* youhong.ai 取明细行中最早时间的一行,将数据放到主表 end ******************* */
/* ******************* youhong.ai 主表选择框自定义渲染为进度条 start ******************* */
$(() => {
const field = 'jz'
const config = {
'-1': 0,
'0': 20,
'1': 40,
'2': 60,
'3': 80,
'4': 100,
}
function customerRender(info, compFn) {
let fieldValue = info.fieldValue;
if (!fieldValue) {
fieldValue = '-1'
}
let {WeaProgress} = ecCom
return React.createElement(WeaProgress, {
strokeColor: '#6c8dc1',
percent: config[fieldValue]
})
}
WfForm.proxyFieldContentComp(WfForm.convertFieldNameToId(field).replace("field", ""), customerRender)
setTimeout(() => {
WfForm.forceRenderField(WfForm.convertFieldNameToId(field));
}, 500)
})
/* ******************* youhong.ai 主表选择框自定义渲染为进度条 end ******************* */
2023-07-06 10:08:21 +08:00
/* ******************* youhong.ai 限制考试按钮点击 start ******************* */
$(() => {
let config = {
2023-07-06 11:11:00 +08:00
// 条件
conditions: {
lx: '',
bxxx: ''
},
// 表名
tableName: "uf_hgpxtz",
// 文档字段
docIdField: 'clwd'
2023-07-06 10:08:21 +08:00
}
function pxlx() {
let datas = ModeList.getTableDatas();
if (datas && datas.length >= 1) {
let obj = datas[0];
let value = obj.lx
2023-07-06 11:11:00 +08:00
Object.keys(config.conditions).forEach(key => {
config.conditions[key] = obj[key]
})
api({
url: "/api/aiyh/exam-btn/control/is-read",
type: "POST",
data: JSON.stringify(config),
contentType: "application/json"
}).then(res => {
if (res && res.code == 200) {
if (res.data) {
let url = "/spa/workflow/index_form.jsp#/main/workflow/req?iscreate=1&workflowid=306&field24498=" + value;
window.open(url);
} else {
ModeList.showMessage("需要查看所有考试相关文档后方可考试,请先查看考试材料!", 1, 2);
}
} else {
ModeList.showMessage("系统错误,请稍后尝试!", 2, 1.5);
}
})
2023-07-06 10:08:21 +08:00
}
}
2023-07-06 11:11:00 +08:00
window.pxlx = pxlx
/**
* @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)
}
2023-07-06 10:08:21 +08:00
})
/* ******************* youhong.ai 限制考试按钮点击 end ******************* */
/* ******************* youhong.ai 随机抽取题库考题 start ******************* */
$(() => {
const config = {
table: '',
// 使用范围字段
scopeOfUse: '',
// 类型明细表
typeDetail: {
// 明细表名
tableName: "",
// 类型字段
typeField: '',
// 类型数量
typeNumber: '',
// 类型数量字段
typeTotalNumber: ''
},
targetDetail: {
tableName: '',
testQuestionField: ''
}
}
/**
* 获取考题分类总数
* @param scopeOfUse 大分类管理员 普通员工
*/
function getTestPaperTypeNumber(scopeOfUse) {
Utils.api({
url: `/api/aiyh/exam-btn/control/count?scopeOfUse=${scopeOfUse}&groupField=${config.typeDetail.typeField}&scopeOfUseField=${config.scopeOfUse}&table=${config.table}`
}).then(res => {
if (res && res.code === 200) {
let typeNumber = res.data
// 监听类型变化
WfForm.bindDetailFieldChangeEvent(WfForm.convertFieldNameToId(config.typeDetail.typeField,
config.typeDetail.tableName), (id, rowIndex, value) => {
let totalNumber = typeNumber[value]
// 更新总数字段
WfForm.changeFieldValue(WfForm.convertFieldNameToId(config.typeDetail.typeTotalNumber,
config.typeDetail.tableName) + "_" + rowIndex, {
value: totalNumber
})
})
}
})
}
/**
* 获取试题类型和数量
* @param scopeOfUse 使用范围
*/
function getTestPaper(scopeOfUse) {
getTestPaperTypeNumber(scopeOfUse)
}
/**
* 生成随机试题
*/
function extractTestQuestions() {
let detailAllRowIndexStr = WfForm.getDetailAllRowIndexStr(config.typeDetail.tableName);
let rowArr = detailAllRowIndexStr.split(",");
let typeNumberObj = {}
rowArr.forEach(item => {
let type = WfForm.getFieldValue(WfForm.convertFieldNameToId(config.typeDetail.typeField, config.typeDetail.tableName) + "_" + item);
let number = WfForm.getFieldValue(WfForm.convertFieldNameToId(config.typeDetail.typeNumber, config.typeDetail.tableName) + "_" + item);
if (number <= 0) {
return
}
typeNumberObj[type] = number
})
let params = {
scopeOfUse: WfForm.getFieldValue(config.scopeOfUse),
groupField: config.typeDetail.typeField,
scopeOfUseField: config.scopeOfUse,
table: config.table,
questNumberMap: typeNumberObj
}
Utils.api({
url: "/api/aiyh/exam-btn/control/random-test-questions",
data: JSON.stringify(params),
}).then(res => {
if (res && res.code == 200) {
let testQuestions = res.data
let n = 0;
WfForm.delDetailRow(config.targetDetail.tableName, "all");
testQuestions.forEach(item => {
let fieldMark = WfForm.convertFieldNameToId(config.targetDetail.testQuestionField, config.targetDetail.tableName)
WfForm.addDetailRow(config.targetDetail.tableName, {
[fieldMark]: {
value: item.id,
specialobj: [{
id: item.id,
name: item.name
}]
}
})
WfForm.triggerFieldAllLinkage(fieldMark + "_" + n++)
})
}
})
}
function runJs() {
// 监听分类数量发生变化
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId(config.typeDetail.typeNumber, config.typeDetail.tableName),
(id, rowIndex, value) => {
if (value == '') {
return
}
let total = WfForm.getFieldValue(WfForm.convertFieldNameToId(config.typeDetail.typeTotalNumber, config.typeDetail.tableName) + "_" + rowIndex);
if (value > total) {
WfForm.showConfirm("抽题数不能大于总题数!", function () {
WfForm.changeFieldValue(WfForm.convertFieldNameToId(config.typeDetail.typeNumber, config.typeDetail.tableName) + "_" + rowIndex, {
value: ""
})
});
}
})
// 监听主表使用范围
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId(config.scopeOfUse), (obj, id, value) => {
if (value == '') {
return
}
getTestPaper(value)
})
// 渲染生成抽取试题按钮
const generateBtnNode = document.querySelector("#cus_generate_test_questions>span")
const {Button} = antd
ReactDOM.render(React.createElement(Button, {
type: "primary",
children: "抽取试题",
onClick: () => {
extractTestQuestions()
}
}), generateBtnNode)
$("#cus_generate_test_questions button").css({
margin: "3px auto"
})
$("#cus_generate_test_questions span").css("color", "#FFF")
}
runJs()
})
/* ******************* youhong.ai 随机抽取题库考题 end ******************* */