'use strict'; /** * * * @author Mai * @date 2018/10/11 * @version */ const tenderListSpec = (function(){ function getTenderNodeHtml(node, arr, pid) { const html = []; html.push(''); // 名称 html.push(''); if (node.cid) { html.push(' '); html.push((node.level === 1 ? '' : ''), node.name, (node.level === 1 ? '' : '')); } else { html.push(''); html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├'); html.push(''); html.push(node.name); } html.push(''); // 计量进度 html.push(''); if (!node.cid && node.cur_flow) { if (node.progress) { html.push(node.progress.title + ' (' + '' + node.progress.status + '' + ')'); } else { html.push(node.cur_flow.title + ' (' + '' + node.cur_flow.status + '' + ')'); } } html.push(''); // 资金来源 html.push(''); if (!node.cid) { html.push(transferInfo.uid === user_id && !transferInfo.is_lock ? '' : node.source); } html.push(''); // 合同金额 html.push(''); html.push(node.total_price || ''); html.push(''); // 截止本期合同 html.push(''); html.push(node.end_contract_tp || ''); html.push(''); // 截止本期变更 html.push(''); html.push(node.end_qc_tp || ''); html.push(''); // 截止本期完成 html.push(''); html.push(node.end_gather_tp || ''); html.push(''); // 截止本期实付 html.push(''); html.push(node.end_sf_tp || ''); html.push(''); // 本次划拨 html.push(''); if (!node.cid) { html.push(transferInfo.uid === user_id && !transferInfo.is_lock ? '' : node.hb_tp); } else { html.push(node.hb_tp || ''); } html.push(''); // 截止上次划拨 html.push(''); html.push(node.pre_hb_tp || ''); html.push(''); // 截止本次划拨 html.push(''); html.push(node.end_hb_tp || ''); html.push(''); // 附件 html.push(''); if (!node.cid) { html.push(' '+ (node.files.length > 0 ? node.files.length : '') +''); } html.push(''); // 操作 if (transferInfo.uid === user_id) { html.push(''); html.push(!node.cid && !transferInfo.is_lock ? '移除' : ''); html.push(''); } html.push(''); return html.join(''); } function getTenderTreeHeaderHtml() { const html = []; const left = $('#sub-menu').css('display') === 'none' ? 56 : 176; html.push('') html.push('', ''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); if (transferInfo.uid === user_id) { html.push(''); } html.push('', ''); return html.join(''); } function calculateTender(tender) { if (tender.stage_tp) { tender.gather_tp = ZhCalc.sum([tender.stage_tp.contract_tp, tender.stage_tp.qc_tp, tender.stage_tp.pc_tp]); tender.end_contract_tp = ZhCalc.sum([tender.stage_tp.pre_contract_tp, tender.stage_tp.contract_tp, tender.stage_tp.contract_pc_tp]); tender.end_qc_tp = ZhCalc.sum([tender.stage_tp.pre_qc_tp, tender.stage_tp.qc_tp, tender.stage_tp.qc_pc_tp]); tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp); tender.pre_gather_tp = ZhCalc.add(tender.stage_tp.pre_contract_tp, tender.stage_tp.pre_qc_tp); tender.yf_tp = ZhCalc.add(tender.stage_tp.yf_tp); tender.end_yf_tp = ZhCalc.add(tender.stage_tp.pre_yf_tp, tender.yf_tp); tender.sf_tp = ZhCalc.add(tender.stage_tp.sf_tp); tender.end_sf_tp = ZhCalc.add(tender.stage_tp.pre_sf_tp, tender.sf_tp); tender.wf_tp = ZhCalc.sub(tender.end_yf_tp, tender.end_sf_tp); } else if (tender.lastStage) { tender.gather_tp = ZhCalc.sum([tender.lastStage.contract_tp, tender.lastStage.qc_tp, tender.lastStage.pc_tp]); tender.end_contract_tp = ZhCalc.sum([tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp, tender.lastStage.contract_pc_tp]); tender.end_qc_tp = ZhCalc.sum([tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp, tender.lastStage.qc_pc_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); tender.sf_tp = ZhCalc.add(tender.lastStage.sf_tp); tender.end_sf_tp = ZhCalc.add(tender.lastStage.pre_sf_tp, tender.sf_tp); tender.wf_tp = ZhCalc.sub(tender.end_yf_tp, tender.end_sf_tp); } tender.end_hb_tp = ZhCalc.add(tender.pre_hb_tp, tender.hb_tp); } function calculateParent(node) { if (node.children && node.cid) { node.total_price = 0; node.gather_tp = 0; node.end_contract_tp = 0; node.end_qc_tp = 0; node.end_gather_tp = 0; node.pre_gather_tp = 0; node.yf_tp = 0; node.end_yf_tp = 0; node.advance_tp = 0; node.contract_price = 0; node.sf_tp = 0; node.end_sf_tp = 0; node.wf_tp = 0; node.hb_tp = 0; node.pre_hb_tp = 0; node.end_hb_tp = 0; for (const c of node.children) { calculateParent(c); node.total_price = ZhCalc.add(node.total_price, c.total_price); node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp); node.end_contract_tp = ZhCalc.add(node.end_contract_tp, c.end_contract_tp); node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp); node.end_gather_tp = ZhCalc.add(node.end_gather_tp, c.end_gather_tp); node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp); node.yf_tp = ZhCalc.add(node.yf_tp, c.yf_tp); node.end_yf_tp = ZhCalc.add(node.end_yf_tp, c.end_yf_tp); node.advance_tp = ZhCalc.add(node.advance_tp, c.advance_tp); node.contract_price = ZhCalc.add(node.contract_price, c.contract_price); node.sf_tp = ZhCalc.add(node.sf_tp, c.sf_tp); node.end_sf_tp = ZhCalc.add(node.end_sf_tp, c.end_sf_tp); node.wf_tp = ZhCalc.add(node.wf_tp, c.wf_tp); node.hb_tp = ZhCalc.add(node.hb_tp, c.hb_tp); node.pre_hb_tp = ZhCalc.add(node.pre_hb_tp, c.pre_hb_tp); node.end_hb_tp = ZhCalc.add(node.end_hb_tp, c.end_hb_tp); } } } return { getTenderNodeHtml, getTenderTreeHeaderHtml, calculateTender, calculateParent } })(); $(function () { autoFlashHeight(); $('#add-tender-btn').click(function () { const addTenders = []; $('input[name="tender_id[]"]:checked:not(:disabled)').each(function () { const tenderId = $(this).val(); if (tenderId) { addTenders.push(parseInt(tenderId)); } }); if (addTenders.length === 0) { toastr.warning('请选择添加标段'); return false; } console.log(addTenders); postData(window.location.pathname + '/update', {postType: 'add-tender', postData: { tenders: addTenders }}, function (result) { window.location.reload(); }); }); $('body').on('click', '#tender-list .del-tender-btn', function () { const ftid = $(this).data('id'); deleteAfterHint(function () { postData(window.location.pathname + '/update', {postType: 'del-tender', postData: { node: ftid }}, function (result) { window.location.reload(); }) }, '确认删除该标段并移除所有附件?'); }); $('#lock-transfer-btn').click(function () { postData(`/sp/${spid}/financial/transfer/update`, {postType: 'lock-transfer', postData: { node: trid, lock: 1 }}, function (result) { window.location.reload(); }); }); $('#unlock-transfer-btn').click(function () { postData(`/sp/${spid}/financial/transfer/update`, {postType: 'lock-transfer', postData: { node: trid, lock: 0 }}, function (result) { window.location.reload(); }); }); $('body').on('change', '#tender-list input[type="text"]', function () { const ftid = $(this).data('ftid'); if (!ftid) { toastr.error('获取资金划拨标段信息失败'); return; } const ftInfo = _.find(tenders, { id: parseInt(ftid) }); if (!ftInfo) { toastr.error('获取资金划拨信息失败'); return; } const key = $(this).data('key'); if (key === 'hb_tp') { const value = $(this).val() || 0; // 判断只能输入数字,支持负数和小数 if (!/^-?\d+(\.\d+)?$/.test(value)) { toastr.error('请输入正确的金额'); $(this).val(ftInfo.hb_tp); return; } postData(window.location.pathname + '/update', {postType: 'update-hb_tp', postData: { node: ftid, hb_tp: parseFloat(value) }}, function (result) { // window.location.reload(); ftInfo.hb_tp = parseFloat(value); // 更新并汇总父节点和截止本次划拨汇总 ftInfo.end_hb_tp = ZhCalc.add(ftInfo.pre_hb_tp, ftInfo.hb_tp); for (const t of tenderTree) { tenderListSpec.calculateParent(t); } $('.c-body').html(getTenderTreeHtml()); }); } else { const value = $(this).val() || ''; if (value.length > 255) { toastr.error('输入内容过长,不能超过255个字符'); $(this).val(ftInfo[key]); return; } postData(window.location.pathname + '/update', {postType: 'update-tender', postData: { node: ftInfo.id, key: key, value: value }}, function (result) { // window.location.reload(); ftInfo[key] = value; }); } }); $('body').on('click', '.open-tender-files', function () { const ftid = $(this).attr('data-ftid'); if (!ftid) { toastr.error('获取资金划拨标段信息失败'); return; } const ftInfo = _.find(tenders, { id: parseInt(ftid) }); if (!ftInfo) { toastr.error('获取资金划拨信息失败'); return; } if (ftInfo.uid === user_id || financialPermission.transfer_file) { $('#tender-file .upload-permission').show(); } else { $('#tender-file .upload-permission').hide(); } $('#tender-file').modal('show'); $('#tender-file input[name="ftid"]').val(ftid); openFinancialTransferTenderFiles(ftInfo); }); // 上传附件 $('#tender-file input[type="file"]').change(function () { const files = Array.from(this.files); const valiData = files.map(v => { const ext = v.name.substring(v.name.lastIndexOf('.') + 1) return { size: v.size, ext } }); const ftid = $('#tender-file input[name="ftid"]').val(); const ftInfo = _.find(tenders, { id: parseInt(ftid) }); if (!ftInfo) { toastr.warning('不存在该资金划拨标段'); $('#tender-file input[type="file"]').val(''); return; } if (validateFiles(valiData)) { if (files.length) { const formData = new FormData() files.forEach(file => { formData.append('name', file.name) formData.append('size', file.size) formData.append('file', file) }) postDataWithFile(`/sp/${spid}/financial/transfer/${trid}/tender/${ftInfo.id}/file/upload`, formData, function (result) { ftInfo.files = result; openFinancialTransferTenderFiles(ftInfo); $('#tender-list tr[data-id="' + ftInfo.id + '"] .file-num').text(ftInfo.files.length ? ftInfo.files.length : ''); }); } } $('#tender-file input[type="file"]').val(''); }); $('body').on('click', '#tender-file .file-del', function () { const ftid = $('#tender-file input[name="ftid"]').val(); const ftInfo = _.find(tenders, { id: parseInt(ftid) }); if (!ftInfo) { toastr.warning('不存在该资金划拨标段'); return; } const fid = $(this).data('id'); deleteAfterHint(function () { postData(`/sp/${spid}/financial/transfer/${trid}/tender/${ftInfo.id}/file/delete`, { id: fid }, function (result) { ftInfo.files = result; openFinancialTransferTenderFiles(ftInfo); $('#tender-list tr[data-id="' + ftInfo.id + '"] .file-num').text(ftInfo.files.length ? ftInfo.files.length : ''); }); }, '确认删除该文件?'); }); function openFinancialTransferTenderFiles(ftInfo, _this = '#tender-file table tbody') { const files = ftInfo.files; let filesHtml = ''; const newFiles = files.map(file => { let showDel = false; if (file.uid === user_id) { showDel = true } return {...file, showDel} }) newFiles.forEach((file, idx) => { filesHtml += ``; }); $(_this).html(filesHtml); } $.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(); } }); // 添加标段树结构加载 const EmptyTenderListHtml = [ '
', '

还没有标段数据

', '
' ]; const tenderListTree = []; let tenderListParentId = 0; function initTenderListTree () { const levelCategory = category.filter(function (c) { return c.show_level && c.show_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 : tenderListTree; 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.show_level, sort_id: ++tenderListParentId, 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); if (cate) { tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1); } } } return tenderCategory; } } return tenderCategory; } tenderListTree.splice(0, tenderListTree.length); for (const t of tenderList) { 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 { tenderListTree.push(t); } } else { tenderListTree.push(t); } } sortTenderTree(tenderListTree); } function recursiveGetTenderListNodeHtml (node, arr, pid) { const html = []; html.push(''); html.push(''); // 名称 html.push(''); // 计量进度 html.push(''); html.push(''); if (node.children) { for (const c of node.children) { html.push(recursiveGetTenderListNodeHtml(c, node.children, node.sort_id)); } } return html.join(''); } // 根据TenderTree数据获取Html代码 function getTenderListTreeHtml () { if (tenderListTree.length > 0) { const html = []; html.push('
', '标段名称', '', '计量进度', '', '资金来源', '', '合同金额', '', '截止本期合同', '', '截止本期变更', '', '截止本期完成', '', '截止本期实付', '', '本次划拨', '', '截止上次划拨', '', '截止本次划拨', '', '附件', '', '操作', '
${idx + 1}${file.filename}${file.username}${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}
${file.viewpath ? `` : ''} ${file.showDel ? `` : ''}
'); if (!node.cid) { 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.name); } html.push(''); if (!node.cid && node.cur_flow) { if (node.progress) { html.push(node.progress.title + ' (' + '' + node.progress.status + '' + ')'); } else { html.push(node.cur_flow.title + ' (' + '' + node.cur_flow.status + '' + ')'); } } html.push('
'); html.push('', ''); html.push(''); html.push(''); html.push(''); html.push('', ''); tenderListParentId = 0; for (const t of tenderListTree) { html.push(recursiveGetTenderListNodeHtml(t, tenderListTree, '')); } html.push('
', '选择', '', '标段名称', '', '计量进度', '
'); return html.join(''); } else { return EmptyTenderListHtml.join(''); } } $('#add-ftt').on('shown.bs.modal', function () { tenderListOrder.reOrderTenders('', '#copyModalContent', false, tenderList); initTenderListTree(); $('#add-tender-list').html(getTenderListTreeHtml()); }); }) /** * 校验文件大小、格式 * @param {Array} files 文件数组 */ function validateFiles(files) { if (files.length > 10) { toastr.error('至多同时上传10个文件'); return false } return files.every(file => { if (file.size > 1024 * 1024 * 50) { toastr.error('文件大小限制为50MB'); return false } if (whiteList.indexOf('.' + file.ext.toLowerCase()) === -1) { toastr.error('请上传正确的格式文件'); return false } return true }) }