12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132 |
- const copyBlockTag = 'zh.calc.copyBlock';
- $(document).ready(function() {
- const ckBillsSpread = '/contract/' + window.location.pathname.split('/')[2] + '/' + contractConst.typeMap[contract_type] + '/detail/contract-billsSelect';
- autoFlashHeight();
- const contractSpreadSetting = {
- cols: [
- {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@', readOnly: 'readOnly.code', cellType: 'tree'},
- {title: '合同编号', colSpan: '1', rowSpan: '2', field: 'c_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
- {title: '项目名称/合同名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 360, formatter: '@', readOnly: 'readOnly.code', wordWrap: true},
- {title: '创建人', colSpan: '1', rowSpan: '2', field: 'username', hAlign: 1, width: 80, formatter: '@', readOnly: true},
- {title: '合同金额', colSpan: '1', rowSpan: '2', field: 'total_price', hAlign: 2, width: 120, formatter: '@', readOnly: true},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- // readOnly: readOnly,
- rowHeader:[
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if (is_admin) return;
- if (_.findIndex(contractTreeAudits, { contract_id: data.contract_id, uid: user_id }) !== -1) {
- return '#dc3545';
- }
- }
- },
- },
- ],
- localCache: {
- key: 'contract-spread',
- colWidth: true,
- },
- };
- const contractCol = {
- getValue: {
- status: function (data) {
- return data.c_code ? (data.settle_code ? '● 已结算' : data.yf_price < data.total_price ? '● 履行中' : '● 已完成') : '';
- }
- },
- foreColor: {
- status: function (data) {
- return data.c_code ? (data.settle_code ? '#6c757d' : data.yf_price < data.total_price ? '#da9500' : '#28a745') : '';
- }
- },
- readOnly: {
- code: function (data) {
- return !permission_edit || data.c_code;
- }
- }
- }
- const getStackedBarTip = function (data) {
- return data.stackedBarTips ? data.stackedBarTips.join('\n') : '';
- };
- if (contract_type === contractConst.type.expenses) {
- contractSpreadSetting.cols.push({title: '累计应付', colSpan: '1', rowSpan: '2', field: 'yf_price', hAlign: 2, width: 120, formatter: '@', readOnly: true});
- contractSpreadSetting.cols.push({title: '支付进度', colSpan: '1', rowSpan: '2', formatter: '@', readOnly: true, field: 'stackedBar', hAlign: 0, width: 200, cellType: 'stackedBar', stackedBarCover: true, bc_type: 'grid', getTip: getStackedBarTip, hintNum: true});
- } else if (contract_type === contractConst.type.income) {
- contractSpreadSetting.cols.push({title: '累计应回', colSpan: '1', rowSpan: '2', field: 'yf_price', hAlign: 2, width: 120, formatter: '@', readOnly: true});
- contractSpreadSetting.cols.push({title: '回款进度', colSpan: '1', rowSpan: '2', formatter: '@', readOnly: true, field: 'stackedBar', hAlign: 0, width: 200, cellType: 'stackedBar', stackedBarCover: true, bc_type: 'grid', getTip: getStackedBarTip, hintNum: true});
- }
- contractSpreadSetting.cols.push({title: '合同状态', colSpan: '1', rowSpan: '2', field: 'status', hAlign: 1, width: 100, formatter: '@', readOnly: true, getValue:'getValue.status', foreColor:'foreColor.status'});
- contractSpreadSetting.cols.push({title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.code', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-1'});
- const contractSpread = SpreadJsObj.createNewSpread($('#contract-spread')[0]);
- const contractSheet = contractSpread.getActiveSheet();
- // sjsSettingObj.setGridSelectStyle(contractSpreadSetting);
- sjsSettingObj.setFxTreeStyle(contractSpreadSetting, sjsSettingObj.FxTreeStyle.contract);
- SpreadJsObj.initSpreadSettingEvents(contractSpreadSetting, contractCol);
- SpreadJsObj.initSheet(contractSheet, contractSpreadSetting);
- const treeSetting = {
- id: 'contract_id',
- pid: 'contract_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tid', 'spid', 'contract_type'],
- calcFields: ['pay_price', 'total_price', 'sf_price', 'debit_price', 'yf_price'],
- autoExpand: 3,
- markExpandKey: 'contract-bills-expand' + window.location.pathname.split('/')[2] + contractConst.typeMap[contract_type],
- markExpandSubKey: window.location.pathname.split('/')[2] + contractConst.typeMap[contract_type],
- };
- const calcField = ['total_price', 'yf_price'];
- const calcFieldColor = {'total_price': '#bbb', 'yf_price': '#28a745'};
- const calcFieldCaption = {'total_price': '合同金额', 'yf_price': contract_type === contractConst.type.expenses ? '累计应付' : '累计应回'};
- treeSetting.calcFun = function (node) {
- if (node && node.c_code) {
- const base = node.total_price;
- node.stackedBar = [];
- node.stackedBarTips = [];
- for (const cf of calcField) {
- node.stackedBar.push({ color: calcFieldColor[cf], percent: ZhCalc.div(node[cf], base), field: cf, hintNum: cf === 'yf_price' });
- node.stackedBarTips.push(`${calcFieldCaption[cf]}: ${node[cf] || 0}`);
- }
- }
- };
- const contractTree = createNewPathTree('revise', treeSetting);
- const contractDetail = ['c_code', 'name', 'total_price', 'pay_price', 'debit_price','yf_price', 'sf_price', 'party_a', 'party_a_user', 'party_b', 'party_b_user', 'sign_date', 'address', 'entity', 'bank', 'bank_account', 'remark', 'settle_code', 'create_time'];
- // 清单 相关方法&绑定spreadjs事件
- const contractTreeSpreadObj = {
- getDefaultSelectInfo: function (sheet) {
- const tree = sheet.zh_tree;
- if (!tree) return;
- const sel = sheet.getSelections()[0];
- const node = sheet.zh_tree.nodes[sel.row];
- if (!node) return;
- let count = 1;
- if (sel.rowCount > 1) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = sheet.zh_tree.nodes[sel.row + r];
- if (rNode.level > node.level) continue;
- if ((rNode.level < node.level) || (rNode.level === node.level && rNode.contract_pid !== node.contract_pid)) {
- toastr.warning('请选择同一节点下的节点,进行该操作');
- return;
- }
- count += 1;
- }
- }
- return [tree, node, count];
- },
- /**
- * 刷新顶部按钮是否可用
- * @param sheet
- * @param selections
- */
- refreshOperationValid: function (sheet, selection) {
- const setObjEnable = function (obj, enable) {
- if (enable) {
- obj.removeClass('disabled');
- } else {
- obj.addClass('disabled');
- }
- };
- const invalidAll = function () {
- setObjEnable($('a[name=base-opr][type=add]'), false);
- setObjEnable($('a[name=base-opr][type=add-child]'), false);
- setObjEnable($('a[name=base-opr][type=delete]'), false);
- setObjEnable($('a[name=base-opr][type=up-move]'), false);
- setObjEnable($('a[name=base-opr][type=down-move]'), false);
- setObjEnable($('a[name=base-opr][type=up-level]'), false);
- setObjEnable($('a[name=base-opr][type=down-level]'), false);
- };
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) {
- invalidAll();
- return;
- }
- const first = sheet.zh_tree.nodes[row];
- if (first && first.c_code) {
- const parent = tree.getParent(first)
- if (parent && permission_add && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: parent.contract_id, uid: user_id }) !== -1)) {
- $('#add-cons-btn').show();
- } else {
- $('#add-cons-btn').hide();
- }
- } else {
- if (first && permission_add && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: first.contract_id, uid: user_id }) !== -1)) {
- $('#add-cons-btn').show();
- } else {
- $('#add-cons-btn').hide();
- }
- }
- if (!first) {
- invalidAll();
- return;
- }
- let last = first, sameParent = true, childCanDel = true;
- // hadContract = this.checkContract(first);
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = tree.nodes[sel.row + r];
- childCanDel = this.checkDelete(rNode, childCanDel);
- // if (!hadContract) hadContract = this.checkContract(rNode);
- if (!rNode) {
- sameParent = false;
- break;
- }
- if (rNode.level > first.level) continue;
- if ((rNode.level < first.level) || (rNode.level === first.level && rNode.contract_pid !== first.contract_pid)) {
- sameParent = false;
- break;
- }
- last = rNode;
- }
- }
- const preNode = tree.getPreSiblingNode(first);
- // if (!hadContract && preNode) hadContract = preNode.c_code !== undefined;
- // const siblings = tree.getChildren(tree.getParent(first));
- let upPower = true;
- // for (let order = last.order; order < siblings.length - 1; order ++) {
- // if (!siblings[order].formc) {
- // upPower = false;
- // break;
- // }
- // }
- const nextNodes = _.filter(tree.getChildren(tree.getParent(first)), function (item){ return item.order > first.order });
- // let nextHadContract = false;
- // for (const next of nextNodes) {
- // if (nextHadContract) continue;
- // nextHadContract = this.checkContract(next);
- // }
- const nextHadContract = _.findIndex(nextNodes, function(item) { return item.c_code; }) !== -1;
- const valid = !sheet.zh_setting.readOnly;
- setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1);
- setObjEnable($('a[name=base-opr][type=add-child]'), valid && first && !first.c_code && first.level >= 1);
- setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && childCanDel && this.checkDelete(first));
- setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
- setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
- setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first)
- && first.level > 2 && (!nextHadContract || tree.isLastSibling(last)) && upPower && first.c_code === undefined);
- setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
- && first.level > 1 && preNode && (preNode.children.length > 0 || preNode.children.length === 0) && preNode.c_code === undefined);
- // setObjEnable($('#cut'), valid);
- // setObjEnable($('#paste'), valid);
- },
- /**
- *
- * @param sheet
- * @param data
- */
- refreshTree: function (sheet, data) {
- SpreadJsObj.massOperationSheet(sheet, function () {
- const tree = sheet.zh_tree;
- // 处理删除
- if (data.delete) {
- data.delete.sort(function (a, b) {
- return b.deleteIndex - a.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);
- }
- }
- }
- }
- });
- },
- changeContractTab: function (node, need = false) {
- if ($('.bc-bar .nav li .active').attr('href') === '#htdetail') {
- if (node.settle_code) {
- $('#edit_contract_btn').hide();
- } else {
- $('#edit_contract_btn').show();
- }
- $('#save_contract_btn').hide();
- $('#cancel_contract_btn').hide();
- $('#add_contract_pay_btn').hide();
- $('a[href*="#cons-upfile"]').hide();
- if (need) {
- for (const c of contractDetail) {
- if (c === 'create_time') {
- $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD HH:mm:ss') : '');
- continue;
- } else if (c === 'sign_date') {
- $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : '');
- continue;
- }
- $('#htdetail_' + c).text(node[c] || '');
- }
- $('#htdetail_df_price').text(ZhCalc.sub(node.yf_price, node.sf_price) || '');
- }
- } else if ($('.bc-bar .nav li .active').attr('href') === '#htpay') {
- $('#edit_contract_btn').hide();
- $('#save_contract_btn').hide();
- $('#cancel_contract_btn').hide();
- if (node.settle_code) {
- $('#add_contract_pay_btn').hide();
- if (need) {
- $('#htpay-table tbody').find('.pay-edit').hide();
- $('#htpay-table tbody').find('.pay-del').hide();
- }
- } else {
- $('#add_contract_pay_btn').show();
- if (need && contractPays && contractPays.length > 0) {
- for (const [i, cp] of contractPays.entries()) {
- if (cp.uid === user_id) {
- $('#htpay-table tbody tr').eq(i).find('.pay-edit').show();
- $('#htpay-table tbody tr').eq(i).find('.pay-del').show();
- }
- }
- }
- }
- $('a[href*="#cons-upfile"]').hide();
- } else if ($('.bc-bar .nav li .active').attr('href') === '#htfile') {
- $('#edit_contract_btn').hide();
- $('#save_contract_btn').hide();
- $('#cancel_contract_btn').hide();
- $('#add_contract_pay_btn').hide();
- $('a[href*="#cons-upfile"]').show();
- }
- },
- openContractPayFiles: function (pay) {
- this.setContractFiles(pay.files, pay.cid, pay.id, '#cons-pay-file table tbody');
- },
- setContractFiles: function (files, cid, cpid = null, _this = '#htfile-table tbody') {
- 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 += `<tr class="text-center">
- <td>${idx + 1}</td><td class="text-left"><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td>
- <td>
- <div class="btn-group-table">
- ${file.viewpath ? `<a href="${file.viewpath}" target="_blank" class="mr-1"><i class="fa fa-eye fa-fw"></i></a>` : ''}
- <a href="${thisUrl}/${contractConst.typeMap[contract_type]}/${cid}${cpid ? '/pay/' + cpid : ''}/file/${file.id}/download" class="mr-1"><i class="fa fa-download fa-fw"></i></a>
- ${file.showDel ? `<a href="javascript: void(0);" class="text-danger file-del mr-1" data-id="${file.id}"><i class="fa fa-trash-o fa-fw text-danger"></i></a>` : ''}
- </div>
- </td>
- </tr>`;
- });
- $(_this).html(filesHtml);
- },
- setContractPays: function (pays, node) {
- contractPays = pays;
- let paysHtml = '';
- const newPays = pays.map(pay => {
- let showEdit = false;
- if (pay.uid === user_id && !node.settle_code) {
- showEdit = true
- }
- return {...pay, showEdit}
- })
- console.log(pays);
- newPays.forEach((pay, idx) => {
- paysHtml += `<tr class="text-center" data-cpid="${pay.id}">
- <td>${idx + 1}</td>
- <td>${moment(pay.pay_time).format('YYYY-MM-DD')}</td>
- <td>${pay.pay_price}</td>
- <td>${pay.debit_price}</td>
- <td>${pay.yf_price}</td>
- <td>${pay.sf_price}</td>
- <td>${pay.pay_type}</td>
- <td>${pay.username}</td>
- <td>${moment(pay.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>
- <td>${pay.remark}</td>
- <td><a href="javascript:void(0);" class="text-primary open-pay-files" data-cpid="${pay.id}"><i class="fa fa-paperclip fa-rotate-90"></i></a> <span class="files-num">${pay.files.length > 0 ? pay.files.length : ''}</span></td>
- <td><a href="javascript:void(0);" class="text-primary pay-edit" data-id="${pay.id}" ${ !pay.showEdit ? `style="display:none"` : ''}>编辑</a> <a href="javascript:void(0);" class="text-danger pay-del" data-id="${pay.id}" ${ !pay.showEdit ? `style="display:none"` : ''}>删除</a></td>
- </tr>`;
- });
- $('#htpay-table tbody').html(paysHtml);
- },
- setContract: function (sheet) {
- const node = SpreadJsObj.getSelectObject(sheet);
- if (node && node.c_code) {
- $('#htdetail-table').show();
- $('#htpay-table').show();
- $('#htfile-table').show();
- for (const c of contractDetail) {
- if (c === 'create_time') {
- $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD HH:mm:ss') : '');
- continue;
- } else if (c === 'sign_date') {
- $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : '');
- continue;
- }
- $('#htdetail_' + c).text(node[c] || '');
- }
- $('#htdetail_df_price').text(ZhCalc.sub(node.yf_price, node.sf_price) || '');
- postData(window.location.pathname + '/update', {postType: 'get-contract', postData: node.id}, function (result) {
- contractTreeSpreadObj.setContractPays(result.pays, node);
- contractTreeSpreadObj.setContractFiles(result.files, node.id);
- });
- if (node.uid === user_id) {
- if (node.settle_code) {
- $('a[href*="#cons-unlock"]').show();
- $('a[href*="#cons-close"]').hide();
- } else {
- $('a[href*="#cons-unlock"]').hide();
- $('a[href*="#cons-close"]').show();
- }
- contractTreeSpreadObj.changeContractTab(node);
- } else {
- $('#edit_contract_btn').hide();
- $('#save_contract_btn').hide();
- $('#cancel_contract_btn').hide();
- $('a[href*="#cons-unlock"]').hide();
- $('a[href*="#cons-close"]').hide();
- $('a[href*="#cons-upfile"]').hide();
- if (node && node.c_code && $('.bc-bar .nav li .active').attr('href') === '#htfile' && permission_att) $('a[href*="#cons-upfile"]').show();
- $('#add_contract_pay_btn').hide();
- }
- } else {
- $('#htdetail-table').hide();
- $('#htpay-table').hide();
- $('#htfile-table').hide();
- $('#edit_contract_btn').hide();
- $('#save_contract_btn').hide();
- $('#cancel_contract_btn').hide();
- $('a[href*="#cons-unlock"]').hide();
- $('a[href*="#cons-close"]').hide();
- $('a[href*="#cons-upfile"]').hide();
- if (node && node.c_code && $('.bc-bar .nav li .active').attr('href') === '#htfile' && permission_att) $('a[href*="#cons-upfile"]').show();
- $('#add_contract_pay_btn').hide();
- }
- },
- selectionChanged: function (e, info) {
- if (info.newSelections) {
- if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
- contractTreeSpreadObj.refreshOperationValid(info.sheet);
- contractTreeSpreadObj.setContract(info.sheet);
- SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
- }
- } else {
- $('#add-cons-btn').hide();
- }
- },
- cleanData: function (result) {
- if (result && result.update && result.update.length > 0) {
- for (const r of result.update) {
- if (!r.c_code) {
- r.total_price = null;
- r.yf_price = null;
- }
- }
- }
- return result;
- },
- /**
- * 新增节点
- * @param spread
- */
- baseOpr: function (sheet, type, addCount = 1) {
- const self = this;
- const [tree, node, count] = this.getDefaultSelectInfo(sheet);
- if (!tree || !node || !count) return;
- // if (type === 'delete') {
- // const parent = tree.getParent(node);
- // const children = parent ? parent.children : tree.children;
- // const index = children.indexOf(node);
- // for (let i = 0; i < count; i++) {
- // const child = children[i+index];
- // if (tree.checkNodeUsed(child, pos)) {
- // toastr.warning('选中的节点已计量,不可删除');
- // return;
- // }
- // }
- // } else if (type === 'up-level') {
- // const parent = tree.getParent(node);
- // const children = parent ? parent.children : tree.children;
- // const index = children.indexOf(node);
- // const lastSelect = children[index + count - 1];
- // // if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
- // // toastr.warning('选中的节点已计量,不可升级');
- // // return;
- // // }
- // } else if (type === 'down-level') {
- // const parent = tree.getParent(node);
- // const children = parent ? parent.children : tree.children;
- // const index = children.indexOf(node);
- // if (index > 0 && children[index-1].used) {
- // toastr.warning('其前节点已计量,选中的节点不可降级');
- // return;
- // }
- // for (let i = index; i < count; i++) {
- // const child = children[i+index];
- // if (tree.checkNodeUsed(child, pos)) {
- // toastr.warning('选中的节点已计量,不可降级');
- // return;
- // }
- // }
- // }
- if (type === 'delete') {
- deleteAfterHint(function () {
- postData(window.location.pathname + '/update', {
- postType: type,
- postData: {
- id: node.contract_id,
- count: type === 'add' ? addCount : count,
- }
- }, function (result) {
- const refreshData = tree.loadPostData(result);
- self.refreshTree(sheet, refreshData);
- const sel = sheet.getSelections()[0];
- if (sel) {
- sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
- }
- contractTreeSpreadObj.setContract(sheet);
- self.refreshOperationValid(sheet);
- });
- }, '确认删除「当前合同或节点及子项」?');
- } else {
- postData(window.location.pathname + '/update', {
- postType: type,
- postData: {
- id: node.contract_id,
- count: type === 'add' ? addCount : count,
- }
- }, function (result) {
- self.cleanData(result);
- const refreshData = tree.loadPostData(result);
- self.refreshTree(sheet, refreshData);
- if (['up-move', 'down-move'].indexOf(type) > -1) {
- const sel = sheet.getSelections()[0];
- if (sel) {
- sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
- }
- } else if (type === 'add' || type === 'add-child') {
- const sel = sheet.getSelections()[0];
- if (sel) {
- sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
- }
- }
- self.refreshOperationValid(sheet);
- });
- }
- },
- /**
- * 编辑单元格响应事件
- * @param {Object} e
- * @param {Object} info
- */
- editEnded: function (e, info) {
- if (info.sheet.zh_setting) {
- const col = info.sheet.zh_setting.cols[info.col];
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const node = sortData[info.row];
- const data = {
- id: node.id,
- };
- // 未改变值则不提交
- const orgValue = node[col.field];
- const newValue = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
- if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
- return;
- }
- // 获取更新数据
- if (info.editingText) {
- const text = newValue;
- data[col.field] = text;
- } else {
- data[col.field] = null;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
- const refreshNode = contractTree.loadPostData(result);
- contractTreeSpreadObj.refreshTree(info.sheet, refreshNode);
- });
- }
- },
- clipboardPasting: function (e, info) {
- const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
- info.cancel = true;
- if (!setting || !tree) return;
- const pasteData = info.pasteData.html
- ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
- : (info.pasteData.text === ''
- ? SpreadJsObj.Clipboard.getAnalysisPasteText()
- : SpreadJsObj.analysisPasteText(info.pasteData.text));
- const datas = [], filterNodes = [];
- let level, filterRow = 0;
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
- const curRow = info.cellRange.row + iRow;
- const node = tree.nodes[curRow];
- if (!node) continue;
- if (!level) level = node.level;
- if (node.level < level) break;
- let bPaste = false;
- const data = info.sheet.zh_tree.getNodeKeyData(node);
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- const value = colSetting.wordWrap ? pasteData[iRow-filterRow][iCol] : trimInvalidChar(pasteData[iRow-filterRow][iCol]);
- data[colSetting.field] = value;
- bPaste = true;
- }
- if (bPaste) {
- datas.push(data);
- } else {
- filterNodes.push(node);
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- const refreshNode = tree.loadPostData(result);
- if (refreshNode.update) {
- refreshNode.update = refreshNode.update.concat(filterNodes);
- }
- contractTreeSpreadObj.refreshTree(info.sheet, refreshNode);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- });
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- }
- },
- clipboardPasted: function (e, info) {
- const tree = info.sheet.zh_tree;
- if (!tree) { return; }
- const sortData = info.sheet.zh_tree.nodes;
- const datas = [], filterNodes = [];
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
- let bPaste = false;
- const curRow = info.cellRange.row + iRow;
- const node = sortData[curRow];
- if (node) {
- const data = info.sheet.zh_tree.getNodeKeyData(node);
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- const value = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
- data[colSetting.field] = value;
- bPaste = true;
- }
- if (bPaste) {
- datas.push(data);
- } else {
- filterNodes.push(node);
- }
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- const refreshNode = tree.loadPostData(result);
- if (refreshNode.update) {
- refreshNode.update = refreshNode.update.concat(filterNodes);
- }
- contractTreeSpreadObj.refreshTree(info.sheet, refreshNode);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- });
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- }
- },
- deletePress: function (sheet) {
- if (!sheet.zh_setting) return;
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_tree.nodes[iRow];
- const data = sheet.zh_tree.getNodeKeyData(node);
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- const style = sheet.getStyle(iRow, iCol);
- if (style.locked) continue;
- data[col.field] = null;
- bDel = true;
- }
- if (bDel) datas.push(data);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- const refreshNode = sheet.zh_tree.loadPostData(result);
- contractTreeSpreadObj.refreshTree(sheet, refreshNode);
- });
- }
- },
- pasteBlock: function (spread, copyInfo) {
- const self = this;
- const sheet = spread.getActiveSheet();
- const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
- postData(window.location.pathname + '/update', {
- postType: 'paste-block',
- postData: {
- id: tree.getNodeKey(node),
- // tid: copyInfo.tid,
- block: copyInfo.block,
- }
- }, function (data) {
- const result = tree.loadPostData(data.ledger);
- self.refreshTree(sheet, result);
- const sel = sheet.getSelections()[0];
- if (sel) {
- sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
- }
- self.refreshOperationValid(sheet);
- removeLocalCache(copyBlockTag);
- }, null, true);
- },
- topRowChanged: function (e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
- },
- editStarting(e, info) {
- if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
- const col = info.sheet.zh_setting.cols[info.col];
- const node = info.sheet.zh_tree.nodes[info.row];
- if (!node) {
- info.cancel = true;
- return;
- }
- },
- cut: function (sheet, sel, callback) {
- if (!sheet || !sel) return;
- if (sel.colCount >= sheet.zh_setting.cols.length) {
- toastr.warning('请勿选中整行剪切');
- return;
- }
- const sortData = SpreadJsObj.getSortData(sheet), datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const node = sortData[iRow];
- if (node) {
- const data = sheet.zh_tree.getNodeKeyData(node);
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const style = sheet.getStyle(iRow, iCol);
- if (style.locked) {
- toastr.error('不可剪切');
- return;
- }
- const colSetting = sheet.zh_setting.cols[iCol];
- data[colSetting.field] = null;
- }
- datas.push(data);
- }
- }
- if (datas.length > 0) {
- callback();
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- const refreshNode = sheet.zh_tree.loadPostData(result);
- contractTreeSpreadObj.refreshTree(sheet, refreshNode);
- });
- }
- },
- sortCode: function (sheet) {
- const tree = sheet.zh_tree;
- if (!tree) return;
- const select = SpreadJsObj.getSelectObject(sheet);
- if (!select || !select.code || select.code === '') return;
- const recursiveSortCode = function (data, parentCode, children) {
- if (!children || children.length === 0) return;
- for (const [i, child] of children.entries()) {
- if (!child.b_code || child.b_code === '') {
- const code = parentCode + '-' + (i + 1);
- const cData = tree.getNodeKeyData(child);
- cData.code = code;
- data.push(cData);
- if (!tree.isLeafXmj(child)) {
- recursiveSortCode(data, code, child.children);
- }
- }
- }
- };
- const data = [];
- recursiveSortCode(data, select.code, select.children);
- if (data.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
- const refreshNode = tree.loadPostData(result);
- contractTreeSpreadObj.refreshTree(sheet, refreshNode);
- })
- }
- },
- checkContract: function (select) {
- let haveContract = false;
- if (select.c_code) {
- haveContract = true;
- } else {
- const selects = contractSheet.zh_tree.getPosterity(select);
- const select_contracts = _.filter(selects, function (item) {
- return item.c_code;
- });
- if (select_contracts.length > 0) haveContract = true;
- }
- return haveContract;
- },
- checkDelete: function (select, oldFlag = true) {
- let canDelete = oldFlag;
- if (select.c_code) {
- if (!(select.uid === user_id || is_admin)) {
- canDelete = false;
- } else if (select.exist_pay) {
- canDelete = false;
- }
- } else {
- const selects = contractSheet.zh_tree.getPosterity(select);
- const select_contracts = _.filter(selects, function (item) {
- return item.c_code;
- });
- if (select_contracts.length > 0) {
- for (const sc of select_contracts) {
- if (!(sc.uid === user_id || is_admin)) {
- canDelete = false;
- break;
- } else if (sc.exist_pay) {
- canDelete = false;
- break;
- }
- }
- }
- }
- return canDelete;
- }
- };
- contractSpread.bind(spreadNS.Events.SelectionChanged, contractTreeSpreadObj.selectionChanged);
- contractSpread.bind(spreadNS.Events.topRowChanged, contractTreeSpreadObj.topRowChanged);
- // 右键菜单
- let batchInsertObj;
- $.contextMenu.types.batchInsert = function (item, opt, root) {
- const self = this;
- if ($.isFunction(item.icon)) {
- item._icon = item.icon.call(this, this, $t, key, item);
- } else {
- if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
- // to enable font awesome
- item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
- } else {
- item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
- }
- }
- this.addClass(item._icon);
- const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
- .appendTo(this);
- const $input = $obj.find('input');
- const event = () => {
- if (self.hasClass('context-menu-disabled')) return;
- item.batchInsert($input[0], root);
- };
- $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
- $input.click((e) => {e.stopPropagation();})
- .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
- .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
- };
- const contractContextMenuOptions = {
- selector: '#contract-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, contractSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {}
- };
- if (permission_edit) {
- contractSpread.bind(spreadNS.Events.EditStarting, contractTreeSpreadObj.editStarting);
- contractSpread.bind(spreadNS.Events.EditEnded, contractTreeSpreadObj.editEnded);
- contractSpread.bind(spreadNS.Events.ButtonClicked, contractTreeSpreadObj.buttonClicked);
- contractSpread.bind(spreadNS.Events.ClipboardPasting, contractTreeSpreadObj.clipboardPasting);
- contractSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
- const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
- SpreadJsObj.Clipboard.setCopyData(copyText);
- });
- SpreadJsObj.addDeleteBind(contractSpread, contractTreeSpreadObj.deletePress);
- SpreadJsObj.addCutEvents(contractSpread, contractTreeSpreadObj.cut);
- $('a[name="base-opr"]').click(function () {
- contractTreeSpreadObj.baseOpr(contractSheet, this.getAttribute('type'));
- });
- $('a[name=cpc]').click(function () {
- contractSpread.commandManager().execute({
- cmd: this.getAttribute('type'),
- sheetName: contractSheet.name()
- });
- });
- contractContextMenuOptions.items.create = {
- name: '新增节点',
- icon: 'fa-plus',
- callback: function (key, opt) {
- contractTreeSpreadObj.baseOpr(contractSheet, 'add');
- },
- disabled: function (key, opt) {
- const sheet = contractSheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return true;
- const first = sheet.zh_tree.nodes[row];
- const valid = !sheet.zh_setting.readOnly;
- return !(valid && first && first.level > 1);
- }
- };
- contractContextMenuOptions.items.create3 = {
- name: '新增子节点',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- contractTreeSpreadObj.baseOpr(contractSheet, 'add-child');
- },
- disabled: function (key, opt) {
- const sheet = contractSheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return true;
- const first = sheet.zh_tree.nodes[row];
- const valid = !sheet.zh_setting.readOnly;
- return !(valid && first && !first.c_code && first.level >= 1);
- }
- };
- }
- if (permission_add) {
- contractContextMenuOptions.items.create2 = {
- name: '新增合同',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- $('#cons-add').modal('show');
- },
- visible: function (key, opt) {
- const sheet = contractSheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return false;
- const first = sheet.zh_tree.nodes[row];
- if (first && first.c_code) {
- const parent = sheet.zh_tree.getParent(first);
- return parent && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: parent.contract_id, uid: user_id }) !== -1);
- }
- return first && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: first.contract_id, uid: user_id }) !== -1);
- },
- disabled: function (key, opt) {
- const sheet = contractSheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return true;
- const first = sheet.zh_tree.nodes[row];
- const valid = !sheet.zh_setting.readOnly;
- return !(valid && first && first.level > 1);
- }
- };
- }
- contractContextMenuOptions.items.delete = {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- contractTreeSpreadObj.baseOpr(contractSheet, 'delete');
- },
- visible: function (key, opt) {
- const sheet = contractSheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return false;
- const first = sheet.zh_tree.nodes[row];
- return (first && first.c_code) || permission_edit;
- },
- disabled: function (key, opt) {
- const sheet = contractSheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return true;
- const first = sheet.zh_tree.nodes[row];
- let last = first, sameParent = true, childCanDel = true;
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = tree.nodes[sel.row + r];
- childCanDel = contractTreeSpreadObj.checkDelete(rNode, childCanDel);
- if (!rNode) {
- sameParent = false;
- break;
- }
- if (rNode.level > first.level) continue;
- if ((rNode.level < first.level) || (rNode.level === first.level && rNode.contract_pid !== first.contract_pid)) {
- sameParent = false;
- break;
- }
- last = rNode;
- }
- }
- const valid = !sheet.zh_setting.readOnly;
- return !(valid && first && first.level > 1 && sameParent && childCanDel && contractTreeSpreadObj.checkDelete(first));
- }
- };
- contractContextMenuOptions.items.sprBase = '----';
- // contractContextMenuOptions.items.copyBlock = {
- // name: '复制整块(只复制节点)',
- // icon: 'fa-files-o',
- // callback: function (key, opt) {
- // const copyBlockList = [];
- // const sheet = contractSheet;
- // const sel = sheet.getSelections()[0];
- // let iRow = sel.row;
- // const pid = sheet.zh_tree.nodes[iRow].contract_pid;
- // while (iRow < sel.row + sel.rowCount) {
- // const node = sheet.zh_tree.nodes[iRow];
- // if (node.contract_pid !== pid) {
- // toastr.error('仅可同时选中同层节点');
- // return;
- // }
- // const posterity = sheet.zh_tree.getPosterity(node);
- // iRow += posterity.length + 1;
- // posterity.unshift(node);
- // const copyData = sheet.zh_tree.getDefaultData(posterity);
- // const newCopyData = _.filter(_.cloneDeep(copyData), function (d) {
- // return d.c_code === undefined;
- // });
- // const newCopyBlock = [];
- // for (const p of newCopyData) {
- // const children = _.filter(newCopyData, function (item) {
- // return item.contract_pid === p.contract_id;
- // });
- // if (children.length > 0) {
- // let i = 1;
- // for (const c of children) {
- // c.order = i;
- // i++;
- // }
- // } else {
- // p.is_leaf = 1;
- // }
- // if (_.findIndex(newCopyBlock, { contract_id: p.contract_id }) === -1) {
- // newCopyBlock.push(p);
- // }
- // }
- // copyBlockList.push(newCopyBlock);
- // }
- // setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
- // },
- // visible: function (key, opt) {
- // const sheet = contractSheet;
- // const selection = sheet.getSelections();
- // const row = selection[0].row;
- // const select = contractTree.nodes[row];
- // return select;
- // },
- // disabled: function (key, opt) {
- // const sheet = contractSheet;
- // const selection = sheet.getSelections();
- // const row = selection[0].row;
- // const select = contractTree.nodes[row];
- // console.log(select);
- // return !(select && select.level > 1 && !select.c_code);
- // }
- // };
- // if (permission_edit) {
- // contractContextMenuOptions.items.pasteBlock = {
- // name: '粘贴整块',
- // icon: 'fa-clipboard',
- // disabled: function (key, opt) {
- // //const block = treeOperationObj.block || [];
- // const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
- // return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
- // },
- // callback: function (key, opt) {
- // //const block = treeOperationObj.block || [];
- // const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
- // if (copyInfo.block.length > 0) {
- // contractTreeSpreadObj.pasteBlock(contractSpread, copyInfo);
- // } else {
- // document.execCommand('paste');
- // }
- // },
- // visible: function (key, opt) {
- // return permission_edit;
- // }
- // };
- // contractContextMenuOptions.items.sprBlock = '----';
- // }
- if (permission_edit) {
- contractContextMenuOptions.items.batchInsert = {
- name: '批量插入',
- type: 'batchInsert',
- value: '2',
- icon: 'fa-sign-in',
- batchInsert: function (obj, root) {
- if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
- obj.value = obj.max;
- toastr.warning('批量插入不可多于' + obj.max);
- } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
- obj.value = obj.min;
- toastr.warning('批量插入不可少于' + obj.min);
- } else {
- contractTreeSpreadObj.baseOpr(contractSheet, 'add', parseInt(obj.value));
- root.$menu.trigger('contextmenu:hide');
- }
- },
- disabled: function (key, opt) {
- const sheet = contractSheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return true;
- const first = sheet.zh_tree.nodes[row];
- const valid = !sheet.zh_setting.readOnly;
- return !(valid && first && first.level > 1);
- }
- };
- contractContextMenuOptions.items.sprTag = '----';
- }
- contractContextMenuOptions.items.showLast = {
- name: '显示至最底层',
- callback: function (key, opt, menu, e) {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- setTimeout(() => {
- showWaitingView();
- contractTree.expandByCustom(x => {
- return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.contract_id + '-') >= 0);
- });
- SpreadJsObj.refreshTreeRowVisible(contractSheet);
- closeWaitingView();
- }, 100);
- },
- };
- $.contextMenu(contractContextMenuOptions);
- $('.bc-bar ul li a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- $('a[href*="#cons-upfile"]').hide();
- if (node && node.c_code) {
- if ($('.bc-bar .nav li .active').attr('href') === '#htfile' && permission_att) $('a[href*="#cons-upfile"]').show();
- if (node.uid === user_id) contractTreeSpreadObj.changeContractTab(node, true);
- }
- });
- $('#edit_contract_btn').on('click', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (node && node.c_code && node.uid === user_id) {
- $('#edit_contract_btn').hide();
- $('#save_contract_btn').show();
- $('#cancel_contract_btn').show();
- for (const c of contractDetail) {
- if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
- if (c === 'sign_date') {
- $('#htdetail_' + c).html('<input type="date" class="form-control form-control-sm" value="' + moment(node[c]).format('YYYY-MM-DD') + '">');
- continue;
- } else if (c === 'remark') {
- $('#htdetail_' + c).html('<textarea class="form-control form-control-sm" rows="3">' + node[c] + '</textarea>');
- continue;
- }
- $('#htdetail_' + c).html('<input type="text" class="form-control form-control-sm" value="' + node[c] + '">');
- }
- }
- }
- });
- $('#save_contract_btn').on('click', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (node && node.c_code && node.uid === user_id) {
- const data = {
- id: node.id,
- };
- for (const c of contractDetail) {
- if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
- if (c === 'sign_date') {
- data[c] = $('#htdetail_' + c + ' input').val() || null;
- continue;
- } else if (c === 'remark') {
- data[c] = $('#htdetail_' + c + ' textarea').val();
- continue;
- }
- data[c] = $('#htdetail_' + c + ' input').val();
- }
- }
- if (data.c_code === '' || data.name === '') {
- toastr.warning('合同编号和合同名称不能为空');
- return;
- }
- if (data.total_price === '') {
- toastr.warning('合同金额不能为空');
- return;
- } else if (!/^\d+(\.\d+)?$/.test(data.total_price)) {
- toastr.warning('合同金额只能输入数字');
- return;
- }
- if (parseFloat(data.total_price) < node.yf_price) {
- const name = contract_type === contractConst.type.expenses ? '付' : '回';
- toastr.warning('合同金额不能小于累计应' + name);
- return;
- }
- if (data.party_b === '') {
- toastr.warning('签订单位(乙方)不能为空');
- return;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) {
- toastr.success('已编辑成功');
- const refreshNode = contractTree.loadPostData(result);
- console.log(refreshNode);
- contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
- const newNode = SpreadJsObj.getSelectObject(contractSheet);
- contractTreeSpreadObj.changeContractTab(newNode, true);
- });
- }
- });
- $('#cancel_contract_btn').on('click', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (node && node.c_code && node.uid === user_id) {
- $('#edit_contract_btn').show();
- $('#save_contract_btn').hide();
- $('#cancel_contract_btn').hide();
- for (const c of contractDetail) {
- if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
- if (c === 'sign_date') {
- $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : '');
- } else {
- $('#htdetail_' + c).html(node[c]);
- }
- }
- }
- }
- });
- $('#file-ok').click(function () {
- const files = Array.from($('#file-modal')[0].files)
- const valiData = files.map(v => {
- const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
- return {
- size: v.size,
- ext
- }
- })
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.warning('请选择合同再上传文件');
- 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(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/file/upload`, formData, function (result) {
- contractTreeSpreadObj.setContractFiles(result, node.id);
- $('#file-modal').val('');
- $('#file-cancel').click()
- });
- }
- }
- });
- $('body').on('click', '#htfile .file-del', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- const fid = $(this).data('id');
- deleteAfterHint(function () {
- postData(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/file/delete`, { id: fid }, function (result) {
- contractTreeSpreadObj.setContractFiles(result, node.id);
- });
- }, '确认删除该文件?');
- });
- $('body').on('click', '#htpay .pay-del', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- const cpid = $(this).data('id');
- if (!node || !node.c_code) {
- toastr.warning('请选择合同节点');
- return;
- }
- if (node.settle_code) {
- toastr.warning('已结算的合同不能删除合同' + contractConst.typeName[contract_type]);
- return;
- }
- deleteAfterHint(function () {
- postData(window.location.pathname + '/update', {postType: 'del-contract-pay', postData: { select: node.id, pay: cpid }}, function (result) {
- const refreshNode = contractTree.loadPostData(result.node);
- contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
- contractTreeSpreadObj.setContractPays(result.pays, node);
- })
- }, '确认删除该合同' + contractConst.typeName[contract_type] + '?');
- });
- const payTime = $('#cons-addpay input[name="pay_time"]').datepicker().data('datepicker');
- $('.datepicker-here').datepicker({
- autoClose: true,
- });
- $('#add_contract_pay_btn').on('click', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- return;
- }
- $('#cons-addpay .modal-title').text('添加' + contractConst.typeName[contract_type]);
- $('#cons-addpay input[name="cpid"]').val('');
- $('#add-contract-pay').show();
- $('#save-contract-pay').hide();
- setPayModalInfo();
- $('#cons-addpay').modal('show');
- });
- $('body').on('click', '#htpay .pay-edit', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- return;
- }
- const cpid = $(this).data('id');
- const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
- if (!cpInfo) {
- toastr.error('未找到该合同' + contractConst.typeName[contract_type]);
- return
- }
- $('#cons-addpay .modal-title').text('编辑' + contractConst.typeName[contract_type]);
- $('#cons-addpay input[name="cpid"]').val(cpid);
- $('#add-contract-pay').hide();
- $('#save-contract-pay').show();
- setPayModalInfo(cpInfo);
- $('#cons-addpay').modal('show');
- });
- function setPayModalInfo(cpInfo = null) {
- $('#cons-addpay input[name="pay_time"]').val(cpInfo ? moment(cpInfo.pay_time).format('YYYY-MM-DD') : '');
- payTime.selectDate(cpInfo ? new Date(cpInfo.pay_time) : '');
- $('#cons-addpay input[name="pay_price"]').val(cpInfo ? cpInfo.pay_price : '');
- $('#cons-addpay input[name="debit_price"]').val(cpInfo ? cpInfo.debit_price : '');
- $('#cons-addpay input[name="yf_price"]').val(cpInfo ? cpInfo.yf_price : '');
- $('#cons-addpay input[name="sf_price"]').val(cpInfo ? cpInfo.sf_price : '');
- $('#cons-addpay select[name="pay_type"]').val(cpInfo ? cpInfo.pay_type : $('#cons-addpay select[name="pay_type"] option:first').text());
- $('#cons-addpay textarea[name="remark"]').val(cpInfo ? cpInfo.remark : '');
- $('#cons-addpay .yf-tips').text('');
- $('#cons-addpay .sf-tips').text('');
- }
- // 上传附件
- $('#cons-pay-file input[type="file"]').change(function () {
- const files = Array.from(this.files);
- console.log(files);
- const valiData = files.map(v => {
- const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
- return {
- size: v.size,
- ext
- }
- })
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.warning('请选择合同再上传文件');
- $('#cons-pay-file input[type="file"]').val('');
- return;
- }
- const cpid = $('#cons-pay-file input[name="cpid"]').val();
- const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
- if (!cpInfo) {
- toastr.warning('请选择合同'+ contractConst.typeName[contract_type] +'再上传文件');
- $('#cons-pay-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(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/pay/${cpInfo.id}/file/upload`, formData, function (result) {
- cpInfo.files = result;
- contractTreeSpreadObj.openContractPayFiles(cpInfo);
- $('#htpay-table tbody').find('tr[data-cpid="' + cpInfo.id + '"]').find('.files-num').text(result.length || '');
- });
- }
- }
- $('#cons-pay-file input[type="file"]').val('');
- });
- $('body').on('click', '#cons-pay-file .file-del', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- const cpid = $('#cons-pay-file input[name="cpid"]').val();
- const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
- if (!cpInfo) {
- toastr.warning('未选择合同' + contractConst.typeName[contract_type]);
- return;
- }
- const fid = $(this).data('id');
- deleteAfterHint(function () {
- postData(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/pay/${cpInfo.id}/file/delete`, { id: fid }, function (result) {
- cpInfo.files = result;
- contractTreeSpreadObj.openContractPayFiles(cpInfo);
- $('#htpay-table tbody').find('tr[data-cpid="' + cpInfo.id + '"]').find('.files-num').text(result.length || '');
- });
- }, '确认删除该文件?');
- });
- postData(window.location.pathname + '/load', {}, function (result) {
- const datas = result.contractTree.concat(result.contractList);
- for (const t of datas) {
- if (!t.is_leaf && _.findIndex(datas, { contract_pid: t.contract_id }) === -1) {
- t.is_leaf = 1;
- }
- }
- contractTree.loadDatas(datas);
- treeCalc.calculateAll(contractTree);
- // contractTree.setExpanded(node, !node.expanded);
- // SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
- SpreadJsObj.loadSheetData(contractSheet, SpreadJsObj.DataType.Tree, contractTree);
- SpreadJsObj.loadTopAndSelect(contractSheet, ckBillsSpread);
- contractTreeSpreadObj.setContract(contractSheet);
- checkShowLast(result.contractTree.length);
- contractTreeSpreadObj.refreshOperationValid(contractSheet);
- // contractTreeSpreadObj.setAllForeColor(contractSheet);
- console.log(contractTree);
- });
- if (is_admin) {
- const sqSpreadSetting = {
- cols: [
- {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@', cellType: 'tree'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 240, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- rowHeader:[
- // {
- // rowHeaderType: 'circle',
- // setting: {
- // size: 5,
- // indent: 16,
- // getColor: function (index, data) {
- // if (!data) return;
- // if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
- // return '#dc3545';
- // }
- // if(data.lid != 0) return;
- // return '#007bff';
- // }
- // },
- // },
- ],
- localCache: {
- key: 'contract-sq-spread',
- colWidth: true,
- }
- };
- const sqSpread = SpreadJsObj.createNewSpread($('#sq-spread')[0]);
- const sqSheet = sqSpread.getActiveSheet();
- // sjsSettingObj.setGridSelectStyle(sqSpreadSetting);
- sjsSettingObj.setFxTreeStyle(sqSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- SpreadJsObj.initSheet(sqSheet, sqSpreadSetting);
- const sqTreeSetting = {
- id: 'contract_id',
- pid: 'contract_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tid', 'spid'],
- autoExpand: 3,
- markExpandKey: 'contract-sq-bills-expand',
- markExpandSubKey: window.location.pathname.split('/')[2],
- };
- sqTreeSetting.calcFun = function (node) {
- };
- const sqTree = createNewPathTree('base', sqTreeSetting);
- const sqTreeSpreadObj = {
- setTreeAudits: function (sheet, selection) {
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) {
- return;
- }
- const first = sheet.zh_tree.nodes[row];
- const auditList = _.orderBy(_.filter(contractTreeAudits, { contract_id: first.contract_id }), ['create_time'], ['desc']);
- let auditHtml = '';
- for (const audit of auditList) {
- audit.name = _.find(accountList, { id: audit.uid }).name;
- auditHtml += `<tr data-id="${audit.uid}">
- <td><input type="checkbox"></td><td>${audit.name}</td><td>${moment(new Date(audit.create_time)).format('YYYY-MM-DD HH:mm:ss')}</td><td>${this.setAuditPermissionTxt(audit)}</td>
- <td><button class="btn btn-sm btn-outline-danger del-tree-audit">移除</button></td>
- </tr>`;
- }
- $('#contract-tree-audits').html(auditHtml);
- },
- setAuditPermissionTxt: function (audit) {
- const txt = [];
- const ca = _.find(contractAudits, { uid: audit.uid });
- if (ca && ca.permission_edit) {
- txt.push('编辑节点');
- }
- if (ca && ca.permission_add) {
- txt.push('添加合同');
- }
- if (ca && ca.permission_show_unit) {
- txt.push('查看本单位合同');
- }
- if (ca && ca.permission_show_node) {
- txt.push('查看本节点合同');
- }
- if (ca && !ca.permission_show_unit && !ca.permission_show_node) {
- txt.push('查看本人合同');
- }
- return txt.join(',');
- },
- selectionChanged: function (e, info) {
- if (info.newSelections) {
- if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
- $('#select-permission-tree-audit-all').prop('checked', false);
- sqTreeSpreadObj.setTreeAudits(info.sheet);
- }
- }
- },
- }
- sqSpread.bind(spreadNS.Events.SelectionChanged, sqTreeSpreadObj.selectionChanged);
- let contractAudits = [];
- let contractAccountGroup = [];
- $('#empower').on('shown.bs.modal', function () {
- postData(window.location.pathname + '/load', {}, function (result) {
- const tree = result.contractTree;
- for (const t of tree) {
- if (!t.is_leaf && _.findIndex(tree, { contract_pid: t.contract_id }) === -1) {
- t.is_leaf = 1;
- }
- }
- sqTree.loadDatas(tree);
- SpreadJsObj.loadSheetData(sqSheet, SpreadJsObj.DataType.Tree, sqTree);
- sqSpread.refresh();
- contractAudits = result.contractAudits;
- contractAccountGroup = result.accountGroup;
- let groupBookListHtml = '';
- result.accountGroup.forEach((group, idx) => {
- groupBookListHtml += '<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';
- let groupListHtml = '';
- group.groupList.forEach(item => {
- groupListHtml += '<dd class="border-bottom p-2 mb-0 " data-id="'+ item.uid + '" >\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';
- });
- groupBookListHtml = groupBookListHtml + groupListHtml + '</div>';
- });
- $('#empower .book-list').html(groupBookListHtml);
- sqTreeSpreadObj.setTreeAudits(sqSheet);
- });
- });
- let timer2 = null
- let oldSearchVal2 = null
- $('#gr-search2').bind('input propertychange', function (e) {
- oldSearchVal2 = e.target.value
- timer2 && clearTimeout(timer2)
- timer2 = setTimeout(() => {
- const newVal = $('#gr-search2').val()
- let html = ''
- if (newVal && newVal === oldSearchVal2) {
- contractAudits.filter(item => item && (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.uid}" >
- <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>`
- })
- $('#empower .book-list').empty()
- $('#empower .book-list').append(html)
- } else {
- if (!$('#empower .acc-btn').length) {
- contractAccountGroup.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 => {
- html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.uid}" >
- <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>'
- })
- $('#empower .book-list').empty()
- $('#empower .book-list').append(html)
- }
- }
- }, 400);
- });
- // 添加到成员中
- $('body').on('click', '#empower dl dd', function () {
- const id = parseInt($(this).data('id'));
- const node = SpreadJsObj.getSelectObject(sqSheet);
- if (!node) {
- toastr.error('请选择节点');
- return;
- }
- if (!isNaN(id) && id !== 0) {
- if (_.findIndex(contractTreeAudits, { uid: id, contract_id: node.contract_id }) !== -1) {
- toastr.error('该成员已存在, 请勿重复添加');
- return;
- }
- postData(window.location.pathname + '/update', {postType: 'add-tree-audit', postData: { select: node, auditId: id }}, function (result) {
- contractTreeAudits.push(result);
- sqTreeSpreadObj.setTreeAudits(sqSheet);
- })
- }
- });
- $('#select-permission-tree-audit-all').on('click', function () {
- $('#contract-tree-audits').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
- });
- $('#batch-del-audits').on('click', function () {
- let uids = [];
- $('#contract-tree-audits').find('input[type="checkbox"]:checked').each(function () {
- uids.push(parseInt($(this).parents('tr').data('id')));
- });
- if (uids.length === 0) {
- toastr.warning('请选择要移除的成员');
- return;
- }
- deleteAfterHint(function () {
- postData(window.location.pathname + '/update', {
- postType: 'del-tree-audit',
- postData: {
- select: SpreadJsObj.getSelectObject(sqSheet),
- auditIds: uids,
- }
- }, function (result) {
- // contractTreeAudits数组清空再赋值
- contractTreeAudits = result;
- sqTreeSpreadObj.setTreeAudits(sqSheet);
- });
- }, '确认移除「当前节点已勾选授权用户」?');
- });
- $('body').on('click', '#empower .del-tree-audit', function () {
- const uid = parseInt($(this).parents('tr').data('id'));
- deleteAfterHint(function () {
- postData(window.location.pathname + '/update', {
- postType: 'del-tree-audit',
- postData: {
- select: SpreadJsObj.getSelectObject(sqSheet),
- auditIds: uid,
- }
- }, function (result) {
- // contractTreeAudits数组清空再赋值
- contractTreeAudits = result;
- sqTreeSpreadObj.setTreeAudits(sqSheet);
- });
- }, '确认移除「当前节点授权用户」?');
- });
- }
- if (permission_add) {
- $('#cons-add').on('show.bs.modal', function () {
- $('#cons-add input[name="code"]').val('');
- $('#cons-add input[name="name"]').val('');
- $('#cons-add input[name="total_price"]').val('');
- $('#cons-add input[name="party_b"]').val('');
- $('#cons-add textarea[name="remark"]').val('');
- });
- $('#add-contract').click(function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node) {
- toastr.error('请选择一个节点');
- return;
- }
- console.log(node);
- const data = {
- code: $('#cons-add input[name="code"]').val(),
- name: $('#cons-add input[name="name"]').val(),
- total_price: $('#cons-add input[name="total_price"]').val(),
- party_b: $('#cons-add input[name="party_b"]').val(),
- remark: $('#cons-add textarea[name="remark"]').val(),
- }
- if (!data.code) {
- toastr.error('请输入合同编号');
- return;
- }
- if (!data.name) {
- toastr.error('请输入合同名称');
- return;
- }
- if (!data.total_price) {
- toastr.error('请输入合同金额');
- return;
- }
- // 金额只能输入数字
- if (!/^\d+(\.\d+)?$/.test(data.total_price)) {
- toastr.error('合同金额只能输入数字');
- return;
- }
- if (!data.party_b) {
- toastr.error('请输入签订单位(乙方)');
- return;
- }
- console.log(node, data);
- postData(window.location.pathname + '/update', {postType: 'add-contract', postData: { select: node, contract: data }}, function (result) {
- const refreshNode = contractTree.loadPostData(result);
- contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
- $('#cons-add').modal('hide');
- })
- });
- }
- $('#cons-addpay input[type="number"]').change(function () {
- const name = $(this).attr('name');
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- return;
- }
- if (node.uid !== user_id) {
- toastr.error('只能修改自己的合同' + contractConst.typeName[contract_type]);
- return;
- }
- if (node.settle_code) {
- toastr.error('该合同已结算,不能修改');
- return;
- }
- let sf_price = $('#cons-addpay input[name="sf_price"]').val() || 0;
- const pay_price = $('#cons-addpay input[name="pay_price"]').val() || 0;
- const debit_price = $('#cons-addpay input[name="debit_price"]').val() || 0;
- const yf_price = ZhCalc.sub(pay_price, debit_price);
- $('#cons-addpay .yf-tips').text('');
- const cpid = $('#cons-addpay input[name="cpid"]').val();
- if (cpid) {
- const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
- const newNodePayPrice = ZhCalc.add(ZhCalc.sub(node.pay_price, cpInfo.pay_price), parseFloat(pay_price));
- const newNodeDebitPrice = ZhCalc.add(ZhCalc.sub(node.debit_price, cpInfo.debit_price), parseFloat(debit_price));
- const newNodeYfPrice = ZhCalc.sub(newNodePayPrice, newNodeDebitPrice);
- if (parseFloat(sf_price) > ZhCalc.add(cpInfo.sf_price, ZhCalc.sub(newNodeYfPrice, node.sf_price))) {
- $('#cons-addpay .sf-tips').text(' ≤ ' + ZhCalc.add(cpInfo.sf_price, ZhCalc.sub(newNodeYfPrice, node.sf_price)));
- } else {
- $('#cons-addpay .sf-tips').text('');
- }
- if (parseFloat(yf_price) > ZhCalc.add(cpInfo.yf_price, ZhCalc.sub(node.total_price, node.yf_price))) {
- $('#cons-addpay .yf-tips').text(' ≤ ' + ZhCalc.add(cpInfo.yf_price, ZhCalc.sub(node.total_price, node.yf_price)));
- } else {
- $('#cons-addpay .yf-tips').text('');
- }
- } else {
- if (name !== 'sf_price') {
- $('#cons-addpay input[name="sf_price"]').val(yf_price);
- sf_price = yf_price;
- }
- if (parseFloat(sf_price) > ZhCalc.sub(ZhCalc.add(node.yf_price, yf_price), node.sf_price)) {
- $('#cons-addpay .sf-tips').text(' ≤ ' + ZhCalc.sub(ZhCalc.add(node.yf_price, yf_price), node.sf_price));
- } else {
- $('#cons-addpay .sf-tips').text('');
- }
- if (parseFloat(yf_price) > ZhCalc.sub(node.total_price, node.yf_price)) {
- $('#cons-addpay .yf-tips').text(' ≤ ' + ZhCalc.sub(node.total_price, node.yf_price));
- } else {
- $('#cons-addpay .yf-tips').text('');
- }
- }
- if (name === 'pay_price' || name === 'debit_price') {
- $('#cons-addpay input[name="yf_price"]').val(yf_price);
- }
- });
- $('#add-contract-pay').click(function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- return;
- }
- if (node.uid !== user_id) {
- toastr.error('只能添加自己的合同' + contractConst.typeName[contract_type]);
- return;
- }
- if (node.settle_code) {
- toastr.error('该合同已结算,不能添加');
- return;
- }
- const data = {
- pay_time: $('#cons-addpay input[name="pay_time"]').val(),
- pay_price: $('#cons-addpay input[name="pay_price"]').val() || 0,
- debit_price: $('#cons-addpay input[name="debit_price"]').val() || 0,
- yf_price: $('#cons-addpay input[name="yf_price"]').val() || 0,
- sf_price: $('#cons-addpay input[name="sf_price"]').val() || 0,
- pay_type: $('#cons-addpay select[name="pay_type"]').val(),
- remark: $('#cons-addpay textarea[name="remark"]').val(),
- }
- const name = contract_type === contractConst.type.expenses ? '付' : '回';
- if (!judgePays(node, data, name)) {
- return;
- }
- console.log(node, data);
- postData(window.location.pathname + '/update', {postType: 'add-contract-pay', postData: { select: node.id, pay: data }}, function (result) {
- const refreshNode = contractTree.loadPostData(result.node);
- contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
- contractTreeSpreadObj.setContractPays(result.pays, node);
- // const selection = contractSheet.getSelections();
- // const sel = selection ? selection[0] : contractSheet.getSelections()[0];
- // const row = sel ? sel.row : -1;
- // contractTreeSpreadObj.setForeColor(contractSheet, row);
- $('#cons-addpay').modal('hide');
- })
- });
- $('#save-contract-pay').click(function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- return;
- }
- if (node.settle_code) {
- toastr.error('该合同已结算,不能修改');
- return;
- }
- const cpid = $('#cons-addpay input[name="cpid"]').val();
- const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
- if (!cpInfo) {
- toastr.error('未找到该合同' + contractConst.typeName[contract_type]);
- return
- }
- if (cpInfo.uid !== user_id) {
- toastr.error('只能编辑自己的合同' + contractConst.typeName[contract_type]);
- return;
- }
- const data = {
- id: cpInfo.id,
- pay_time: $('#cons-addpay input[name="pay_time"]').val(),
- pay_price: $('#cons-addpay input[name="pay_price"]').val() || 0,
- debit_price: $('#cons-addpay input[name="debit_price"]').val() || 0,
- yf_price: $('#cons-addpay input[name="yf_price"]').val() || 0,
- sf_price: $('#cons-addpay input[name="sf_price"]').val() || 0,
- pay_type: $('#cons-addpay select[name="pay_type"]').val(),
- remark: $('#cons-addpay textarea[name="remark"]').val(),
- }
- const name = contract_type === contractConst.type.expenses ? '付' : '回';
- if (!judgePays(node, data, name, cpInfo)) {
- return;
- }
- console.log(node, data);
- postData(window.location.pathname + '/update', {postType: 'save-contract-pay', postData: { select: node.id, pay: data }}, function (result) {
- const refreshNode = contractTree.loadPostData(result.node);
- contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
- contractTreeSpreadObj.setContractPays(result.pays, node);
- // const selection = contractSheet.getSelections();
- // const sel = selection ? selection[0] : contractSheet.getSelections()[0];
- // const row = sel ? sel.row : -1;
- // contractTreeSpreadObj.setForeColor(contractSheet, row);
- $('#cons-addpay').modal('hide');
- })
- });
- function judgePays(node, data, name, cpInfo = null) {
- let flag = true;
- if (!data.pay_time) {
- toastr.error('请输入'+ (name === '付' ? '支付' : '回款') +'日期');
- return false;
- }
- if (!data.pay_price) {
- toastr.error('请输入'+ name +'款金额');
- return false;
- }
- // 金额只能输入数字
- if (!/^\d+(\.\d+)?$/.test(data.pay_price)) {
- toastr.error(name + '款金额只能输入数字');
- return false;
- }
- if (data.debit_price && !/^\d+(\.\d+)?$/.test(data.debit_price)) {
- toastr.error('扣款金额只能输入数字');
- return false;
- }
- if (parseFloat(data.debit_price) > parseFloat(data.pay_price)) {
- toastr.error('扣款金额不能大于'+ name +'款金额');
- return false;
- }
- if (data.sf_price && !/^\d+(\.\d+)?$/.test(data.sf_price)) {
- toastr.error('实'+ name +'金额只能输入数字');
- return false;
- }
- if (cpInfo) {
- const newNodePayPrice = ZhCalc.add(ZhCalc.sub(node.pay_price, cpInfo.pay_price), parseFloat(data.pay_price));
- const newNodeDebitPrice = ZhCalc.add(ZhCalc.sub(node.debit_price, cpInfo.debit_price), parseFloat(data.debit_price));
- const newNodeYfPrice = ZhCalc.sub(newNodePayPrice, newNodeDebitPrice);
- const newNodeSfPrice = ZhCalc.add(ZhCalc.sub(node.sf_price, cpInfo.sf_price), parseFloat(data.sf_price));
- if (newNodeYfPrice > node.total_price) {
- toastr.error('累计应'+ name +'金额不能大于合同金额');
- return false;
- }
- if (newNodeSfPrice > newNodeYfPrice) {
- toastr.error('累计实'+ name +'金额不能大于累计应'+ name +'金额');
- return false;
- }
- } else {
- if (ZhCalc.add(parseFloat(data.yf_price), node.yf_price) > node.total_price) {
- toastr.error('累计应'+ name +'金额不能大于合同金额');
- return false;
- }
- if (ZhCalc.add(parseFloat(data.sf_price), node.sf_price) > ZhCalc.add(parseFloat(data.yf_price), node.yf_price)) {
- toastr.error('累计实'+ name +'金额不能大于累计应'+ name +'金额');
- return false;
- }
- }
- // if (parseFloat(data.sf_price) > parseFloat(data.yf_price)) {
- // toastr.error('实'+ name +'金额不能大于应'+ name +'金额');
- // return false;
- // }
- if (!data.pay_type) {
- toastr.error('请选择' + contractConst.typeName[contract_type] + '方式');
- return false;
- }
- return flag;
- }
- $('body').on('click', '.open-pay-files', function () {
- const cpid = $(this).attr('data-cpid');
- if (!cpid) {
- toastr.error('获取合同'+ contractConst.typeName[contract_type] +'信息失败');
- return;
- }
- const pay = _.find(contractPays, { id: parseInt(cpid) });
- if (!pay) {
- toastr.error('获取合同'+ contractConst.typeName[contract_type] +'信息失败');
- return;
- }
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- return;
- }
- if (node.uid !== user_id && !permission_att) {
- $('#cons-pay-file .upload-permission').hide();
- } else {
- $('#cons-pay-file .upload-permission').show();
- }
- $('#cons-pay-file').modal('show');
- $('#cons-pay-file input[name="cpid"]').val(cpid);
- contractTreeSpreadObj.openContractPayFiles(pay);
- });
- $('#cons-close').on('show.bs.modal', function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- $('#cons-close').modal('hide');
- return;
- }
- const df_price = ZhCalc.sub(ZhCalc.sub(node.yf_price, node.sf_price) || 0);
- if (df_price !== 0) {
- $('#close_df_price').text(df_price);
- $('#close_df_price').parents('h5').show();
- } else {
- $('#close_df_price').parents('h5').hide();
- }
- $('#close_contract_code').text(node.c_code + '/' + node.name);
- $('#close_settle_code').val('');
- });
- $('#close_contract_btn').click(function () {
- const settle_code = $('#close_settle_code').val();
- if (!settle_code) {
- toastr.error('请输入结算书编号');
- return;
- }
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- return;
- }
- const data = {
- id: node.id,
- settle_code,
- }
- // 更新至服务器
- postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) {
- const refreshNode = contractTree.loadPostData(result);
- contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
- const newNode = SpreadJsObj.getSelectObject(contractSheet);
- contractTreeSpreadObj.changeContractTab(newNode, true);
- // const selection = contractSheet.getSelections();
- // const sel = selection ? selection[0] : contractSheet.getSelections()[0];
- // const row = sel ? sel.row : -1;
- // contractTreeSpreadObj.setForeColor(contractSheet, row);
- $('#cons-close').modal('hide');
- $('a[href*="#cons-unlock"]').show();
- $('a[href*="#cons-close"]').hide();
- });
- });
- $('#unlock_contract_btn').click(function () {
- const node = SpreadJsObj.getSelectObject(contractSheet);
- if (!node || !node.c_code) {
- toastr.error('请选择一个合同节点');
- return;
- }
- const data = {
- id: node.id,
- settle_code: '',
- }
- // 更新至服务器
- postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) {
- const refreshNode = contractTree.loadPostData(result);
- contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
- const newNode = SpreadJsObj.getSelectObject(contractSheet);
- contractTreeSpreadObj.changeContractTab(newNode, true);
- // const selection = contractSheet.getSelections();
- // const sel = selection ? selection[0] : contractSheet.getSelections()[0];
- // const row = sel ? sel.row : -1;
- // contractTreeSpreadObj.setForeColor(contractSheet, row);
- $('#cons-unlock').modal('hide');
- $('a[href*="#cons-unlock"]').hide();
- $('a[href*="#cons-close"]').show();
- });
- });
- // 显示层次
- (function (select, sheet) {
- $(select).click(function () {
- if (!sheet.zh_tree) return;
- const tag = $(this).attr('tag');
- const tree = sheet.zh_tree;
- setTimeout(() => {
- showWaitingView();
- switch (tag) {
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- tree.expandByLevel(parseInt(tag));
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "last":
- tree.expandByCustom(() => { return true; });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "leafXmj":
- tree.expandToLeafXmj();
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- }
- closeWaitingView();
- }, 100);
- });
- })('a[name=showLevel]', contractSheet);
- $.divResizer({
- select: '#contract-resize',
- callback: function () {
- contractSpread.refresh();
- let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-30);
- // posSpread.refresh();
- }
- });
- $.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();
- contractSpread.refresh();
- }
- });
- });
- /**
- * 校验文件大小、格式
- * @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
- })
- }
|