1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128 |
- 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: 240, formatter: '@', readOnly: 'readOnly.code', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-1'},
- {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();
- $('#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();
- $('#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);
- if (node && node.c_code && 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) {
- $('#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
- })
- }
|