123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127 |
- 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});
- } 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});
- }
- 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 });
- 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="/contract/${stid}/detail/${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);
- }
- 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 = 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 = 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 = 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('/contract/' + stid + '/detail/' + 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('/contract/' + stid + '/detail/' + 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('/contract/' + stid + '/detail/' + 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('/contract/' + stid + '/detail/' + 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 * 30) {
- toastr.error('文件大小限制为30MB');
- return false
- }
- if (whiteList.indexOf('.' + file.ext.toLowerCase()) === -1) {
- toastr.error('请上传正确的格式文件');
- return false
- }
- return true
- })
- }
|