12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060 |
- 'use strict';
- /**
- * 台账修订页面js
- *
- * @author Mai
- * @date
- * @version
- */
- const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
- const invalidFields = {
- parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price', 'ex_qty1', 'ex_tp1'],
- gcl: ['dgn_qty1', 'dgn_qty2'],
- posCode: ['b_code'],
- posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'ex_qty1', 'ex_tp1'],
- posXmj: ['code'],
- };
- function getExprInfo (field, converse = false) {
- const exprField = [
- {qty: 'sgfh_qty', expr: 'sgfh_expr'},
- {qty: 'sjcl_qty', expr: 'sjcl_expr'},
- {qty: 'qtcl_qty', expr: 'qtcl_expr'},
- ];
- return converse ? _.find(exprField, {expr: field}) : _.find(exprField, {qty: field});
- }
- function transExpr(expr) {
- return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
- }
- const copyBlockTag = 'zh.calc.copyBlock';
- const dskCompilation = 'zh.calc.dskCompilation';
- const checkOption = {
- sibling: { enable: 1 },
- empty_code: { enable: 1 },
- calc: {
- enable: 1,
- fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
- },
- zero: { enable: 1 },
- zeroPos: { enable: 1 },
- tp: {
- enable: 1,
- fields: [
- {qty: 'sgfh_qty', tp: 'sgfh_tp'},
- {qty: 'sjcl_qty', tp: 'sjcl_tp'},
- {qty: 'qtcl_qty', tp: 'qtcl_tp'},
- {qty: 'quantity', tp: 'total_price'},
- {qty: 'deal_qty', tp: 'deal_tp'},
- ],
- },
- same_code: { enable: 1 },
- same_bills: { enable: 1 },
- };
- $(document).ready(() => {
- let stdXmj, stdGcl, searchLedger;
- autoFlashHeight();
- billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
- const billsIndex = _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) : (_.findIndex(billsSpreadSetting.cols, { field: 'sgfh_tp' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'sgfh_tp' }) + 1 : billsSpreadSetting.cols.length - 1);
- console.log(billsSpreadSetting.cols);
- billsSpreadSetting.cols.splice(billsIndex, 0, { title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isValuation', getValue: 'getValue.isValuation' });
- billsSpreadSetting.cols.splice(billsIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
- billsSpreadSetting.cols.splice(billsIndex + 2, 0, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},);
- if (!billsSpreadSetting.readOnly) {
- for (const col of billsSpreadSetting.cols) {
- if (!col.readOnly || col.readOnly === false)
- col.readOnly = 'readOnly.isChangeAdd';
- }
- }
- posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
- const posIndex = _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) : posSpreadSetting.cols.length;
- posSpreadSetting.cols.splice(posIndex, 0, { title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isValuation', getValue: 'getValue.isValuation' });
- posSpreadSetting.cols.splice(posIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
- if (!posSpreadSetting.readOnly) {
- for (const col of posSpreadSetting.cols) {
- if (!col.readOnly || col.readOnly === false)
- col.readOnly = 'readOnly.isChangeAdd';
- }
- }
- const billsCol = {
- getValue: {
- isChange: function (data) {
- if (!data) return 0;
- if (!data.name) return 0;
- const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
- return cInfo ? 1 : 0;
- },
- isValuation: function (data) {
- if (!data) return 0;
- if (!data.name) return 0;
- const cList = _.filter(changeList, { gcl_id: data.id });
- if (cList.length === 0) return 0;
- return _.find(cList, { is_valuation: 0 }) ? 0 : 1;
- },
- camount: function (data) {
- const cInfo = _.find(changeList, {gcl_id: data.id, mx_id: ''});
- return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(data.unit)) : ZhCalc.round(data.camount, findDecimal(data.unit));
- }
- },
- readOnly: {
- isChangeAdd: function (data) {
- return !readOnly && !data.formc;
- },
- isChangeList: function (data) {
- if (!data) return true;
- let edit = !readOnly && !(data.is_leaf && data.b_code);
- if (!edit && data.id) {
- const lPos = pos.getLedgerPos(data.id);
- if (lPos && lPos.length > 0) {
- edit = true;
- }
- }
- return edit;
- },
- isValuation: function (data) {
- if (!data) return true;
- return !readOnly && !(data && data.name && _.findIndex(changeList, { gcl_id: data.id, mx_id: '' }) !== -1);
- },
- isSettle: function (data) {
- if (!data) return true;
- return !readOnly && !(data && data.name && _.findIndex(changeList, { gcl_id: data.id, mx_id: '' }) !== -1 && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
- }
- }
- };
- const posCol = {
- getValue: {
- isChange: function (data) {
- if (!data) return 0;
- if (!data.name) return 0;
- const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
- return cInfo ? 1 : 0;
- },
- isValuation: function (data) {
- if (!data) return 0;
- if (!data.name) return 0;
- const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
- return cInfo ? cInfo.is_valuation : 0;
- },
- camount: function (data) {
- if (!data) return '';
- if (!data.name) return '';
- const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
- return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)) : '';
- }
- },
- readOnly: {
- isChangeAdd: function (data) {
- return !readOnly && !data.formc && (!data.settle_status || (data.settle_status && data.settle_status === settleStatus.finish));
- },
- isChangeList: function (data) {
- if (!data) return true;
- // console.log(data.name);
- return !readOnly && !data.name;
- },
- isValuation: function (data) {
- if (!data) return true;
- return !readOnly && !posCol.getValue.isChange(data);
- },
- isSettle: function (data) {
- if (!data) return true;
- return !readOnly && !(data && data.name && _.findIndex(changeList, { gcl_id: data.lid, mx_id: data.id }) !== -1 && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
- }
- }
- };
- console.log(posSpreadSetting);
- // 判断是否是已结算清单
- function checkIsSettle(data) {
- const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
- if (info && info.settle_status && info.settle_status === settleStatus.finish) {
- return true;
- }
- return false;
- }
- // 初始化spread
- const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
- const billsSheet = billsSpread.getActiveSheet();
- billsSpreadSetting.rowHeader = [
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if(!data.formc && !data.cid) return;
- return '#dc3545';
- }
- },
- },
- ];
- billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
- if (data && data.settle_status && data.settle_status === settleStatus.finish) {
- return spreadColor.stage.settle;
- }
- if (data && data.is_change) {
- return '#c3e6cb';
- }
- return defaultColor;
- };
- billsSpreadSetting.localCache = {
- key: 'changes-ledger-spread',
- colWidth: true,
- };
- sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
- sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
- SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
- SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
- const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
- const posSheet = posSpread.getActiveSheet();
- posSpreadSetting.rowHeader = [
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if(!data.formc) return;
- return '#dc3545';
- }
- },
- },
- ];
- posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
- if (data && data.settle_status && data.settle_status === settleStatus.finish) {
- return spreadColor.stage.settle;
- }
- return defaultColor;
- };
- posSpreadSetting.localCache = {
- key: 'changes-pos-spread',
- colWidth: true,
- };
- sjsSettingObj.setGridSelectStyle(posSpreadSetting);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
- SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
- SpreadJsObj.initSheet(posSheet, posSpreadSetting);
- const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
- const errorList = $.cs_errorList({
- tabSelector: '#error-list-tab',
- selector: '#error-list',
- relaSpread: billsSpread,
- storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
- afterLocated: function () {
- posSpreadObj.loadCurPosData();
- },
- afterShow: function () {
- billsSpread.refresh();
- if (posSpread) posSpread.refresh();
- },
- });
- const checkList = $.ledger_checkList({
- id: 'check-list',
- tabSelector: '#check-list-tab',
- selector: '#check-list',
- relaSpread: billsSpread,
- storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
- checkType: getCheckType(checkOption),
- afterLocated: function () {
- posSpreadObj.loadCurPosData();
- },
- afterShow: function () {
- billsSpread.refresh();
- if (posSpread) posSpread.refresh();
- },
- });
- const sumLoadMiss = $.sumLoadMiss({
- tabSelector: '#sum-load-miss-tab',
- selector: '#sum-load-miss',
- relaSpread: billsSpread,
- storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
- id: 'revise-slm',
- afterLocated: function () {
- posSpreadObj.loadCurPosData();
- },
- afterShow: function () {
- billsSpread.refresh();
- if (posSpread) posSpread.refresh();
- },
- });
- // 初始化 节点树结构
- const treeSetting = {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tender_id', 'ledger_id'],
- calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'ca_tp', 'ex_tp1'],
- autoExpand: 3,
- markExpandKey: 'change-bills-expand',
- markExpandSubKey: window.location.pathname.split('/')[2],
- };
- if (!isTz) {
- treeSetting.calcFields.push('deal_tp');
- }
- treeSetting.calcFun = function (node) {
- if (node && node.b_code) {
- const posData = pos.getLedgerPos(node.id) || [];
- let camount = ZhCalc.round(node.camount, findDecimal(node.unit)) || 0;
- if (posData.length > 0) {
- let sgfh_qty = 0;
- let sjcl_qty = 0;
- let qtcl_qty = 0;
- let ex_qty1 = 0;
- camount = 0;
- for (const np of posData) {
- sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
- sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
- qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
- ex_qty1 = ZhCalc.add(ex_qty1, np.ex_qty1);
- const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
- camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(node.unit))) : camount;
- }
- if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
- node.sgfh_qty = sgfh_qty;
- node.sjcl_qty = sjcl_qty;
- node.qtcl_qty = qtcl_qty;
- node.ex_qty1 = ex_qty1;
- node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
- node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
- node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
- node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
- node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
- }
- if (!_.isEqual(node.ex_qty1, ex_qty1)) {
- node.ex_qty1 = ex_qty1;
- node.ex_tp1 = ZhCalc.mul(node.ex_qty1, node.unit_price, decimal.tp) || 0;
- }
- }
- node.camount = camount;
- node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
- }
- node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
- };
- const billsTree = createNewPathTree('revise', treeSetting);
- console.log(billsTree, treeSetting);
- // 初始化 计量单元
- const pos = new PosData({ id: 'id', ledgerId: 'lid' });
- // 清单 相关方法&绑定spreadjs事件
- const billsTreeSpreadObj = {
- loadExprToInput(sheet) {
- const sel = sheet.getSelections()[0];
- const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
- if (col && col.field === 'camount') {
- const data = SpreadJsObj.getSelectObject(sheet);
- if (data) {
- const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
- if (!cInfo) {
- $('#bills-expr').val('').attr('readOnly', true);
- $('#bills-expr').removeAttr('data-row');
- } else {
- const value = cInfo.camount_expr ? cInfo.camount_expr : ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit));
- $('#bills-expr').val(value).attr('field', col.field).attr('org', ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)))
- .attr('readOnly', billsCol.readOnly.isSettle(data)).attr('data-row', sel.row);
- }
- } else {
- $('#bills-expr').val('').attr('readOnly', true);
- $('#bills-expr').removeAttr('data-row');
- }
- } else if (col && col.type === 'Number') {
- const data = SpreadJsObj.getSelectObject(sheet);
- if (data) {
- const exprInfo = getExprInfo(col.field);
- if (exprInfo) {
- $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
- .attr('field', col.field).attr('org', data[col.field]);
- } else {
- $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
- }
- if (col.field.indexOf('dgn') >= 0) {
- $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
- } else if (col.field === 'unit_price') {
- $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
- } else {
- const nodePos = pos.getLedgerPos(data.id);
- if (nodePos && nodePos.length > 0) {
- $('#bills-expr').val('').attr('readOnly', true);
- $('#bills-expr').removeAttr('data-row');
- } else {
- $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
- }
- }
- $('#bills-expr').attr('data-row', sel.row);
- } else {
- $('#bills-expr').val('').attr('readOnly', true);
- $('#bills-expr').removeAttr('data-row');
- }
- } else {
- $('#bills-expr').val('').attr('readOnly', true);
- $('#bills-expr').removeAttr('data-row');
- }
- },
- 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.pid !== node.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=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) {
- invalidAll();
- return;
- }
- let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = tree.nodes[sel.row + r];
- if (!rNode) {
- sameParent = false;
- break;
- }
- if (!rNode.formc) {
- sameParent = false;
- break;
- }
- nodeUsed = nodeUsed || rNode.used;
- settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
- if (rNode.level > first.level) continue;
- if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
- sameParent = false;
- break;
- }
- last = rNode;
- }
- }
- const preNode = tree.getPreSiblingNode(first);
- 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 valid = !sheet.zh_setting.readOnly;
- setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
- setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
- setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
- setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
- const posRange = last ? pos.getLedgerPos(last.id) : [];
- setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
- && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
- const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
- setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
- && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
- 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);
- }
- }
- }
- }
- });
- },
- 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) {
- billsTreeSpreadObj.refreshOperationValid(info.sheet);
- billsTreeSpreadObj.refreshPosData();
- }
- }
- billsTreeSpreadObj.loadExprToInput(info.sheet);
- },
- refreshPosData: function() {
- SpreadJsObj.resetTopAndSelect(posSheet);
- posSpreadObj.loadCurPosData();
- SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
- posSearch.search($('#pos-keyword').val());
- },
- /**
- * 新增节点
- * @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;
- }
- if (child.settle_status === settleStatus.finish) {
- 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;
- }
- if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
- toastr.warning('选中的节点已结算,不可升级');
- return;
- }
- // for (let i = index; i < children.length; i++) {
- // const child = children[index];
- // if (tree.checkNodeUsed(child, pos)) {
- // if (i >= index + count) {
- // toastr.warning('其后节点已计量,选中的节点不可升级');
- // } else {
- // 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;
- }
- if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
- toastr.warning('其前节点已结算,选中的节点不可降级');
- return;
- }
- for (let i = index; i < count; i++) {
- const child = children[i+index];
- if (tree.checkNodeUsed(child, pos)) {
- toastr.warning('选中的节点已计量,不可降级');
- return;
- }
- if (tree.settle_status === settleStatus.finish) {
- toastr.warning('选中的节点已结算,不可降级');
- return;
- }
- }
- } else if (type === 'add') {
- if (node.settle_status === settleStatus.finish) {
- toastr.warning('选中的节点已结算,不可新增子项');
- return;
- }
- }
- if (type === 'delete') {
- deleteAfterHint(function () {
- postData(window.location.pathname + '/update', {
- postType: type,
- postData: {
- id: node.ledger_id,
- count: type === 'add' ? addCount : count,
- }
- }, function (result) {
- changeList = result.changeList;
- 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);
- billsTreeSpreadObj.refreshPosData();
- }
- self.refreshOperationValid(sheet);
- });
- });
- } else {
- postData(window.location.pathname + '/update', {
- postType: type,
- postData: {
- id: node.ledger_id,
- count: type === 'add' ? addCount : count,
- }
- }, function (result) {
- changeList = result.changeList;
- 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') {
- 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])]);
- billsTreeSpreadObj.refreshPosData();
- }
- }
- self.refreshOperationValid(sheet);
- });
- }
- },
- buttonClicked: function (e, info, v) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_change') {
- if (billsCol.readOnly.isChangeList(select)) {
- return
- }
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- if (is_change) {
- makeGclGatherData();
- const gclInfo = _.find(gclGatherData, function (item) {
- return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
- });
- const xmjInfo = gclInfo.leafXmjs.find(function (item) {
- return item.gcl_id === select.id;
- });
- const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
- const data = {
- lid: gclInfo.leafXmjs[0].gcl_id || select.id,
- code: gclInfo.b_code,
- name: gclInfo.name || '',
- unit: gclInfo.unit || '',
- unit_price: gclInfo.unit_price,
- oamount: xmjInfo.quantity,
- oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
- bwmx: xmjInfo.bwmx || xmjInfo.jldy,
- xmj_code: xmjInfo.code || '',
- xmj_jldy: xmjInfo.jldy || '',
- xmj_dwgc: xmjInfo.dwgc || '',
- xmj_fbgc: xmjInfo.fbgc || '',
- xmj_fxgc: xmjInfo.fxgc || '',
- gcl_id: select.id,
- mx_id: '',
- };
- if (oldCInfo) {
- data.detail = oldCInfo.detail;
- data.camount = oldCInfo.camount;
- data.camount_expr = oldCInfo.camount_expr;
- data.spamount = oldCInfo.spamount;
- data.is_valuation = oldCInfo.is_valuation;
- data.delimit = oldCInfo.delimit;
- }
- // 更新至服务器
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
- changeList = result.changeList;
- select.is_change = 1;
- select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
- if (oldCInfo) {
- select.camount = data.camount;
- const refreshNode = billsTree.loadPostData({ update: [select] });
- billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- }, function () {
- info.sheet.setValue(info.row, info.col, 0);
- });
- } else {
- if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
- toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
- info.sheet.setValue(info.row, info.col, 1);
- return
- }
- const cInfo = _.find(changeList, { gcl_id: select.id });
- if (_.find(changeUsedData, { cbid: cInfo.id })) {
- toastr.warning('该清单计量单元已被使用,无法取消勾选');
- info.sheet.setValue(info.row, info.col, 1);
- return
- } else if (checkIsSettle(cInfo)) {
- toastr.warning('该清单计量单元已结算,无法取消勾选');
- info.sheet.setValue(info.row, info.col, 1);
- return
- } else {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
- changeList = result.changeList;
- select.is_change = 0;
- select.is_valuation = 0;
- select.camount = null;
- const billsNode = select;
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const loadResult = { update: [billsNode] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- // 重算申请数量金额
- // const refreshNode = billsTree.loadPostData(result);
- // billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- }, function () {
- info.sheet.setValue(info.row, info.col, 1);
- });
- }
- }
- } else if (col.field === 'is_valuation') {
- if (billsCol.readOnly.isChangeList(select)) {
- return;
- }
- if (!billsCol.getValue.isChange(select)) {
- toastr.warning('请先勾选变更清单才能勾选计价');
- info.sheet.setValue(info.row, info.col, 0);
- return;
- }
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- const cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
- if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
- toastr.warning('该变更清单已被调用,无法更改计价');
- info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
- return;
- }
- const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- // select.is_valuation = is_valuation;
- cInfo.is_valuation = is_valuation;
- delete cInfo.waitingLoading;
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
- // SpreadJsObj.reLoadRowData(info.sheet, info.row);
- info.sheet.setValue(info.row, info.col, is_valuation);
- }, function () {
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- cInfo.is_valuation = select.is_valuation;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- }
- }
- },
- /**
- * 编辑单元格响应事件
- * @param {Object} e
- * @param {Object} info
- */
- editEnded: function (e, info) {
- if (info.sheet.zh_setting) {
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_change' || col.field === 'is_valuation') {
- return;
- }
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const node = sortData[info.row];
- if (col.field === 'camount') {
- if (!node) {
- toastr.error('数据错误,请选择台账节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
- if (!cInfo) {
- toastr.error('未勾选变更清单,无法编辑申请数量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
- const orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
- : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
- cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
- cInfo.camount_expr = exprQuantity.expr;
- node[col.field] = cInfo[col.field];
- delete cInfo.waitingLoading;
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- const billsNode = node;
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const loadResult = { update: [billsNode] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- }, function () {
- cInfo[col.field] = orgValue;
- cInfo.spamount = orgValue;
- node[col.field] = orgValue;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- return;
- }
- const data = {
- id: node.id,
- tender_id: node.tender_id,
- ledger_id: node.ledger_id
- };
- // 未改变值则不提交
- const orgValue = node[col.field];
- const newValue = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
- if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
- return;
- }
- // 台账模式,检查计量单元相关
- if (isTz) {
- if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
- col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
- col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
- col.field === 'ex_qty1' || col.field === 'ex_tp1') {
- if (!node.children || node.children.length ===0) {
- const lPos = pos.getLedgerPos(node.id);
- if (lPos && lPos.length > 0) {
- toastr.error('清单含有计量单元,不可修改施工图复核数量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- if (col.field === 'b_code' && (newValue === '' || !newValue)) {
- const lPos = pos.getLedgerPos(node.id);
- if (lPos && lPos.length > 0) {
- toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- // 获取更新数据
- const exprInfo = getExprInfo(col.field);
- if (info.editingText) {
- const text = newValue;
- if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
- toastr.error('节点已计量,请勿删除编号');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.type === 'Number') {
- const num = _.toNumber(text);
- if (_.isFinite(num)) {
- data[col.field] = num;
- if (exprInfo) {
- data[exprInfo.expr] = '';
- }
- } else {
- try {
- data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
- if (exprInfo) {
- data[exprInfo.expr] = newValue;
- }
- } catch(err) {
- toastr.error('输入的表达式非法');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- } else {
- data[col.field] = text;
- }
- } else {
- if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
- toastr.error('节点已计量,请勿删除编号');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- data[col.field] = null;
- if (exprInfo) {
- data[exprInfo.expr] = '';
- }
- }
- if (col.field === 'b_code' && newValue) {
- const ledgerData = _.filter(billsTree.nodes, function (item) {
- return item.b_code !== null && item.b_code !== '' && !item.formc;
- });
- const ledgerOneData = _.find(ledgerData, { b_code: newValue });
- if (ledgerOneData) {
- data.name = ledgerOneData.name;
- data.unit = ledgerOneData.unit;
- data.unit_price = ledgerOneData.unit_price;
- }
- }
- // 更新至服务器
- postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
- changeList = result.changeList;
- const refreshNode = billsTree.loadPostData(result);
- for (const u of refreshNode.update) {
- billsTreeSpreadObj.reCalcCamount(u);
- }
- billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
- billsTreeSpreadObj.refreshPosData();
- });
- }
- },
- clipboardPasting: function (e, info) {
- const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
- info.cancel = true;
- if (!setting || !tree) return;
- // const range = info.cellRange;
- // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
- // const node = tree.nodes[iRow];
- // if (tree.checkNodeUsed(node, pos)) {
- // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
- // return;
- // }
- // }
- const pasteData = info.pasteData.html
- ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
- : (info.pasteData.text === ''
- ? SpreadJsObj.Clipboard.getAnalysisPasteText()
- : SpreadJsObj.analysisPasteText(info.pasteData.text));
- const hint = {
- usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
- usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
- invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
- posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
- posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
- parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
- gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
- posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
- // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
- settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
- };
- const datas = [], filterNodes = [], camountData = [];
- let pid, 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 (!pid) pid = node.ledger_pid;
- if (!level) level = node.level;
- // if (node.ledger_pid !== pid) {
- // toastMessageUniq(hint.sameParent);
- // filterRow+=1;
- // continue;
- // }
- 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]);
- if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
- toastMessageUniq(hint.parent);
- continue;
- }
- if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
- toastMessageUniq(hint.gcl);
- continue;
- }
- const lPos = pos.getLedgerPos(node.id);
- if (lPos && lPos.length > 0) {
- if (value === '' && colSetting.field === 'b_code') {
- toastMessageUniq(hint.posCode);
- continue;
- }
- if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
- colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
- colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
- colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
- colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
- if (isTz) {
- toastMessageUniq(hint.posQty);
- continue;
- }
- }
- if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
- toastMessageUniq(hint.posXmj);
- continue;
- }
- }
- if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
- toastMessageUniq (hint.usedUp);
- continue;
- }
- if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
- toastMessageUniq(hint.settle);
- continue;
- }
- if (colSetting.field === 'camount') {
- bPaste = true;
- let validText = value;
- const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
- if (!cInfo) {
- bPaste = false;
- continue;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastMessageUniq(hint.invalidExpr);
- bPaste = false;
- continue;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastMessageUniq(hint.invalidExpr);
- bPaste = false;
- continue;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- if (bPaste) {
- node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
- filterNodes.push(node);
- camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
- } else {
- filterNodes.push(node);
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- continue;
- }
- if (colSetting.type === 'Number') {
- const num = _.toNumber(value);
- if (num) {
- data[colSetting.field] = num;
- } else {
- try {
- data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
- const exprInfo = getExprInfo(colSetting.field);
- if (exprInfo) {
- data[exprInfo.expr] = value;
- }
- bPaste = true;
- } catch (err) {
- toastMessageUniq(hint.invalidExpr);
- continue;
- }
- }
- } else {
- if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
- && data[colSetting.field] !== '' && value === '') {
- toastMessageUniq(hint.usedCode);
- continue;
- }
- data[colSetting.field] = value;
- }
- if (colSetting.field === 'b_code' && value) {
- const ledgerData = _.filter(billsTree.nodes, function (item) {
- return item.b_code !== null && item.b_code !== '' && !item.formc;
- });
- const ledgerOneData = _.find(ledgerData, { b_code: value });
- if (ledgerOneData) {
- data.name = ledgerOneData.name;
- data.unit = ledgerOneData.unit;
- data.unit_price = ledgerOneData.unit_price;
- }
- }
- bPaste = true;
- }
- if (bPaste) {
- datas.push(data);
- } else {
- filterNodes.push(node);
- }
- }
- if (camountData.length > 0) {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountData }, function (result) {
- changeList = result;
- const loadResult = { update: filterNodes };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- billsTreeSpreadObj.loadExprToInput(billsSheet);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- return;
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- changeList = result.changeList;
- const refreshNode = tree.loadPostData(result);
- if (refreshNode.update) {
- refreshNode.update = refreshNode.update.concat(filterNodes);
- }
- billsTreeSpreadObj.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 hint = {
- usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
- usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
- invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
- posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
- posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
- };
- const tree = info.sheet.zh_tree;
- if (!tree) { return; }
- const sortData = info.sheet.zh_tree.nodes;
- const datas = [], filterNodes = [], camountData = [];
- 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));
- const lPos = pos.getLedgerPos(node.id);
- if (lPos && lPos.length > 0) {
- if (value === '' && colSetting.field === 'b_code') {
- toastMessageUniq(hint.posCode);
- continue;
- }
- if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
- colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
- colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
- colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
- colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
- toastMessageUniq(hint.posQty);
- continue;
- }
- }
- if (node.used && colSetting.field === 'unit_price') {
- toastMessageUniq (hint.usedUp);
- continue;
- }
- if (colSetting.field === 'camount') {
- bPaste = true;
- let validText = value;
- const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
- if (!cInfo) {
- bPaste = false;
- continue;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastMessageUniq(hint.invalidExpr);
- bPaste = false;
- continue;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastMessageUniq(hint.invalidExpr);
- bPaste = false;
- continue;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- if (bPaste) {
- node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
- filterNodes.push(node);
- camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
- } else {
- filterNodes.push(node);
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- continue;
- }
- if (colSetting.type === 'Number') {
- const num = _.toNumber(value);
- if (num) {
- data[colSetting.field] = num;
- } else {
- try {
- data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
- } catch (err) {
- toastMessageUniq(hint.invalidExpr);
- continue;
- }
- }
- } else {
- if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
- && data[colSetting.field] !== '' && value === '') {
- toastMessageUniq(hint.usedCode);
- continue;
- }
- data[colSetting.field] = value;
- }
- if (colSetting.field === 'b_code' && value) {
- const ledgerData = _.filter(billsTree.nodes, function (item) {
- return item.b_code !== null && item.b_code !== '' && !item.formc;
- });
- const ledgerOneData = _.find(ledgerData, { b_code: value });
- if (ledgerOneData) {
- data.name = ledgerOneData.name;
- data.unit = ledgerOneData.unit;
- data.unit_price = ledgerOneData.unit_price;
- }
- }
- bPaste = true;
- }
- if (bPaste) {
- datas.push(data);
- } else {
- filterNodes.push(node);
- }
- }
- }
- if (camountData.length > 0) {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountData }, function (result) {
- changeList = result;
- const loadResult = { update: filterNodes };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- billsTreeSpreadObj.loadExprToInput(billsSheet);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- return;
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- changeList = result.changeList;
- const refreshNode = tree.loadPostData(result);
- if (refreshNode.update) {
- refreshNode.update = refreshNode.update.concat(filterNodes);
- }
- billsTreeSpreadObj.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 = [], camountDatas = [];
- 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);
- const cData = {};
- 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 || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
- if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
- if (['dgn_qty1', 'dgn_qty2', 'camount'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
- toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
- return;
- }
- if (col.field === 'camount') {
- const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
- if (!cInfo) continue;
- cData.id = cInfo.id;
- cData.camount = null;
- cData.camount_expr = '';
- cData.spamount = null;
- data.camount = null;
- } else {
- data[col.field] = null;
- const exprInfo = getExprInfo(col.field);
- if (exprInfo) {
- data[exprInfo.expr] = '';
- }
- }
- bDel = true;
- }
- if (bDel) {
- datas.push(data);
- if (cData.id) camountDatas.push(cData);
- }
- }
- if (camountDatas.length > 0) {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
- changeList = result;
- for (const d of datas) {
- billsTreeSpreadObj.reCalcCamount(d);
- }
- const loadResult = { update: datas };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- billsTreeSpreadObj.loadExprToInput(billsSheet);
- });
- return;
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- changeList = result.changeList;
- const refreshNode = sheet.zh_tree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(sheet, refreshNode);
- billsTreeSpreadObj.loadExprToInput(sheet);
- });
- }
- },
- pasteBlock: function (spread, copyInfo) {
- const self = this;
- const sheet = spread.getActiveSheet();
- const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
- if (node.settle_status === settleStatus.finish) {
- toastr.warning('选中的节点已结算,不可粘贴整块');
- return;
- }
- postData(window.location.pathname + '/update', {
- postType: 'paste-block',
- postData: {
- id: tree.getNodeKey(node),
- tid: copyInfo.tid,
- block: copyInfo.block,
- }
- }, function (data) {
- changeList = data.changeList;
- pos.updateDatas(data.pos);
- 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;
- }
- if (col.field === 'camount') {
- const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
- if (!cInfo) {
- toastr.error('未勾选变更清单,无法编辑申请数量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (cInfo.camount_expr && cInfo.camount_expr !== '') {
- info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
- }
- if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
- info.cancel = true;
- }
- } else {
- const exprInfo = getExprInfo(col.field);
- if (exprInfo) {
- if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
- info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
- }
- }
- switch (col.field) {
- case 'code':
- const posRange = pos.getLedgerPos(node.id);
- info.cancel = posRange && posRange.length > 0;
- break;
- case 'unit_price':
- info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
- break;
- case 'sgfh_qty':
- case 'sgfh_tp':
- case 'sjcl_qty':
- case 'sjcl_tp':
- case 'qtcl_qty':
- case 'qtcl_tp':
- case 'deal_qty':
- case 'deal_tp':
- case 'ex_qty1':
- case 'ex_tp1':
- info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
- break;
- case 'dgn_qty1':
- case 'dgn_qty2':
- info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
- break;
- }
- }
- },
- 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 col = sheet.zh_setting.cols[iCol];
- if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
- col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
- col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
- col.field === 'ex_qty1' || col.field === 'ex_tp1') {
- const lPos = pos.getLedgerPos(node.id);
- if (lPos && lPos.length > 0) {
- toastr.error('不可剪切');
- return;
- }
- }
- const style = sheet.getStyle(iRow, iCol);
- if (style.locked) {
- toastr.error('不可剪切');
- return;
- }
- const colSetting = sheet.zh_setting.cols[iCol];
- data[colSetting.field] = null;
- const exprInfo = getExprInfo(colSetting.field);
- if (exprInfo) {
- data[exprInfo.expr] = '';
- }
- }
- datas.push(data);
- }
- }
- if (datas.length > 0) {
- callback();
- postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
- changeList = result.changeList;
- const refreshNode = sheet.zh_tree.loadPostData(result);
- billsTreeSpreadObj.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) {
- changeList = result.changeList;
- const refreshNode = tree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(sheet, refreshNode);
- })
- }
- },
- reCalcCamount: function (node) {
- if (node && node.b_code) {
- const posData = pos.getLedgerPos(node.id) || [];
- let camount = node.camount || 0;
- let is_valuation = node.is_valuation || 0;
- if (posData.length > 0) {
- camount = 0;
- for (const np of posData) {
- const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
- camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit))) : camount;
- if (cInfo && cInfo.is_valuation) {
- is_valuation = 1;
- }
- }
- }
- node.camount = camount;
- node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
- node.is_valuation = is_valuation;
- }
- },
- _checkExprValid(expr) {
- if (!expr) return [true, null];
- const param = [];
- let num = '', base = '';
- for (let i = 0, iLen = expr.length; i < iLen; i++) {
- if (/^[\d\.%]+/.test(expr[i])) {
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- num = num + expr[i];
- } else if (expr[i] === '(') {
- if (num !== '') {
- param.push({type: 'num', value: num});
- num = '';
- }
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- param.push({type: 'left', value: '('});
- } else if (expr[i] === ')') {
- if (num !== '') {
- param.push({type: 'num', value: num});
- num = '';
- }
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- param.push({type: 'right', value: ')'});
- } else if (/^[\+\-*\/]/.test(expr[i])) {
- if (num !== '') {
- param.push({type: 'num', value: num});
- num = '';
- }
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- param.push({type: 'calc', value: expr[i]});
- } else {
- return [false, '输入的表达式含有非法字符: ' + expr[i]];
- }
- }
- if (num !== '') {
- param.push({type: 'num', value: num});
- num = '';
- }
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- if (param.length === 0) return true;
- if (param.length > 1) {
- if (param[0].value === '-' && param[1].type === 'num') {
- param[1].value = '-' + param[1].value;
- param.shift();
- }
- }
- const iLen = param.length;
- let iLeftCount = 0, iRightCount = 0;
- for (const [i, p] of param.entries()) {
- if (p.type === 'calc') {
- if (i === 0 || i === iLen - 1)
- return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
- }
- if (p.type === 'num') {
- num = p.value.replace('%', '');
- if (p.value.length - num.length > 1)
- return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
- num = _.toNumber(num);
- if (num === undefined || num === null || _.isNaN(num))
- return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
- if (i > 0) {
- if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
- return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
- } else if (param[i - 1].value === '/' && num === 0) {
- return [false, '输入的表达式非法:请勿除0'];
- }
- }
- }
- if (p.type === 'base') {
- if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
- return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
- }
- if (p.type === 'left') {
- iLeftCount += 1;
- if (i !== 0 && param[i-1].type !== 'calc')
- return [false, '输入的表达式非法:(前应有运算符'];
- }
- if (p.type === 'right') {
- iRightCount += 1;
- if (i !== iLen - 1 && param[i+1].type !== 'calc')
- return [false, '输入的表达式非法:)后应有运算符'];
- if (iRightCount > iLeftCount)
- return [false, '输入的表达式非法:")"前无对应的"("'];
- }
- }
- if (iLeftCount > iRightCount)
- return [false, '输入的表达式非法:"("后无对应的")"'];
- return [true, ''];
- },
- _checkExpr: function (text, data) {
- if (text) {
- const num = _.toNumber(text);
- if (num) {
- data.quantity = num;
- data.expr = '';
- } else {
- const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
- const [valid, msg] = this._checkExprValid(expr);
- if (!valid) return [valid, msg];
- data.expr = expr;
- data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
- // const ce = new CalcEvalMin();
- // data.quantity = ce.eval(expr);
- // console.log(data.quantity);
- }
- } else {
- data.quantity = 0;
- data.expr = '';
- }
- return [true, ''];
- },
- };
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- billsTreeSpreadObj.loadExprToInput(billsSheet);
- billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
- billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
- if (!readOnly) {
- // 增删上下移升降级
- $('a[name="base-opr"]').click(function () {
- billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
- });
- $('a[name=cpc]').click(function () {
- billsSpread.commandManager().execute({
- cmd: this.getAttribute('type'),
- sheetName: billsSheet.name()
- });
- });
- $('#bills-expr').bind('change onblur', function () {
- if (this.readOnly) return;
- const expr = $(this);
- const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
- const select = billsTree.getItemsByIndex(row);
- if (!select) return;
- const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
- if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
- if (field === 'camount') {
- const cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
- if (!cInfo) {
- toastr.error('未勾选变更清单,无法编辑申请数量');
- return;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- return;
- }
- const camount = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- return;
- }
- cInfo.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
- select.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
- cInfo.spamount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
- cInfo.camount_expr = exprQuantity.expr;
- delete cInfo.waitingLoading;
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(billsSheet, row);
- billsTreeSpreadObj.reCalcCamount(select);
- const loadResult = { update: [select] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- billsTreeSpreadObj.loadExprToInput(billsSheet);
- }, function () {
- cInfo.camount = orgValue;
- cInfo.spamount = orgValue;
- select.camount = orgValue;
- SpreadJsObj.reLoadRowData(billsSheet, row);
- });
- return;
- }
- const data = {
- id: select.id,
- tender_id: select.tender_id,
- ledger_id: select.ledger_id
- };
- const exprInfo = getExprInfo(field);
- if (newValue !== '') {
- const num = _.toNumber(newValue);
- if (num) {
- data[field] = num;
- if (exprInfo) {
- data[exprInfo.expr] = '';
- }
- } else {
- try {
- data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
- if (exprInfo) {
- data[exprInfo.expr] = newValue;
- }
- } catch (err) {
- toastr.error('输入的表达式非法');
- return;
- }
- }
- } else {
- data[field] = null;
- if (exprInfo) {
- data[exprInfo.expr] = '';
- }
- }
- // 更新至服务器
- postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
- changeList = result.changeList;
- const refreshNode = billsTree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- });
- });
- billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
- billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
- billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
- billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
- billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
- const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
- SpreadJsObj.Clipboard.setCopyData(copyText);
- });
- SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
- SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
- }
- // 右键菜单
- 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 billsContextMenuOptions = {
- selector: '#bills-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {}
- };
- if (!readOnly) {
- billsContextMenuOptions.items.create = {
- name: '新增',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- billsTreeSpreadObj.baseOpr(billsSheet, 'add');
- },
- disabled: function (key, opt) {
- const sheet = billsSheet;
- 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 && first.settle_status !== settleStatus.finish);
- }
- };
- billsContextMenuOptions.items.delete = {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
- },
- disabled: function (key, opt) {
- const sheet = billsSheet;
- 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, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = tree.nodes[sel.row + r];
- if (!rNode) {
- sameParent = false;
- break;
- }
- if (!rNode.formc) {
- return true;
- }
- nodeUsed = nodeUsed || rNode.used;
- settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
- if (rNode.level > first.level) continue;
- if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
- sameParent = false;
- break;
- }
- last = rNode;
- }
- }
- const valid = !sheet.zh_setting.readOnly;
- return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
- }
- };
- billsContextMenuOptions.items.sprBase = '----';
- }
- billsContextMenuOptions.items.copyBlock = {
- name: '复制整块',
- icon: 'fa-files-o',
- callback: function (key, opt) {
- const copyBlockList = [];
- const sheet = billsSheet;
- const sel = sheet.getSelections()[0];
- let iRow = sel.row;
- const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
- while (iRow < sel.row + sel.rowCount) {
- const node = sheet.zh_tree.nodes[iRow];
- if (node.ledger_pid !== pid) {
- toastr.error('仅可同时选中同层节点');
- return;
- }
- const posterity = sheet.zh_tree.getPosterity(node);
- iRow += posterity.length + 1;
- posterity.unshift(node);
- copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
- }
- for (const cbl of copyBlockList) {
- for (const b of cbl) {
- const posRange = pos.getLedgerPos(b.id);
- if (posRange && posRange.length > 0) b.pos = posRange;
- }
- }
- setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
- },
- visible: function (key, opt) {
- const sheet = billsSheet;
- const selection = sheet.getSelections();
- const row = selection[0].row;
- const select = billsTree.nodes[row];
- return select;
- },
- disabled: function (key, opt) {
- const sheet = billsSheet;
- const selection = sheet.getSelections();
- const row = selection[0].row;
- const select = billsTree.nodes[row];
- return select && select.level <= 1;
- }
- };
- billsContextMenuOptions.items.copyBlockXmj = {
- name: '复制整块(只复制项目节)',
- icon: 'fa-files-o',
- callback: function (key, opt) {
- const copyBlockList = [];
- const sheet = billsSheet;
- const sel = sheet.getSelections()[0];
- let iRow = sel.row;
- const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
- while (iRow < sel.row + sel.rowCount) {
- const node = sheet.zh_tree.nodes[iRow];
- if (node.ledger_pid !== pid) {
- toastr.error('仅可同时选中同层节点');
- return;
- }
- const posterity = sheet.zh_tree.getPosterity(node);
- iRow += posterity.length + 1;
- const copyPosterity = posterity.filter(x => { return !x.b_code; });
- copyPosterity.unshift(node);
- const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
- for (const p of copyData) {
- const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
- p.is_leaf = children.length === 0;
- }
- copyBlockList.push(copyData);
- }
- setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
- },
- visible: function (key, opt) {
- const sheet = billsSheet;
- const selection = sheet.getSelections();
- const row = selection[0].row;
- const select = billsTree.nodes[row];
- return select;
- },
- disabled: function (key, opt) {
- const sheet = billsSheet;
- const selection = sheet.getSelections();
- const row = selection[0].row;
- const select = billsTree.nodes[row];
- return select && select.level <= 1;
- }
- };
- if (!readOnly) {
- billsContextMenuOptions.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) {
- billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
- } else {
- document.execCommand('paste');
- }
- },
- visible: function (key, opt) {
- return !readOnly;
- }
- };
- billsContextMenuOptions.items.sprBlock = '----';
- }
- if (!readOnly) {
- billsContextMenuOptions.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 {
- billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
- root.$menu.trigger('contextmenu:hide');
- }
- },
- disabled: function (key, opt) {
- const sheet = billsSheet;
- 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 && first.settle_status !== settleStatus.finish);
- }
- };
- billsContextMenuOptions.items.batchInsertBillsPos = {
- name: '批量插入清单-计量单元',
- icon: 'fa-sign-in',
- visible: function (key, opt) {
- return false;
- },
- disabled: function (key, opt) {
- if (!isTz) return true;
- const select = SpreadJsObj.getSelectObject(billsSheet);
- if (select) {
- if (select.code && select.code !== '') {
- return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
- } else {
- const parent = billsTree.getParent(select);
- return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
- }
- } else {
- return false;
- }
- },
- callback: function (key, opt) {
- if (!batchInsertObj) {
- batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
- } else {
- batchInsertObj.initView();
- }
- $('#batch').modal('show');
- }
- };
- }
- billsContextMenuOptions.items.sprTag = '----';
- billsContextMenuOptions.items.showLast = {
- name: '显示至最底层',
- callback: function (key, opt, menu, e) {
- const node = SpreadJsObj.getSelectObject(billsSheet);
- setTimeout(() => {
- showWaitingView();
- billsTree.expandByCustom(x => {
- return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
- });
- SpreadJsObj.refreshTreeRowVisible(billsSheet);
- closeWaitingView();
- }, 100);
- },
- };
- $.contextMenu(billsContextMenuOptions);
- // 计量单元 相关方法&绑定spreadjs事件
- const posSpreadObj = {
- refreshOperationValid: function (sheet, selection) {
- const setObjEnable = function (obj, enable) {
- if (enable) {
- obj.removeClass('disabled');
- } else {
- obj.addClass('disabled');
- }
- };
- const invalidAll = function () {
- setObjEnable($('a[name=pos-opr][type=up-move]'), false);
- setObjEnable($('a[name=pos-opr][type=down-move]'), false);
- };
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const first = sheet.zh_data[row];
- if (!first) {
- invalidAll();
- return;
- }
- let last = first;
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = sheet.zh_data[sel.row + r];
- if (!rNode) break;
- last = rNode;
- }
- }
- const preNode = sheet.zh_data[row - 1];
- const valid = !sheet.zh_setting.readOnly;
- setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
- setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
- },
- loadExprToInput: function () {
- const sel = posSheet.getSelections()[0];
- if (!sel) return;
- const col = posSheet.zh_setting.cols[sel.col];
- const cell = posSheet.getCell(sel.col, sel.col);
- if (col && col.field === 'camount') {
- const data = SpreadJsObj.getSelectObject(posSheet);
- if (data) {
- const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
- if (!cInfo) {
- $('#pos-expr').val('').attr('readOnly', true);
- $('#pos-expr').removeAttr('data-row');
- } else {
- const value = cInfo.camount_expr ? cInfo.camount_expr : cInfo.camount;
- $('#pos-expr').val(value).attr('field', col.field).attr('org', cInfo.camount)
- .attr('readOnly', posCol.readOnly.isSettle(data)).attr('data-row', sel.row);
- }
- } else {
- $('#pos-expr').val('').attr('readOnly', true);
- $('#pos-expr').removeAttr('data-row');
- }
- } else if (col && col.type === 'Number') {
- const data = SpreadJsObj.getSelectObject(posSheet);
- if (data) {
- const exprInfo = getExprInfo(col.field);
- const value = exprInfo
- ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
- : data[col.field];
- $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
- .attr('readOnly', readOnly || !data.formc || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
- } else {
- $('#pos-expr').val('').attr('readOnly', true);
- $('#pos-expr').removeAttr('data-row');
- }
- } else {
- $('#pos-expr').val('').attr('readOnly', true);
- $('#pos-expr').removeAttr('data-row');
- }
- },
- /**
- * 加载计量单元 根据当前台账选择节点
- */
- loadCurPosData: function () {
- const node = SpreadJsObj.getSelectObject(billsSheet);
- // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
- // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
- if (node) {
- const posData = pos.getLedgerPos(node.id) || [];
- console.log(posData);
- SpreadJsObj.loadSheetData(posSheet, 'data', posData);
- posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
- } else {
- SpreadJsObj.loadSheetData(posSheet, 'data', []);
- posSheet.zh_setting.readOnly = true;
- }
- SpreadJsObj.massOperationSheet(posSheet, function () {
- if (posSheet.zh_setting) {
- posSheet.zh_setting.cols.forEach(function (col, i) {
- for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
- if (i !== 0 && col.field !== 'camount' && col.field !== 'is_valuation') {
- posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
- } else {
- let lock = false;
- if (!posSheet.zh_data[iRow]) {
- lock = true;
- }
- if (col.field === 'camount' && posCol.readOnly.isSettle(posSheet.zh_data[iRow])) {
- lock = true;
- }
- posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
- }
- }
- });
- }
- });
- // SpreadJsObj.refreshSheetReadOnly(posSheet);
- posSpreadObj.loadExprToInput();
- posSpreadObj.refreshOperationValid(posSheet);
- },
- baseOpr: function (sheet, type) {
- const data = {
- postType: 'pos',
- posPostType: type === 'delete' ? type : 'update',
- postData: [],
- };
- const selection = sheet.getSelections();
- const row = selection[0].row, count = selection[0].rowCount;
- const first = sheet.zh_data[row];
- if (type === 'delete') {
- for (let iRow = 0; iRow < count; iRow++) {
- const posData = sheet.zh_data[iRow + row];
- if (posData) {
- if (posData.used) {
- toastr.error('"' + posData.name + '"已计量,请勿删除');
- return;
- }
- if (posData.settle_status) {
- toastr.error('"' + posData.name + '"已结算,请勿删除');
- return;
- }
- data.postData.push(sheet.zh_data[iRow + row].id);
- }
- }
- } else if (type === 'up-move') {
- const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
- for (let iRow = 0; iRow < count; iRow++) {
- const posData = sheet.zh_data[iRow + row];
- if (posData) {
- data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
- preUpdate.porder = posData.porder;
- }
- }
- data.postData.push(preUpdate);
- } else if (type === 'down-move') {
- const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
- for (let iRow = count - 1; iRow >= 0; iRow--) {
- const posData = sheet.zh_data[iRow + row];
- if (posData) {
- data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
- nextUpdate.porder = posData.porder;
- }
- }
- data.postData.push(nextUpdate);
- } else if (type === 'add') {
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- if (billsNode.settle_status === settleStatus.finish) {
- toastr.warning('清单已结算,不可新增计量单元');
- return;
- }
- }
- if (data.postData.length > 0) {
- postData(window.location.pathname + '/update', data, function (result) {
- changeList = result.changeList;
- if (type === 'delete') {
- pos.removeDatas(result.pos);
- sheet.deleteRows(row, count);
- const loadResult = billsTree.loadPostData(result.ledger);
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- posSpreadObj.refreshOperationValid(posSheet);
- } else {
- pos.updateDatas(result.pos);
- const sel = selection[0];
- if (sel) {
- sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
- }
- posSpreadObj.loadCurPosData();
- }
- });
- }
- },
- editStarting: function (e, info) {
- posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
- const sel = info.sheet.getSelections();
- if (!sel || !sel[0]) return;
- const col = info.sheet.zh_setting.cols[sel[0].col];
- const node = SpreadJsObj.getSelectObject(info.sheet);
- const exprInfo = getExprInfo(col.field);
- if (col.field === 'camount') {
- const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
- if (!cInfo) {
- toastr.error('未勾选变更清单,无法编辑申请数量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (cInfo.camount_expr && cInfo.camount_expr !== '') {
- info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
- }
- } else if (node && exprInfo) {
- if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
- info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
- }
- }
- if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
- info.cancel = true;
- }
- },
- buttonClicked: function (e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_change') {
- if (posCol.readOnly.isChangeList(select)) {
- info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
- return
- }
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- // const valutaionCol = _.findIndex(info.sheet.zh_setting.cols, { field: 'is_valuation' });
- if (is_change) {
- makeGclGatherData();
- const gclInfo = _.find(gclGatherData, function (item) {
- return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
- });
- const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
- const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
- const data = {
- lid: select.lid,
- code: gclInfo.b_code,
- name: gclInfo.name || '',
- unit: gclInfo.unit || '',
- unit_price: gclInfo.unit_price,
- oamount: xmjInfo.quantity,
- oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
- bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
- xmj_code: xmjInfo.code || '',
- xmj_jldy: xmjInfo.jldy || '',
- xmj_dwgc: xmjInfo.dwgc || '',
- xmj_fbgc: xmjInfo.fbgc || '',
- xmj_fxgc: xmjInfo.fxgc || '',
- gcl_id: select.lid,
- mx_id: select.id,
- }
- if (oldCInfo) {
- data.detail = oldCInfo.detail;
- data.camount = oldCInfo.camount;
- data.camount_expr = oldCInfo.camount_expr;
- data.spamount = oldCInfo.spamount;
- data.is_valuation = oldCInfo.is_valuation;
- data.delimit = oldCInfo.delimit;
- }
- // 更新至服务器
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
- changeList = result.changeList;
- select.is_change = 1;
- select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
- if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- billsNode.is_change = 1;
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const loadResult = { update: [billsNode] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- }
- }, function () {
- info.sheet.setValue(info.row, info.col, 0);
- });
- } else {
- if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
- toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
- info.sheet.setValue(info.row, info.col, 1);
- return
- }
- const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
- if (_.find(changeUsedData, { cbid: cInfo.id })) {
- toastr.warning('该计量单元已被使用,无法取消变更');
- info.sheet.setValue(info.row, info.col, 1);
- return
- } else if (checkIsSettle(cInfo)) {
- toastr.warning('该计量单元已结算,无法取消变更');
- info.sheet.setValue(info.row, info.col, 1);
- return
- } else {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
- changeList = result.changeList;
- select.is_change = 0;
- select.is_valuation = 0;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- // info.sheet.setValue(info.row, valutaionCol, 0);
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- billsTreeSpreadObj.reCalcCamount(billsNode);
- // 判断是否只剩一个,并同步去勾
- if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
- billsNode.is_change = 0;
- }
- const loadResult = { update: [billsNode] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- }, function () {
- info.sheet.setValue(info.row, info.col, 1);
- });
- }
- }
- } else if (col.field === 'is_valuation') {
- if (!posCol.getValue.isChange(select)) {
- toastr.warning('请先勾选变更清单才能勾选计价');
- info.sheet.setValue(info.row, info.col, !select || !select.is_valuation ? 0 : 1);
- return;
- }
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
- if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
- toastr.warning('该变更清单已被调用,无法更改计价');
- info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
- return;
- }
- const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- // select.is_valuation = is_valuation;
- cInfo.is_valuation = is_valuation;
- delete cInfo.waitingLoading;
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
- // SpreadJsObj.reLoadRowData(info.sheet, info.row);
- info.sheet.setValue(info.row, info.col, is_valuation);
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- SpreadJsObj.reLoadRowData(billsSheet, billsTree.getNodeIndex(billsNode));
- }, function () {
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- cInfo.is_valuation = select.is_valuation;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- }
- }
- },
- /**
- * 编辑单元格响应事件
- * @param {Object} e
- * @param {Object} info
- */
- editEnded: function (e, info) {
- if (!info.sheet.zh_setting) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- const node = posSpreadObj.billsNode;
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_change' || col.field === 'is_valuation') {
- return;
- }
- if (col.field === 'camount') {
- if (!node) {
- toastr.error('数据错误,请选择台账节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
- if (!cInfo) {
- toastr.error('未勾选变更清单,无法编辑申请数量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
- const orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
- : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
- cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
- cInfo.camount_expr = exprQuantity.expr;
- delete cInfo.waitingLoading;
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- const billsNode = node;
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const loadResult = { update: [billsNode] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- }, function () {
- cInfo[col.field] = orgValue;
- cInfo.spamount = orgValue;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- return;
- }
- const orgText = posData ? posData[col.field] : null;
- const newText = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
- if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
- if (!node) {
- toastr.error('数据错误,请选择台账节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (newText && newText !== '' && node.children && node.children.length > 0) {
- toastr.error('父节点不可插入计量单元');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
- toastr.error('项目节不可插入计量单元');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const data = {postType: 'pos'};
- if (col.field === 'name') {
- if (newText === '' && posData) {
- toastr.error('部位名称不可为空', 'error');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (!posData) {
- if (newText && newText !== '') {
- data.posPostType = 'add';
- const sortData = info.sheet.zh_data;
- const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
- data.postData = { name: newText, lid: node.id, porder: order};
- if (node.settle_status === settleStatus.finish) {
- toastr.error('已结算清单不可插入计量单元');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- } else {
- return;
- }
- } else {
- data.posPostType = 'update';
- data.postData = {id: posData.id, name: newText};
- if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
- toastr.error('计量单元已结算,不可修改');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- } else if (!posData) {
- toastr.warning('新增计量单元请先输入名称');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else {
- data.posPostType = 'update';
- data.postData = {id: posData.id};
- if (col.type === 'Number') {
- const exprInfo = getExprInfo(col.field);
- const num = _.toNumber(newText);
- if (_.isFinite(num)) {
- data.postData[col.field] = num;
- if (exprInfo) {
- data.postData[exprInfo.expr] = '';
- }
- } else {
- try {
- data.postData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
- if (exprInfo) {
- data.postData[exprInfo.expr] = newText;
- }
- } catch(err) {
- toastr.error('输入的表达式非法');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- } else if (col.field.indexOf('_expr') > 0) {
- const exprInfo = getExprInfo(col.field, true);
- if (!exprInfo) return;
- if (newText) {
- try {
- data.postData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
- data.postData[exprInfo.expr] = newText;
- } catch(err) {
- toastr.error('输入的表达式非法');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- } else {
- data.postData[exprInfo.qty] = 0;
- data.postData[exprInfo.expr] = '';
- }
- } else {
- data.postData[col.field] = newText;
- }
- }
- postData(window.location.pathname + '/update', data, function (result) {
- changeList = result.changeList;
- const updateRst = pos.updateDatas(result.pos);
- // 刷新当前行, 不适用于新增(在非下一空白行新增)
- if (updateRst.create.length > 0) {
- posSpreadObj.loadCurPosData();
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- }
- const loadResult = billsTree.loadPostData(result.ledger);
- // 判断是否只剩一个,并同步去勾
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- // billsNode.is_change = ? 1 : 0;
- if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
- billsNode.is_change = 1;
- } else {
- billsNode.is_change = 0;
- billsNode.is_valuation = 0;
- billsNode.camount = null;
- billsNode.ca_tp = null;
- }
- if (loadResult.update) {
- const r = _.find(loadResult.update, { id: billsNode.id });
- r.is_change = billsNode.is_change;
- } else {
- loadResult.update = [billsNode];
- }
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- },
- /**
- * 删除按钮响应事件
- * @param sheet
- */
- deletePress: function (sheet) {
- if (!sheet.zh_setting) return;
- const sortData = sheet.zh_data;
- const datas = [], posSelects = [], camountDatas = [];
- const sel = sheet.getSelections()[0];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sortData[iRow];
- if (node) {
- const data = {id: node.id};
- const cData = {};
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (colSetting.field === 'name') {
- toastr.error('部位名称不能为空');
- return;
- }
- const style = sheet.getStyle(iRow, iCol);
- if (!style.locked) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (colSetting.field === 'camount') {
- const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
- if (!cInfo) continue;
- cData.id = cInfo.id;
- cData.camount = null;
- cData.camount_expr = '';
- cData.spamount = null;
- } else if (colSetting.field.indexOf('_expr') > 0) {
- const exprInfo = getExprInfo(colSetting.field, true);
- if (!exprInfo) continue;
- data[exprInfo.expr] = '';
- data[exprInfo.qty] = 0;
- } else {
- data[colSetting.field] = null;
- const exprInfo = getExprInfo(colSetting.field);
- if (exprInfo) data[exprInfo.expr] = '';
- }
- bDel = true;
- }
- }
- if (bDel) {
- datas.push(data);
- if (cData.id) camountDatas.push(cData);
- posSelects.push(node);
- }
- }
- }
- if (camountDatas.length > 0) {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
- changeList = result;
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const loadResult = { update: [billsNode] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- posSpreadObj.loadCurPosData();
- }, function () {
- posSpreadObj.loadCurPosData();
- });
- return;
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
- changeList = result.changeList;
- pos.updateDatas(result.pos);
- posSpreadObj.loadCurPosData();
- const loadResult = billsTree.loadPostData(result.ledger);
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- }, function () {
- posSpreadObj.loadCurPosData();
- });
- }
- },
- /**
- * 删除 计量单元
- * @param sheet
- */
- deletePos: function (sheet) {
- const selection = sheet.getSelections();
- const data = {
- postType: 'pos',
- posPostType: 'delete',
- postData: [],
- };
- const row = selection[0].row, count = selection[0].rowCount;
- const sortData = sheet.zh_data;
- for (let iRow = 0; iRow < count; iRow++) {
- const posData = sortData[iRow + row];
- if (posData) {
- if (posData.used) {
- toastr.error('"' + posData.name + '"已计量,请勿删除');
- return;
- }
- if (posData.settle_status === settleStatus.finish) {
- toastr.error(`"${posData.name}"已计量,请勿删除`);
- return;
- }
- data.postData.push(sortData[iRow + row].id);
- }
- }
- if (data.postData.length > 0) {
- postData(window.location.pathname + '/update', data, function (result) {
- changeList = result.changeList;
- pos.removeDatas(result.pos);
- sheet.deleteRows(row, count);
- const loadResult = billsTree.loadPostData(result.ledger);
- // 判断是否只剩一个,并同步去勾
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
- if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
- billsNode.is_change = 1;
- } else {
- billsNode.is_change = 0;
- billsNode.is_valuation = 0;
- billsNode.camount = null;
- billsNode.ca_tp = null;
- }
- if (loadResult.update) {
- const r = _.find(loadResult.update, { id: billsNode.id });
- r.is_change = billsNode.is_change;
- } else {
- loadResult.update = [billsNode];
- }
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- });
- }
- },
- /**
- * 粘贴单元格响应事件
- * @param e
- * @param info
- */
- clipboardPasted: function (e, info) {
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const node = SpreadJsObj.getSelectObject(billsSheet);
- if (node.code && (node.code !== '')) {
- toastr.error('项目节不可含有节点明细');
- posSpreadObj.loadCurPosData();
- return;
- }
- if (node.children && (node.children.length > 0)) {
- toastr.error('仅节点子项可以含有计量单元');
- posSpreadObj.loadCurPosData();
- return;
- }
- if (node.settle_status === settleStatus.finish) {
- toastr.error('清单已结算,请勿修改计量单元数据');
- posSpread.loadCurPosData();
- return;
- }
- if (!info.sheet.zh_setting) {
- posSpreadObj.loadCurPosData();
- return;
- }
- const data = [];
- const camountData = [];
- const sortData = info.sheet.zh_data || [];
- const hint = {
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
- };
- if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
- const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
- if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
- toastr.warning('新增计量单元请先输入名称');
- posSpreadObj.loadCurPosData();
- return;
- }
- }
- let bHint = false;
- const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- let bPaste = true;
- const curRow = info.cellRange.row + iRow;
- const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- if (!colSetting) continue;
- posData[colSetting.field] = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
- if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
- bPaste = false;
- toastMessageUniq(hint.settle);
- continue;
- }
- if (colSetting.field === 'camount') {
- bPaste = true;
- let validText = posData[colSetting.field];
- const cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
- if (!cInfo) {
- bPaste = false;
- continue;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastMessageUniq(hint.expr);
- bPaste = false;
- continue;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastMessageUniq(hint.expr);
- bPaste = false;
- continue;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(curRow ? '计量单元第' + (curRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(curRow ? '计量单元第' + (curRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- if (bPaste) {
- camountData.push({id: cInfo.id, camount: ZhCalc.round(validText, findDecimal(node.unit)) || 0, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- continue;
- }
- if (colSetting.type === 'Number') {
- const num = _.toNumber(posData[colSetting.field]);
- if (num) {
- posData[colSetting.field] = num;
- } else {
- try {
- posData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(posData[colSetting.field]));
- const exprInfo = getExprInfo(colSetting.field);
- if (exprInfo) {
- posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
- }
- } catch (err) {
- if (!bHint) {
- toastr.warning('粘贴了非法表达式,已过滤');
- bHint = true;
- }
- bPaste = false;
- }
- }
- } else if (colSetting.field.indexOf('_expr') > 0) {
- try {
- const exprInfo = getExprInfo(colSetting.field, true);
- posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
- if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
- posData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(posData[exprInfo.expr]));
- }
- bPaste = true;
- } catch (err) {
- toastMessageUniq(hint.expr);
- }
- } else {
- bPaste = true;
- }
- }
- if (bPaste) {
- data.push(posData);
- }
- }
- if (camountData.length > 0) {
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountData }, function (result) {
- changeList = result;
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const loadResult = { update: [billsNode] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- posSpreadObj.loadCurPosData();
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- return;
- }
- if (data.length === 0) {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
- changeList = result.changeList;
- pos.updateDatas(result.pos);
- posSpreadObj.loadCurPosData();
- const loadResult = result.ledger;
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
- // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
- if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
- billsNode.is_change = 1;
- } else {
- billsNode.is_change = 0;
- billsNode.is_valuation = 0;
- billsNode.camount = null;
- billsNode.ca_tp = null;
- }
- if (loadResult.update) {
- const r = _.find(loadResult.update, { id: billsNode.id });
- r.is_change = billsNode.is_change;
- } else {
- loadResult.update = [billsNode];
- }
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- posSpreadObj.loadCurPosData();
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- });
- },
- selectionChanged: function (e, info) {
- posSpreadObj.loadExprToInput();
- posSpreadObj.refreshOperationValid(posSheet);
- },
- addPegs: function (pegs) {
- if (!pegs || pegs.length <= 0) return;
- const node = SpreadJsObj.getSelectObject(billsSheet);
- if (!node) return;
- const sheet = posSpread.getActiveSheet();
- const sortData = sheet.zh_data || [];
- let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
- pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
- postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
- changeList = result.changeList;
- pos.updateDatas(result.pos);
- posSpreadObj.loadCurPosData();
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- });
- }
- };
- posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
- if (!readOnly) {
- $('a[name="pos-opr"]').click(function () {
- posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
- });
- $('#pos-expr').bind('change onblur', function () {
- if (this.readOnly) return;
- const expr = $(this);
- const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
- const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
- if (!select) return;
- const billsNode = SpreadJsObj.getSelectObject(billsSheet);
- const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
- if (orgValue === newValue || (!orgValue && newValue == '')) return;
- if (field === 'camount') {
- const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
- if (!cInfo) {
- toastr.error('未勾选变更清单,无法编辑申请数量');
- return;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- return;
- }
- const camount = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- return;
- }
- cInfo.camount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
- cInfo.spamount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
- cInfo.camount_expr = exprQuantity.expr;
- delete cInfo.waitingLoading;
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(posSheet, row);
- billsTreeSpreadObj.reCalcCamount(billsNode);
- const loadResult = { update: [billsNode] };
- const refreshNode = billsTree.loadPostData(loadResult);
- billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
- posSpreadObj.loadExprToInput(posSheet);
- }, function () {
- cInfo.camount = orgValue;
- cInfo.spamount = orgValue;
- SpreadJsObj.reLoadRowData(posSheet, row);
- });
- return;
- }
- const data = {id: select.id};
- const exprInfo = getExprInfo(field);
- if (newValue !== '') {
- const num = _.toNumber(newValue);
- if (num) {
- data[field] = num;
- if (exprInfo) data[exprInfo.expr] = '';
- } else {
- try {
- data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
- if (exprInfo) data[exprInfo.expr] = newValue;
- } catch (err) {
- toastr.error('输入的表达式非法');
- return;
- }
- }
- } else {
- data[field] = null;
- if (exprInfo) data[exprInfo.expr] = '';
- }
- // 更新至服务器
- postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
- changeList = result.changeList;
- const updateRst = pos.updateDatas(result.pos);
- // 刷新当前行, 不适用于新增(在非下一空白行新增)
- SpreadJsObj.reLoadRowData(posSheet, row);
- const loadResult = billsTree.loadPostData(result.ledger);
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- });
- });
- posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
- posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
- posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
- posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
- SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
- $.contextMenu({
- selector: '#pos-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'delete': {
- name: '删除',
- icon: 'fa-remove',
- disabled: function (key, opt) {
- if (posSheet.zh_data) {
- const selection = posSheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const rowCount = sel.rowCount;
- let settleFinish = false;
- for (let i = row; i < row + rowCount; i++) {
- if (!posSheet.zh_data[i]) continue;
- settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
- }
- return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
- } else {
- return true;
- }
- },
- callback: function (key, opt) {
- posSpreadObj.deletePos(posSheet);
- }
- },
- }
- });
- }
- // 加载清单&计量单元数据
- const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
- let gclGatherData;
- postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
- for (const b of result.bills) {
- if (!(b.is_leaf && b.b_code)) {
- b.is_change = 0;
- b.is_valutaion = 0;
- } else {
- const cInfo = _.find(changeList, { gcl_id: b.id });
- b.is_change = cInfo ? 1 : 0;
- b.is_valuation = cInfo ? cInfo.is_valuation : 0;
- b.camount = cInfo ? cInfo.camount : 0;
- }
- }
- billsTree.loadDatas(result.bills);
- pos.loadDatas(result.pos);
- treeCalc.calculateAll(billsTree);
- SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
- SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
- checkShowLast(result.bills.length);
- posSpreadObj.loadCurPosData();
- SpreadJsObj.resetTopAndSelect(posSheet);
- billsTreeSpreadObj.refreshOperationValid(billsSheet);
- billsTreeSpreadObj.loadExprToInput(billsSheet);
- checkList.loadHisCheckData();
- console.log(billsTree);
- }, null);
- $.divResizer({
- select: '#revise-resize',
- callback: function () {
- billsSpread.refresh();
- let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-30);
- posSpread.refresh();
- }
- });
- function makeGclGatherData() {
- gclGatherModel.loadLedgerData(billsTree.datas);
- gclGatherModel.loadPosData(pos.datas);
- gclGatherData = gclGatherModel.gatherGclData();
- gclGatherData = _.filter(gclGatherData, function (item) {
- return item.leafXmjs && item.leafXmjs.length !== 0;
- });
- gclGatherData = gclGatherData.sort(sortByCode);
- }
- class DealBills {
- constructor (selector, spreadSetting) {
- const self = this;
- this.loaded = false;
- this.obj = $(selector)[0];
- this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
- this.spreadSetting = spreadSetting;
- this.spread = SpreadJsObj.createNewSpread(this.obj);
- SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
- if (!readOnly) {
- this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const dealSheet = info.sheet;
- const mainSheet = billsSheet;
- const dealBills = SpreadJsObj.getSelectObject(dealSheet);
- if (!dealBills) { return; }
- const mainTree = mainSheet.zh_tree;
- const mainNode = SpreadJsObj.getSelectObject(mainSheet);
- if (!mainNode || !mainTree) { return; }
- if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
- toastr.warning('非最底层项目下,不应添加节点');
- return;
- }
- if (mainNode.settle_status === settleStatus.finish) {
- toastr.warning('已结算节点下,不应添加签约清单');
- return;
- }
- postData(window.location.pathname + '/update', {
- postType: 'add-deal',
- postData: {
- id: mainNode.ledger_id,
- type: mainNode.code ? 'child' : 'next',
- dealBills: {
- b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
- unit_price: dealBills.unit_price,
- }
- },
- }, function (result) {
- changeList = result.changeList;
- const refreshData = mainTree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
- const sel = mainSheet.getSelections()[0];
- if (sel && refreshData.create[0]) {
- mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
- }
- billsTreeSpreadObj.refreshOperationValid(mainSheet);
- billsSpread.focus();
- posSpreadObj.loadCurPosData();
- });
- });
- }
- SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
- }
- loadData (callback) {
- if (this.loaded) {
- if (callback) callback();
- return;
- }
- const self = this;
- postData(this.url+'/get-data', {}, function (data) {
- self.data = data;
- SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
- self.loaded = true;
- if (callback) callback();
- });
- }
- calculateData () {
- if (this.data) {
- for (const d of this.data) {
- d.total_price = _.multiply(d.quantity, d.unit_price);
- }
- }
- }
- }
- class BatchInsertBillsPosObj {
- constructor (obj) {
- const self = this;
- this.obj = obj;
- this.billsCount = 6;
- this.posCount = 1000;
- this.filter = getLocalCache('zh-calc-batch-filter');
- if (!this.filter) {
- this.filter = '1';
- }
- $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
- // 初始化 清单编号窗口 参数
- this.qdSpreadSetting = {
- cols: [
- {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
- ],
- emptyRows: this.billsCount,
- headRows: 1,
- headRowHeight: [32],
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- };
- this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
- // 初始化 部位数量复核表 参数
- this.posSpreadSetting = {
- cols: [
- {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
- {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
- ],
- emptyRows: this.posCount,
- headRows: 1,
- headRowHeight: [32],
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- };
- for (let iNum = 1; iNum <= this.billsCount; iNum++) {
- this.posSpreadSetting.cols.push(
- {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
- )
- }
- this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
- // 初始化 签约节点 参数
- this.dealSpreadSetting = {
- cols: [
- {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
- {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- };
- this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
- // 初始化 清单编号、部位数量复核表 表格
- this.initView();
- SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
- SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
- // 拉取签约节点数据
- dealBills.loadData(() => {
- SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
- });
- // 双击签约节点,自动添加到清单编号窗口
- this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
- const deal = info.sheet.zh_data[info.row];
- const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
- const sel = qdSheet.getSelections()[0];
- qdSheet.getCell(sel.row, 0).value(deal.code);
- qdSheet.getCell(sel.row, 1).value(deal.name);
- qdSheet.getCell(sel.row, 2).value(deal.unit);
- qdSheet.getCell(sel.row, 3).value(deal.unit_price);
- if (sel.row + 1 === qdSheet.getRowCount()) {
- const count = sel.row + 2;
- qdSheet.setRowCount(count);
- qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
- const colCount = posSheet.getColumnCount() + 1;
- posSheet.setColumnCount(colCount);
- posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
- }
- qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
- qdSheet.getParent().focus();
- });
- this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
- const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
- const count = posSheet.getColumnCount() - 2;
- if (billsCount > count) {
- posSheet.setColumnCount(billsCount + 2);
- for (let i = count + 1; i <= billsCount; i++) {
- info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
- posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
- }
- }
- if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
- const dealBills = self.dealSpread.getActiveSheet().zh_data;
- if (dealBills && dealBills.length > 0) {
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = iRow + info.cellRange.row;
- const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
- if (bills) {
- info.sheet.getCell(curRow, 1).value(bills.name);
- info.sheet.getCell(curRow, 2).value(bills.unit);
- info.sheet.getCell(curRow, 3).value(bills.unit_price);
- }
- }
- }
- }
- });
- this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
- const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
- const count = qdSheet.getRowCount();
- if (billsCount > count) {
- qdSheet.setRowCount(billsCount);
- for (let i = count + 1; i <= billsCount; i++) {
- qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
- info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
- }
- }
- });
- this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
- if (info.col === 0) {
- const dealBills = self.dealSpread.getActiveSheet().zh_data;
- if (dealBills && dealBills.length > 0) {
- const bills = _.find(dealBills, {code: info.editingText});
- if (bills) {
- info.sheet.getCell(info.row, 1).value(bills.name);
- info.sheet.getCell(info.row, 2).value(bills.unit);
- info.sheet.getCell(info.row, 3).value(bills.unit_price);
- }
- }
- }
- });
- this.obj.bind('shown.bs.modal', function () {
- self.qdSpread.refresh();
- self.posSpread.refresh();
- self.dealSpread.refresh();
- });
- $('#batch-ok').click(function () {
- const selection = billsSheet.getSelections();
- const sel = selection[0];
- const row = selection[0].row;
- const select = billsTree.nodes[row];
- if (select) {
- const insertData = {};
- insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
- insertData.id = select[billsTree.setting.id];
- insertData.batchData = self.getBatchData();
- if (insertData.batchData.length > 0) {
- postData(window.location.pathname + '/update', {
- postType: 'batch-insert',
- postData: insertData
- }, function (data) {
- changeList = result.changeList;
- pos.updateDatas(data.pos);
- const result = billsTree.loadPostData(data.ledger);
- billsTreeSpreadObj.refreshTree(billsSheet, result);
- billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
- billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
- posSpreadObj.loadCurPosData();
- self.obj.modal('hide');
- }, null, true);
- } else {
- self.obj.modal('hide');
- }
- }
- });
- $('input[name=batch-filter]').change(function () {
- setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
- });
- $.contextMenu({
- selector: '.batch-l-t',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'create': {
- name: '新增行',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- const qdSheet = self.qdSpread.getActiveSheet();
- const posSheet = self.posSpread.getActiveSheet();
- qdSheet.addRows(qdSheet.getRowCount(), 1);
- const index = qdSheet.getRowCount();
- qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
- posSheet.addColumns(posSheet.getColumnCount(), 1);
- posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
- },
- },
- 'delete': {
- name: '删除行',
- icon: 'fa-remove',
- callback: function (key, opt) {
- const qdSheet = self.qdSpread.getActiveSheet();
- const posSheet = self.posSpread.getActiveSheet();
- const sel = qdSheet.getSelections()[0];
- qdSheet.deleteRows(sel.row, sel.rowCount);
- posSheet.deleteColumns(sel.row + 2, sel.rowCount);
- for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
- qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
- }
- for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
- posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
- }
- qdSheet.setSelection(sel.row, sel.col, 1, 1);
- },
- },
- }
- });
- }
- // 初始化左侧表格
- initView () {
- // 初始化 清单编号
- const qdSheet = this.qdSpread.getActiveSheet();
- SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
- SpreadJsObj.refreshColumnAlign(qdSheet);
- // 清理原有数据
- SpreadJsObj.beginMassOperation(qdSheet);
- qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
- for (let iRow = 1; iRow <= this.billsCount; iRow++) {
- qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
- }
- qdSheet.setSelection(0, 0, 1 ,1);
- SpreadJsObj.endMassOperation(qdSheet);
- // 初始化 部位数量复核表
- const posSheet = this.posSpread.getActiveSheet();
- SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
- SpreadJsObj.refreshColumnAlign(posSheet);
- // 清理原有数据
- SpreadJsObj.beginMassOperation(posSheet);
- posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
- posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
- posSheet.setSelection(0, 0, 1 ,1);
- SpreadJsObj.endMassOperation(posSheet);
- // 检查签约节点数据,以工具栏数据为准
- if (dealBills) {
- SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
- }
- this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
- }
- // 获取界面数据
- getBatchData () {
- const result = [];
- const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
- for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
- if (qdSheet.getText(iRow, 0) === '') { continue; }
- const qd = {
- b_code: qdSheet.getText(iRow, 0),
- name: qdSheet.getText(iRow, 1),
- unit: qdSheet.getText(iRow, 2),
- price: _.toNumber(qdSheet.getText(iRow, 3)),
- pos: [],
- };
- for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
- const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
- if (value !== 0 && !isNaN(value)) {
- qd.pos.push({
- name: posSheet.getText(iPosRow, 0),
- drawing_code: posSheet.getText(iPosRow, 1),
- quantity: value, porder: qd.pos.length + 1,
- });
- }
- }
- if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
- }
- return result;
- }
- }
- const dealBills = new DealBills('#deal-bills-spread', {
- cols: [
- {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
- {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
- {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
- {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- });
- class Jlzf {
- constructor (selector, spreadSetting) {
- const self = this;
- this.loaded = false;
- this.obj = $(selector);
- const relaSelect = {
- showLevel: `cb-${spreadSetting.stdType}-sl`,
- searchText: `cb-${spreadSetting.stdType}-st`,
- searchResult: `cb-${spreadSetting.stdType}-sr`,
- searchPre: `cb-${spreadSetting.stdType}-sp`,
- searchNext: `cb-${spreadSetting.stdType}-sn`,
- searchClose: `cb-${spreadSetting.stdType}-sc`,
- };
- this.obj.html(
- '<div class="sjs-bar d-flex">\n' +
- ' <div class="ml-1">\n' +
- ' <div class="px-2 border-primary border-1 d-flex">\n' +
- ' <div class="d-inline-block">\n' +
- ' <div class="input-group input-group-sm mr-1">' +
- ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
- ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
- ' <div class="input-group-append" >\n' +
- ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
- ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
- ' </div>\n' +
- ' </div>' +
- '</div>\n' +
- `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
- );
- autoFlashHeight();
- const sh = `.cb-${spreadSetting.stdType}-sh`;
- function getObjHeight(select) {
- return select.length > 0 ? select.height() : 0;
- }
- const cHeader = getObjHeight($(".c-header"));
- $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
- // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
- this.spreadSetting = spreadSetting;
- this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
- const searchSheet = this.spread.getActiveSheet();
- SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
- if (!readOnly) {
- this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const dealSheet = info.sheet;
- const mainSheet = billsSheet;
- const dealBills = SpreadJsObj.getSelectObject(dealSheet);
- if (!dealBills) { return; }
- const mainTree = mainSheet.zh_tree;
- const mainNode = SpreadJsObj.getSelectObject(mainSheet);
- if (!mainNode || !mainTree) { return; }
- if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
- toastr.warning('非最底层项目下,不应添加节点');
- return;
- }
- if (mainNode.settle_status === settleStatus.finish) {
- toastr.warning('已结算节点下,不应添加签约清单');
- return;
- }
- postData(window.location.pathname + '/update', {
- postType: 'add-deal',
- postData: {
- id: mainNode.ledger_id,
- type: mainNode.code ? 'child' : 'next',
- dealBills: {
- b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
- unit_price: dealBills.unit_price,
- }
- },
- }, function (result) {
- changeList = result.changeList;
- const refreshData = mainTree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
- const sel = mainSheet.getSelections()[0];
- if (sel && refreshData.create[0]) {
- mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
- }
- billsTreeSpreadObj.refreshOperationValid(mainSheet);
- billsSpread.focus();
- posSpreadObj.loadCurPosData();
- });
- });
- }
- SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
- const searchObj = {
- result: [],
- cur: 0,
- searchStdNode: function() {
- const keyword = $(`#${relaSelect.searchText}`).val();
- const sortData = SpreadJsObj.getSortData(searchSheet);
- searchObj.result = keyword ? sortData.filter(x => {
- return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
- }) : [];
- $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
- searchObj.cur = 0;
- if (searchObj.result.length > 0) {
- SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
- }
- },
- searchPre: function () {
- if (searchObj.result.length === 0) return;
- searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
- SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
- },
- searchNext: function () {
- if (searchObj.result.length === 0) return;
- searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
- SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
- },
- clear: function () {
- $(`#${relaSelect.searchText}`).val('');
- $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
- searchObj.result = [];
- searchObj.cur = 0;
- }
- };
- $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
- $(`#${relaSelect.searchPre}`).click(function (e) {
- searchObj.searchPre();
- e.stopPropagation();
- });
- $(`#${relaSelect.searchNext}`).click(function (e) {
- searchObj.searchNext();
- e.stopPropagation();
- });
- $(`#${relaSelect.searchClose}`).click(function (e) {
- searchObj.clear();
- e.stopPropagation();
- });
- };
- loadData (callback) {
- // if (this.loaded) {
- // if (callback) callback();
- // return;
- // }
- const self = this;
- const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
- const showDatas = [];
- for (const d of datas) {
- if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
- showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
- }
- }
- SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
- // self.loaded = true;
- if (callback) callback();
- }
- }
- const jlzfBills = new Jlzf('#jlzf-spread', {
- cols: [
- // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
- {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- stdType: 'jlzf',
- });
- class Dsk {
- constructor (selector, spreadSetting) {
- const self = this;
- this.loaded = false;
- this.obj = $(selector);
- const dskProjectHtml = spreadSetting.libs.map(l => {
- return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
- });
- const relaSelect = {
- showLevel: `cb-${spreadSetting.stdType}-sl`,
- searchText: `cb-${spreadSetting.stdType}-st`,
- searchResult: `cb-${spreadSetting.stdType}-sr`,
- searchPre: `cb-${spreadSetting.stdType}-sp`,
- searchNext: `cb-${spreadSetting.stdType}-sn`,
- searchClose: `cb-${spreadSetting.stdType}-sc`,
- };
- this.obj.html(
- '<div class="sjs-bar d-flex">\n' +
- ' <div class="dropdown mr-1">\n' +
- ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
- ' <i class="fa fa-list-ol"></i> 显示层级\n' +
- ' </button>\n' +
- ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
- ' </div>\n' +
- ' </div>' +
- ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
- ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
- ' <div class="ml-1">\n' +
- ' <div class="dropdown">\n' +
- ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
- ' <i class="fa fa-search"></i>\n' +
- ' </button>\n' +
- ' <div class="dropdown-menu dropdown-menu-right">\n' +
- ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
- ' <div class="d-inline-block">\n' +
- ' <div class="input-group input-group-sm mr-1">' +
- ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
- ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
- ' <div class="input-group-append" >\n' +
- ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
- ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>' +
- '</div>\n' +
- `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
- );
- autoFlashHeight();
- const sh = `.cb-${spreadSetting.stdType}-sh`;
- function getObjHeight(select) {
- return select.length > 0 ? select.height() : 0;
- }
- const cHeader = getObjHeight($(".c-header"));
- $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
- // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
- this.spreadSetting = spreadSetting;
- this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
- const searchSheet = this.spread.getActiveSheet();
- SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
- (function (select, sheet) {
- $(select).click(function () {
- if (!sheet.zh_tree) return;
- const tag = $(this).attr('tag');
- const tree = sheet.zh_tree;
- setTimeout(() => {
- 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;
- }
- }, 100);
- });
- })(`a[name=${relaSelect.showLevel}]`, searchSheet);
- if (!readOnly) {
- this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const dealSheet = info.sheet;
- const mainSheet = billsSheet;
- const dealBills = SpreadJsObj.getSelectObject(dealSheet);
- if (!dealBills) { return; }
- const mainTree = mainSheet.zh_tree;
- const mainNode = SpreadJsObj.getSelectObject(mainSheet);
- if (!mainNode || !mainTree) { return; }
- if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
- toastr.warning('非最底层项目下,不应添加节点');
- return;
- }
- if (mainNode.settle_status === settleStatus.finish) {
- toastr.warning('已结算节点下,不应添加签约清单');
- return;
- }
- const is_bill = dealBills.kind === 4;
- const oneBills = {
- b_code: is_bill ? dealBills.code : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
- unit_price: is_bill ? dealBills.unitPrice : null, quantity: is_bill ? dealBills.quantity : null, total_price: is_bill ? dealBills.totalPrice : null,
- sgfh_qty: is_bill ? dealBills.quantity : null, sgfh_tp: is_bill ? dealBills.totalPrice : null,
- };
- postData(window.location.pathname + '/update', {
- postType: 'add-deal',
- postData: {
- id: mainNode.ledger_id,
- type: mainNode.code ? 'child' : 'next',
- dealBills: oneBills,
- },
- }, function (result) {
- changeList = result.changeList;
- const refreshData = mainTree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
- const sel = mainSheet.getSelections()[0];
- if (sel && refreshData.create[0]) {
- mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
- }
- billsTreeSpreadObj.refreshOperationValid(mainSheet);
- billsSpread.focus();
- posSpreadObj.loadCurPosData();
- });
- });
- }
- SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
- const searchObj = {
- result: [],
- cur: 0,
- searchStdNode: function() {
- const keyword = $(`#${relaSelect.searchText}`).val();
- searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
- return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
- }) : [];
- // searchObj.result = [];
- // for (const x of pathTree.nodes) {
- // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
- // searchObj.result.push(x);
- // }
- // }
- $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
- searchObj.cur = 0;
- if (searchObj.result.length > 0) {
- SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
- }
- },
- searchPre: function () {
- if (searchObj.result.length === 0) return;
- searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
- SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
- },
- searchNext: function () {
- if (searchObj.result.length === 0) return;
- searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
- SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
- },
- clear: function () {
- $(`#${relaSelect.searchText}`).val('');
- $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
- searchObj.result = [];
- searchObj.cur = 0;
- }
- };
- $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
- $(`#${relaSelect.searchPre}`).click(function (e) {
- searchObj.searchPre();
- e.stopPropagation();
- });
- $(`#${relaSelect.searchNext}`).click(function (e) {
- searchObj.searchNext();
- e.stopPropagation();
- });
- $(`#${relaSelect.searchClose}`).click(function (e) {
- searchObj.clear();
- e.stopPropagation();
- });
- };
- loadData (callback) {
- if (this.loaded) {
- if (callback) callback();
- return;
- }
- const self = this;
- if (dskAccountData && dskAccountData.select_project) {
- self.loaded = true;
- changeDskProject(dskAccountData.select_project);
- } else {
- SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
- self.loaded = true;
- }
- if (callback) callback();
- }
- }
- $('body').on('change', '#change-dsk-project', function () {
- const pid = $(this).val();
- changeDskProject(pid);
- });
- $('body').on('change', '#change-dsk-project-tree', function () {
- const treeId = $(this).val();
- const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
- changeDskProjectTree(projectInfo, treeId);
- });
- function setDskProjectTreeSelect(trees) {
- let html = '';
- for (const tree of trees) {
- html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
- }
- $('#change-dsk-project-tree').html(html);
- }
- function changeDskProject(pid) {
- const projectInfo = _.find(dskProjects, { pid });
- if (!projectInfo) {
- dskAccountData.select_project = null;
- dskAccountData.select_tree = null;
- const tree = dskProjectBills2Tree.convert([]);
- SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
- return;
- }
- postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
- const trees = _.filter(datas, x => x.type === 4);
- dskAccountData.select_project = projectInfo.pid;
- setDskProjectTreeSelect(trees);
- changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
- });
- }
- function changeDskProjectTree(projectInfo, treeId) {
- dskAccountData.select_tree = treeId;
- if (!treeId) {
- const tree = dskProjectBills2Tree.convert([]);
- SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
- return;
- }
- postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
- const tree = dskProjectBills2Tree.convert(result);
- SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
- });
- }
- const dskBills = new Dsk('#dsk-spread', {
- cols: [
- {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
- {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
- {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
- {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- stdType: 'dsk',
- libs: dskProjects,
- select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
- });
- const dskProjectBills2Tree = (function () {
- const treeSetting = {
- id: 'dpb_id',
- pid: 'dpb_pid',
- order: 'seq',
- level: 'level',
- rootId: '-1',
- fullPath: 'full_path',
- };
- const tenderTree = createNewPathTree('gather', treeSetting);
- function setChildrenNode(node, dxs, files, tenders) {
- const dxchildren = _.filter(dxs, { parentID: node.bid });
- const children = _.filter(files, { parentID: node.bid });
- const tenderChildren = _.filter(tenders, { parentID: node.bid });
- const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
- for (const t of checkChildren) {
- const child = {
- bid: t.ID,
- parentID: t.parentID,
- name: t.name,
- kind: t.kind,
- code: t.code,
- quantity: t.quantity,
- quantity2: t.quantity2,
- unit: t.unit,
- unitPrice: t.unitPrice,
- totalPrice: t.totalPrice,
- formulaCode: t.formulaCode,
- flag: t.flag,
- remark: t.remark,
- };
- tenderTree.addNode(child, node);
- setChildrenNode(child, dxs, files, tenders);
- }
- }
- function convert (projects) {
- tenderTree.clearDatas();
- // 区分文件夹及项目
- const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
- const dxs = _.filter(projects, { kind: 1 });
- const files = _.filter(projects, { kind: 4 });
- const tenders = _.filter(projects, { kind: 8 });
- for (const t of topLevel) {
- const node = {
- bid: t.ID,
- parentID: t.parentID,
- name: t.name,
- kind: t.kind,
- code: t.code,
- quantity: t.quantity,
- quantity2: t.quantity2,
- unit: t.unit,
- unitPrice: t.unitPrice,
- totalPrice: t.totalPrice,
- formulaCode: t.formulaCode,
- flag: t.flag,
- remark: t.remark,
- };
- tenderTree.addNode(node, null);
- setChildrenNode(node, dxs, files, tenders);
- }
- tenderTree.sortTreeNode(true);
- return tenderTree;
- }
- return { tenderTree, convert }
- })();
- $.divResizer({
- select: '#revise-right-spr',
- callback: function () {
- billsSpread.refresh();
- if (posSpread) posSpread.refresh();
- if (stdXmj) stdXmj.spread.refresh();
- if (stdGcl) stdGcl.spread.refresh();
- if (dealBills) dealBills.spread.refresh();
- if (searchLedger) searchLedger.spread.refresh();
- if (errorList) errorList.spread.refresh();
- if (checkList) checkList.spread.refresh();
- if (sumLoadMiss) sumLoadMiss.spread.refresh();
- if (jlzfBills) jlzfBills.spread.refresh();
- if (dskBills) dskBills.spread.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();
- billsSpread.refresh();
- if (posSpread) posSpread.refresh();
- if (stdXmj) stdXmj.spread.refresh();
- if (stdGcl) stdGcl.spread.refresh();
- if (dealBills) dealBills.spread.refresh();
- if (searchLedger) searchLedger.spread.refresh();
- if (errorList) errorList.spread.refresh();
- if (checkList) checkList.spread.refresh();
- if (sumLoadMiss) sumLoadMiss.spread.refresh();
- if (jlzfBills) jlzfBills.spread.refresh();
- if (dskBills) dskBills.spread.refresh();
- }
- });
- // showSideTools(true);
- billsSpread.refresh();
- if (posSpread) posSpread.refresh();
- const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
- const mainSheet = billsSheet;
- if (!stdTree || !mainSheet.zh_tree) { return; }
- const mainTree = mainSheet.zh_tree;
- const sel = mainSheet.getSelections()[0];
- const mainNode = mainTree.nodes[sel.row];
- if (!stdNode) return;
- if (updateData.postData.stdType === 'gcl') {
- if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
- toastr.warning('非最底层项目下,不应添加节点');
- return;
- }
- if (mainNode.settle_status === settleStatus.finish) {
- toastr.warning('已结算节点下,不可添加工程量清单');
- return;
- }
- } else {
- const stdNodes = stdTree.getAllParents(stdNode);
- for (const node of stdNodes) {
- const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
- if (parent && parent.settle_status === settleStatus.finish) {
- toastr.warning('项目节父项已结算,不可添加节点');
- return;
- }
- }
- }
- postData(window.location.pathname + '/update', {
- postType: 'add-std',
- postData: {
- id: mainTree.getNodeKey(mainNode),
- tender_id: mainNode.tender_id,
- stdType: updateData.postData.stdType,
- stdLibId: stdNode.list_id,
- stdNode: stdTree.getNodeKey(stdNode)
- }
- }, function (result) {
- changeList = result.changeList;
- const refreshNode = mainTree.loadPostData(result);
- billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
- if (sel) {
- if (refreshNode.create && refreshNode.create.length > 0) {
- mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
- } else {
- const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
- if (node) {
- mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
- }
- }
- }
- billsTreeSpreadObj.refreshOperationValid(mainSheet);
- billsSpread.focus();
- posSpreadObj.loadCurPosData();
- });
- };
- const stdXmjSetting = {
- selector: '#std-xmj',
- stdType: 'xmj',
- libs: stdChapters,
- treeSetting: {
- id: 'chapter_id',
- pid: 'pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'list_id', 'chapter_id'],
- },
- spreadSetting: {
- cols: [
- {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
- {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
- ],
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [30],
- selectedBackColor: '#fffacd',
- },
- cellDoubleClick: stdLibCellDoubleClick,
- page: 'revise',
- tid: window.location.pathname.split('/')[2],
- };
- const stdGclSetting = {
- selector: '#std-gcl',
- stdType: 'gcl',
- libs: stdBills,
- treeSetting: {
- id: 'bill_id',
- pid: 'pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'list_id', 'bill_id']
- },
- spreadSetting: {
- cols: [
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
- {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
- ],
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [30],
- selectedBackColor: '#fffacd',
- },
- cellDoubleClick: stdLibCellDoubleClick,
- page: 'revise',
- tid: window.location.pathname.split('/')[2],
- };
- // 展开收起标准节点
- $('a', '#side-menu').bind('click', function (e) {
- e.preventDefault();
- const tab = $(this), tabPanel = $(tab.attr('content'));
- // 展开工具栏、切换标签
- if (!tab.hasClass('active')) {
- const close = $('.active', '#side-menu').length === 0;
- $('a', '#side-menu').removeClass('active');
- tab.addClass('active');
- $('.tab-content .tab-pane').removeClass('active');
- tabPanel.addClass('active');
- showSideTools(tab.hasClass('active'));
- if (tab.attr('content') === '#std-xmj') {
- if (!stdXmj) {
- stdXmj = $.stdLib(stdXmjSetting);
- }
- stdXmj.spread.refresh();
- } else if (tab.attr('content') === '#std-gcl') {
- if (!stdGcl) {
- stdGcl = $.stdLib(stdGclSetting);
- }
- stdGcl.spread.refresh();
- } else if (tab.attr('content') === '#deal-bills') {
- dealBills.loadData();
- dealBills.spread.refresh();
- } else if (tab.attr('content') === '#search') {
- if (!searchLedger) {
- searchLedger = $.ledgerSearch({
- selector: '#search',
- ledger: { billsTree: billsTree, pos: pos },
- searchOver: true,
- searchEmpty: true,
- resultSpreadSetting: {
- cols: [
- {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
- {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- {title: '数量', field: 'quantity', hAlign: 2, width: 50},
- {title: '部位', field: 'bw', hAlign: 2, width: 90},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- },
- locate: function(cur) {
- if (!cur.lid) return;
- SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
- posSpreadObj.loadCurPosData();
- if (cur.pid && cur.pid !== -1) {
- const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
- SpreadJsObj.locateRow(posSheet, pIndex);
- }
- },
- customSearch: [
- {
- key: 'revise', title: '新增部位', valid: true, parent: true,
- check: function (node) {
- if (node.formc || node.cid) {
- return true;
- } else {
- return false;
- }
- }
- }
- ],
- });
- }
- searchLedger.spread.refresh();
- } else if (tab.attr('content') === '#error-list') {
- errorList.spread.refresh();
- } else if (tab.attr('content') === '#check-list') {
- checkList.spread.refresh();
- } else if (tab.attr('content') === '#sum-load-miss') {
- sumLoadMiss.spread.refresh();
- } else if (tab.attr('content') === '#dsk-list') {
- const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
- $(dskActiveTab).addClass('active');
- if (dskActiveTab === '#jlzf-spread') {
- $('#get-dsk-btn').hide();
- $('#get-dsk-bills-btn').hide();
- jlzfBills.loadData();
- jlzfBills.spread.refresh();
- } else if (dskActiveTab === '#dsk-spread') {
- $('#get-dsk-btn').show();
- $('#get-dsk-bills-btn').show();
- dskBills.loadData();
- dskBills.spread.refresh();
- }
- }
- }
- else {// 收起工具栏
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showSideTools(tab.hasClass('active'));
- }
- billsSpread.refresh();
- if (posSpread) posSpread.refresh();
- });
- // 新增清单切换tab
- $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- e.preventDefault();
- const dskActiveTab = $(this).attr('href');
- if (dskActiveTab === '#jlzf-spread') {
- $('#get-dsk-btn').hide();
- $('#get-dsk-bills-btn').hide();
- jlzfBills.loadData();
- jlzfBills.spread.refresh();
- } else if (dskActiveTab === '#dsk-spread') {
- $('#get-dsk-btn').show();
- $('#get-dsk-bills-btn').show();
- dskBills.loadData();
- dskBills.spread.refresh();
- }
- });
- // 显示层次
- (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]', billsSheet);
- const dataChecker = DataChecker({
- checkUrl: window.location.pathname + '/check',
- completeData: function (data) {
- pos.updateDatas({update: data.source.pos});
- const loadResult = billsTree.loadPostData({update: data.source.bills});
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- posSpreadObj.loadCurPosData();
- for (const e of data.error) {
- e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
- }
- },
- errorList: errorList,
- });
- $('#ledger-check2').click(() => {
- ledgerCheck2({
- ledgerTree: billsTree,
- ledgerPos: pos,
- checkList: checkList,
- decimal: decimal,
- checkOption: checkOption,
- }).then(result => {
- check2Viewing({
- extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
- randomWait: true,
- prefix: 'check2-',
- checks: result,
- checkList: checkList,
- });
- });
- });
- if (isYb) {
- let compilationList = [];
- $('#get-dsk-btn').click(function () {
- // 判断是否已绑定dsk用户
- postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
- if (result === 1) {
- $('#error-dsk .modal-body').find('h5').eq(0).show();
- $('#error-dsk .modal-body').find('h5').eq(1).hide();
- $('#error-dsk').modal('show');
- $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
- } else if (result === 2) {
- $('#error-dsk .modal-body').find('h5').eq(1).show();
- $('#error-dsk .modal-body').find('h5').eq(0).hide();
- $('#error-dsk').modal('show');
- $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
- } else {
- postData('/profile/dsk/api', {
- type: 'compilation',
- getProject: 1,
- compilationId: getLocalCache(dskCompilation)
- }, function (result) {
- let html = '';
- for (const data of result.compilation) {
- if (data.ID !== '5c66649650da2d000d8d37ba' && data.ID !== '5b52b027fd3bb0000b257cf8') {
- html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
- }
- }
- dskAccountData = result.dskAccountData;
- compilationList = result.compilation;
- console.log(compilationList);
- $('#dsk-compilation-list').html(html);
- $('#add-dsk').modal('show');
- setLocalCache(dskCompilation, result.select_compilation);
- makeDskProjectSjsHtml(result.project);
- });
- }
- })
- });
- $('#get-dsk-bills-btn').click(function () {
- const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
- changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
- });
- $('body').on('change', '#dsk-compilation-list', function () {
- const compilationId = $(this).val();
- setLocalCache(dskCompilation, compilationId);
- dskProjectSpreadObj.refreshSourceTree();
- });
- $('.hide-dsk-modal').click(function () {
- $('#error-dsk').modal('hide');
- });
- let dp = false;
- let gsObj = {
- setting: null,
- gsSheet: null,
- grSheet: null,
- tenderSourceTree: null,
- grArray: dskProjects ? dskProjects : [],
- orgSelect: null,
- };
- function makeDskProjectSjsHtml(datas) {
- if (!dp) {
- initDskProjectTree();
- dp = true;
- }
- gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
- SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
- SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
- if (datas.length === 0) {
- $('#show-project-0').show();
- } else {
- $('#show-project-0').hide();
- }
- }
- const dskProjectSpreadObj = {
- _addTender: function (tender) {
- const gr = gsObj.grArray.find(function (x) {
- return x.pid === tender.pid;
- });
- const c_id = getLocalCache(dskCompilation);
- const t = {
- pid: tender.pid,
- name: tender.name,
- compilationId: c_id,
- compilationName: _.find(compilationList, {ID: c_id}).name
- };
- if (!gr) gsObj.grArray.push(t);
- return t;
- },
- _removeTender: function (tender) {
- const gri = gsObj.grArray.findIndex(function (x, i, arr) {
- return x.pid === tender.pid;
- });
- if (gri >= 0) gsObj.grArray.splice(gri, 1);
- },
- reloadResultData: function () {
- SpreadJsObj.reLoadSheetData(gsObj.grSheet);
- },
- refreshSourceTree: function () {
- const c_id = getLocalCache(dskCompilation);
- if (c_id) {
- postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
- makeDskProjectSjsHtml(result);
- });
- }
- },
- gsButtonClicked: function (e, info) {
- if (!info.sheet.zh_setting) return;
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field !== 'selected') return;
- const node = SpreadJsObj.getSelectObject(info.sheet);
- node.selected = !node.selected;
- if (node.children && node.children.length > 0) {
- const posterity = gsObj.tenderSourceTree.getPosterity(node);
- for (const p of posterity) {
- p.selected = node.selected;
- if ((!p.children || p.children.length === 0) && p.type === 2) {
- if (p.selected) {
- dskProjectSpreadObj._addTender(p);
- } else {
- dskProjectSpreadObj._removeTender(p);
- }
- }
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
- } else if (node.type === 2) {
- if (node.selected) {
- dskProjectSpreadObj._addTender(node);
- } else {
- dskProjectSpreadObj._removeTender(node);
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
- }
- dskProjectSpreadObj.reloadResultData();
- },
- deleteGr: function () {
- if (gsObj.grArray.length === 0) return;
- if (gsObj.grSheet.getSelections().length === 0) return;
- const selections = gsObj.grSheet.getSelections();
- const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
- const row = sel && sel.row !== undefined ? sel.row : -1;
- if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
- return false;
- }
- const delList = [];
- for (let r = 0; r < sel.rowCount; r++) {
- const select = gsObj.grArray[row + r];
- delList.push(select);
- }
- _.pullAll(gsObj.grArray, delList);
- dskProjectSpreadObj.reloadResultData();
- dskProjectSpreadObj.refreshSourceTree();
- },
- };
- const initDskProjectTree = function () {
- const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
- gsObj.gsSheet = gsSpread.getActiveSheet();
- const gsSpreadSetting = {
- cols: [
- {
- title: '选择',
- field: 'selected',
- hAlign: 1,
- width: 40,
- formatter: '@',
- cellType: 'checkbox',
- readOnly: true,
- },
- {
- title: '名称',
- field: 'name',
- hAlign: 0,
- width: 400,
- formatter: '@',
- readOnly: true,
- folderCell: true,
- cellType: 'tree'
- },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [0],
- selectedBackColor: '#fffacd',
- };
- SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
- gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
- const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
- gsObj.grSheet = grSpread.getActiveSheet();
- const grSpreadSetting = {
- cols: [
- {
- title: '名称',
- colSpan: '1',
- rowSpan: '1',
- field: 'name',
- hAlign: 0,
- width: 250,
- formatter: '@',
- readOnly: true,
- cellType: 'ellipsisAutoTip',
- scrollHeightClass: '.modal-height-500'
- },
- {
- title: '所属编办',
- colSpan: '1',
- rowSpan: '1',
- field: 'compilationName',
- hAlign: 0,
- width: 150,
- formatter: '@',
- readOnly: true
- },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: []
- };
- SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
- // 右键删除已选项目
- const gsContextMenuOptions = {
- selector: '#dsk-project-result-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- delete: {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- dskProjectSpreadObj.deleteGr();
- },
- disabled: function (key, opt) {
- const selection = gsObj.grSheet.getSelections();
- const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
- const row = sel && sel.row !== undefined ? sel.row : -1;
- if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
- return true;
- }
- return false;
- }
- },
- }
- };
- $.contextMenu(gsContextMenuOptions);
- $('#add-dsk').bind('shown.bs.modal', function () {
- if (gsSpread) gsSpread.refresh();
- if (grSpread) grSpread.refresh();
- });
- };
- const dskProject2Tree = (function () {
- const treeSetting = {
- id: 'tmt_id',
- pid: 'tmt_pid',
- order: 'seq',
- level: 'level',
- rootId: '-1',
- fullPath: 'full_path',
- };
- const tenderTree = createNewPathTree('gather', treeSetting);
- function setChildrenNode(node, files, tenders) {
- const children = _.filter(files, {parentID: node.pid});
- const tenderChildren = _.filter(tenders, {parentID: node.pid});
- const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
- for (const c of checkChildren) {
- // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
- // // 判断文件夹下有无东西,没有就不插入
- // continue;
- // }
- const child = {
- pid: c.ID,
- parentID: c.parentID,
- name: c.name,
- type: c.type,
- selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
- };
- tenderTree.addNode(child, node);
- if (c.type === 1) setChildrenNode(child, files, tenders);
- }
- }
- function convert(projects) {
- tenderTree.clearDatas();
- const result = filterFolders(projects);
- const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
- const files = _.filter(result, {type: 1});
- const tenders = _.filter(result, {type: 2});
- for (const t of topLevel) {
- const node = {
- pid: t.ID,
- parentID: t.parentID,
- name: t.name,
- type: t.type,
- selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
- };
- tenderTree.addNode(node, null);
- if (t.type === 1) setChildrenNode(node, files, tenders);
- }
- tenderTree.sortTreeNode(true);
- return tenderTree;
- }
- return {tenderTree, convert}
- })();
- function filterFolders(data) {
- // 构建ID到节点的映射
- const idMap = data.reduce((map, node) => {
- map[node.ID] = node;
- return map;
- }, {});
- // 建立父子关系映射
- const parentMap = data.reduce((map, node) => {
- if (node.parentID !== '-1') {
- if (!map[node.parentID]) {
- map[node.parentID] = [];
- }
- map[node.parentID].push(node.ID);
- }
- return map;
- }, {});
- // 检查节点及其子节点是否包含清单(type=1)
- const hasChecklist = (id) => {
- const node = idMap[id];
- if (node.type === 2) {
- return true;
- }
- if (!parentMap[id]) {
- return false;
- }
- return parentMap[id].some(childID => hasChecklist(childID));
- };
- // 过滤节点
- const filteredIDs = new Set();
- data.forEach(node => {
- if (node.type === 2 || hasChecklist(node.ID)) {
- let currentID = node.ID;
- while (currentID !== '-1') {
- filteredIDs.add(currentID);
- currentID = idMap[currentID].parentID;
- }
- }
- });
- // 返回过滤后的数据
- return data.filter(node => filteredIDs.has(node.ID));
- }
- $('#set-dsk-project').click(function () {
- postData('/profile/dsk/api', {
- type: 'save_projects',
- tid: window.location.pathname.split('/')[2],
- project_list: gsObj.grArray
- }, function (result) {
- // dskAccountData.select_project = result;
- dskProjects = gsObj.grArray;
- if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
- dskAccountData.select_project = result;
- changeDskProject(result);
- dskBills.spread.refresh();
- }
- setDskProjectSelect(gsObj.grArray);
- $('#add-dsk').modal('hide');
- });
- });
- $('#add-dsk').on('hide.bs.modal', function () {
- $('#autoTip').hide();
- });
- function setDskProjectSelect(projects) {
- let html = '';
- for (const project of projects) {
- html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
- }
- $('#change-dsk-project').html(html);
- }
- // 选中所有新增部位/清单
- $('#add-all-revise').click(function() {
- const this_cid = window.location.pathname.split('/')[4];
- makeGclGatherData();
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
- type: 'get-revise-list',
- }, function (result) {
- const addDatas = [];
- for (const ggd in gclGatherData) {
- gclGatherData[ggd].code = gclGatherData[ggd].b_code;
- let hadcid = 0;
- for (const xmj of gclGatherData[ggd].leafXmjs) {
- const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
- const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
- if (changeLedger || changePos) {
- xmj.cid = 1;
- xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
- hadcid = 1;
- }
- }
- if (hadcid !== 0) gclGatherData[ggd].cid = 1;
- }
- for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
- const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
- if (leafXmjs.length > 0) {
- gclInfo.is_change = 1;
- for (const xmj of leafXmjs) {
- if (_.findIndex(changeList, function (item) {
- return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
- }) === -1) {
- addDatas.push({
- lid: xmj.gcl_id,
- code: gclInfo.code,
- name: gclInfo.name || '',
- unit: gclInfo.unit || '',
- unit_price: gclInfo.unit_price,
- oamount: xmj.quantity,
- oamount2: xmj.quantity,
- bwmx: xmj.bwmx || xmj.jldy || '',
- xmj_code: xmj.code || '',
- xmj_jldy: xmj.jldy || '',
- xmj_dwgc: xmj.dwgc || '',
- xmj_fbgc: xmj.fbgc || '',
- xmj_fxgc: xmj.fxgc || '',
- gcl_id: xmj.gcl_id,
- mx_id: xmj.mx_id || '',
- });
- }
- }
- }
- }
- console.log(addDatas);
- if (addDatas.length > 0) {
- // 更新至服务器
- postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
- type: 'add-change-list',
- postData: addDatas,
- }, function (result) {
- toastr.success('已新增当前变更令新增的所有部位/清单');
- changeList = result.changeList;
- const sortData = SpreadJsObj.getSortData(billsSheet);
- const billsNodes = _.filter(sortData, function (item) {
- return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
- });
- for (const billsNode of billsNodes) {
- billsNode.is_change = 1;
- }
- const loadResult = { update: billsNodes };
- billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
- posSpreadObj.loadCurPosData();
- });
- } else {
- toastr.warning('未存在当前变更令新增的部位/清单');
- }
- });
- });
- }
- });
- function findDecimal(unit) {
- let value = precision.other.value;
- const changeUnits = precision;
- for (const d in changeUnits) {
- if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
- value = changeUnits[d].value;
- break;
- }
- }
- return value;
- }
- // 编号排序,多重判断
- function sortByCode(a, b, code = 'b_code') {
- let code1 = a[code].split('-');
- let code2 = b[code].split('-');
- let code1length = code1.length;
- let code2length = code2.length;
- for (let i = 0; i < code1length; i ++) {
- if (i+1 <= code2length) {
- if (code1[i] != code2[i]) {
- if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
- return parseInt(code1[i]) - parseInt(code2[i]);
- } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
- return 1;
- } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
- return -1;
- } else {
- const str1length = code1[i].length;
- const str2length = code2[i].length;
- for (let j = 0; j < str1length; j++) {
- if (j+1 <= str2length) {
- if (code1[i].charAt(j) != code2[i].charAt(j)) {
- return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
- } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
- if (str1length == str2length) {
- return 0;
- } else {
- return str1length - str2length;
- }
- }
- } else {
- if (j+1 >= str1length) {
- return 1;
- } else {
- return -1;
- }
- }
- }
- }
- } else if (i+1 == code1length && code1[i] == code2[i]) {
- if (code1length == code2length) {
- return 0;
- } else {
- return code1length - code2length;
- }
- }
- } else {
- if (i+1 >= code1length) {
- return 1;
- } else {
- return -1;
- }
- }
- }
- }
|