123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967 |
- '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,
- sort: cateValue.sort,
- };
- 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);
- }
- }
- sortTenderTree();
- }
- function recursiveGetTenderNodeHtml (node, arr, pid, this_code, this_status, aidList = []) {
- const html = [];
- html.push('<tr pid="' + pid + '">');
- // 名称
- html.push('<td class="in-' + node.level + '">');
- if (node.cid) {
- html.push('<i class="fa fa-folder-o"></i> ', node.name);
- } else {
- html.push('<span class="text-muted mr-2">');
- html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
- html.push('</span>');
- //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
- html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
- }
- html.push('</td>');
- // 创建人
- // html.push('<td>', sp_status_list[node.shenpiInfo[shenpi_type]].name, '</td>');
- html.push('<td>');
- 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 {
- console.log(node);
- 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('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
- 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
- }
- }
- html.push('</td>');
- html.push('<td>');
- if (!node.cid) {
- html.push('<input data-tid="'+ node.id +'" type="checkbox"'+ (cur_tenderid === node.id ? ' checked disabled' : '') +'>');
- }
- html.push('</td>');
- html.push('</tr>');
- 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('<table class="table table-hover table-bordered">');
- html.push('<thead>', '<tr>');
- html.push('<th>名称</th>');
- html.push('<th width="100">审批流程</th>');
- html.push('<th width="40">选择</th>');
- html.push('</tr>', '</thead>');
- parentId = 0;
- for (const t of tenderTree) {
- html.push(recursiveGetTenderNodeHtml(t, tenderTree, '', this_code, this_status, aidList));
- }
- html.push('</table>');
- return html.join('');
- } else {
- return EmptyTenderHtml.join('');
- }
- }
- function getShenpiHtml (this_code) {
- const html = [];
- html.push('<table class="table table-hover table-bordered">');
- html.push('<thead>', '<tr>');
- html.push('<th>名称</th>');
- html.push('<th width="100">审批流程</th>');
- html.push('<th width="40">选择</th>');
- html.push('</tr>', '</thead>');
- for (const sp of sp_lc) {
- html.push('<tr>');
- html.push('<td>', sp.name, '</td>');
- html.push('<td>');
- const this_status = parseInt($('.' + sp.code + '_div').children('.lc-show').siblings('.form-group').find('input:checked').val());
- html.push(sp_status_list[this_status].name);
- if(this_status !== sp_status.sqspr) {
- const nameList = [];
- const aid_num = $('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').length;
- const aidList = [];
- for (let i = 0; i < aid_num; i++) {
- const aid = parseInt($('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
- aidList.push(aid);
- }
- if(aidList.length > 0) {
- for (const uid of aidList) {
- const user = _.find(accountList, { id: uid });
- nameList.push(user.name);
- }
- }
- html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
- 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
- }
- html.push('</td>');
- html.push('<td>', this_code !== sp.code ? '<input type="checkbox" data-code="'+ sp.code +'">' : '', '</td>');
- html.push('</tr>');
- }
- html.push('</table>');
- 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 += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
- <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
- class="ml-auto">${item.mobile || ''}</span></p>
- <span class="text-muted">${item.role || ''}</span>
- </dd>`
- });
- $('#' + 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 += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
- </a> ${group.groupName}</dt>
- <div class="dd-content" data-toggleid="${idx}">`;
- group.groupList.forEach(item => {
- if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
- html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
- <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
- class="ml-auto">${item.mobile || ''}</span></p>
- <span class="text-muted">${item.role || ''}</span>
- </dd>`;
- }
- });
- html += '</div>';
- });
- $('#' + 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) {
- $('#stage_cooperation').hide();
- if (this_status === sp_status.sqspr) {
- _self.parents('.form-group').siblings('.lc-show').html('');
- } else if (this_status === sp_status.gdspl) {
- let addhtml = '<ul class="list-unstyled">\n';
- if (data.length !== 0) {
- for(const [i, audit] of data.entries()) {
- addhtml += makeAudit(audit, transFormToChinese(i+1));
- }
- addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
- } else {
- addhtml += makeSelectAudit(this_code, '一');
- }
- addhtml += '</ul>\n';
- _self.parents('.form-group').siblings('.lc-show').html(addhtml);
- $('#stage_cooperation').show();
- } else if (this_status === sp_status.gdzs) {
- let addhtml = '<ul class="list-unstyled">\n' +
- ' <li class="d-flex justify-content-start mb-3">\n' +
- ' <span class="col-auto">授权审批人</span>\n' +
- ' <span class="col-7">\n' +
- ' <span class="d-inline-block"></span>\n' +
- ' </span>\n' +
- ' </li>\n';
- addhtml += data ? makeAudit(data) : makeSelectAudit(this_code);
- addhtml += '</ul>\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('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
- }
- _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
- '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ user.id +'"><i class="fa fa-remove"></i></a></span> </span>');
- });
- }
- });
- // 移除审批人
- $('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 = '<ul class="list-unstyled">\n';
- addhtml += makeSelectAudit(this_code, '一');
- addhtml += '</ul>\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 = '<ul class="list-unstyled">\n' +
- ' <li class="d-flex justify-content-start mb-3">\n' +
- ' <span class="col-auto">授权审批人</span>\n' +
- ' <span class="col-7">\n' +
- ' <span class="d-inline-block"></span>\n' +
- ' </span>\n' +
- ' </li>\n';
- addhtml += makeSelectAudit(this_code);
- addhtml += '</ul>\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 '<li class="d-flex justify-content-start mb-3">\n' +
- ' <span class="col-auto">'+ i +'审</span>\n' +
- ' <span class="col-7 spr-span">\n' +
- ' <span class="d-inline-block"></span>\n' +
- ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ audit.audit_id +'"><i class="fa fa-remove"></i></a></span> </span>\n' +
- ' </span>\n' +
- ' </li>';
- }
- // 审批流程-选择审批人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)) ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
- '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
- ' class="ml-auto">' + item.mobile + '</span></p>\n' +
- ' <span class="text-muted">' + item.role + '</span>\n' +
- ' </dd>\n' : '';
- });
- divhtml += '<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="' + idx + '" data-type="hide"><i class="fa fa-plus-square"></i></a> ' + group.groupName + '</dt>\n' +
- ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
- ' </div>\n';
- }
- });
- let html = '<li class="d-flex justify-content-start mb-3">\n' +
- ' <span class="col-auto">' + i + '审</span>\n' +
- ' <span class="col-7 spr-span">\n' +
- ' <span class="d-inline-block">\n' +
- ' <div class="dropdown text-right">\n' +
- ' <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button" id="' + code + '_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
- ' 选择审批人\n' +
- ' </button>\n' +
- ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
- ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
- ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
- ' <dl class="list-unstyled book-list">\n' + divhtml +
- ' </dl>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </span>\n' +
- ' </span>\n' +
- ' </li>';
- 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)
- })
- });
- const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
- const treeSetting = {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- fullPath: 'full_path',
- };
- const ledgerTree = createNewPathTree('base', treeSetting);
- const ledgerSpreadSetting = {
- cols: [
- {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 185, formatter: '@', readOnly: true, cellType: 'tree'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 205, formatter: '@', readOnly: true},
- {title: '密码', colSpan: '1', rowSpan: '2', field: 'pwd', hAlign: 0, width: 120, formatter: '@', getValue:'getValue.pwd', readOnly: 'readOnly.pwd'},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- // readOnly: true,
- localCache: {
- key: 'ledger-bills',
- colWidth: true,
- }
- };
- const ledgerCol = {
- getValue: {
- pwd: function (data) {
- let txt = '';
- if (data.is_leaf) {
- if (data.pwd && data.pwd !== '' && data.pwd !== null) {
- txt = data.pwd;
- } else {
- txt = '设置密码';
- }
- }
- return txt;
- }
- },
- readOnly: {
- pwd: function (data) {
- return !data.is_leaf;
- },
- },
- };
- const ledgerSpreadObj = {
- setFontColor: function(row = null) {
- if(row) {
- const value = ledgerSpread.getActiveSheet().getValue(row, 2);
- if (value === '设置密码') {
- ledgerSpread.getActiveSheet().getCell(row, 2).foreColor('#007bff');
- } else {
- ledgerSpread.getActiveSheet().getCell(row, 2).foreColor('#000');
- }
- } else {
- const rowCount = ledgerSpread.getActiveSheet().getRowCount();
- for(let i = 0; i < rowCount; i++){
- const value = ledgerSpread.getActiveSheet().getValue(i, 2);
- if (value === '设置密码') {
- ledgerSpread.getActiveSheet().getCell(i, 2).foreColor('#007bff');
- } else {
- ledgerSpread.getActiveSheet().getCell(i, 2).foreColor('#000');
- }
- }
- }
- },
- setAllRightPwd: function(uid) {
- const selects = [];
- for (const l of ledgerTree.datas) {
- const coo = _.find(ledger_cooperation_list, { 'ledger_id': l.ledger_id, 'user_id': parseInt(uid) });
- if (l.pwd && !coo) {
- delete l.pwd;
- selects.push(l);
- } else if(coo) {
- l.pwd = coo.pwd;
- selects.push(l);
- }
- }
- if(selects.length > 0) {
- const refreshNode = ledgerTree.loadPostData({update: selects});
- ledgerSpreadObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
- ledgerSpreadObj.setFontColor();
- }
- },
- refreshTree: function (sheet, data) {
- SpreadJsObj.massOperationSheet(sheet, function () {
- const tree = sheet.zh_tree;
- // 处理删除
- if (data.delete) {
- data.delete.sort(function (x, y) {
- return y.deleteIndex - x.deleteIndex;
- });
- for (const d of data.delete) {
- sheet.deleteRows(d.deleteIndex, 1);
- }
- }
- // 处理新增
- if (data.create) {
- const newNodes = data.create;
- if (newNodes) {
- newNodes.sort(function (a, b) {
- return a.index - b.index;
- });
- for (const node of newNodes) {
- sheet.addRows(node.index, 1);
- SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
- }
- }
- }
- // 处理更新
- if (data.update) {
- const rows = [];
- for (const u of data.update) {
- rows.push(tree.nodes.indexOf(u));
- }
- SpreadJsObj.reLoadRowsData(sheet, rows);
- }
- // 处理展开
- if (data.expand) {
- const expanded = [];
- for (const e of data.expand) {
- if (expanded.indexOf(e) === -1) {
- const posterity = tree.getPosterity(e);
- for (const p of posterity) {
- sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
- expanded.push(p);
- }
- }
- }
- }
- });
- },
- editStarting: function (e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- const col = info.sheet.zh_setting.cols[info.col];
- ledgerSpread.getActiveSheet().getCell(info.row, 2).foreColor('#000');
- if(col.getValue(select) === '设置密码') {
- ledgerSpread.getActiveSheet().setValue(info.row, 2, '');
- }
- }
- },
- editEnded: function (e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- const col = info.sheet.zh_setting.cols[info.col];
- const validText = trimInvalidChar(info.editingText);
- const user_id = parseInt($('#stage_audits').val());
- const orgValue = select[col.field];
- const reg = /^[0-9a-zA-Z]+$/;
- if(validText !== '' && !reg.test(validText)) {
- toastr.error('不能输入非数字和字母的字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- ledgerSpreadObj.setFontColor(info.row);
- return;
- }
- if((validText === '' && orgValue === undefined) || validText == orgValue) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- ledgerSpreadObj.setFontColor(info.row);
- return;
- }
- select.pwd = validText;
- const data = {
- type: 'pwd',
- ledger_id: select.ledger_id,
- user_id,
- pwd: validText,
- };
- postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
- const lcindex = _.findIndex(ledger_cooperation_list, { ledger_id: select.ledger_id, user_id });
- if(lcindex !== -1) {
- validText === '' ? ledger_cooperation_list.splice(lcindex, 1) : ledger_cooperation_list.splice(lcindex, 1, result);
- } else {
- ledger_cooperation_list.push(result);
- }
- setLeftTable(ledgerTree.datas, ledger_cooperation_list, user_id, $('#stage_audits option:selected').text());
- const refreshNode = ledgerTree.loadPostData({update: select});
- ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
- ledgerSpreadObj.setFontColor();
- });
- }
- },
- deletePress: function (sheet) {
- return;
- },
- clipboardPasted(e, info) {
- // 禁止复制粘贴
- SpreadJsObj.reLoadSheetHeader(ledgerSpread.getActiveSheet());
- SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());
- return;
- }
- };
- sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
- SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);
- SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
- SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
- ledgerSpread.bind(spreadNS.Events.EditStarting, ledgerSpreadObj.editStarting);
- ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerSpreadObj.editEnded);
- SpreadJsObj.addDeleteBind(ledgerSpread, ledgerSpreadObj.deletePress);
- ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerSpreadObj.clipboardPasted);
- let ledger_data, ledger_cooperation_list = [];
- // 多人协同
- $('#cooperation').on('shown.bs.modal', function () {
- // 执行一些动作...
- // 更新新的多人协同表格信息
- const newUidList = [];
- $('.stage_div ul li').each(function (k, v) {
- const uid = $(v).find('a').data('id');
- if(uid) newUidList.push(uid);
- });
- const oldUidList = [];
- $('#stage_audits option').each(function (k, v) {
- const uid = parseInt($(v).val());
- if(k !== 0) oldUidList.push(uid);
- });
- if (!_.isEqual(oldUidList, newUidList)) {
- const yb = _.find(accountList, { 'id': cur_uid });
- let newhtml = '<option value="' + yb.id + '">' + yb.name + '(原报)</option>';
- if(newUidList.length > 0) {
- for (const [i,id] of newUidList.entries()) {
- const audit = _.find(accountList, { 'id': id });
- newhtml += '<option value="' + audit.id + '">' + audit.name + '(' + transFormToChinese(i+1) + '审)</option>';
- }
- }
- $('#stage_audits').html(newhtml);
- if(ledger_data) {
- setLeftTable(ledgerTree.datas, ledger_cooperation_list, cur_uid, yb.name + '(原报)');
- ledgerSpreadObj.setAllRightPwd(cur_uid);
- }
- }
- if(!ledger_data) {
- postData('/tender/' + cur_tenderid + '/shenpi/ledger/load', {}, function (data) {
- ledger_data = true;
- const ledgerList = setRightData(data.ledgerList, data.ledgerCooperationList);
- ledgerTree.loadDatas(ledgerList);
- ledger_cooperation_list = data.ledgerCooperationList;
- const yb = _.find(accountList, { 'id': cur_uid });
- setLeftTable(ledgerList, ledger_cooperation_list, cur_uid, yb.name + '(原报)');
- // treeCalc.calculateAll(ledgerTree);
- console.log(ledgerTree);
- SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
- ledgerSpreadObj.setFontColor();
- }, null, true);
- }
- ledgerSpread.refresh();
- });
- $('#stage_audits').change(function () {
- const uid = $(this).val();
- const title = $("#stage_audits option:selected").text();
- setLeftTable(ledgerTree.datas, ledger_cooperation_list, uid, title);
- ledgerSpreadObj.setAllRightPwd(uid);
- });
- $('body').on('click', '.del-pwd', function () {
- const ledger_id = parseInt($(this).data('lid'));
- const user_id = parseInt($(this).data('uid'));
- const data = {
- type: 'pwd',
- user_id,
- ledger_id,
- pwd: '',
- };
- postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
- const lcindex = _.findIndex(ledger_cooperation_list, { ledger_id, user_id });
- ledger_cooperation_list.splice(lcindex, 1);
- setLeftTable(ledgerTree.datas, ledger_cooperation_list, user_id, $('#stage_audits option:selected').text());
- const select = _.find(ledgerTree.datas, { ledger_id });
- delete select.pwd;
- const refreshNode = ledgerTree.loadPostData({update: select});
- ledgerSpreadObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
- ledgerSpreadObj.setFontColor();
- });
- });
- $('body').on('click', '.edit-pwd', function () {
- const pwd = $(this).data('pwd');
- const html = `<div class="input-group input-group-sm">
- <input type="text" class="form-control" value="${pwd}" placeholder="输入新密码" aria-describedby="button-${$(this).data('lid')}" style="width:50px">
- <div class="input-group-append" id="button-${$(this).data('lid')}">
- <button class="btn btn-outline-primary confirm-btn" data-pwd="${pwd}" data-lid="${$(this).data('lid')}" data-uid="${$(this).data('uid')}" type="button">确认</button>
- <button class="btn btn-outline-secondary cancel-btn" data-pwd="${pwd}" data-lid="${$(this).data('lid')}" data-uid="${$(this).data('uid')}" type="button">取消</button>
- </div>
- </div>`;
- $(this).parents('td').html(html);
- });
- $('body').on('click', '.cancel-btn', function () {
- const html = `<p class="mb-0">${$(this).data('pwd')}</p><a href="javascript:void(0);" data-lid="${$(this).data('lid')}" data-uid="${$(this).data('uid')}" data-pwd="${$(this).data('pwd')}" class="edit-pwd">修改</a> <a href="javascript:void(0)" data-lid="${$(this).data('lid')}" data-uid="${$(this).data('uid')}" class="del-pwd text-danger">移除</a>`;
- $(this).parents('td').html(html);
- });
- $('body').on('click', '.confirm-btn', function () {
- const validText = $(this).parents('td').find('input').val();
- const orgValue = $(this).data('pwd');
- const ledger_id = parseInt($(this).data('lid'));
- const user_id = parseInt($(this).data('uid'));
- const reg = /^[0-9a-zA-Z]+$/;
- if(!reg.test(validText)) {
- toastr.error('不能输入非数字和字母的字符');
- return;
- }
- if(validText == orgValue) {
- const html = `<p class="mb-0">${$(this).data('pwd')}</p><a href="javascript:void(0);" data-lid="${$(this).data('lid')}" data-uid="${$(this).data('uid')}" data-pwd="${$(this).data('pwd')}" class="edit-pwd">修改</a> <a href="javascript:void(0)" data-lid="${$(this).data('lid')}" data-uid="${$(this).data('uid')}" class="del-pwd text-danger">移除</a>`;
- $(this).parents('td').html(html);
- return;
- }
- const data = {
- type: 'pwd',
- ledger_id,
- user_id,
- pwd: validText,
- };
- postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
- const lcindex = _.findIndex(ledger_cooperation_list, { ledger_id, user_id });
- ledger_cooperation_list.splice(lcindex, 1, result);
- setLeftTable(ledgerTree.datas, ledger_cooperation_list, user_id, $('#stage_audits option:selected').text());
- const select = _.find(ledgerTree.datas, { ledger_id });
- select.pwd = validText;
- const refreshNode = ledgerTree.loadPostData({update: select});
- ledgerSpreadObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
- ledgerSpreadObj.setFontColor();
- });
- });
- $.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();
- }
- });
- });
- function setRightData(datas, coolist) {
- const newdatas = [];
- const reg = /(^GD([a-zA-Z0-9\-]+))|(\d+)/;
- for (const l of datas) {
- if (reg.test(l.code) && l.level <= 4) {
- if(l.level === 4 && l.is_leaf === false) {
- l.is_leaf = true;
- }
- if(l.is_leaf) {
- const coo = _.find(coolist, { 'ledger_id': l.ledger_id, 'user_id': cur_uid });
- if(coo) {
- l.pwd = coo.pwd;
- }
- }
- newdatas.push(l);
- }
- }
- return newdatas;
- }
- function setLeftTable(ledgerList, coolist, uid, title) {
- $('#stage_audit').text(title);
- const showCooList = _.filter(coolist, { 'user_id': parseInt(uid) });
- const removeList = [];
- for (const sc of showCooList) {
- const info = _.find(ledgerList, { 'ledger_id': sc.ledger_id });
- if (info) {
- sc.code = info.code;
- sc.name = info.name;
- } else {
- removeList.push(sc);
- }
- }
- if (removeList.length > 0) {
- // 移除
- _.pull(showCooList, ...removeList);
- console.log(removeList);
- }
- let html = '';
- for (const sc of showCooList) {
- const pichtml = sc.sign_path ? `<img src="${sc.sign_path}" width="60"><a href="javascript:void(0);" class="d-inline-flex">更改</a>` : '<input type="file">';
- html += `<tr>` +
- `<td>${sc.code} ${sc.name}</td>` +
- `<td><p class="mb-0">${sc.pwd}</p><a href="javascript:void(0);" data-lid="${sc.ledger_id}" data-uid="${sc.user_id}" data-pwd="${sc.pwd}" class="edit-pwd">修改</a> <a href="javascript:void(0)" data-lid="${sc.ledger_id}" data-uid="${sc.user_id}" class="del-pwd text-danger">移除</a></td>` +
- `<td>${pichtml}</td>` +
- `</tr>`;
- }
- $('#coo_table').html(html);
- }
|