'use strict';
/**
*
*
* @author Ellisran
* @date 2020/10/09
* @version
*/
// 冲突解决,要把这里丢tenderTree改成tenderTree2
const tenderTree2 = [];
let parentId2 = 0;
let selects;
let auditUtils;
const needYB = ['advance', 'ledger', 'revise', 'change', 'audit-ass'];
// 查询方法
function findNode2 (key, value, arr) {
for (const a of arr) {
if (a[key] && a[key] === value) {
return a;
}
}
}
// 分类数据排序
function sortCategory2() {
category.sort(function (a, b) {
return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;
});
}
// 初始化TenderTree数据
function initTenderTree2 () {
const levelCategory = category.filter(function (c) {
return c.level && c.level > 0;
});
function findCategoryNode2(cid, value, array) {
for (const a of array) {
if (a.cid === cid && a.vid === value) {
return a;
}
}
}
function getCategoryNode2(category, value, parent, i = null) {
const array = parent ? parent.children : tenderTree2;
let cate = findCategoryNode2(category.id, value, array);
if (!cate) {
const cateValue = findNode2('id', value, category.value);
if (!cateValue) return null;
cate = {
cid: category.id,
vid: value,
name: cateValue.value,
children: [],
level: i ? i : category.level,
sort_id: ++parentId2,
sort: cateValue.sort,
};
array.push(cate);
}
return cate;
}
function loadTenderCategory2 (tender) {
let tenderCategory = null;
for (const [index,lc] of levelCategory.entries()) {
const tenderCate = findNode2('cid', lc.id, tender.category);
if (tenderCate) {
tenderCategory = getCategoryNode2(lc, tenderCate.value, tenderCategory);
} else {
if (index === 0 && tender.category) {
for (const [i,c] of tender.category.entries()) {
const cate = findNode2('id', c.cid, category);
if (cate) tenderCategory = getCategoryNode2(cate, c.value, tenderCategory, i+1);
}
}
return tenderCategory;
}
}
return tenderCategory;
}
function calculateTender2(tender) {
if (tender.lastStage) {
tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
}
}
tenderTree2.splice(0, tenderTree2.length);
for (const t of tenders) {
calculateTender2(t);
t.valid = true;
delete t.level;
if (t.category && levelCategory.length > 0) {
const parent = loadTenderCategory2(t);
if (parent) {
t.level = parent.level + 1;
parent.children.push(t);
} else {
tenderTree2.push(t);
}
} else {
tenderTree2.push(t);
}
}
sortTenderTree(tenderTree2);
console.log(tenderTree2);
}
function recursiveGetTenderNodeHtml2 (node, arr, pid, this_code, this_status, aidList = []) {
const html = [];
html.push('
');
// 名称
html.push('');
if (node.cid) {
html.push(' ', node.name);
} else {
html.push('');
html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
html.push('');
//html.push('', node[c.field], '');
html.push('', node.name, '');
}
html.push(' | ');
// 创建人
// html.push('', sp_status_list[node.shenpiInfo[shenpi_type]].name, ' | ');
html.push('');
if (!node.cid) {
if(cur_tenderid === node.id) {
html.push(sp_status_list[this_status].name);
} else {
html.push(sp_status_list[node.shenpiInfo[this_code]].name);
}
}
html.push(' | ');
html.push('');
if (!node.cid) {
let auditList = [];
let tender_status = 1;
if(cur_tenderid === node.id) {
auditList = aidList;
tender_status = this_status;
} else {
auditList = node.shenpiauditList[this_code];
tender_status = node.shenpiInfo[this_code];
}
if(tender_status === sp_status.gdspl || tender_status === sp_status.gdzs) {
const nameList = [];
if(auditList) {
for (const uid of auditList) {
const user = _.find(accountList, { id: uid });
nameList.push(user.name);
}
}
// html.push(' 0 ? nameList.join('-') : '') +'">');
html.push(nameList.length > 0 ? nameList.join('-') : '');
}
}
html.push(' | ');
html.push('');
if (!node.cid) {
html.push('');
}
html.push(' | ');
html.push('
');
if (node.children) {
for (const c of node.children) {
html.push(recursiveGetTenderNodeHtml2(c, node.children, node.sort_id, this_code, this_status, aidList));
}
}
return html.join('');
}
// 根据TenderTree数据获取Html代码
function getTenderTreeHtml2 (this_code, this_status, aidList = []) {
if (tenderTree2.length > 0) {
const html = [];
html.push('');
html.push('', '');
html.push('名称 | ');
html.push('流程模式 | ');
html.push('详细流程 | ');
html.push('选择 | ');
html.push('
', '');
parentId2 = 0;
for (const t of tenderTree2) {
html.push(recursiveGetTenderNodeHtml2(t, tenderTree2, '', this_code, this_status, aidList));
}
html.push('
');
return html.join('');
} else {
return EmptyTenderHtml.join('');
}
}
function getShenpiHtml (this_code) {
const html = [];
html.push('');
return html.join('');
}
$(document).ready(function () {
auditUtils = {
getAuditHtml: function(audit) {
return ''+ audit.name +' \n' +
' \n' +
' \n' +
' ' +
' \n'
},
getAuditTypeHtml: function(code, type) {
const html = [];
html.push(` ');
return html.join('');
},
getSelectAuditHtml: function (code) {
let divhtml = '';
accountGroup.forEach((group, idx) => {
let didivhtml = '';
if(group) {
group.groupList.forEach(item => {
didivhtml += (item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1)) ? '\n' +
'' + item.name + '' + item.mobile + '
\n' +
' ' + item.role + '\n' +
' \n' : '';
});
divhtml += ' ' + group.groupName + '\n' +
' \n' + didivhtml +
'
\n';
}
});
const html =
' \n' +
' \n' +
' \n' +
' \n' +
'
\n' +
' \n';
return html;
},
// 以下i从1开始
getAuditGroupInnerHtml: function(code, auditGroup, i) {
const html = [];
const type = auditGroup.length > 0 ? auditGroup[0].audit_type : auditType.key.common;
html.push(`${transFormToChinese(i)}审`);
html.push(this.getAuditTypeHtml(code, type));
for (const audit of auditGroup) {
html.push(this.getAuditHtml(audit));
}
if (type !== auditType.key.common || auditGroup.length === 0) {
html.push(this.getSelectAuditHtml(code));
}
if (type === auditType.key.union && auditGroup.length > 0) {
html.push(``);
}
html.push('');
return html.join('');
},
getAuditGroupHtml: function (code, auditGroup, i) {
return `${this.getAuditGroupInnerHtml(code, auditGroup, i)}`;
},
getFinalAuditHtml: function (audit) {
const html = [];
html.push('终审');
html.push(this.getAuditHtml(audit));
html.push('');
return html.join('');
},
getGroupHtml: function (flow, this_code) {
let html = '';
if (flow && flow.groupList && flow.groupList.length > 0) {
let groupSelectHtml = '';
for (const group of flow.groupList) {
groupSelectHtml += ``;
}
const selectGroup = flow.groupList.find(x => { return x.is_select === 1 });
html += '\n' +
'
当前审批组:\n' +
'
\n' +
' \n' +
' \n' +
`
编辑审批组\n` +
`
添加审批组\n` +
'
';
}
return html;
},
getgdsplHtml(flow, this_code) {
let addhtml = '';
if (flow.auditGroupList.length !== 0) {
for(const [i, auditGroup] of flow.auditGroupList.entries()) {
addhtml += this.getAuditGroupHtml(this_code, auditGroup, i + 1);
}
const addGroupHtml = this_code === 'change' && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
` 存为审批组\n` : '';
addhtml += '\n' +
' 添加流程\n' + addGroupHtml +
' ';
} else {
addhtml += this.getAuditGroupHtml(this_code, [], 1);
}
return addhtml;
},
// 以下i从0开始
addAudit: function (code, user, i) {
const flow = sp_lc.find(x => { return x.code === code });
if (!flow.auditGroupList) flow.auditGroupList = [];
if (!flow.auditGroupList[i]) flow.auditGroupList[i] = [];
flow.auditGroupList[i].push(user);
return flow.auditGroupList[i];
},
removeAudit: function (code, audit_id, i) {
const flow = sp_lc.find(x => { return x.code === code });
if (flow.auditGroupList[i].length === 1) {
flow.auditGroupList.splice(i, 1);
return null;
}
flow.auditGroupList[i].splice(flow.auditGroupList[i].findIndex(x => { return x.audit_id === audit_id; }), 1);
return flow.auditGroupList[i];
},
setAuditType: function (code, audit_type, i) {
const flow = sp_lc.find(x => { return x.code === code });
if (!flow || !flow.auditGroupList || !flow.auditGroupList[i]) return;
flow.auditGroupList[i].forEach(x => { x.audit_type = audit_type});
return flow.auditGroupList[i];
}
};
let timer = null;
let oldSearchVal = null;
$('body').on('input propertychange', 'div[id$="_dropdownMenu"] .gr-search', function(e) {
oldSearchVal = e.target.value;
timer && clearTimeout(timer);
timer = setTimeout(() => {
const newVal = $(this).val();
const code = $(this).attr('data-code');
let html = '';
if (newVal && newVal === oldSearchVal) {
accountList.filter(item => item && (item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1)) && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
html += `
${item.name}${item.mobile || ''}
${item.role || ''}
`
});
$('#' + code + '_dropdownMenu .book-list').empty();
$('#' + code + '_dropdownMenu .book-list').append(html);
} else {
if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
accountGroup.forEach((group, idx) => {
if (!group) return;
html += `
${group.groupName}
`;
group.groupList.forEach(item => {
if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
html += `
${item.name}${item.mobile || ''}
${item.role || ''}
`;
}
});
html += '
';
});
$('#' + code + '_dropdownMenu .book-list').empty();
$('#' + code + '_dropdownMenu .book-list').append(html);
}
}
}, 400);
});
// 添加审批流程按钮逻辑
$('body').on('click', 'div[id$="_dropdownMenu"] .book-list dt', function () {
const idx = $(this).find('.acc-btn').attr('data-groupid');
const type = $(this).find('.acc-btn').attr('data-type');
if (type === 'hide') {
$(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
$(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
$(this).find('.acc-btn').attr('data-type', 'show');
})
} else {
$(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
$(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
$(this).find('.acc-btn').attr('data-type', 'hide');
})
}
return false;
});
// 更改审批流程状态
$('body').on('change', '.form-check input[type="radio"]', function () {
// 获取所有审批的checked值并更新
const this_status = parseInt($(this).val());
const this_code = $(this).data('code');
const spt = sp_status_list[this_status];
$(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
// 拼接post json
const prop = {
code: this_code,
status: this_status
};
const _self = $(this);
postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
if (this_status === sp_status.sqspr) {
_self.parents('.form-group').siblings('.lc-show').html('');
} else if (this_status === sp_status.gdspl) {
const flow = sp_lc.find(x => { return x.code === this_code; });
flow.auditGroupList = data.auditList;
flow.groupList = data.groupList;
let addhtml = auditUtils.getGroupHtml(flow, this_code);
addhtml += '\n';
addhtml += auditUtils.getgdsplHtml(flow, this_code);
addhtml += '
\n';
_self.parents('.form-group').siblings('.lc-show').html(addhtml);
} else if (this_status === sp_status.gdzs) {
let addhtml = '\n' +
' - \n' +
' 授权审批人\n' +
' \n' +
' \n' +
' \n' +
'
\n';
addhtml += data.auditList ? makeAudit(data.auditList) : makeSelectAudit(this_code);
addhtml += '
\n';
_self.parents('.form-group').siblings('.lc-show').html(addhtml);
}
if(this_code === 'stage') {
if(this_status === sp_status.gdspl) {
$('#stage_cooperation').show();
} else {
$('#stage_cooperation').hide();
}
}
});
});
// 选中审批人
$('body').on('click', 'div[id$="_dropdownMenu"] dl dd', function () {
const id = parseInt($(this).data('id'));
if (!id) return;
let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
if (!this_code) this_code = $(this).parents('.dropdown').data('code');
const user = _.find(accountList, function (item) {
return item.id === id;
});
if (this_code === 'audit-ass') {
auditAss.setAuditAssist(user);
} else {
const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
if (this_status === sp_status.gdspl) {
// 判断是否已存在审批人
const aid_num = $(this).parents('ul').find('.remove-audit').length;
for (let i = 0; i < aid_num; i++) {
const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
if (aid === id) {
toastr.warning('该审核人已存在,请勿重复添加');
return;
}
}
}
const prop = {
status: this_status,
code: sp_type[this_code],
audit_id: id,
type: 'add',
};
if (this_status === sp_status.gdspl) {
prop.audit_type = parseInt($(this).parents('li').find('select[class*="audit-type-key"]')[0].value);
prop.audit_order = $(this).parents('li').index() + 1;
}
const _self = $(this);
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
if (this_status === sp_status.gdspl) {
const auditGroup = auditUtils.addAudit(this_code, { audit_id: data.audit_id, name: user.name, audit_type: data.audit_type, audit_order: data.audit_order }, prop.audit_order - 1);
if (_self.parents('ul').find('.add-audit').length === 0) {
const flow = sp_lc.find(x => { return x.code === this_code; });
const addGroupHtml = this_code === 'change' && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
` 存为审批组\n` : '';
_self.parents('ul').append('\n' +
' 添加流程\n' + addGroupHtml +
' ');
}
_self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, prop.audit_order));
} else {
_self.parents('.spr-span').html('\n' +
''+ user.name +' \n' +
' \n' +
' \n' +
' ' +
' \n');
}
});
}
});
// 移除审批人
$('body').on('click', '.remove-audit', function () {
const id = parseInt($(this).data('id'));
const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
const prop = {
status: this_status,
code: sp_type[this_code],
audit_id: id,
type: 'del',
};
const _self = $(this);
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
if (this_status === sp_status.gdspl) {
const index = _self.parents('li').index();
const auditGroup = auditUtils.removeAudit(this_code, id, index);
if (auditGroup) {
_self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, index + 1));
} else {
const _selflc = _self.parents('.lc-show');
_self.parents('li').remove();
const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
if (aid_num === 0) {
_selflc.children('ul').html(auditUtils.getAuditGroupHtml(this_code, [], 1));
} else {
for (let i = 0; i < aid_num; i++) {
_selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
}
}
}
} else if (this_status === sp_status.gdzs) {
let addhtml = '\n' +
' - \n' +
' 授权审批人\n' +
' \n' +
' \n' +
' \n' +
'
\n';
addhtml += makeSelectAudit(this_code);
addhtml += '
\n';
_self.parents('.lc-show').html(addhtml);
}
})
});
// 固定审批流-添加流程
$('body').on('click', '.add-audit', function () {
const num = $(this).parents('ul').children('li').length;
const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
//const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
const addhtml = auditUtils.getAuditGroupHtml(this_code, [], num);
$(this).parents('ul').append(addhtml);
$(this).parents('li').remove();
});
sortCategory2();
initTenderTree2();
$('body').on('click', '.set-otherTender', function () {
const this_code = $(this).data('code');
const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
const lis = $(this).siblings('.lc-show').find('li');
const auditList = [], aidList = [];
lis.each((i, li) => {
const removes = $(li).find('.remove-audit');
if (removes.length === 0) return;
const select = $(li).find('select[class*="audit-type-key"]');
const audit_type = select.length > 0 ? parseInt(select.val()) : 1;
for (const remove of removes) {
auditList.push({ audit_id: parseInt(remove.getAttribute('data-id')), audit_type, audit_order: i + 1 });
aidList.push(parseInt(remove.getAttribute('data-id')));
}
});
const html = getTenderTreeHtml2(this_code, this_status, aidList);
$('#shenpi-name').text($(this).data('name'));
$('#shenpi_code').val(this_code);
$('#shenpi_status').val(this_status);
$('#shenpi_auditors').val(JSON.stringify(auditList));
$('#tender-list').html(html);
$('#search-audit').val('');
$('#search-result').text('0/0');
$('#up-search').attr('disabled', true);
$('#down-search').attr('disabled', true);
setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
});
$('#save-other-tender').click(function () {
$(this).attr('disabled', true);
const num = $('#tender-list input:checked').length;
if (num < 2) {
toastr.warning('请选择需要设置审批同步的标段');
$(this).removeAttr('disabled');
return;
}
const data = {
type: 'copy2ot',
status: parseInt($('#shenpi_status').val()),
code: $('#shenpi_code').val(),
};
if(data.status !== shenpi_status.gdspl) {
data.auditList = JSON.parse($('#shenpi_auditors').val());
}
// 获取已选中的标段
const tenderList = [];
for (let i = 0; i < num; i++) {
const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
if (tid !== cur_tenderid) {
tenderList.push(tid);
}
}
data.tidList = tenderList.join(',');
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
toastr.success('设置成功');
setTimeout(function () {
window.location.reload();
}, 1000)
})
});
$('body').on('click', '.set-otherShenpi', function () {
let canSetOther = true;
const this_code = $(this).data('code');
// if (['stage', 'change'].indexOf(this_code) !== -1) {
// const select = $(this).siblings('.lc-show').find('select[class*="audit-type-key"]');
// select.each((i, s) => {
// if (s.value !== '1') canSetOther = false;
// });
// }
// if (!canSetOther) {
// toastr.warning('该流程含有会签或签,不可同步至其他流程');
// $('#batch2').modal('hide');
// return;
// }
const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
const copyFlow = [];
const flow = $('li.d-flex', $(this).siblings('.lc-show'));
for (const f of flow) {
const audit_type = $('select', f).val() || 1;
const auditors = $('.remove-audit', f);
if (auditors.length === 0) continue;
const aid = [];
for (const a of auditors) {
aid.push(a.getAttribute('data-id'));
}
copyFlow.push(`${audit_type}:${aid.join(',')}`);
}
const html = getShenpiHtml(this_code);
$('#shenpi-name2').text($(this).data('name'));
$('#shenpi_code2').val(this_code);
$('#shenpi_status2').val(this_status);
$('#shenpi_auditors2').val(copyFlow.join(';'));
$('#shenpi-list').html(html);
setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
$('#batch2').modal('show');
});
$('#save-other-shenpi').click(function () {
$(this).attr('disabled', true);
const num = $('#shenpi-list input:checked').length;
if (num < 1) {
toastr.warning('请选择需要设置审批同步的流程');
$(this).removeAttr('disabled');
return;
}
const data = {
type: 'copy2os',
status: parseInt($('#shenpi_status2').val()),
code: $('#shenpi_code2').val(),
};
if(data.status !== shenpi_status.gdspl) {
data.flowList = $('#shenpi_auditors2').val();
}
// 获取已选中的标段
const shenpiList = [];
for (let i = 0; i < num; i++) {
const code = $('#shenpi-list input:checked').eq(i).data('code');
shenpiList.push(code);
}
data.shenpiList = shenpiList.join(',');
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
toastr.success('设置成功');
setTimeout(function () {
window.location.reload();
}, 1000)
})
});
// 设置会签、或签
$('body').on('change', 'select[class*="audit-type-key"]', function() {
const removes = $(this).parents('.d-flex').find('.remove-audit');
if (removes.length === 0) return;
const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
const ids = [];
const liParent = $(this).parents('li');
removes.each((i, r) => { ids.push(parseInt(r.getAttribute('data-id'))); });
const prop = {
status: this_status,
code: sp_type[this_code],
audit_id: ids,
audit_type: parseInt(this.value),
type: 'audit-type',
};
if (prop.audit_type === auditType.key.common && ids.length > 1) {
toastr.warning('设置个人审批前请先删除多余的审批人');
this.value = this.getAttribute('data-type');
return;
}
const _self = this;
postData('/tender/'+ cur_tenderid +'/shenpi/audit/save', prop, function () {
_self.setAttribute('data-type', _self.value);
const auditGroup = auditUtils.setAuditType(this_code, prop.audit_type, liParent.index());
liParent.html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, liParent.index() + 1));
});
});
class AuditAss {
constructor() {
this.spread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
this.sheet = this.spread.getActiveSheet();
this.tree = createNewPathTree('base', {
id: 'ledger_id',
pid: 'ledger_pid',
order: 'order',
level: 'level',
rootId: -1,
});
this.spreadSetting = {
cols: [
{title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree'},
{title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
{title: '协同人', colSpan: '1', rowSpan: '2', field: 'ass_name', hAlign: 1, width: 100, formatter: '@'},
],
emptyRows: 0,
headRows: 1,
headRowHeight: [25, 25],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
readOnly: true,
localCache: {
key: 'ledger-cooperation',
colWidth: true,
}
};
sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
const self = this;
SpreadJsObj.addDeleteBind(this.spread, function() { return; });
SpreadJsObj.selChangedRefreshBackColor(this.sheet);
this.spread.bind(spreadNS.Events.SelectionChanged, function() {
self.refreshOperate();
});
$('#stage_audits').change(function () {
self.uid = $(this).val();
});
// 多人协同
$('#cooperation').on('shown.bs.modal', function () {
// 执行一些动作...
// 更新新的多人协同表格信息
const newUidList = [];
$('.stage_div ul li').each(function (k, v) {
const audit_type = parseInt($(v).find('select').val());
if (audit_type !== auditType.key.common) return;
const uid = $(v).find('button').eq(0).data('id');
if(uid) newUidList.push({ order: k + 1, audit_id: uid });
});
const yb = _.find(accountList, { 'id': cur_uid });
let newhtml = '';
if(newUidList.length > 0) {
for (const id of newUidList) {
const audit = _.find(accountList, { 'id': id.audit_id });
newhtml += '';
}
}
$('#stage_audits').html(newhtml);
self.uid = cur_uid;
self.initLedgerTree(cur_uid);
});
$('#del-audit-ass').click(function () {
self.setAuditAssist();
});
$('body').on('click', 'button[asid]', function () {
self.removeAuditAss(parseInt(this.getAttribute('asid')));
});
}
set uid(id) {
this._uid = parseInt(id);
this._refreshAss();
}
get uid() {
return this._uid;
}
_refreshAssTable(){
$('#stage_audit').text($("#stage_audits option:selected").text());
const html = [];
for (const sa of this.showAssList) {
const lid = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
html.push(`${sa.name} | ${sa.company} | ${lid.length} |
`);
}
$('#coo_table').html(html.join(''));
}
_refreshAssTree() {
const ledgerAss = {};
for (const sa of this.showAssList) {
const ledger = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
ledger.forEach(l => { ledgerAss[l] = sa; });
}
for (const n of this.tree.nodes) {
const la = ledgerAss[n.ledger_id];
n.ass_audit_id = la ? la.ass_user_id : null;
n.ass_name = la ? la.name : '';
}
SpreadJsObj.reloadColData(this.sheet, 2);
}
_refreshAss() {
this.showAssList = _.filter(this.assList, { 'user_id': parseInt(this.uid) });
this._refreshAssTable();
this._refreshAssTree();
}
initLedgerTree(uid) {
if (this.loaded) return;
this.spread.refresh();
const self = this;
postData('/tender/' + cur_tenderid + '/shenpi/ass/load', {}, function (data) {
self.loaded = true;
self.assList = data.auditAssList;
self.tree.loadDatas(data.ledgerList);
SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
self.uid = uid;
self.refreshOperate();
}, null, true);
}
loadPostData(data) {
if (data.add) {
this.assList.push(data.add);
}
if (data.del) {
this.assList.splice(this.assList.findIndex(x => { return x.id === data.del.id }), 1);
}
if (data.update) {
for (const d of data.update) {
const od = this.assList.find(x => { return x.id === d.id });
if (!od) continue;
od.ass_ledger_id = d.ass_ledger_id;
}
}
this._refreshAss();
}
setAuditAssist(assist){
const node = SpreadJsObj.getSelectObject(this.sheet);
if (assist && node.ass_audit_id === assist.id) return;
if (assist && assist.id === this.uid) {
toastr.warning('请勿添加本人');
return;
}
const self = this;
const data = { type: 'audit-ass'};
if (assist) {
const newAss = this.showAssList.find(x => { return x.ass_user_id === assist.id; });
if (!newAss) {
data.add = { user_id: this.uid, ass_user_id: assist.id, name: assist.name, company: assist.company, role: assist.role, ass_ledger_id: node.ledger_id + '' };
} else {
data.update = [{ id: newAss.id, ass_ledger_id: newAss.ass_ledger_id + ',' + node.ledger_id}];
}
}
if (node.ass_audit_id) {
const orgAss = this.showAssList.find(x => { return x.ass_user_id === node.ass_audit_id; });
const rela_lid = orgAss.ass_ledger_id ? orgAss.ass_ledger_id.split(',') : [];
rela_lid.splice(rela_lid.indexOf(node.ledger_id + ''), 1);
if (rela_lid.length === 0) {
data.del = { id: orgAss.id };
} else {
if (!data.update) data.update = [];
data.update.push({ id: orgAss.id, ass_ledger_id: rela_lid.join(',')});
}
}
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
self.loadPostData(result);
self.refreshOperate();
});
}
removeAuditAss(assistId) {
const self = this;
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', { type: 'audit-ass', del: { id: assistId } }, function (result) {
self.loadPostData(result);
self.refreshOperate();
});
}
refreshOperate() {
const node = SpreadJsObj.getSelectObject(this.sheet);
if (node && node.ass_audit_id) {
$('#del-audit-ass').show();
$('#audit-ass_dropdownMenuButton')[0].innerHTML = '替换协同人';
} else {
$('#del-audit-ass').hide();
$('#audit-ass_dropdownMenuButton')[0].innerHTML = '添加协同人';
}
}
}
const auditAss = new AuditAss();
class AuditUnion {
constructor() {
this.spread = SpreadJsObj.createNewSpread($('#union-spread')[0]);
this.sheet = this.spread.getActiveSheet();
this.tree = createNewPathTree('base', {
id: 'ledger_id',
pid: 'ledger_pid',
order: 'order',
level: 'level',
rootId: -1,
});
this.selectUnion = [{ value: 0, text: '' }];
this.spreadSetting = {
cols: [
{title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree', readOnly: true },
{title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true },
{title: '协同人', colSpan: '1', rowSpan: '1', field: 'audit_id', hAlign: 1, width: 100, cellType: 'customizeCombo', comboItems: this.selectUnion },
],
emptyRows: 0,
headRows: 1,
headRowHeight: [32],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
};
sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
const self = this;
SpreadJsObj.addDeleteBind(this.spread, function() { return; });
SpreadJsObj.selChangedRefreshBackColor(this.sheet);
this.spread.bind(spreadNS.Events.EditEnded, function(e, info) {
const node = SpreadJsObj.getSelectObject(info.sheet);
if (!node) return;
const refreshAuditId = [];
if (node.audit_id) refreshAuditId.push(node.audit_id);
const col = info.sheet.zh_setting.cols[info.col];
node[col.field] = info.editingText;
if (node.audit_id) refreshAuditId.push(node.audit_id);
self.refreshUnionCount(refreshAuditId);
});
$('#union').on('shown.bs.modal', function() {
self.spread.refresh();
});
$('#union-ok').click(function() {
const data = self.getUnionAuditLedgerData();
postData(`/tender/${cur_tenderid}/shenpi/union/save`, data, function(result) {
$('#union').modal('hide');
});
});
$('body').on('click', '[name=clear-union]', function() {
const aid = parseInt(this.getAttribute('aid'));
for (const node of self.tree.nodes) {
if (node.audit_id === aid) node.audit_id = 0;
}
SpreadJsObj.reloadColData(self.sheet, 2);
self.refreshUnionCount(aid);
});
}
_refreshUnionTree() {
const ledgerAss = {};
for (const a of this.auditors) {
a.lid.forEach(l => { ledgerAss[l] = a; });
}
for (const n of this.tree.nodes) {
const la = ledgerAss[n.ledger_id];
n.audit_id = la ? la.audit_id : 0;
n.audit_name = la ? la.name : '';
}
SpreadJsObj.reloadColData(this.sheet, 2);
}
setUnionAuditors(auditors) {
this.auditors = auditors;
this.selectUnion.length = 1;
const html = [];
for (const auditor of auditors) {
auditor.lid = auditor.audit_ledger_id ? auditor.audit_ledger_id.split(',') : [];
html.push(`${auditor.name} | ${auditor.company} | ${auditor.lid.length} |
`);
this.selectUnion.push({ value: auditor.audit_id, text: auditor.name });
}
$('#union_table').html(html.join(''));
this._refreshUnionTree();
}
refreshUnionCount(auditId) {
const auditIds = auditId instanceof Array ? auditId : [auditId];
for (const aid of auditIds) {
const unionNodes = this.tree.nodes.filter(x => { return x.audit_id === aid; });
$(`span[aid=${aid}]`).html(unionNodes.length);
}
}
loadUnionData(sp_type, audit_order) {
const data = { sp_type, audit_order };
if (!this.loaded) data.ledger = 1;
const self = this;
postData(`/tender/${cur_tenderid}/shenpi/union/load`, data, function(result) {
self.loaded = true;
if (result.ledgerList) {
self.tree.loadDatas(result.ledgerList);
SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
}
self.setUnionAuditors(result.unionAuditors);
if (self.auditors.length > 0) {
$('#union').modal('show');
} else {
toastr.warning(`${audit_order}审未添加任何协同人,请先添加协同人再分配协同台账`);
}
});
}
getUnionAuditLedgerData() {
this.auditors.forEach(a => { a.lid = []; });
for (const node of this.tree.nodes) {
if (node.audit_id > 0) {
const relaAudit = this.auditors.find(x => { return x.audit_id === node.audit_id; });
if (relaAudit) relaAudit.lid.push(node.ledger_id);
}
}
return this.auditors.map(a => {
return { id: a.id, audit_ledger_id: a.lid.join(',') };
});
}
}
const auditUnion = new AuditUnion();
$('body').on('click', '[name=union-set]', function() {
auditUnion.loadUnionData(this.getAttribute('sp_type'), this.getAttribute('audit_order'));
});
$.subMenu({
menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
key: 'menu.1.0.0',
miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
callback: function (info) {
if (info.mini) {
$('.panel-title').addClass('fluid');
$('#sub-menu').removeClass('panel-sidebar');
} else {
$('.panel-title').removeClass('fluid');
$('#sub-menu').addClass('panel-sidebar');
}
autoFlashHeight();
}
});
let timer2 = null;
let oldSearchVal2 = null;
$('body').on('input propertychange', '#batch input[name="audit-name"]', function(e) {
oldSearchVal2 = e.target.value;
timer2 && clearTimeout(timer2);
timer2 = setTimeout(() => {
const newVal = $(this).val();
const resultLength = $('#tender-list').find('.result').length;
if (resultLength > 0) {
let content = $('#tender-list').html();
const replaceStr = $('#tender-list').find('.result').eq(0).html();
const regExp2 = new RegExp('' + replaceStr + '', 'g');
content = content.replace(regExp2, replaceStr);
const regExp3 = new RegExp('' + replaceStr + '', 'g');
content = content.replace(regExp3, replaceStr);
$('#tender-list').html(content);
}
$('#search-result').text('0/0');
$('#up-search').attr('disabled', true);
$('#down-search').attr('disabled', true);
if (newVal && newVal === oldSearchVal2) {
const regExp = new RegExp(newVal, 'g');
for (let i = 0; i < $('#tender-list tr').length; i++) {
if (_.includes($('#tender-list tr').eq(i).children('td').eq(2).html(), newVal)) {
$('#tender-list tr').eq(i).children('td').eq(2).html($('#tender-list tr').eq(i).children('td').eq(2).html().replace(regExp, '' + newVal + ''))
}
}
const resultLength2 = $('#tender-list').find('.result').length;
if (resultLength2 > 0) {
$('#tender-list').find('.result').eq(0).css('background', 'orange');
$('#search-result').text('1/' + resultLength2);
$('#up-search').attr('disabled', false);
$('#down-search').attr('disabled', false);
}
}
if($('#tender-list').find('.result').length > 0) {
const X = $('#tender-list').find('.result').eq(0).offset().top;
$('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
}
}, 400);
});
$('#up-search').on('click', function () {
const cur = parseInt($('#search-result').text().split('/')[0]);
const total = parseInt($('#search-result').text().split('/')[1]);
const now = cur - 1 !== 0 ? cur - 1: total;
$('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
$('#tender-list').find('.result').eq(now-1).css('background', 'orange');
// $('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html().replace('', ''))
// $('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html().replace('', ''))
$('#search-result').text(now + '/' + total);
const X = $('#tender-list').find('.result').eq(now-1).offset().top;
$('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
});
$('#down-search').on('click', function () {
const cur = parseInt($('#search-result').text().split('/')[0]);
const total = parseInt($('#search-result').text().split('/')[1]);
const now = cur + 1 > total ? 1: cur + 1;
$('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
$('#tender-list').find('.result').eq(now-1).css('background', 'orange');
// $('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html().replace('', ''))
// $('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html().replace('', ''))
$('#search-result').text(now + '/' + total);
const X = $('#tender-list').find('.result').eq(now-1).offset().top;
$('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() -30);
});
// 审批组
$('body').on('click', '.show-spzsave', function () {
const this_code = $(this).attr('data-code');
const groupId = $(this).attr('data-group') || null;
const flow = sp_lc.find(x => { return x.code === this_code; });
$('#save-code').val(this_code);
const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
if (group) {
$('#save-group-id').val(group.id);
$('#spzsave input[name="group_name"]').val(group.name);
$('#show-delete-group-btn').show();
} else {
$('#save-group-id').val('');
$('#spzsave input[name="group_name"]').val('');
$('#show-delete-group-btn').hide();
}
if (this_code === 'change') {
if (group) {
$('#show-change-type input').each(function () {
if (group.change_type[$(this).data('type')]) {
$(this).prop('checked', true);
} else {
$(this).prop('checked', false);
}
});
} else {
$('#show-change-type input').each(function () {
$(this).prop('checked', false);
});
$('#show-change-type input[data-type="change"]').prop('checked', true);
}
$('#show-change-type input').removeAttr('disabled');
$('#show-change-type').show();
} else {
$('#show-change-type input').attr('disabled', true);
$('#show-change-type').hide();
}
$('#spzsave').modal('show');
});
$('#save-group-btn').click(function () {
const name = _.trim($('#spzsave input[name="group_name"]').val());
if (!name) {
toastr.error('审批组名称不能为空');
return false;
}
if (name.length > 50) {
toastr.error('审批组名称不能超过50个字符');
return false;
}
const code = $('#save-code').val();
const prop = {
type: 'save-group',
name,
code,
}
const groupId = $('#save-group-id').val();
const flow = sp_lc.find(x => { return x.code === code; });
if (flow.groupList && flow.groupList.length >= 0 && _.findIndex(flow.groupList, function (item) {
return item.name === name && item.id !== parseInt(groupId);
}) !== -1) {
toastr.error('审批组名称已存在, 请更改名称');
return false;
}
if (groupId) {
const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
if (!group) {
toastr.error('审批组不存在');
return false;
}
prop.groupId = group.id;
}
if (code === 'change') {
const change_type = {};
let change_flag = false;
$('#show-change-type input').each(function () {
change_type[$(this).data('type')] = $(this).prop('checked');
if ($(this).prop('checked')) {
change_flag = true;
}
});
if (!change_flag) {
toastr.error('请至少选择一种变更显示模块');
return false;
}
prop.change_type = change_type;
}
console.log(prop);
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
flow.auditGroupList = data.group.auditGroupList || [];
if (groupId) {
const index = flow.groupList.findIndex(x => { return x.id === parseInt(groupId); });
flow.groupList[index] = data.group;
} else {
if (!flow.groupList) flow.groupList = [];
for (const g of flow.groupList) {
g.is_select = 0;
}
flow.groupList.push(data.group);
}
// 配置页面
let addhtml = auditUtils.getGroupHtml(flow, code);
addhtml += '\n';
addhtml += auditUtils.getgdsplHtml(flow, code);
addhtml += '
\n';
$('.' + code + '_div').children('.lc-show').html(addhtml);
$('#spzsave').modal('hide');
});
});
// 切换审批组
$('body').on('change', '.group-list', function () {
const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
const flow = sp_lc.find(x => { return x.code === this_code; });
const groupId = parseInt($(this).val());
const _self = $(this);
const prop = {
type: 'change-group',
groupId,
}
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
flow.groupList.forEach(function (item) {
item.is_select = 0;
});
const group = flow.groupList.find(x => { return x.id === groupId; });
group.is_select = 1;
flow.auditGroupList = group.auditGroupList;
const addhtml = auditUtils.getgdsplHtml(flow, this_code);
_self.parents('.lc-show').children('ul').html(addhtml);
_self.parents('.lc-show').find('.edit-spzsave').attr('data-group', groupId);
});
});
$('#show-delete-group-btn').click(function () {
const code = $('#save-code').val();
const groupId = $('#save-group-id').val();
const flow = sp_lc.find(x => { return x.code === code; });
const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
if (!group) {
toastr.error('该审批组不存在');
return false;
}
$('#delete-group-name').text(group.name);
$('#delete-group-id').val(group.id);
$('#delete-code').val(code);
$('#spzsave').modal('hide');
$('#spzdelete').modal('show');
});
$('#delete-group-btn').click(function () {
const code = $('#delete-code').val();
const groupId = $('#delete-group-id').val();
const flow = sp_lc.find(x => { return x.code === code; });
const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
if (!group) {
toastr.error('该审批组不存在');
return false;
}
const prop = {
type: 'delete-group',
groupId: group.id,
}
console.log(prop);
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
// const flow = findSplc(code);
const index = flow.groupList.findIndex(x => { return x.id === group.id; });
flow.groupList.splice(index, 1);
flow.auditGroupList = flow.groupList.length > 0 ? flow.groupList[0].auditGroupList : [];
if (flow.groupList.length > 0) flow.groupList[0].is_select = 1;
// 配置页面
let addhtml = auditUtils.getGroupHtml(flow, code);
addhtml += '\n';
addhtml += auditUtils.getgdsplHtml(flow, code);
addhtml += '
\n';
$('.' + code + '_div').children('.lc-show').html(addhtml);
$('#spzdelete').modal('hide');
});
});
});
// 审批流程-审批人html 生成
function makeAudit(audit, i = '终') {
return '\n' +
' '+ i +'审\n' +
' \n' +
' \n' +
' '+ audit.name +' \n' +
' \n' +
' \n' +
' ' +
// ' \n' +
' \n' +
' ';
}
// 审批流程-选择审批人html 生成
function makeSelectAudit(code, i = '终') {
let divhtml = '';
accountGroup.forEach((group, idx) => {
let didivhtml = '';
if(group) {
group.groupList.forEach(item => {
didivhtml += (item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1)) ? '\n' +
'' + item.name + '' + item.mobile + '
\n' +
' ' + item.role + '\n' +
' \n' : '';
});
divhtml += ' ' + group.groupName + '\n' +
' \n' + didivhtml +
'
\n';
}
});
let html = '\n' +
' ' + i + '审\n' +
' \n' +
' \n' +
' \n' +
' \n' +
' \n' +
'
\n' +
' \n' +
' \n' +
' ';
return html;
}