'use strict';
/**
*
*
* @author Ellisran
* @date 2020/10/09
* @version
*/
const tenderTree = [];
let parentId = 0;
// 查询方法
function findNode (key, value, arr) {
for (const a of arr) {
if (a[key] && a[key] === value) {
return a;
}
}
}
// 初始化TenderTree数据
function initTenderTree () {
const levelCategory = category.filter(function (c) {
return c.level && c.level > 0;
});
function findCategoryNode(cid, value, array) {
for (const a of array) {
if (a.cid === cid && a.vid === value) {
return a;
}
}
}
function getCategoryNode(category, value, parent, i = null) {
const array = parent ? parent.children : tenderTree;
let cate = findCategoryNode(category.id, value, array);
if (!cate) {
const cateValue = findNode('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: ++parentId,
};
array.push(cate);
}
return cate;
}
function loadTenderCategory (tender) {
let tenderCategory = null;
for (const [index,lc] of levelCategory.entries()) {
const tenderCate = findNode('cid', lc.id, tender.category);
if (tenderCate) {
tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
} else {
if (index === 0 && tender.category) {
for (const [i,c] of tender.category.entries()) {
const cate = findNode('id', c.cid, category);
tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
}
}
return tenderCategory;
}
}
return tenderCategory;
}
function calculateTender(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);
}
}
tenderTree.splice(0, tenderTree.length);
for (const t of tenders) {
calculateTender(t);
t.valid = true;
delete t.level;
if (t.category && levelCategory.length > 0) {
const parent = loadTenderCategory(t);
if (parent) {
t.level = parent.level + 1;
parent.children.push(t);
} else {
tenderTree.push(t);
}
} else {
tenderTree.push(t);
}
}
}
function recursiveGetTenderNodeHtml (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) {
let auditList = [];
let tender_status = 1;
if(cur_tenderid === node.id) {
html.push(sp_status_list[this_status].name);
auditList = aidList;
tender_status = this_status;
} else {
html.push(sp_status_list[node.shenpiInfo[this_code]].name);
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(' | ');
html.push('');
if (!node.cid) {
html.push('');
}
html.push(' | ');
html.push('
');
if (node.children) {
for (const c of node.children) {
html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id, this_code, this_status, aidList));
}
}
return html.join('');
}
// 根据TenderTree数据获取Html代码
function getTenderTreeHtml (this_code, this_status, aidList = []) {
if (tenderTree.length > 0) {
const html = [];
html.push('');
html.push('', '');
html.push('名称 | ');
html.push('审批流程 | ');
html.push('选择 | ');
html.push('
', '');
parentId = 0;
for (const t of tenderTree) {
html.push(recursiveGetTenderNodeHtml(t, tenderTree, '', 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 () {
let timer = null;
let oldSearchVal = null;
const needYB = ['ledger', 'revise', 'change'];
$('body').on('input propertychange', '.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', '.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;
});
// 更改审批流程状态
$('.form-check input').on('change', 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) {
let addhtml = '\n';
if (data.length !== 0) {
for(const [i, audit] of data.entries()) {
addhtml += makeAudit(audit, transFormToChinese(i+1));
}
addhtml += '- 添加流程
';
} else {
addhtml += makeSelectAudit(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 ? makeAudit(data) : makeSelectAudit(this_code);
addhtml += '
\n';
_self.parents('.form-group').siblings('.lc-show').html(addhtml);
}
});
});
// 选中审批人
$('body').on('click', 'dl dd', function () {
const id = parseInt($(this).data('id'));
if (id) {
const user = _.find(accountList, function (item) {
return item.id === 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');
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',
};
const _self = $(this);
postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
if (this_status === sp_status.gdspl) {
_self.parents('ul').append(' 添加流程');
}
_self.parents('.spr-span').html('\n' +
''+ user.name +' ');
});
}
});
// 移除审批人
$('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 _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) {
let addhtml = '\n';
addhtml += makeSelectAudit(this_code, '一');
addhtml += '
\n';
_selflc.html(addhtml);
} 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));
$(this).parents('ul').append(addhtml);
$(this).parents('li').remove();
});
// 审批流程-审批人html 生成
function makeAudit(audit, i = '终') {
return '\n' +
' '+ i +'审\n' +
' \n' +
' \n' +
' '+ audit.name +' \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;
}
initTenderTree();
$('.set-otherTender').on('click', function () {
const this_code = $(this).data('code');
const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
const aid_num = $(this).siblings('.lc-show').children('ul').find('.remove-audit').length;
const aidList = [];
for (let i = 0; i < aid_num; i++) {
const aid = parseInt($(this).siblings('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
aidList.push(aid);
}
const html = getTenderTreeHtml(this_code, this_status, aidList);
$('#shenpi-name').text($(this).data('name'));
$('#shenpi_code').val(this_code);
$('#shenpi_status').val(this_status);
$('#shenpi_auditors').val(aidList.join(','));
$('#tender-list').html(html);
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('请选择需要设置审批同步的标段');
return;
}
const data = {
type: 'copy2ot',
status: parseInt($('#shenpi_status').val()),
code: $('#shenpi_code').val(),
};
if(data.status !== shenpi_status.gdspl) {
data.aidList = $('#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)
})
});
$('.set-otherShenpi').on('click', function () {
const this_code = $(this).data('code');
const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
const aid_num = $(this).siblings('.lc-show').children('ul').find('.remove-audit').length;
const aidList = [];
for (let i = 0; i < aid_num; i++) {
const aid = parseInt($(this).siblings('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
aidList.push(aid);
}
const html = getShenpiHtml(this_code);
$('#shenpi-name2').text($(this).data('name'));
$('#shenpi_code2').val(this_code);
$('#shenpi_status2').val(this_status);
$('#shenpi_auditors2').val(aidList.join(','));
$('#shenpi-list').html(html);
setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
});
$('#save-other-shenpi').click(function () {
$(this).attr('disabled', true);
const num = $('#shenpi-list input:checked').length;
if (num < 1) {
toastr.warning('请选择需要设置审批同步的流程');
return;
}
const data = {
type: 'copy2os',
status: parseInt($('#shenpi_status2').val()),
code: $('#shenpi_code2').val(),
};
if(data.status !== shenpi_status.gdspl) {
data.aidList = $('#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)
})
});
});