Files
zszq-trs/YLErpWeb/wwwroot/Scripts/app/system/Approvalprocess.js
T
2026-07-16 17:17:21 +08:00

1482 lines
63 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
$(function () {
});
function initSelectize(selector, options) {
var defaultOptions = {
plugins: ['remove_button'],
onItemAdd: function (value, $item) {
$item.on('dblclick', function () {
var selectize = $item.closest('.selectize-control').prev('select')[0].selectize;
selectize.removeItem(value, true);
});
}
};
options = _.assign({}, defaultOptions, options || {});
$(selector).selectize(options);
}
function setRuleDiv() {
// 先销毁已有的 selectize 实例,避免在隐藏容器(v-show)里初始化后尺寸错位
$("[name='selectRule']").each(function () {
if (this.selectize) {
this.selectize.destroy();
}
});
initSelectize("[name='selectRule']", {
options: getRules(),
valueField: 'Value',
labelField: 'Text',
searchField: 'Text'
});
}
function getRules() {
var items = [];
for (var i = 0; i < selectItems.length; i++) {
// 隐藏"投资规模"选项(仅保留"字段复核")
if (selectItems[i].Text === '投资规模') continue;
items.push({
Value: selectItems[i].Value,
Text: selectItems[i].Text
});
}
return items;
}
var app = new Vue({
el: '#app',
data: {
selected: '0',
options: [
{ text: '--请选择--', value: '0' },
{ text: '客户开户', value: '1' },
{ text: '客户信息修改', value: '5' },
{ text: '交易新增与修改', value: '2' },
{ text: '交易了结', value: '6' },
/* { text: '资信与授信', value: '3' },*/
{ text: '出金', value: '4' }
],
isOpen: false,
isTrade: false,
isClose: false,
isCredit: false,
isOutCash: false,
isClient: false,
openItems: [],
clientItems: [],
tradeItems: [],
closeItems: [],
creditItems: [],
outCashItems: [],
openCounter: 0,
tradeCounter: 0,
creditCounter: 0,
clientCounter: 0,
tradeIndex: 0,
grouplist: [],
node: 0,
// 需求①:节点触发条件字段(期初名义本金 / 本次交易名义本金)
// 开仓流程只能选期初名义本金;了结流程两个都可选
conditionFields: [
{ value: 'initialNotional', text: '期初名义本金' },
{ value: 'currentNotional', text: '本次交易名义本金' }
],
// 开仓流程可选字段(仅期初)
conditionFieldsOpen: [
{ value: 'initialNotional', text: '期初名义本金' }
],
conditionOps: [
{ value: 'gt', text: '>' },
//{ value: 'lt', text: '<' },
{ value: 'gte', text: '>=' },
//{ value: 'lte', text: '<=' },
//{ value: 'eq', text: '=' },
//{ value: 'neq', text: '≠' }
],
conditionLogics: [
{ value: 'AND', text: '满足全部条件时触发' },
{ value: 'OR', text: '满足任一条件时触发' }
],
roleOptions: []
},
computed: {
filterBranch() {
return this.tradeItems.filter(x => x.approvalCondition != 0);
},
openFilterBranch() {
return this.openItems.filter(x => x.approvalCondition != 0);
},
clientFilterBranch() {
return this.clientItems.filter(x => x.approvalCondition != 0);
},
// 需求①:开仓流程只能选期初名义本金;了结流程两个都可选
availableConditionFields() {
return this.isClose ? this.conditionFields : this.conditionFieldsOpen;
}
},
methods: {
loadRoleOptions: function () {
var thisObj = this;
main.post("/AccountOpeningProcess/GetRolesOption", {}, { async: false }).done(
function (res) {
var items = [];
for (var i = 0; i < res.length; i++) {
items.push({
Value: res[i].Value,
Text: res[i].Text
});
}
thisObj.roleOptions = items;
}
);
},
changeType: function () {
var thisObj = this;
$("#addtooltip-warpper").hide();
if (thisObj.selected === '1') {
thisObj.isOpen = true;
thisObj.isTrade = false;
thisObj.isClose = false;
thisObj.isCredit = false;
thisObj.isOutCash = false;
thisObj.isClient = false;
} else if (thisObj.selected === '2') {
thisObj.isOpen = false;
thisObj.isTrade = true;
thisObj.isClose = false;
thisObj.isCredit = false;
thisObj.isOutCash = false;
thisObj.isClient = false;
} else if (thisObj.selected === '6') { // 需求②:交易了结流程
thisObj.isOpen = false;
thisObj.isTrade = false;
thisObj.isClose = true;
thisObj.isCredit = false;
thisObj.isOutCash = false;
thisObj.isClient = false;
} else if (thisObj.selected === '3') {
thisObj.isOpen = false;
thisObj.isTrade = false;
thisObj.isClose = false;
thisObj.isCredit = true;
thisObj.isOutCash = false;
thisObj.isClient = false;
}
else if (thisObj.selected === '4') {
thisObj.isOpen = false;
thisObj.isTrade = false;
thisObj.isClose = false;
thisObj.isCredit = false;
thisObj.isOutCash = true;
thisObj.isClient = false;
}
else if (thisObj.selected === '5') {
thisObj.isOpen = false;
thisObj.isTrade = false;
thisObj.isClose = false;
thisObj.isCredit = false;
thisObj.isOutCash = false;
thisObj.isClient = true;
}
else {
thisObj.isOpen = false;
thisObj.isTrade = false;
thisObj.isClose = false;
thisObj.isCredit = false;
thisObj.isOutCash = false;
thisObj.isClient = false;
}
thisObj.getProcess();
},
selectChangeType: function (index, value) {
var thisObj = this;
var selectType = thisObj.selected;
if (selectType === "1") { //客户开户
for (var i = 0; i < thisObj.openItems.length; i++) {
if (i === index) continue;
if (thisObj.openItems[i].SelectValue === parseInt(value) && thisObj.openItems[i].node == 0) {
main.message("不得选择重复角色");
return;
}
}
}
if (selectType === "2") { //交易
for (var j = 0; j < thisObj.tradeItems.length; j++) {
if (j === index) continue;
if (thisObj.tradeItems[j].SelectValue === parseInt(value) && thisObj.tradeItems[j].node == 0) {
main.message("不得选择重复角色");
return;
}
}
}
if (selectType === "3") {//资信与授信
for (var n = 0; n < thisObj.creditItems.length; n++) {
if (n === index) continue;
if (thisObj.creditItems[n].SelectValue === parseInt(value)) {
main.message("不得选择重复角色");
return;
}
}
}
if (selectType === "4") {//出金
for (var n = 0; n < thisObj.outCashItems.length; n++) {
if (n === index) continue;
if (thisObj.outCashItems[n].SelectValue === parseInt(value)) {
main.message("不得选择重复角色");
return;
}
}
}
if (selectType === "5") {//客户信息
for (var n = 0; n < thisObj.clientItems.length; n++) {
if (n === index) continue;
if (thisObj.clientItems[n].SelectValue === parseInt(value) && thisObj.clientItems[n].node==0) {
main.message("不得选择重复角色");
return;
}
}
}
},
showProcess(index, child, obj) {
var thisObj = this;
var selectType = thisObj.selected;
var tradeBranch = thisObj.tradeItems.find(x => x.approvalCondition != 0);
var openBranch = thisObj.openItems.find(x => x.approvalCondition != 0);
var clientBranch = thisObj.clientItems.find(x => x.approvalCondition != 0);
if ((selectType === "1" && !openBranch)
|| (selectType == "2" && !tradeBranch)
|| (selectType == "5" && !clientBranch)
) {
let offsetTop = $(obj.target).offset().top;
let offsetLeft = $(obj.target).offset().left;
$("#addtooltip-warpper").css({ "left": offsetLeft - 180, "top": offsetTop - 110, "margin-left": "30px" });
$("#addtooltip-warpper").hide();
$("#addtooltip-warpper").show(150);
this.tradeIndex = index;
thisObj.node = index;
} else {
thisObj.addProcess(index, child, 0);
$("#addtooltip-warpper").hide(100);
}
},
tradeAddProcess(type) {
var thisObj = this;
var selectType = thisObj.selected;
if (type == 1) {
thisObj.addProcess(thisObj.node, false, 0);
} else {
var typeName = 'TradeProcess';
if (selectType == "1") {
typeName = 'OpenProcess'
}
if (selectType == "5") {
typeName = 'ClientProcess'
}
if (selectType == "6") {
typeName = 'CloseProcess'
}
var item = {
id: 0,
Type: typeName,
Index: thisObj.node + 1,
SelectValue: 0,
approvalCondition: 1,
node: 1,
parentNode: thisObj.node,
approvalGroupId: 0,
conditionConfig: '',
triggerCondition: '',
_trigger: { tokens: [] }
}
var item2 = {
id: 0,
Type: typeName,
Index: thisObj.node + 1,
SelectValue: 0,
approvalCondition: 1,
node: 2,
parentNode: thisObj.node,
approvalGroupId: 0,
conditionConfig: '',
triggerCondition: '',
_trigger: { tokens: [] }
}
if (selectType == "2") { //交易
thisObj.tradeItems.splice(thisObj.node, 0, item, item2);
thisObj.initTradeItemIndex();
} else if (selectType == "1") { //开户
thisObj.openItems.splice(thisObj.node, 0, item, item2);
thisObj.initOpenItemIndex();
}
else if (selectType == "5") { //客户信息
thisObj.clientItems.splice(thisObj.node, 0, item, item2);
thisObj.initClientItemIndex();
}
else if (selectType == "6") { //交易了结
thisObj.closeItems.splice(thisObj.node, 0, item, item2);
thisObj.initCloseItemIndex();
}
}
$("#addtooltip-warpper").hide(100);
},
addProcess: function (index, child, node) {
var thisObj = this;
var selectType = thisObj.selected;
if (selectType === '0') {
main.message('请选择流程类型');
return;
}
if (selectType === "1") { //客户开户
thisObj.addOpenProcess(index, child, node);
return;
}
else if (selectType === "2") { //交易
thisObj.addTradeProcess(index, child, node);
return;
}
else if (selectType === "3") {//资信与授信
var item = {
Type: 'CreditProcess',
Index: index + 1,
SelectValue: 0
}
thisObj.creditItems.forEach(x => {
if (x.Index >= index) {
x.Index = x.Index + 1;
}
});
thisObj.creditItems.splice(index, 0, item);
thisObj.creditItems.forEach((x, index) => {
x.Index = index + 1;
});
thisObj.creditItems = thisObj.creditItems.sort((a, b) => a.Index - b.Index);
return;
}
else if (selectType === "4") {//出金
var item = {
Type: 'OutCashProcess',
Index: index + 1,
SelectValue: 0
}
thisObj.outCashItems.forEach(x => {
if (x.Index >= index) {
x.Index = x.Index + 1;
}
});
thisObj.outCashItems.splice(index, 0, item);
thisObj.outCashItems.forEach((x, index) => {
x.Index = index + 1;
});
thisObj.outCashItems = thisObj.outCashItems.sort((a, b) => a.Index - b.Index);
return;
}
else if (selectType === "5") { //客户信息
thisObj.addClientProcess(index, child, node);
return;
}
else if (selectType === "6") { //交易了结
thisObj.addCloseNode(index, child, node);
return;
}
},
delProcess: function (openItem) {
var thisObj = this;
var selectType = thisObj.selected;
if (selectType === "0") {
main.message('请选择流程类型后删除!');
return;
}
if (selectType === "1" || selectType === "2" || selectType === "5" || selectType === "6") {
// 客户开户/交易/客户信息/交易了结:统一走通用删除(支持多分支)
thisObj.commonDeleteProcess(openItem);
return;
}
else if (selectType === "3") {//资信与授信
var index = thisObj.creditItems.indexOf(openItem);
thisObj.creditItems.splice(index, 1);
thisObj.creditItems.forEach((x, index) => {
x.Index = index + 1;
});
return;
}
else if (selectType === "4") {//出金
var index = thisObj.outCashItems.indexOf(openItem);
thisObj.outCashItems.splice(index, 1);
thisObj.outCashItems.forEach((x, index) => {
x.Index = index + 1;
});
return;
}
},
addOpenProcess(index, child, node) {
var thisObj = this;
var item = {
Type: 'OpenProcess',
Index: index + 1,
SelectValue: 0,
approvalCondition: 0,
node: node,
parentNode: child ? index : 0,
approvalGroupId: 0,
conditionConfig: '',
triggerCondition: '',
_trigger: { tokens: [] }
}
var childNodes = thisObj.openItems.filter(x => x.Index > index);
childNodes.forEach(item => {
if (item.parentNode != 0) {
item.parentNode = item.parentNode + 1;
}
item.Index = item.Index + 1;
});
thisObj.openItems.splice(index, 0, item);
thisObj.initOpenItemIndex();
},
addTradeProcess(index, child, node) {
var thisObj = this;
var item = {
id: 0,
Type: 'TradeProcess',
Index: index + 1,
SelectValue: 0,
approvalCondition: 0,
node: node,
parentNode: child ? index : 0,
approvalGroupId: 0,
conditionConfig: '',
triggerCondition: '',
_trigger: { tokens: [] }
}
thisObj.getRuleType();
var childNodes = thisObj.tradeItems.filter(x => x.Index > index);
childNodes.forEach(item => {
if (item.parentNode != 0) {
item.parentNode = item.parentNode + 1;
}
item.Index = item.Index + 1;
});
thisObj.tradeItems.splice(index, 0, item);
thisObj.initTradeItemIndex();
},
addClientProcess(index, child, node) {
var thisObj = this;
var item = {
id: 0,
Type: 'ClientProcess',
Index: index + 1,
SelectValue: 0,
approvalCondition: 0,
node: node,
parentNode: child ? index : 0,
approvalGroupId: 0,
conditionConfig: '',
triggerCondition: '',
_trigger: { tokens: [] }
}
var childNodes = thisObj.clientItems.filter(x => x.Index > index);
childNodes.forEach(item => {
if (item.parentNode != 0) {
item.parentNode = item.parentNode + 1;
}
item.Index = item.Index + 1;
});
thisObj.clientItems.splice(index, 0, item);
thisObj.initClientItemIndex();
},
ok: function () {
var thisObj = this;
var selectType = thisObj.selected;
if (selectType === "0") {
main.message('请选择流程类型后进行确认提交!');
return;
}
else if (selectType === "1") { //客户开户
thisObj.openOk();
return;
}
else if (selectType === "2") { //交易
thisObj.tradeOk();
return;
}
else if (selectType === "3") {//资信与授信
thisObj.creditOk();
return;
}
else if (selectType === "4") {//出金
thisObj.cashOk();
return;
}
else if (selectType === "5") {
thisObj.clientOk();
return;
}
else if (selectType === "6") { // 需求②:交易了结
thisObj.saveCloseProcess();
return;
}
},
openOk() {
var thisObj = this;
var openLength = thisObj.openItems.length;
for (var j = 0; j < openLength; j++) {
if (thisObj.openItems[j].approvalCondition == 0) {
if (thisObj.openItems[j].SelectValue === "" || thisObj.openItems[j].SelectValue === 0) {
main.message('流程中断,请重新选择');
return;
}
} else {
if (thisObj.openItems[j].approvalGroupId === "" || thisObj.openItems[j].approvalGroupId === 0) {
main.message('流程中断,请重新选择');
return;
}
}
}
var temp1 = 0;
for (var w1 = 0; w1 < openLength - 1; w1++) {
for (var n1 = 1; n1 < openLength; n1++) {
if (w1 !== n1) {
if (parseInt(thisObj.openItems[w1].SelectValue) === parseInt(thisObj.openItems[n1].SelectValue) && parseInt(thisObj.openItems[n1].SelectValue) != 0) {
if (parseInt(thisObj.openItems[w1].node) == parseInt(thisObj.openItems[n1].node)) {
temp1 = temp1 + 1;
}
}
}
}
}
var approvalGroupItems = thisObj.openItems.filter(x => x.approvalGroupId != 0);
var approvalOpenLength = approvalGroupItems.length;
var temp2 = 0;
for (var w1 = 0; w1 < approvalOpenLength - 1; w1++) {
for (var n1 = 1; n1 < approvalOpenLength; n1++) {
if (w1 !== n1) {
if (parseInt(approvalGroupItems[w1].approvalCondition) === parseInt(approvalGroupItems[n1].approvalCondition) && parseInt(approvalGroupItems[w1].approvalGroupId) === parseInt(approvalGroupItems[n1].approvalGroupId)) {
temp2 = temp2 + 1;
}
}
}
}
if (temp1 > 0 || temp2 > 0) {
main.message('流程包含重复项,请重新选择');
return;
}
thisObj.initOpenItemIndex();
var firstChildOpenItem = thisObj.openItems.filter(x => x.node == 1);
var secondchildOpenItem = thisObj.openItems.filter(x => x.node == 2);
if (firstChildOpenItem.length == 1 && secondchildOpenItem.length == 1) {
main.message('分支节点流程未设置完毕');
return;
}
if (thisObj.openItems != null && thisObj.openItems.length > 0) {
main.confirm("修改客户开户流程后,处于审批中的客户需要重新审批,确认修改?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: thisObj.openItems[0].Type, data: thisObj.openItems },
{ async: false }).done(
function (res) {
thisObj.getProcess();
});
});
} else {
main.confirm("删除审批流程后,开户审批就会直接审批通过,确认删除?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: "OpenProcess" },
{ async: false }).done(
function (res) {
});
});
}
},
tradeOk() {
var thisObj = this;
var tradeLength = thisObj.tradeItems.length;
for (var j = 0; j < tradeLength; j++) {
if (thisObj.tradeItems[j].approvalCondition == 0) {
if (thisObj.tradeItems[j].SelectValue === "" || thisObj.tradeItems[j].SelectValue === 0) {
main.message('流程中断,请重新选择');
return;
}
} else {
if (thisObj.tradeItems[j].approvalGroupId === "" || thisObj.tradeItems[j].approvalGroupId === 0) {
main.message('流程中断,请重新选择');
return;
}
}
}
var temp1 = 0;
for (var w1 = 0; w1 < tradeLength - 1; w1++) {
for (var n1 = 1; n1 < tradeLength; n1++) {
if (w1 !== n1) {
if (parseInt(thisObj.tradeItems[w1].SelectValue) === parseInt(thisObj.tradeItems[n1].SelectValue) && parseInt(thisObj.tradeItems[n1].SelectValue) != 0) {
if (parseInt(thisObj.tradeItems[w1].node) == parseInt(thisObj.tradeItems[n1].node)) {
temp1 = temp1 + 1;
}
}
}
}
}
var approvalGroupItems = thisObj.tradeItems.filter(x => x.approvalGroupId != 0);
var approvalTradeLength = approvalGroupItems.length;
var temp2 = 0;
for (var w1 = 0; w1 < approvalTradeLength - 1; w1++) {
for (var n1 = 1; n1 < approvalTradeLength; n1++) {
if (w1 !== n1) {
if (parseInt(approvalGroupItems[w1].approvalCondition) === parseInt(approvalGroupItems[n1].approvalCondition) && parseInt(approvalGroupItems[w1].approvalGroupId) === parseInt(approvalGroupItems[n1].approvalGroupId)) {
temp2 = temp2 + 1;
}
}
}
}
if (temp1 > 0 || temp2 > 0) {
main.message('流程包含重复项,请重新选择');
return;
}
thisObj.getRuleType();
thisObj.initTradeItemIndex();
var triggerValid = thisObj.validateAllTriggers(thisObj.tradeItems);
if (!triggerValid.valid) {
main.message(triggerValid.message);
return;
}
thisObj.stringifyAllTrigger(thisObj.tradeItems); // 需求①:序列化触发条件
var firstChildTradeItem = thisObj.tradeItems.filter(x => x.node == 1);
var secondchildTradeItem = thisObj.tradeItems.filter(x => x.node == 2);
if (firstChildTradeItem.length == 1 && secondchildTradeItem.length == 1) {
main.message('分支节点流程未设置完毕');
return;
}
if (thisObj.tradeItems != null && thisObj.tradeItems.length > 0) {
main.confirm("审批页面存在未审批完的交易,修改审批流程后这些交易需要重新审批,确认修改?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: thisObj.tradeItems[0].Type, data: thisObj.tradeItems },
{ async: false }).done(
function (res) {
thisObj.getProcess();
});
});
} else {
main.confirm("删除审批流程后,交易审批就会直接审批通过,确认删除?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: "TradeProcess" },
{ async: false }).done(
function (res) {
});
});
}
},
creditOk() {
var thisObj = this;
var creditLength = thisObj.creditItems.length;
for (var n = 0; n < creditLength; n++) {
if (thisObj.creditItems[n].SelectValue === "" || thisObj.creditItems[n].SelectValue === 0) {
main.message('流程中断,请重新选择');
return;
}
}
var tempr = 0;
for (var wr = 0; wr < creditLength - 1; wr++) {
for (var nr = 0; nr < creditLength; nr++) {
if (wr !== nr) {
if (parseInt(thisObj.creditItems[wr].SelectValue) === parseInt(thisObj.creditItems[nr].SelectValue)) {
tempr = tempr + 1;
}
}
}
}
if (tempr > 0) {
main.message('流程包含重复项,请重新选择');
return;
}
if (thisObj.creditItems != null && thisObj.creditItems.length > 0) {
thisObj.creditItems.forEach((x, index) => {
x.Index = index + 1;
});
main.confirm("修改资信与授信审批流程后,处于审批中的资信与授信需要重新审批,确认修改?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: thisObj.creditItems[0].Type, data: thisObj.creditItems },
{ async: false }).done(
function (res) {
});
});
} else {
main.confirm("删除审批流程后,资信与授信审批就会直接审批通过,确认删除?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: "CreditProcess" },
{ async: false }).done(
function (res) {
});
});
}
},
cashOk() {
var thisObj = this;
var outCashLength = thisObj.outCashItems.length;
for (var n = 0; n < outCashLength; n++) {
if (thisObj.outCashItems[n].SelectValue === "" || thisObj.outCashItems[n].SelectValue === 0) {
main.message('流程中断,请重新选择');
return;
}
}
var tempr = 0;
for (var wr = 0; wr < outCashLength - 1; wr++) {
for (var nr = 0; nr < outCashLength; nr++) {
if (wr !== nr) {
if (parseInt(thisObj.outCashItems[wr].SelectValue) === parseInt(thisObj.outCashItems[nr].SelectValue)) {
tempr = tempr + 1;
}
}
}
}
if (tempr > 0) {
main.message('流程包含重复项,请重新选择');
return;
}
if (thisObj.outCashItems != null && thisObj.outCashItems.length > 0) {
thisObj.outCashItems.forEach((x, index) => {
x.Index = index + 1;
});
main.confirm("确认修改出金审批流程?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: thisObj.outCashItems[0].Type, data: thisObj.outCashItems },
{ async: false }).done(
function (res) {
});
});
} else {
main.confirm("删除审批流程后,出金审批就会直接审批通过,确认删除?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: "OutCashProcess" },
{ async: false }).done(
function (res) {
});
});
}
},
clientOk() {
var thisObj = this;
var clientLength = thisObj.clientItems.length;
for (var j = 0; j < clientLength; j++) {
if (thisObj.clientItems[j].approvalCondition == 0) {
if (thisObj.clientItems[j].SelectValue === "" || thisObj.clientItems[j].SelectValue === 0) {
main.message('流程中断,请重新选择');
return;
}
} else {
if (thisObj.clientItems[j].approvalGroupId === "" || thisObj.clientItems[j].approvalGroupId === 0) {
main.message('流程中断,请重新选择');
return;
}
}
}
var temp1 = 0;
for (var w1 = 0; w1 < clientLength - 1; w1++) {
for (var n1 = 1; n1 < clientLength; n1++) {
if (w1 !== n1) {
if (parseInt(thisObj.clientItems[w1].SelectValue) === parseInt(thisObj.clientItems[n1].SelectValue) && parseInt(thisObj.clientItems[n1].SelectValue) != 0) {
if (parseInt(thisObj.clientItems[w1].node) == parseInt(thisObj.clientItems[n1].node)) {
temp1 = temp1 + 1;
}
}
}
}
}
var approvalGroupItems = thisObj.clientItems.filter(x => x.approvalGroupId != 0);
var approvalClientLength = approvalGroupItems.length;
var temp2 = 0;
for (var w1 = 0; w1 < approvalClientLength - 1; w1++) {
for (var n1 = 1; n1 < approvalClientLength; n1++) {
if (w1 !== n1) {
if (parseInt(approvalGroupItems[w1].approvalCondition) === parseInt(approvalGroupItems[n1].approvalCondition) && parseInt(approvalGroupItems[w1].approvalGroupId) === parseInt(approvalGroupItems[n1].approvalGroupId)) {
temp2 = temp2 + 1;
}
}
}
}
if (temp1 > 0 || temp2 > 0) {
main.message('流程包含重复项,请重新选择');
return;
}
thisObj.initClientItemIndex();
var firstChildClientItem = thisObj.clientItems.filter(x => x.node == 1);
var secondchildClientItem = thisObj.clientItems.filter(x => x.node == 2);
if (firstChildClientItem.length == 1 && secondchildClientItem.length == 1) {
main.message('分支节点流程未设置完毕');
return;
}
if (thisObj.clientItems != null && thisObj.clientItems.length > 0) {
main.confirm("修改客户信息流程后,处于审批中的客户信息需要重新审批,确认修改?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: thisObj.clientItems[0].Type, data: thisObj.clientItems },
{ async: false }).done(
function (res) {
thisObj.getProcess();
});
});
} else {
main.confirm("删除审批流程后,客户信息审批就会直接审批通过,确认删除?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: "ClientProcess" },
{ async: false }).done(
function (res) {
});
});
}
},
getProcess() {
var thisObj = this;
thisObj.openItems = [];
thisObj.tradeItems = [];
thisObj.closeItems = [];
thisObj.creditItems = [];
thisObj.outCashItems = [];
thisObj.clientItems = [];
main.post("/AccountOpeningProcess/GetProcess",
{},
{ async: false }).done(
function (res) {
res.OpenProcess.forEach(function (value, index, array) {
thisObj.openItems.push({
id: value.id,
Type: value.processType,
Index: value.order,
SelectValue: value.roleId,
node: value.node,
parentNode: value.parentNode,
approvalGroupId: value.approvalGroupId,
approvalCondition: value.approvalCondition,
conditionConfig: value.conditionConfig,
triggerCondition: value.triggerCondition
});
});
res.TradeProcess.forEach(function (value, index, array) {
thisObj.tradeItems.push({
id: value.id,
Type: value.processType,
Index: value.order,
SelectValue: value.roleId,
ApprovalRules: value.ruleType,
node: value.node,
parentNode: value.parentNode,
approvalGroupId: value.approvalGroupId,
approvalCondition: value.approvalCondition,
conditionConfig: value.conditionConfig,
triggerCondition: value.triggerCondition
});
});
// 需求②:了结/平仓/行权审批流程
if (res.CloseProcess) {
res.CloseProcess.forEach(function (value, index, array) {
thisObj.closeItems.push({
id: value.id,
Type: value.processType,
Index: value.order,
SelectValue: value.roleId,
ApprovalRules: value.ruleType,
node: value.node,
parentNode: value.parentNode,
approvalGroupId: value.approvalGroupId,
approvalCondition: value.approvalCondition,
conditionConfig: value.conditionConfig,
triggerCondition: value.triggerCondition
});
});
}
res.CreditProcess.forEach(function (value, index, array) {
thisObj.creditItems.push({
Type: value.processType,
Index: value.order,
SelectValue: value.roleId
});
});
res.OutCashProcess.forEach(function (value, index, array) {
thisObj.outCashItems.push({
Type: value.processType,
Index: value.order,
SelectValue: value.roleId
});
});
res.ClientProcess.forEach(function (value, index, array) {
thisObj.clientItems.push({
id: value.id,
Type: value.processType,
Index: value.order,
SelectValue: value.roleId,
node: value.node,
parentNode: value.parentNode,
approvalGroupId: value.approvalGroupId,
approvalCondition: value.approvalCondition,
conditionConfig: value.conditionConfig,
triggerCondition: value.triggerCondition
});
});
// 需求①:加载后把 triggerCondition(JSON)解析为结构化对象供 UI 编辑
['openItems', 'tradeItems', 'closeItems', 'clientItems'].forEach(function (arr) {
thisObj[arr].forEach(function (item) {
thisObj.parseTriggerCondition(item);
});
});
}
);
},
getApprovalGroup() {
var thisObj = this;
main.post("/System/ApplovalGroupSearch", { MemberName: "" }).done(function (resp) {
thisObj.grouplist = resp.obj;
}).fail(function () {
main.alert("加载失败");
})
},
filterChild(node) {
return this.tradeItems.filter(x => x.node == node && x.approvalCondition == 0);
},
openFilterChild(node) {
return this.openItems.filter(x => x.node == node && x.approvalCondition == 0);
},
clientFilterChild(node) {
return this.clientItems.filter(x => x.node == node && x.approvalCondition == 0);
},
// ===== 需求③:多分支支持(参考中粮版)通用方法 =====
// 通用分支重编号:动态把分支节点编号为 1,2,3...N(不再写死 1/2
commonInitIndex(targetProp) {
const that = this;
const newSortedItems = [];
const mainItems = that[targetProp].filter(x => x.node == 0).sort((a, b) => a.Index - b.Index);
const childItems = that[targetProp].filter(x => x.node != 0);
const sortedChildItems = childItems.sort((a, b) => a.Index - b.Index);
const firstChildIndex = sortedChildItems.length > 0 ? sortedChildItems[0].Index : -1;
let j = 1;
for (let i = 0; i < mainItems.length; i++) {
if (mainItems[i].Index >= firstChildIndex) {
if (sortedChildItems.length > 0) {
mainItems[i].Index = sortedChildItems[sortedChildItems.length - 1].Index + j;
j++;
} else {
mainItems[i].Index = i + 1;
}
}
newSortedItems.push(mainItems[i]);
}
// 为分支条件的 node 重新排序(1,2,3...N)——多分支的核心
let tempNode = 1;
childItems.forEach((i) => {
if (i.approvalCondition != 0) {
i.node = tempNode++;
}
});
// 按分支 node 分组,重建每个分支下的子节点 Index/parentNode
for (let i = 0; i < childItems.length; i++) {
var filteredChildItems = childItems.filter(x => x.node == i + 1);
filteredChildItems.forEach((i, index) => {
if (i.approvalCondition == 0) {
i.Index = firstChildIndex + index;
i.parentNode = firstChildIndex + index - 1;
}
newSortedItems.push(i);
});
}
that[targetProp] = newSortedItems.sort((a, b) => a.Index - b.Index);
},
// 通用添加分支条件:push 一个 node:999 占位的分支节点,再重编号
commonAddCondition(item) {
const that = this;
const typeToPropMap = {
'OpenProcess': 'openItems',
'ClientProcess': 'clientItems',
'TradeProcess': 'tradeItems',
'CloseProcess': 'closeItems'
};
const typeToInitFnMap = {
'OpenProcess': that.initOpenItemIndex,
'ClientProcess': that.initClientItemIndex,
'TradeProcess': that.initTradeItemIndex,
'CloseProcess': that.initCloseItemIndex
};
const prop = typeToPropMap[item.Type];
const initFn = typeToInitFnMap[item.Type];
that[prop].push({
id: 0,
Type: item.Type,
Index: item.Index,
SelectValue: 0,
approvalCondition: 1,
node: 999,
parentNode: item.Index,
ApprovalRules: '',
approvalGroupId: 0,
conditionConfig: '',
triggerCondition: '',
_trigger: { tokens: [] }
});
initFn();
},
// 添加条件入口("添加条件"按钮调用)
addCondition(item) {
this.commonAddCondition(item);
},
// 通用删除分支/节点
commonDeleteProcess(item) {
const that = this;
const typeToPropMap = {
'OpenProcess': 'openItems',
'ClientProcess': 'clientItems',
'TradeProcess': 'tradeItems',
'CloseProcess': 'closeItems'
};
const typeToInitFnMap = {
'OpenProcess': that.initOpenItemIndex,
'ClientProcess': that.initClientItemIndex,
'TradeProcess': that.initTradeItemIndex,
'CloseProcess': that.initCloseItemIndex
};
const prop = typeToPropMap[item.Type];
const initFn = typeToInitFnMap[item.Type];
// 删除的不是分支条件节点(普通审批节点)
if (item.approvalCondition == 0) {
const index = that[prop].indexOf(item);
that[prop].splice(index, 1);
const nodes = that[prop].filter(x => x.Index >= item.Index);
nodes.forEach(item => {
item.Index = item.Index - 1;
});
initFn();
return;
}
// 分支条件数量<=2 时,删除整个分支组
var conditionBranchesLen = that[prop].filter(i => i.approvalCondition != 0 && i.node != 0).length;
if (item.approvalCondition != 0 && conditionBranchesLen <= 2) {
var childNodes = that[prop].filter(x => x.node != 0);
that[prop] = that[prop].filter(x => childNodes.indexOf(x) === -1);
initFn();
return;
}
// 分支条件数量>2 时,只删除该分支(同 node 的全部节点)
if (item.node != 0 && item.approvalCondition != 0) {
that[prop] = that[prop].filter(x => x.node != item.node);
initFn();
}
},
initTradeItemIndex() {
this.commonInitIndex('tradeItems');
this.initRuleType();
},
// ===== 需求①:节点触发条件 结构化编辑器(token 数组,支持每行独立且/或 + 括号)=====
// _trigger = { tokens: [ {type:'condition',condition:{field,op,value}}, {type:'operator',connector:'and'|'or'}, {type:'lparen'|'rparen'} ] }
// op 用字母标识符(gt/lt/gte/lte/eq/neq),规避 > < 在传输中被 HTML 编码导致加载不出来的问题
// 把历史符号 op 归一化为字母标识符
normalizeOp(op) {
var map = { '>': 'gt', '<': 'lt', '>=': 'gte', '<=': 'lte', '==': 'eq', '!=': 'neq', '=': 'eq', '<>': 'neq' };
if (!op) return 'gt';
var lower = ('' + op).toLowerCase();
if (['gt','lt','gte','lte','eq','neq'].indexOf(lower) >= 0) return lower;
return map[op] || lower;
},
// 字段归一化:历史 notional → initialNotional;空默认 initialNotional
normalizeField(field) {
if (!field) return 'initialNotional';
var f = ('' + field);
// 历史兼容
if (f.toLowerCase() == 'notional') return 'initialNotional';
return f;
},
// 把 item.triggerCondition(JSON 字符串)解析为 item._trigger 结构化对象供 UI 编辑
parseTriggerCondition(item) {
if (!item) return;
if (item._trigger) return; // 已解析则不重复处理
var thisObj = this;
var parsed = { tokens: [] };
if (item.triggerCondition) {
try {
var obj = JSON.parse(item.triggerCondition);
if (obj.tokens && obj.tokens.length) {
// 新结构:直接复用 token,规范化字段
parsed.tokens = obj.tokens.map(function (t) {
if (t.type == 'condition') {
var c = t.condition || {};
return { type: 'condition', condition: { field: thisObj.normalizeField(c.field), op: thisObj.normalizeOp(c.op), value: c.value != null ? c.value : '' } };
}
if (t.type == 'operator') return { type: 'operator', connector: (t.connector || 'and').toLowerCase() };
if (t.type == 'lparen') return { type: 'lparen' };
if (t.type == 'rparen') return { type: 'rparen' };
return null;
}).filter(function (t) { return t != null; });
}
} catch (e) {
// 非法 JSON,按空处理
}
}
this.$set(item, '_trigger', parsed);
},
// 新增一条触发条件(自动在前方补连接符,首个不补)
addTriggerCondition(item) {
this.parseTriggerCondition(item);
var toks = item._trigger.tokens;
if (toks.length > 0) {
var last = toks[toks.length - 1];
// 若上一 token 是条件或右括号,则需要连接符
if (last.type == 'condition' || last.type == 'rparen') {
toks.push({ type: 'operator', connector: 'and' });
}
}
toks.push({ type: 'condition', condition: { field: 'initialNotional', op: 'gt', value: '' } });
},
// 切换某连接符 and/or
toggleTriggerConnector(item, idx) {
var t = item._trigger.tokens[idx];
if (t && t.type == 'operator') {
t.connector = (t.connector == 'and') ? 'or' : 'and';
}
},
// 插入左/右括号
addTriggerParen(item, side) {
this.parseTriggerCondition(item);
var toks = item._trigger.tokens;
var type = side == 'left' ? 'lparen' : 'rparen';
if (type == 'lparen') {
// 左括号前若接条件/右括号,需补连接符
if (toks.length > 0) {
var last = toks[toks.length - 1];
if (last.type == 'condition' || last.type == 'rparen') {
toks.push({ type: 'operator', connector: 'and' });
}
}
toks.push({ type: 'lparen' });
} else {
toks.push({ type: 'rparen' });
}
},
// 删除一个 token,并清理其旁孤立连接符
removeTriggerToken(item, idx) {
var toks = item._trigger.tokens;
if (idx < 0 || idx >= toks.length) return;
toks.splice(idx, 1);
// 清理首部连接符 / 尾部连接符 / 连续连接符
var i = 0;
while (i < toks.length) {
var t = toks[i];
if (t.type == 'operator' && (i == 0 || i == toks.length - 1
|| toks[i - 1].type == 'operator')) {
toks.splice(i, 1);
} else {
i++;
}
}
},
// 保存前:把 item._trigger 序列化回 item.triggerCondition JSON
stringifyTriggerCondition(item) {
if (!item || !item._trigger) return;
var toks = item._trigger.tokens || [];
if (toks.length == 0) {
item.triggerCondition = '';
return;
}
// 过滤掉无效条件(字段/值缺失)
var valid = toks.filter(function (t) {
if (t.type == 'condition') {
var c = t.condition || {};
return c.field && c.op && c.value !== '';
}
return true;
});
// 移除首尾连接符
while (valid.length > 0 && valid[0].type == 'operator') valid.shift();
while (valid.length > 0 && valid[valid.length - 1].type == 'operator') valid.pop();
item.triggerCondition = valid.length > 0 ? JSON.stringify({ tokens: valid }) : '';
},
// 批量把一组 items 的 _trigger 序列化(保存前调用)
stringifyAllTrigger(items) {
var thisObj = this;
if (!items) return;
items.forEach(function (item) {
if (item.node == 0 || item.approvalCondition == 0) {
thisObj.stringifyTriggerCondition(item);
}
});
},
// 校验触发条件 token 列表是否合法:括号平衡、无空括号、无首尾连接符等
validateTriggerTokens(tokens) {
if (!tokens || tokens.length == 0) return { valid: true, message: '' };
var paren = 0;
for (var i = 0; i < tokens.length; i++) {
var t = tokens[i];
if (t.type == 'lparen') paren++;
if (t.type == 'rparen') paren--;
if (paren < 0) return { valid: false, message: '触发条件中右括号过多,请检查括号匹配' };
if (t.type == 'operator') {
if (i == 0 || i == tokens.length - 1) return { valid: false, message: '触发条件首尾不能为连接符(且/或)' };
var prev = tokens[i - 1];
if (prev.type == 'operator' || prev.type == 'lparen') return { valid: false, message: '触发条件中连接符(且/或)位置不正确' };
}
if (t.type == 'condition') {
var c = t.condition || {};
if (!c.field || !c.op || c.value === '') return { valid: false, message: '触发条件中存在未填写完整的条件' };
}
}
if (paren != 0) return { valid: false, message: '触发条件中括号不匹配,请检查' };
return { valid: true, message: '' };
},
// 校验一组 items 的触发条件,返回第一个错误信息
validateAllTriggers(items) {
var thisObj = this;
if (!items) return { valid: true, message: '' };
for (var i = 0; i < items.length; i++) {
var item = items[i];
if ((item.node == 0 || item.approvalCondition == 0) && item._trigger && item._trigger.tokens) {
var res = thisObj.validateTriggerTokens(item._trigger.tokens);
if (!res.valid) return res;
}
}
return { valid: true, message: '' };
},
// ===== 需求②:交易了结流程(closeItems)方法集,算法同交易流程 =====
closeFilterBranch() {
return this.closeItems.filter(x => x.approvalCondition != 0);
},
closeFilterChild(node) {
return this.closeItems.filter(x => x.node == node && x.approvalCondition == 0);
},
initCloseItemIndex() {
this.commonInitIndex('closeItems');
this.initRuleType();
},
closeShowProcess(index, child, obj) {
var thisObj = this;
var closeBranch = thisObj.closeItems.find(x => x.approvalCondition != 0);
if (!closeBranch) {
let offsetTop = $(obj.target).offset().top;
let offsetLeft = $(obj.target).offset().left;
$("#addtooltip-warpper").css({ "left": offsetLeft - 180, "top": offsetTop - 110, "margin-left": "30px" });
$("#addtooltip-warpper").hide();
$("#addtooltip-warpper").show(150);
this.tradeIndex = index;
thisObj.node = index;
} else {
thisObj.closeAddProcess(index, child, 0);
$("#addtooltip-warpper").hide(100);
}
},
closeAddProcess(index, child, node) {
var thisObj = this;
thisObj.addCloseNode(index, child, node);
$("#addtooltip-warpper").hide(100);
},
addCloseNode(index, child, node) {
var thisObj = this;
var item = {
id: 0,
Type: 'CloseProcess',
Index: index + 1,
SelectValue: 0,
ApprovalRules: '',
node: node,
parentNode: child ? index : 0,
approvalGroupId: 0,
approvalCondition: 0,
conditionConfig: '',
triggerCondition: '',
_trigger: { tokens: [] }
};
thisObj.closeItems.forEach(x => {
if (x.Index >= index) {
x.Index = x.Index + 1;
}
});
thisObj.closeItems.splice(index, 0, item);
thisObj.initCloseItemIndex();
},
closeSelectChangeType(index, value) {
var thisObj = this;
for (var j = 0; j < thisObj.closeItems.length; j++) {
if (j === index) continue;
if (thisObj.closeItems[j].SelectValue === parseInt(value) && thisObj.closeItems[j].node == 0) {
main.message("不得选择重复角色");
return;
}
}
},
saveCloseProcess() {
var thisObj = this;
// 角色非空校验
for (var i = 0; i < thisObj.closeItems.length; i++) {
if (thisObj.closeItems[i].SelectValue === "" || thisObj.closeItems[i].SelectValue === 0) {
if (thisObj.closeItems[i].approvalCondition == 0) {
main.message('流程中断,请重新选择');
return;
}
}
}
var temp1 = 0;
var closeLength = thisObj.closeItems.length;
for (var w1 = 0; w1 < closeLength - 1; w1++) {
for (var n1 = 1; n1 < closeLength; n1++) {
if (w1 !== n1) {
if (parseInt(thisObj.closeItems[w1].SelectValue) === parseInt(thisObj.closeItems[n1].SelectValue) && parseInt(thisObj.closeItems[n1].SelectValue) != 0) {
if (parseInt(thisObj.closeItems[w1].node) == parseInt(thisObj.closeItems[n1].node)) {
temp1 = temp1 + 1;
}
}
}
}
}
var approvalGroupItems = thisObj.closeItems.filter(x => x.approvalGroupId != 0);
var approvalCloseLength = approvalGroupItems.length;
var temp2 = 0;
for (var w1 = 0; w1 < approvalCloseLength - 1; w1++) {
for (var n1 = 1; n1 < approvalCloseLength; n1++) {
if (w1 !== n1) {
if (parseInt(approvalGroupItems[w1].approvalCondition) === parseInt(approvalGroupItems[n1].approvalCondition) && parseInt(approvalGroupItems[w1].approvalGroupId) === parseInt(approvalGroupItems[n1].approvalGroupId)) {
temp2 = temp2 + 1;
}
}
}
}
if (temp1 > 0 || temp2 > 0) {
main.message('流程包含重复项,请重新选择');
return;
}
thisObj.getCloseRuleType();
thisObj.initCloseItemIndex();
var firstChildCloseItem = thisObj.closeItems.filter(x => x.node == 1);
var secondchildCloseItem = thisObj.closeItems.filter(x => x.node == 2);
if (firstChildCloseItem.length == 1 && secondchildCloseItem.length == 1) {
main.message('分支节点流程未设置完毕');
return;
}
var triggerValid = thisObj.validateAllTriggers(thisObj.closeItems);
if (!triggerValid.valid) {
main.message(triggerValid.message);
return;
}
thisObj.stringifyAllTrigger(thisObj.closeItems); // 需求①:序列化触发条件
if (thisObj.closeItems != null && thisObj.closeItems.length > 0) {
main.confirm("审批页面存在未审批完的交易,修改审批流程后这些交易需要重新审批,确认修改?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: "CloseProcess", data: thisObj.closeItems },
{ async: false }).done(
function (res) {
thisObj.getProcess();
});
});
} else {
main.confirm("删除审批流程后,交易了结审批就会直接审批通过,确认删除?", function () {
main.post("/AccountOpeningProcess/AddProcess",
{ type: "CloseProcess" },
{ async: false }).done(
function (res) {
});
});
}
},
initOpenItemIndex() {
this.commonInitIndex('openItems');
},
initClientItemIndex() {
this.commonInitIndex('clientItems');
},
initRuleTypeFor(items, prefix) {
var thisObj = this;
var length = items.length;
for (var i = 0; i < length; i++) {
var ruleId = "#" + prefix + items[i].Index + items[i].node;
var el = $(ruleId).get(0);
if (!el || !el.selectize) continue; // DOM 尚未渲染或未初始化 selectize,跳过
if (items[i].ApprovalRules != null && items[i].ApprovalRules.length > 0) {
var ruleArr = items[i].ApprovalRules.split(',');
el.selectize.setValue(ruleArr);
} else {
el.selectize.setValue([]);
}
}
},
initRuleType() {
this.initRuleTypeFor(this.tradeItems, 'ruleType');
this.initRuleTypeFor(this.closeItems, 'closeRuleType');
},
getRuleTypeFor(items, prefix) {
var thisObj = this;
var length = items.length;
for (var i = 0; i < length; i++) {
var ruleId = "#" + prefix + items[i].Index + items[i].node;
var $selectize = $(ruleId).get(0);
if ($selectize) {
var ruleArr = $selectize.selectize.items;
items[i].ApprovalRules = ruleArr.join(',');
}
}
},
getRuleType() {
this.getRuleTypeFor(this.tradeItems, 'ruleType');
},
getCloseRuleType() {
this.getRuleTypeFor(this.closeItems, 'closeRuleType');
}
},
mounted: function () {
this.getProcess();
this.getApprovalGroup();
this.loadRoleOptions();
},
watch: {
tradeItems:
{
handler(val, oldVal) {
this.$nextTick(function () {
setRuleDiv();
this.initRuleType();
})
},
},
closeItems:
{
handler(val, oldVal) {
this.$nextTick(function () {
setRuleDiv();
this.initRuleType();
})
},
}
}
});