change_revise.js 271 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price', 'ex_qty1', 'ex_tp1'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'ex_qty1', 'ex_tp1'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field, converse = false) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return converse ? _.find(exprField, {expr: field}) : _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { enable: 1 },
  39. tp: {
  40. enable: 1,
  41. fields: [
  42. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  43. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  44. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  45. {qty: 'quantity', tp: 'total_price'},
  46. {qty: 'deal_qty', tp: 'deal_tp'},
  47. ],
  48. },
  49. same_code: { enable: 1 },
  50. same_bills: { enable: 1 },
  51. };
  52. $(document).ready(() => {
  53. let stdXmj, stdGcl, searchLedger;
  54. autoFlashHeight();
  55. billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
  56. const billsIndex = _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) : (_.findIndex(billsSpreadSetting.cols, { field: 'ex_tp1' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'ex_tp1' }) + 1 : billsSpreadSetting.cols.length - 1);
  57. console.log(billsSpreadSetting.cols);
  58. 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' });
  59. 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'},);
  60. billsSpreadSetting.cols.splice(billsIndex + 2, 0, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},);
  61. if (!billsSpreadSetting.readOnly) {
  62. for (const col of billsSpreadSetting.cols) {
  63. if (!col.readOnly || col.readOnly === false)
  64. col.readOnly = 'readOnly.isChangeAdd';
  65. }
  66. }
  67. posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
  68. const posIndex = _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) : posSpreadSetting.cols.length;
  69. 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' });
  70. posSpreadSetting.cols.splice(posIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
  71. if (!posSpreadSetting.readOnly) {
  72. for (const col of posSpreadSetting.cols) {
  73. if (!col.readOnly || col.readOnly === false)
  74. col.readOnly = 'readOnly.isChangeAdd';
  75. }
  76. }
  77. const billsCol = {
  78. getValue: {
  79. isChange: function (data) {
  80. if (!data) return 0;
  81. if (!data.name) return 0;
  82. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  83. return cInfo ? 1 : 0;
  84. },
  85. isValuation: function (data) {
  86. if (!data) return 0;
  87. if (!data.name) return 0;
  88. const cList = _.filter(changeList, { gcl_id: data.id });
  89. if (cList.length === 0) return 0;
  90. return _.find(cList, { is_valuation: 0 }) ? 0 : 1;
  91. },
  92. camount: function (data) {
  93. const cInfo = _.find(changeList, {gcl_id: data.id, mx_id: ''});
  94. return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(data.unit)) : ZhCalc.round(data.camount, findDecimal(data.unit));
  95. }
  96. },
  97. readOnly: {
  98. isChangeAdd: function (data) {
  99. return !readOnly && !data.formc;
  100. },
  101. isChangeList: function (data) {
  102. if (!data) return true;
  103. let edit = !readOnly && !(data.is_leaf && data.b_code);
  104. if (!edit && data.id) {
  105. const lPos = pos.getLedgerPos(data.id);
  106. if (lPos && lPos.length > 0) {
  107. edit = true;
  108. }
  109. }
  110. return edit;
  111. },
  112. isValuation: function (data) {
  113. if (!data) return true;
  114. return !readOnly && !(data && data.name && _.findIndex(changeList, { gcl_id: data.id, mx_id: '' }) !== -1);
  115. },
  116. isSettle: function (data) {
  117. if (!data) return true;
  118. return !readOnly && !(!billsCol.readOnly.isChangeList(data) && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
  119. }
  120. }
  121. };
  122. const posCol = {
  123. getValue: {
  124. isChange: function (data) {
  125. if (!data) return 0;
  126. if (!data.name) return 0;
  127. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  128. return cInfo ? 1 : 0;
  129. },
  130. isValuation: function (data) {
  131. if (!data) return 0;
  132. if (!data.name) return 0;
  133. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  134. return cInfo ? cInfo.is_valuation : 0;
  135. },
  136. camount: function (data) {
  137. if (!data) return '';
  138. if (!data.name) return '';
  139. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  140. return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)) : '';
  141. }
  142. },
  143. readOnly: {
  144. isChangeAdd: function (data) {
  145. return !readOnly && !data.formc && (!data.settle_status || (data.settle_status && data.settle_status === settleStatus.finish));
  146. },
  147. isChangeList: function (data) {
  148. if (!data) return true;
  149. // console.log(data.name);
  150. return !readOnly && !data.name;
  151. },
  152. isValuation: function (data) {
  153. if (!data) return true;
  154. return !readOnly && !posCol.getValue.isChange(data);
  155. },
  156. isSettle: function (data) {
  157. if (!data) return true;
  158. return !readOnly && !(!posCol.readOnly.isChangeList(data) && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
  159. }
  160. }
  161. };
  162. console.log(posSpreadSetting);
  163. // 判断是否是已结算清单
  164. function checkIsSettle(data) {
  165. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  166. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  167. return true;
  168. }
  169. return false;
  170. }
  171. // 初始化spread
  172. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  173. const billsSheet = billsSpread.getActiveSheet();
  174. billsSpreadSetting.rowHeader = [
  175. {
  176. rowHeaderType: 'circle',
  177. setting: {
  178. size: 5,
  179. indent: 16,
  180. getColor: function (index, data) {
  181. if (!data) return;
  182. if(!data.formc && !data.cid) return;
  183. return '#dc3545';
  184. }
  185. },
  186. },
  187. ];
  188. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  189. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  190. return spreadColor.stage.settle;
  191. }
  192. if (data && data.is_change) {
  193. return '#c3e6cb';
  194. }
  195. return defaultColor;
  196. };
  197. billsSpreadSetting.localCache = {
  198. key: 'changes-ledger-spread',
  199. colWidth: true,
  200. };
  201. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  202. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  203. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  204. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  205. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  206. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  207. const posSheet = posSpread.getActiveSheet();
  208. posSpreadSetting.rowHeader = [
  209. {
  210. rowHeaderType: 'circle',
  211. setting: {
  212. size: 5,
  213. indent: 16,
  214. getColor: function (index, data) {
  215. if (!data) return;
  216. if(!data.formc) return;
  217. return '#dc3545';
  218. }
  219. },
  220. },
  221. ];
  222. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  223. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  224. return spreadColor.stage.settle;
  225. }
  226. return defaultColor;
  227. };
  228. posSpreadSetting.localCache = {
  229. key: 'changes-pos-spread',
  230. colWidth: true,
  231. };
  232. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  233. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  234. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  235. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  236. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  237. const errorList = $.cs_errorList({
  238. tabSelector: '#error-list-tab',
  239. selector: '#error-list',
  240. relaSpread: billsSpread,
  241. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  242. afterLocated: function () {
  243. posSpreadObj.loadCurPosData();
  244. },
  245. afterShow: function () {
  246. billsSpread.refresh();
  247. if (posSpread) posSpread.refresh();
  248. },
  249. });
  250. const checkList = $.ledger_checkList({
  251. id: 'check-list',
  252. tabSelector: '#check-list-tab',
  253. selector: '#check-list',
  254. relaSpread: billsSpread,
  255. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  256. checkType: getCheckType(checkOption),
  257. afterLocated: function () {
  258. posSpreadObj.loadCurPosData();
  259. },
  260. afterShow: function () {
  261. billsSpread.refresh();
  262. if (posSpread) posSpread.refresh();
  263. },
  264. });
  265. const sumLoadMiss = $.sumLoadMiss({
  266. tabSelector: '#sum-load-miss-tab',
  267. selector: '#sum-load-miss',
  268. relaSpread: billsSpread,
  269. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  270. id: 'revise-slm',
  271. afterLocated: function () {
  272. posSpreadObj.loadCurPosData();
  273. },
  274. afterShow: function () {
  275. billsSpread.refresh();
  276. if (posSpread) posSpread.refresh();
  277. },
  278. });
  279. // 初始化 节点树结构
  280. const treeSetting = {
  281. id: 'ledger_id',
  282. pid: 'ledger_pid',
  283. order: 'order',
  284. level: 'level',
  285. rootId: -1,
  286. keys: ['id', 'tender_id', 'ledger_id'],
  287. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'ca_tp', 'ex_tp1'],
  288. autoExpand: 3,
  289. markExpandKey: 'change-bills-expand',
  290. markExpandSubKey: window.location.pathname.split('/')[2],
  291. };
  292. if (!isTz) {
  293. treeSetting.calcFields.push('deal_tp');
  294. }
  295. treeSetting.calcFun = function (node) {
  296. if (node && node.b_code) {
  297. const posData = pos.getLedgerPos(node.id) || [];
  298. let camount = ZhCalc.round(node.camount, findDecimal(node.unit)) || 0;
  299. if (posData.length > 0) {
  300. let sgfh_qty = 0;
  301. let sjcl_qty = 0;
  302. let qtcl_qty = 0;
  303. let ex_qty1 = 0;
  304. camount = 0;
  305. for (const np of posData) {
  306. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  307. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  308. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  309. ex_qty1 = ZhCalc.add(ex_qty1, np.ex_qty1);
  310. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  311. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(node.unit))) : camount;
  312. }
  313. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  314. node.sgfh_qty = sgfh_qty;
  315. node.sjcl_qty = sjcl_qty;
  316. node.qtcl_qty = qtcl_qty;
  317. node.ex_qty1 = ex_qty1;
  318. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  319. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  320. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  321. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  322. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  323. }
  324. if (!_.isEqual(node.ex_qty1, ex_qty1)) {
  325. node.ex_qty1 = ex_qty1;
  326. node.ex_tp1 = ZhCalc.mul(node.ex_qty1, node.unit_price, decimal.tp) || 0;
  327. }
  328. }
  329. node.camount = camount;
  330. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  331. }
  332. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  333. };
  334. const billsTree = createNewPathTree('revise', treeSetting);
  335. console.log(billsTree, treeSetting);
  336. // 初始化 计量单元
  337. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  338. // 清单 相关方法&绑定spreadjs事件
  339. const billsTreeSpreadObj = {
  340. loadExprToInput(sheet) {
  341. const sel = sheet.getSelections()[0];
  342. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  343. if (col && col.field === 'camount') {
  344. const data = SpreadJsObj.getSelectObject(sheet);
  345. if (data) {
  346. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  347. if (!cInfo) {
  348. if (billsCol.readOnly.isChangeList(data)) {
  349. $('#bills-expr').val('').attr('readOnly', true);
  350. $('#bills-expr').removeAttr('data-row');
  351. } else {
  352. $('#bills-expr').val('').attr('field', col.field).attr('org', '')
  353. .attr('readOnly', false).attr('data-row', sel.row);
  354. }
  355. } else {
  356. const value = cInfo.camount_expr ? cInfo.camount_expr : ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit));
  357. $('#bills-expr').val(value).attr('field', col.field).attr('org', ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)))
  358. .attr('readOnly', billsCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  359. }
  360. } else {
  361. $('#bills-expr').val('').attr('readOnly', true);
  362. $('#bills-expr').removeAttr('data-row');
  363. }
  364. } else if (col && col.type === 'Number') {
  365. const data = SpreadJsObj.getSelectObject(sheet);
  366. if (data) {
  367. const exprInfo = getExprInfo(col.field);
  368. if (exprInfo) {
  369. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  370. .attr('field', col.field).attr('org', data[col.field]);
  371. } else {
  372. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  373. }
  374. if (col.field.indexOf('dgn') >= 0) {
  375. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  376. } else if (col.field === 'unit_price') {
  377. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  378. } else {
  379. const nodePos = pos.getLedgerPos(data.id);
  380. if (nodePos && nodePos.length > 0) {
  381. $('#bills-expr').val('').attr('readOnly', true);
  382. $('#bills-expr').removeAttr('data-row');
  383. } else {
  384. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  385. }
  386. }
  387. $('#bills-expr').attr('data-row', sel.row);
  388. } else {
  389. $('#bills-expr').val('').attr('readOnly', true);
  390. $('#bills-expr').removeAttr('data-row');
  391. }
  392. } else {
  393. $('#bills-expr').val('').attr('readOnly', true);
  394. $('#bills-expr').removeAttr('data-row');
  395. }
  396. },
  397. getDefaultSelectInfo: function (sheet) {
  398. const tree = sheet.zh_tree;
  399. if (!tree) return;
  400. const sel = sheet.getSelections()[0];
  401. const node = sheet.zh_tree.nodes[sel.row];
  402. if (!node) return;
  403. let count = 1;
  404. if (sel.rowCount > 1) {
  405. for (let r = 1; r < sel.rowCount; r++) {
  406. const rNode = sheet.zh_tree.nodes[sel.row + r];
  407. if (rNode.level > node.level) continue;
  408. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  409. toastr.warning('请选择同一节点下的节点,进行该操作');
  410. return;
  411. }
  412. count += 1;
  413. }
  414. }
  415. return [tree, node, count];
  416. },
  417. /**
  418. * 刷新顶部按钮是否可用
  419. * @param sheet
  420. * @param selections
  421. */
  422. refreshOperationValid: function (sheet, selection) {
  423. const setObjEnable = function (obj, enable) {
  424. if (enable) {
  425. obj.removeClass('disabled');
  426. } else {
  427. obj.addClass('disabled');
  428. }
  429. };
  430. const invalidAll = function () {
  431. setObjEnable($('a[name=base-opr][type=add]'), false);
  432. setObjEnable($('a[name=base-opr][type=delete]'), false);
  433. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  434. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  435. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  436. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  437. };
  438. const sel = selection ? selection[0] : sheet.getSelections()[0];
  439. const row = sel ? sel.row : -1;
  440. const tree = sheet.zh_tree;
  441. if (!tree) {
  442. invalidAll();
  443. return;
  444. }
  445. const first = sheet.zh_tree.nodes[row];
  446. if (!first) {
  447. invalidAll();
  448. return;
  449. }
  450. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  451. if (sel.rowCount > 1 && first) {
  452. for (let r = 1; r < sel.rowCount; r++) {
  453. const rNode = tree.nodes[sel.row + r];
  454. if (!rNode) {
  455. sameParent = false;
  456. break;
  457. }
  458. if (!rNode.formc) {
  459. sameParent = false;
  460. break;
  461. }
  462. nodeUsed = nodeUsed || rNode.used;
  463. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  464. if (rNode.level > first.level) continue;
  465. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  466. sameParent = false;
  467. break;
  468. }
  469. last = rNode;
  470. }
  471. }
  472. const preNode = tree.getPreSiblingNode(first);
  473. const siblings = tree.getChildren(tree.getParent(first));
  474. let upPower = true;
  475. for (let order = last.order; order < siblings.length - 1; order ++) {
  476. if (!siblings[order].formc) {
  477. upPower = false;
  478. break;
  479. }
  480. }
  481. const valid = !sheet.zh_setting.readOnly;
  482. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  483. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  484. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  485. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  486. const posRange = last ? pos.getLedgerPos(last.id) : [];
  487. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  488. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  489. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  490. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  491. && 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);
  492. setObjEnable($('#cut'), valid);
  493. setObjEnable($('#paste'), valid);
  494. },
  495. /**
  496. *
  497. * @param sheet
  498. * @param data
  499. */
  500. refreshTree: function (sheet, data) {
  501. SpreadJsObj.massOperationSheet(sheet, function () {
  502. const tree = sheet.zh_tree;
  503. // 处理删除
  504. if (data.delete) {
  505. data.delete.sort(function (a, b) {
  506. return b.deleteIndex - a.deleteIndex;
  507. });
  508. for (const d of data.delete) {
  509. sheet.deleteRows(d.deleteIndex, 1);
  510. }
  511. }
  512. // 处理新增
  513. if (data.create) {
  514. const newNodes = data.create;
  515. if (newNodes) {
  516. newNodes.sort(function (a, b) {
  517. return a.index - b.index;
  518. });
  519. for (const node of newNodes) {
  520. sheet.addRows(node.index, 1);
  521. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  522. }
  523. }
  524. }
  525. // 处理更新
  526. if (data.update) {
  527. const rows = [];
  528. for (const u of data.update) {
  529. rows.push(tree.nodes.indexOf(u));
  530. }
  531. SpreadJsObj.reLoadRowsData(sheet, rows);
  532. }
  533. // 处理展开
  534. if (data.expand) {
  535. const expanded = [];
  536. for (const e of data.expand) {
  537. if (expanded.indexOf(e) === -1) {
  538. const posterity = tree.getPosterity(e);
  539. for (const p of posterity) {
  540. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  541. expanded.push(p);
  542. }
  543. }
  544. }
  545. }
  546. });
  547. },
  548. selectionChanged: function (e, info) {
  549. if (info.newSelections) {
  550. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  551. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  552. billsTreeSpreadObj.refreshPosData();
  553. }
  554. }
  555. billsTreeSpreadObj.loadExprToInput(info.sheet);
  556. },
  557. refreshPosData: function() {
  558. SpreadJsObj.resetTopAndSelect(posSheet);
  559. posSpreadObj.loadCurPosData();
  560. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  561. posSearch.search($('#pos-keyword').val());
  562. },
  563. /**
  564. * 新增节点
  565. * @param spread
  566. */
  567. baseOpr: function (sheet, type, addCount = 1) {
  568. const self = this;
  569. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  570. if (!tree || !node || !count) return;
  571. if (type === 'delete') {
  572. const parent = tree.getParent(node);
  573. const children = parent ? parent.children : tree.children;
  574. const index = children.indexOf(node);
  575. for (let i = 0; i < count; i++) {
  576. const child = children[i+index];
  577. if (tree.checkNodeUsed(child, pos)) {
  578. toastr.warning('选中的节点已计量,不可删除');
  579. return;
  580. }
  581. if (child.settle_status === settleStatus.finish) {
  582. toastr.warning('选中的节点已结算,不可删除');
  583. return;
  584. }
  585. }
  586. } else if (type === 'up-level') {
  587. const parent = tree.getParent(node);
  588. const children = parent ? parent.children : tree.children;
  589. const index = children.indexOf(node);
  590. const lastSelect = children[index + count - 1];
  591. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  592. toastr.warning('选中的节点已计量,不可升级');
  593. return;
  594. }
  595. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  596. toastr.warning('选中的节点已结算,不可升级');
  597. return;
  598. }
  599. // for (let i = index; i < children.length; i++) {
  600. // const child = children[index];
  601. // if (tree.checkNodeUsed(child, pos)) {
  602. // if (i >= index + count) {
  603. // toastr.warning('其后节点已计量,选中的节点不可升级');
  604. // } else {
  605. // toastr.warning('选中的节点已计量,不可升级');
  606. // }
  607. // return;
  608. // }
  609. // }
  610. } else if (type === 'down-level') {
  611. const parent = tree.getParent(node);
  612. const children = parent ? parent.children : tree.children;
  613. const index = children.indexOf(node);
  614. if (index > 0 && children[index-1].used) {
  615. toastr.warning('其前节点已计量,选中的节点不可降级');
  616. return;
  617. }
  618. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  619. toastr.warning('其前节点已结算,选中的节点不可降级');
  620. return;
  621. }
  622. for (let i = index; i < count; i++) {
  623. const child = children[i+index];
  624. if (tree.checkNodeUsed(child, pos)) {
  625. toastr.warning('选中的节点已计量,不可降级');
  626. return;
  627. }
  628. if (tree.settle_status === settleStatus.finish) {
  629. toastr.warning('选中的节点已结算,不可降级');
  630. return;
  631. }
  632. }
  633. } else if (type === 'add') {
  634. if (node.settle_status === settleStatus.finish) {
  635. toastr.warning('选中的节点已结算,不可新增子项');
  636. return;
  637. }
  638. }
  639. if (type === 'delete') {
  640. deleteAfterHint(function () {
  641. postData(window.location.pathname + '/update', {
  642. postType: type,
  643. postData: {
  644. id: node.ledger_id,
  645. count: type === 'add' ? addCount : count,
  646. }
  647. }, function (result) {
  648. changeList = result.changeList;
  649. const refreshData = tree.loadPostData(result);
  650. self.refreshTree(sheet, refreshData);
  651. const sel = sheet.getSelections()[0];
  652. if (sel) {
  653. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  654. billsTreeSpreadObj.refreshPosData();
  655. }
  656. self.refreshOperationValid(sheet);
  657. });
  658. });
  659. } else {
  660. postData(window.location.pathname + '/update', {
  661. postType: type,
  662. postData: {
  663. id: node.ledger_id,
  664. count: type === 'add' ? addCount : count,
  665. }
  666. }, function (result) {
  667. changeList = result.changeList;
  668. const refreshData = tree.loadPostData(result);
  669. self.refreshTree(sheet, refreshData);
  670. if (['up-move', 'down-move'].indexOf(type) > -1) {
  671. const sel = sheet.getSelections()[0];
  672. if (sel) {
  673. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  674. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  675. }
  676. } else if (type === 'add') {
  677. const sel = sheet.getSelections()[0];
  678. if (sel) {
  679. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  680. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  681. billsTreeSpreadObj.refreshPosData();
  682. }
  683. }
  684. self.refreshOperationValid(sheet);
  685. });
  686. }
  687. },
  688. buttonClicked: function (e, info, v) {
  689. if (info.sheet.zh_setting) {
  690. const select = SpreadJsObj.getSelectObject(info.sheet);
  691. const col = info.sheet.zh_setting.cols[info.col];
  692. if (col.field === 'is_change') {
  693. if (billsCol.readOnly.isChangeList(select)) {
  694. return
  695. }
  696. if (info.sheet.isEditing()) {
  697. info.sheet.endEdit(true);
  698. }
  699. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  700. if (is_change) {
  701. makeGclGatherData();
  702. const gclInfo = _.find(gclGatherData, function (item) {
  703. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  704. });
  705. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  706. return item.gcl_id === select.id;
  707. });
  708. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  709. const data = {
  710. lid: gclInfo.leafXmjs[0].gcl_id || select.id,
  711. code: gclInfo.b_code,
  712. name: gclInfo.name || '',
  713. unit: gclInfo.unit || '',
  714. unit_price: gclInfo.unit_price,
  715. oamount: xmjInfo.quantity,
  716. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  717. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  718. xmj_code: xmjInfo.code || '',
  719. xmj_jldy: xmjInfo.jldy || '',
  720. xmj_dwgc: xmjInfo.dwgc || '',
  721. xmj_fbgc: xmjInfo.fbgc || '',
  722. xmj_fxgc: xmjInfo.fxgc || '',
  723. gcl_id: select.id,
  724. mx_id: '',
  725. };
  726. if (oldCInfo) {
  727. data.detail = oldCInfo.detail;
  728. data.camount = oldCInfo.camount;
  729. data.camount_expr = oldCInfo.camount_expr;
  730. data.spamount = oldCInfo.spamount;
  731. data.is_valuation = oldCInfo.is_valuation;
  732. data.delimit = oldCInfo.delimit;
  733. }
  734. // 更新至服务器
  735. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  736. changeList = result.changeList;
  737. select.is_change = 1;
  738. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  739. if (oldCInfo) {
  740. select.camount = data.camount;
  741. const refreshNode = billsTree.loadPostData({ update: [select] });
  742. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  743. }
  744. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  745. }, function () {
  746. info.sheet.setValue(info.row, info.col, 0);
  747. });
  748. } else {
  749. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
  750. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  751. info.sheet.setValue(info.row, info.col, 1);
  752. return
  753. }
  754. const cInfo = _.find(changeList, { gcl_id: select.id });
  755. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  756. toastr.warning('该清单计量单元已被使用,无法取消勾选');
  757. info.sheet.setValue(info.row, info.col, 1);
  758. return
  759. } else if (checkIsSettle(cInfo)) {
  760. toastr.warning('该清单计量单元已结算,无法取消勾选');
  761. info.sheet.setValue(info.row, info.col, 1);
  762. return
  763. } else {
  764. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  765. changeList = result.changeList;
  766. select.is_change = 0;
  767. select.is_valuation = 0;
  768. select.camount = null;
  769. const billsNode = select;
  770. billsTreeSpreadObj.reCalcCamount(billsNode);
  771. const loadResult = { update: [billsNode] };
  772. const refreshNode = billsTree.loadPostData(loadResult);
  773. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  774. // 重算申请数量金额
  775. // const refreshNode = billsTree.loadPostData(result);
  776. // billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  777. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  778. }, function () {
  779. info.sheet.setValue(info.row, info.col, 1);
  780. });
  781. }
  782. }
  783. } else if (col.field === 'is_valuation') {
  784. if (billsCol.readOnly.isChangeList(select)) {
  785. return;
  786. }
  787. if (!billsCol.getValue.isChange(select)) {
  788. toastr.warning('请先勾选变更清单才能勾选计价');
  789. info.sheet.setValue(info.row, info.col, 0);
  790. return;
  791. }
  792. if (info.sheet.isEditing()) {
  793. info.sheet.endEdit(true);
  794. }
  795. const cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
  796. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  797. toastr.warning('该变更清单已被调用,无法更改计价');
  798. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  799. return;
  800. }
  801. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  802. // select.is_valuation = is_valuation;
  803. cInfo.is_valuation = is_valuation;
  804. delete cInfo.waitingLoading;
  805. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  806. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  807. info.sheet.setValue(info.row, info.col, is_valuation);
  808. }, function () {
  809. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  810. cInfo.is_valuation = select.is_valuation;
  811. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  812. });
  813. }
  814. }
  815. },
  816. /**
  817. * 编辑单元格响应事件
  818. * @param {Object} e
  819. * @param {Object} info
  820. */
  821. editEnded: function (e, info) {
  822. if (info.sheet.zh_setting) {
  823. const col = info.sheet.zh_setting.cols[info.col];
  824. if (col.field === 'is_change' || col.field === 'is_valuation') {
  825. return;
  826. }
  827. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  828. const node = sortData[info.row];
  829. if (col.field === 'camount') {
  830. if (!node) {
  831. toastr.error('数据错误,请选择台账节点后再试');
  832. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  833. return;
  834. }
  835. let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  836. if (!cInfo) {
  837. if (billsCol.readOnly.isSettle(node)) {
  838. toastr.error('清单数据未完善,无法编辑申请数量');
  839. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  840. return;
  841. }
  842. makeGclGatherData();
  843. const gclInfo = _.find(gclGatherData, function (item) {
  844. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
  845. });
  846. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  847. return item.gcl_id === node.id;
  848. });
  849. const oldCInfo = _.find(oldChangeList, { gcl_id: node.id, mx_id: '' });
  850. const data = {
  851. lid: gclInfo.leafXmjs[0].gcl_id || node.id,
  852. code: gclInfo.b_code,
  853. name: gclInfo.name || '',
  854. unit: gclInfo.unit || '',
  855. unit_price: gclInfo.unit_price,
  856. oamount: xmjInfo.quantity,
  857. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  858. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  859. xmj_code: xmjInfo.code || '',
  860. xmj_jldy: xmjInfo.jldy || '',
  861. xmj_dwgc: xmjInfo.dwgc || '',
  862. xmj_fbgc: xmjInfo.fbgc || '',
  863. xmj_fxgc: xmjInfo.fxgc || '',
  864. gcl_id: node.id,
  865. mx_id: '',
  866. };
  867. if (oldCInfo) {
  868. data.detail = oldCInfo.detail;
  869. data.camount = oldCInfo.camount;
  870. data.camount_expr = oldCInfo.camount_expr;
  871. data.spamount = oldCInfo.spamount;
  872. data.is_valuation = oldCInfo.is_valuation;
  873. data.delimit = oldCInfo.delimit;
  874. }
  875. cInfo = data;
  876. // toastr.error('未勾选变更清单,无法编辑申请数量');
  877. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  878. // return;
  879. }
  880. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  881. const orgValue = validText && validText !== ''
  882. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  883. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  884. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  885. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  886. return;
  887. }
  888. const exprQuantity = {
  889. expr: '',
  890. quantity: 0,
  891. };
  892. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  893. if (!valid) {
  894. toastr.error(msg);
  895. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  896. return;
  897. }
  898. if (isNaN(exprQuantity.quantity)) {
  899. toastr.error('不能输入其它非数字类型字符');
  900. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  901. return;
  902. }
  903. validText = parseFloat(exprQuantity.quantity);
  904. if (cInfo.id) {
  905. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  906. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  907. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  908. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  909. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  910. return;
  911. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  912. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  913. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  914. return;
  915. }
  916. }
  917. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  918. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  919. cInfo.camount_expr = exprQuantity.expr;
  920. node[col.field] = cInfo[col.field];
  921. delete cInfo.waitingLoading;
  922. if (cInfo.id) {
  923. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  924. type: 'update',
  925. updateData: cInfo
  926. }, function (result) {
  927. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  928. const billsNode = node;
  929. billsTreeSpreadObj.reCalcCamount(billsNode);
  930. const loadResult = {update: [billsNode]};
  931. const refreshNode = billsTree.loadPostData(loadResult);
  932. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  933. }, function () {
  934. cInfo[col.field] = orgValue;
  935. cInfo.spamount = orgValue;
  936. node[col.field] = orgValue;
  937. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  938. });
  939. } else {
  940. // 更新至服务器
  941. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  942. changeList = result.changeList;
  943. node.is_change = 1;
  944. node.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  945. node.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  946. billsTreeSpreadObj.reCalcCamount(node);
  947. const refreshNode = billsTree.loadPostData({ update: [node] });
  948. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  949. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  950. }, function () {
  951. cInfo[col.field] = orgValue;
  952. cInfo.spamount = orgValue;
  953. node[col.field] = orgValue;
  954. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  955. });
  956. }
  957. return;
  958. }
  959. const data = {
  960. id: node.id,
  961. tender_id: node.tender_id,
  962. ledger_id: node.ledger_id
  963. };
  964. // 未改变值则不提交
  965. const orgValue = node[col.field];
  966. const newValue = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  967. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  968. return;
  969. }
  970. // 台账模式,检查计量单元相关
  971. if (isTz) {
  972. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  973. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  974. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  975. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  976. if (!node.children || node.children.length ===0) {
  977. const lPos = pos.getLedgerPos(node.id);
  978. if (lPos && lPos.length > 0) {
  979. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  980. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  981. return;
  982. }
  983. }
  984. }
  985. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  986. const lPos = pos.getLedgerPos(node.id);
  987. if (lPos && lPos.length > 0) {
  988. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  989. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  990. return;
  991. }
  992. }
  993. }
  994. // 获取更新数据
  995. const exprInfo = getExprInfo(col.field);
  996. if (info.editingText) {
  997. const text = newValue;
  998. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  999. toastr.error('节点已计量,请勿删除编号');
  1000. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1001. return;
  1002. }
  1003. if (col.type === 'Number') {
  1004. const num = _.toNumber(text);
  1005. if (_.isFinite(num)) {
  1006. data[col.field] = num;
  1007. if (exprInfo) {
  1008. data[exprInfo.expr] = '';
  1009. }
  1010. } else {
  1011. try {
  1012. data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  1013. if (exprInfo) {
  1014. data[exprInfo.expr] = newValue;
  1015. }
  1016. } catch(err) {
  1017. toastr.error('输入的表达式非法');
  1018. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1019. return;
  1020. }
  1021. }
  1022. } else {
  1023. data[col.field] = text;
  1024. }
  1025. } else {
  1026. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  1027. toastr.error('节点已计量,请勿删除编号');
  1028. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1029. return;
  1030. }
  1031. data[col.field] = null;
  1032. if (exprInfo) {
  1033. data[exprInfo.expr] = '';
  1034. }
  1035. }
  1036. if (col.field === 'b_code' && newValue) {
  1037. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1038. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1039. });
  1040. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  1041. if (ledgerOneData) {
  1042. data.name = ledgerOneData.name;
  1043. data.unit = ledgerOneData.unit;
  1044. data.unit_price = ledgerOneData.unit_price;
  1045. }
  1046. }
  1047. // 更新至服务器
  1048. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1049. changeList = result.changeList;
  1050. const refreshNode = billsTree.loadPostData(result);
  1051. for (const u of refreshNode.update) {
  1052. billsTreeSpreadObj.reCalcCamount(u);
  1053. }
  1054. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1055. billsTreeSpreadObj.refreshPosData();
  1056. });
  1057. }
  1058. },
  1059. clipboardPasting: function (e, info) {
  1060. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  1061. info.cancel = true;
  1062. if (!setting || !tree) return;
  1063. // const range = info.cellRange;
  1064. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1065. // const node = tree.nodes[iRow];
  1066. // if (tree.checkNodeUsed(node, pos)) {
  1067. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  1068. // return;
  1069. // }
  1070. // }
  1071. const pasteData = info.pasteData.html
  1072. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  1073. : (info.pasteData.text === ''
  1074. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  1075. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  1076. const hint = {
  1077. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  1078. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  1079. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  1080. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  1081. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  1082. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  1083. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  1084. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  1085. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  1086. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  1087. };
  1088. const datas = [], filterNodes = [], camountData = [], insertCamountData = [];
  1089. let pid, level, filterRow = 0;
  1090. makeGclGatherData();
  1091. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  1092. const curRow = info.cellRange.row + iRow;
  1093. const node = tree.nodes[curRow];
  1094. if (!node) continue;
  1095. if (!pid) pid = node.ledger_pid;
  1096. if (!level) level = node.level;
  1097. // if (node.ledger_pid !== pid) {
  1098. // toastMessageUniq(hint.sameParent);
  1099. // filterRow+=1;
  1100. // continue;
  1101. // }
  1102. if (node.level < level) break;
  1103. let bPaste = false;
  1104. const data = info.sheet.zh_tree.getNodeKeyData(node);
  1105. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1106. const curCol = info.cellRange.col + iCol;
  1107. const colSetting = info.sheet.zh_setting.cols[curCol];
  1108. const value = colSetting.wordWrap ? pasteData[iRow-filterRow][iCol] : trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  1109. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  1110. toastMessageUniq(hint.parent);
  1111. continue;
  1112. }
  1113. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  1114. toastMessageUniq(hint.gcl);
  1115. continue;
  1116. }
  1117. const lPos = pos.getLedgerPos(node.id);
  1118. if (lPos && lPos.length > 0) {
  1119. if (value === '' && colSetting.field === 'b_code') {
  1120. toastMessageUniq(hint.posCode);
  1121. continue;
  1122. }
  1123. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  1124. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  1125. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  1126. colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
  1127. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  1128. if (isTz) {
  1129. toastMessageUniq(hint.posQty);
  1130. continue;
  1131. }
  1132. }
  1133. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  1134. toastMessageUniq(hint.posXmj);
  1135. continue;
  1136. }
  1137. }
  1138. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  1139. toastMessageUniq (hint.usedUp);
  1140. continue;
  1141. }
  1142. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  1143. toastMessageUniq(hint.settle);
  1144. continue;
  1145. }
  1146. if (colSetting.field === 'camount') {
  1147. bPaste = true;
  1148. let validText = value;
  1149. let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1150. if (!cInfo) {
  1151. const gclInfo = _.find(gclGatherData, function (item) {
  1152. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
  1153. });
  1154. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  1155. return item.gcl_id === node.id;
  1156. });
  1157. const oldCInfo = _.find(oldChangeList, { gcl_id: node.id, mx_id: '' });
  1158. const data = {
  1159. lid: gclInfo.leafXmjs[0].gcl_id || node.id,
  1160. code: gclInfo.b_code,
  1161. name: gclInfo.name || '',
  1162. unit: gclInfo.unit || '',
  1163. unit_price: gclInfo.unit_price,
  1164. oamount: xmjInfo.quantity,
  1165. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1166. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  1167. xmj_code: xmjInfo.code || '',
  1168. xmj_jldy: xmjInfo.jldy || '',
  1169. xmj_dwgc: xmjInfo.dwgc || '',
  1170. xmj_fbgc: xmjInfo.fbgc || '',
  1171. xmj_fxgc: xmjInfo.fxgc || '',
  1172. gcl_id: node.id,
  1173. mx_id: '',
  1174. };
  1175. if (oldCInfo) {
  1176. data.detail = oldCInfo.detail;
  1177. data.camount = oldCInfo.camount;
  1178. data.camount_expr = oldCInfo.camount_expr;
  1179. data.spamount = oldCInfo.spamount;
  1180. data.is_valuation = oldCInfo.is_valuation;
  1181. data.delimit = oldCInfo.delimit;
  1182. }
  1183. cInfo = data;
  1184. // bPaste = false;
  1185. // continue;
  1186. }
  1187. const exprQuantity = {
  1188. expr: '',
  1189. quantity: 0,
  1190. };
  1191. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  1192. if (!valid) {
  1193. toastMessageUniq(hint.invalidExpr);
  1194. bPaste = false;
  1195. continue;
  1196. }
  1197. if (isNaN(exprQuantity.quantity)) {
  1198. toastMessageUniq(hint.invalidExpr);
  1199. bPaste = false;
  1200. continue;
  1201. }
  1202. validText = parseFloat(exprQuantity.quantity);
  1203. if (cInfo.id) {
  1204. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1205. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  1206. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1207. toastr.error(curRow ? '台账第' + (curRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1208. bPaste = false;
  1209. continue;
  1210. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1211. toastr.error(curRow ? '台账第' + (curRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1212. bPaste = false;
  1213. continue;
  1214. }
  1215. }
  1216. if (bPaste) {
  1217. node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1218. filterNodes.push(node);
  1219. if (cInfo.id) {
  1220. camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  1221. } else {
  1222. cInfo.camount = node.camount;
  1223. cInfo.camount_expr = exprQuantity.expr;
  1224. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1225. insertCamountData.push(cInfo);
  1226. }
  1227. } else {
  1228. filterNodes.push(node);
  1229. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1230. }
  1231. continue;
  1232. }
  1233. if (colSetting.type === 'Number') {
  1234. const num = _.toNumber(value);
  1235. if (num) {
  1236. data[colSetting.field] = num;
  1237. } else {
  1238. try {
  1239. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  1240. const exprInfo = getExprInfo(colSetting.field);
  1241. if (exprInfo) {
  1242. data[exprInfo.expr] = value;
  1243. }
  1244. bPaste = true;
  1245. } catch (err) {
  1246. toastMessageUniq(hint.invalidExpr);
  1247. continue;
  1248. }
  1249. }
  1250. } else {
  1251. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  1252. && data[colSetting.field] !== '' && value === '') {
  1253. toastMessageUniq(hint.usedCode);
  1254. continue;
  1255. }
  1256. data[colSetting.field] = value;
  1257. }
  1258. if (colSetting.field === 'b_code' && value) {
  1259. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1260. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1261. });
  1262. const ledgerOneData = _.find(ledgerData, { b_code: value });
  1263. if (ledgerOneData) {
  1264. data.name = ledgerOneData.name;
  1265. data.unit = ledgerOneData.unit;
  1266. data.unit_price = ledgerOneData.unit_price;
  1267. }
  1268. }
  1269. bPaste = true;
  1270. }
  1271. if (bPaste) {
  1272. datas.push(data);
  1273. } else {
  1274. filterNodes.push(node);
  1275. }
  1276. }
  1277. if (camountData.length > 0 || insertCamountData.length > 0) {
  1278. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: insertCamountData, updateData: camountData }, function (result) {
  1279. changeList = result;
  1280. // 给所有filterNodes 加上is_change=1
  1281. filterNodes.forEach(function (item) {
  1282. item.is_change = 1;
  1283. });
  1284. const loadResult = { update: filterNodes };
  1285. const refreshNode = billsTree.loadPostData(loadResult);
  1286. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1287. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1288. }, function () {
  1289. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1290. return;
  1291. });
  1292. return;
  1293. }
  1294. if (datas.length > 0) {
  1295. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1296. changeList = result.changeList;
  1297. const refreshNode = tree.loadPostData(result);
  1298. if (refreshNode.update) {
  1299. refreshNode.update = refreshNode.update.concat(filterNodes);
  1300. }
  1301. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1302. }, function () {
  1303. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1304. });
  1305. } else {
  1306. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1307. }
  1308. },
  1309. clipboardPasted: function (e, info) {
  1310. const hint = {
  1311. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  1312. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  1313. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  1314. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  1315. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  1316. };
  1317. const tree = info.sheet.zh_tree;
  1318. if (!tree) { return; }
  1319. const sortData = info.sheet.zh_tree.nodes;
  1320. const datas = [], filterNodes = [], camountData = [];
  1321. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  1322. let bPaste = false;
  1323. const curRow = info.cellRange.row + iRow;
  1324. const node = sortData[curRow];
  1325. if (node) {
  1326. const data = info.sheet.zh_tree.getNodeKeyData(node);
  1327. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1328. const curCol = info.cellRange.col + iCol;
  1329. const colSetting = info.sheet.zh_setting.cols[curCol];
  1330. const value = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  1331. const lPos = pos.getLedgerPos(node.id);
  1332. if (lPos && lPos.length > 0) {
  1333. if (value === '' && colSetting.field === 'b_code') {
  1334. toastMessageUniq(hint.posCode);
  1335. continue;
  1336. }
  1337. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  1338. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  1339. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  1340. colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
  1341. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  1342. toastMessageUniq(hint.posQty);
  1343. continue;
  1344. }
  1345. }
  1346. if (node.used && colSetting.field === 'unit_price') {
  1347. toastMessageUniq (hint.usedUp);
  1348. continue;
  1349. }
  1350. if (colSetting.field === 'camount') {
  1351. bPaste = true;
  1352. let validText = value;
  1353. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1354. if (!cInfo) {
  1355. bPaste = false;
  1356. continue;
  1357. }
  1358. const exprQuantity = {
  1359. expr: '',
  1360. quantity: 0,
  1361. };
  1362. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  1363. if (!valid) {
  1364. toastMessageUniq(hint.invalidExpr);
  1365. bPaste = false;
  1366. continue;
  1367. }
  1368. if (isNaN(exprQuantity.quantity)) {
  1369. toastMessageUniq(hint.invalidExpr);
  1370. bPaste = false;
  1371. continue;
  1372. }
  1373. validText = parseFloat(exprQuantity.quantity);
  1374. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1375. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1376. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1377. toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1378. bPaste = false;
  1379. continue;
  1380. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1381. toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1382. bPaste = false;
  1383. continue;
  1384. }
  1385. if (bPaste) {
  1386. node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1387. filterNodes.push(node);
  1388. camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  1389. } else {
  1390. filterNodes.push(node);
  1391. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1392. }
  1393. continue;
  1394. }
  1395. if (colSetting.type === 'Number') {
  1396. const num = _.toNumber(value);
  1397. if (num) {
  1398. data[colSetting.field] = num;
  1399. } else {
  1400. try {
  1401. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  1402. } catch (err) {
  1403. toastMessageUniq(hint.invalidExpr);
  1404. continue;
  1405. }
  1406. }
  1407. } else {
  1408. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  1409. && data[colSetting.field] !== '' && value === '') {
  1410. toastMessageUniq(hint.usedCode);
  1411. continue;
  1412. }
  1413. data[colSetting.field] = value;
  1414. }
  1415. if (colSetting.field === 'b_code' && value) {
  1416. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1417. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1418. });
  1419. const ledgerOneData = _.find(ledgerData, { b_code: value });
  1420. if (ledgerOneData) {
  1421. data.name = ledgerOneData.name;
  1422. data.unit = ledgerOneData.unit;
  1423. data.unit_price = ledgerOneData.unit_price;
  1424. }
  1425. }
  1426. bPaste = true;
  1427. }
  1428. if (bPaste) {
  1429. datas.push(data);
  1430. } else {
  1431. filterNodes.push(node);
  1432. }
  1433. }
  1434. }
  1435. if (camountData.length > 0) {
  1436. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountData }, function (result) {
  1437. changeList = result;
  1438. const loadResult = { update: filterNodes };
  1439. const refreshNode = billsTree.loadPostData(loadResult);
  1440. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1441. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1442. }, function () {
  1443. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1444. return;
  1445. });
  1446. return;
  1447. }
  1448. if (datas.length > 0) {
  1449. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1450. changeList = result.changeList;
  1451. const refreshNode = tree.loadPostData(result);
  1452. if (refreshNode.update) {
  1453. refreshNode.update = refreshNode.update.concat(filterNodes);
  1454. }
  1455. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1456. }, function () {
  1457. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1458. });
  1459. } else {
  1460. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1461. }
  1462. },
  1463. deletePress: function (sheet) {
  1464. if (!sheet.zh_setting) return;
  1465. const sel = sheet.getSelections()[0], datas = [], camountDatas = [];
  1466. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1467. let bDel = false;
  1468. const node = sheet.zh_tree.nodes[iRow];
  1469. const data = sheet.zh_tree.getNodeKeyData(node);
  1470. const cData = {};
  1471. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1472. const col = sheet.zh_setting.cols[iCol];
  1473. const style = sheet.getStyle(iRow, iCol);
  1474. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  1475. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  1476. if (['dgn_qty1', 'dgn_qty2', 'camount'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  1477. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  1478. return;
  1479. }
  1480. if (col.field === 'camount') {
  1481. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1482. if (!cInfo) continue;
  1483. cData.id = cInfo.id;
  1484. cData.camount = null;
  1485. cData.camount_expr = '';
  1486. cData.spamount = null;
  1487. data.camount = null;
  1488. } else {
  1489. data[col.field] = null;
  1490. const exprInfo = getExprInfo(col.field);
  1491. if (exprInfo) {
  1492. data[exprInfo.expr] = '';
  1493. }
  1494. }
  1495. bDel = true;
  1496. }
  1497. if (bDel) {
  1498. datas.push(data);
  1499. if (cData.id) camountDatas.push(cData);
  1500. }
  1501. }
  1502. if (camountDatas.length > 0) {
  1503. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  1504. changeList = result;
  1505. for (const d of datas) {
  1506. billsTreeSpreadObj.reCalcCamount(d);
  1507. }
  1508. const loadResult = { update: datas };
  1509. const refreshNode = billsTree.loadPostData(loadResult);
  1510. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1511. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1512. });
  1513. return;
  1514. }
  1515. if (datas.length > 0) {
  1516. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1517. changeList = result.changeList;
  1518. const refreshNode = sheet.zh_tree.loadPostData(result);
  1519. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1520. billsTreeSpreadObj.loadExprToInput(sheet);
  1521. });
  1522. }
  1523. },
  1524. pasteBlock: function (spread, copyInfo) {
  1525. const self = this;
  1526. const sheet = spread.getActiveSheet();
  1527. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  1528. if (node.settle_status === settleStatus.finish) {
  1529. toastr.warning('选中的节点已结算,不可粘贴整块');
  1530. return;
  1531. }
  1532. postData(window.location.pathname + '/update', {
  1533. postType: 'paste-block',
  1534. postData: {
  1535. id: tree.getNodeKey(node),
  1536. tid: copyInfo.tid,
  1537. block: copyInfo.block,
  1538. }
  1539. }, function (data) {
  1540. changeList = data.changeList;
  1541. pos.updateDatas(data.pos);
  1542. const result = tree.loadPostData(data.ledger);
  1543. self.refreshTree(sheet, result);
  1544. const sel = sheet.getSelections()[0];
  1545. if (sel) {
  1546. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  1547. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  1548. }
  1549. self.refreshOperationValid(sheet);
  1550. removeLocalCache(copyBlockTag);
  1551. }, null, true);
  1552. },
  1553. topRowChanged: function (e, info) {
  1554. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1555. },
  1556. editStarting(e, info) {
  1557. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1558. const col = info.sheet.zh_setting.cols[info.col];
  1559. const node = info.sheet.zh_tree.nodes[info.row];
  1560. if (!node) {
  1561. info.cancel = true;
  1562. return;
  1563. }
  1564. if (col.field === 'camount') {
  1565. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1566. if (!cInfo) {
  1567. if (billsCol.readOnly.isSettle(node)) {
  1568. toastr.error('清单数据未完善,无法编辑申请数量');
  1569. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1570. return
  1571. }
  1572. return;
  1573. }
  1574. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  1575. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  1576. }
  1577. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1578. info.cancel = true;
  1579. }
  1580. } else {
  1581. const exprInfo = getExprInfo(col.field);
  1582. if (exprInfo) {
  1583. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1584. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1585. }
  1586. }
  1587. switch (col.field) {
  1588. case 'code':
  1589. const posRange = pos.getLedgerPos(node.id);
  1590. info.cancel = posRange && posRange.length > 0;
  1591. break;
  1592. case 'unit_price':
  1593. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  1594. break;
  1595. case 'sgfh_qty':
  1596. case 'sgfh_tp':
  1597. case 'sjcl_qty':
  1598. case 'sjcl_tp':
  1599. case 'qtcl_qty':
  1600. case 'qtcl_tp':
  1601. case 'deal_qty':
  1602. case 'deal_tp':
  1603. case 'ex_qty1':
  1604. case 'ex_tp1':
  1605. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  1606. break;
  1607. case 'dgn_qty1':
  1608. case 'dgn_qty2':
  1609. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  1610. break;
  1611. }
  1612. }
  1613. },
  1614. cut: function (sheet, sel, callback) {
  1615. if (!sheet || !sel) return;
  1616. if (sel.colCount >= sheet.zh_setting.cols.length) {
  1617. toastr.warning('请勿选中整行剪切');
  1618. return;
  1619. }
  1620. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1621. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1622. const node = sortData[iRow];
  1623. if (node) {
  1624. const data = sheet.zh_tree.getNodeKeyData(node);
  1625. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1626. const col = sheet.zh_setting.cols[iCol];
  1627. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1628. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1629. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  1630. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  1631. const lPos = pos.getLedgerPos(node.id);
  1632. if (lPos && lPos.length > 0) {
  1633. toastr.error('不可剪切');
  1634. return;
  1635. }
  1636. }
  1637. const style = sheet.getStyle(iRow, iCol);
  1638. if (style.locked) {
  1639. toastr.error('不可剪切');
  1640. return;
  1641. }
  1642. const colSetting = sheet.zh_setting.cols[iCol];
  1643. data[colSetting.field] = null;
  1644. const exprInfo = getExprInfo(colSetting.field);
  1645. if (exprInfo) {
  1646. data[exprInfo.expr] = '';
  1647. }
  1648. }
  1649. datas.push(data);
  1650. }
  1651. }
  1652. if (datas.length > 0) {
  1653. callback();
  1654. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1655. changeList = result.changeList;
  1656. const refreshNode = sheet.zh_tree.loadPostData(result);
  1657. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1658. });
  1659. }
  1660. },
  1661. sortCode: function (sheet) {
  1662. const tree = sheet.zh_tree;
  1663. if (!tree) return;
  1664. const select = SpreadJsObj.getSelectObject(sheet);
  1665. if (!select || !select.code || select.code === '') return;
  1666. const recursiveSortCode = function (data, parentCode, children) {
  1667. if (!children || children.length === 0) return;
  1668. for (const [i, child] of children.entries()) {
  1669. if (!child.b_code || child.b_code === '') {
  1670. const code = parentCode + '-' + (i + 1);
  1671. const cData = tree.getNodeKeyData(child);
  1672. cData.code = code;
  1673. data.push(cData);
  1674. if (!tree.isLeafXmj(child)) {
  1675. recursiveSortCode(data, code, child.children);
  1676. }
  1677. }
  1678. }
  1679. };
  1680. const data = [];
  1681. recursiveSortCode(data, select.code, select.children);
  1682. if (data.length > 0) {
  1683. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1684. changeList = result.changeList;
  1685. const refreshNode = tree.loadPostData(result);
  1686. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1687. })
  1688. }
  1689. },
  1690. reCalcCamount: function (node) {
  1691. if (node && node.b_code) {
  1692. const posData = pos.getLedgerPos(node.id) || [];
  1693. let camount = node.camount || 0;
  1694. let is_valuation = node.is_valuation || 0;
  1695. if (posData.length > 0) {
  1696. camount = 0;
  1697. for (const np of posData) {
  1698. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  1699. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit))) : camount;
  1700. if (cInfo && cInfo.is_valuation) {
  1701. is_valuation = 1;
  1702. }
  1703. }
  1704. }
  1705. node.camount = camount;
  1706. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  1707. node.is_valuation = is_valuation;
  1708. }
  1709. },
  1710. _checkExprValid(expr) {
  1711. if (!expr) return [true, null];
  1712. const param = [];
  1713. let num = '', base = '';
  1714. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1715. if (/^[\d\.%]+/.test(expr[i])) {
  1716. if (base !== '') {
  1717. param.push({type: 'base', value: base});
  1718. base = '';
  1719. }
  1720. num = num + expr[i];
  1721. } else if (expr[i] === '(') {
  1722. if (num !== '') {
  1723. param.push({type: 'num', value: num});
  1724. num = '';
  1725. }
  1726. if (base !== '') {
  1727. param.push({type: 'base', value: base});
  1728. base = '';
  1729. }
  1730. param.push({type: 'left', value: '('});
  1731. } else if (expr[i] === ')') {
  1732. if (num !== '') {
  1733. param.push({type: 'num', value: num});
  1734. num = '';
  1735. }
  1736. if (base !== '') {
  1737. param.push({type: 'base', value: base});
  1738. base = '';
  1739. }
  1740. param.push({type: 'right', value: ')'});
  1741. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1742. if (num !== '') {
  1743. param.push({type: 'num', value: num});
  1744. num = '';
  1745. }
  1746. if (base !== '') {
  1747. param.push({type: 'base', value: base});
  1748. base = '';
  1749. }
  1750. param.push({type: 'calc', value: expr[i]});
  1751. } else {
  1752. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1753. }
  1754. }
  1755. if (num !== '') {
  1756. param.push({type: 'num', value: num});
  1757. num = '';
  1758. }
  1759. if (base !== '') {
  1760. param.push({type: 'base', value: base});
  1761. base = '';
  1762. }
  1763. if (param.length === 0) return true;
  1764. if (param.length > 1) {
  1765. if (param[0].value === '-' && param[1].type === 'num') {
  1766. param[1].value = '-' + param[1].value;
  1767. param.shift();
  1768. }
  1769. }
  1770. const iLen = param.length;
  1771. let iLeftCount = 0, iRightCount = 0;
  1772. for (const [i, p] of param.entries()) {
  1773. if (p.type === 'calc') {
  1774. if (i === 0 || i === iLen - 1)
  1775. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1776. }
  1777. if (p.type === 'num') {
  1778. num = p.value.replace('%', '');
  1779. if (p.value.length - num.length > 1)
  1780. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1781. num = _.toNumber(num);
  1782. if (num === undefined || num === null || _.isNaN(num))
  1783. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1784. if (i > 0) {
  1785. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1786. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1787. } else if (param[i - 1].value === '/' && num === 0) {
  1788. return [false, '输入的表达式非法:请勿除0'];
  1789. }
  1790. }
  1791. }
  1792. if (p.type === 'base') {
  1793. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1794. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1795. }
  1796. if (p.type === 'left') {
  1797. iLeftCount += 1;
  1798. if (i !== 0 && param[i-1].type !== 'calc')
  1799. return [false, '输入的表达式非法:(前应有运算符'];
  1800. }
  1801. if (p.type === 'right') {
  1802. iRightCount += 1;
  1803. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1804. return [false, '输入的表达式非法:)后应有运算符'];
  1805. if (iRightCount > iLeftCount)
  1806. return [false, '输入的表达式非法:")"前无对应的"("'];
  1807. }
  1808. }
  1809. if (iLeftCount > iRightCount)
  1810. return [false, '输入的表达式非法:"("后无对应的")"'];
  1811. return [true, ''];
  1812. },
  1813. _checkExpr: function (text, data) {
  1814. if (text) {
  1815. const num = _.toNumber(text);
  1816. if (num) {
  1817. data.quantity = num;
  1818. data.expr = '';
  1819. } else {
  1820. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1821. const [valid, msg] = this._checkExprValid(expr);
  1822. if (!valid) return [valid, msg];
  1823. data.expr = expr;
  1824. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
  1825. // const ce = new CalcEvalMin();
  1826. // data.quantity = ce.eval(expr);
  1827. // console.log(data.quantity);
  1828. }
  1829. } else {
  1830. data.quantity = 0;
  1831. data.expr = '';
  1832. }
  1833. return [true, ''];
  1834. },
  1835. };
  1836. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1837. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1838. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1839. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1840. if (!readOnly) {
  1841. // 增删上下移升降级
  1842. $('a[name="base-opr"]').click(function () {
  1843. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1844. });
  1845. $('a[name=cpc]').click(function () {
  1846. billsSpread.commandManager().execute({
  1847. cmd: this.getAttribute('type'),
  1848. sheetName: billsSheet.name()
  1849. });
  1850. });
  1851. $('#bills-expr').bind('change onblur', function () {
  1852. if (this.readOnly) return;
  1853. const expr = $(this);
  1854. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1855. const select = billsTree.getItemsByIndex(row);
  1856. if (!select) return;
  1857. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1858. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1859. if (field === 'camount') {
  1860. let cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
  1861. if (!cInfo) {
  1862. if (billsCol.readOnly.isChangeList(select)) {
  1863. toastr.error('清单数据未完善,无法编辑申请数量');
  1864. SpreadJsObj.reLoadRowData(billsSheet, row);
  1865. return;
  1866. }
  1867. makeGclGatherData();
  1868. const gclInfo = _.find(gclGatherData, function (item) {
  1869. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  1870. });
  1871. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  1872. return item.gcl_id === select.id;
  1873. });
  1874. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  1875. const data = {
  1876. lid: gclInfo.leafXmjs[0].gcl_id || select.id,
  1877. code: gclInfo.b_code,
  1878. name: gclInfo.name || '',
  1879. unit: gclInfo.unit || '',
  1880. unit_price: gclInfo.unit_price,
  1881. oamount: xmjInfo.quantity,
  1882. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1883. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  1884. xmj_code: xmjInfo.code || '',
  1885. xmj_jldy: xmjInfo.jldy || '',
  1886. xmj_dwgc: xmjInfo.dwgc || '',
  1887. xmj_fbgc: xmjInfo.fbgc || '',
  1888. xmj_fxgc: xmjInfo.fxgc || '',
  1889. gcl_id: select.id,
  1890. mx_id: '',
  1891. };
  1892. if (oldCInfo) {
  1893. data.detail = oldCInfo.detail;
  1894. data.camount = oldCInfo.camount;
  1895. data.camount_expr = oldCInfo.camount_expr;
  1896. data.spamount = oldCInfo.spamount;
  1897. data.is_valuation = oldCInfo.is_valuation;
  1898. data.delimit = oldCInfo.delimit;
  1899. }
  1900. cInfo = data;
  1901. // toastr.error('未勾选变更清单,无法编辑申请数量');
  1902. // return;
  1903. }
  1904. const exprQuantity = {
  1905. expr: '',
  1906. quantity: 0,
  1907. };
  1908. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  1909. if (!valid) {
  1910. toastr.error(msg);
  1911. return;
  1912. }
  1913. if (isNaN(exprQuantity.quantity)) {
  1914. toastr.error('不能输入其它非数字类型字符');
  1915. return;
  1916. }
  1917. const camount = parseFloat(exprQuantity.quantity);
  1918. if (cInfo.id) {
  1919. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1920. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1921. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1922. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1923. return;
  1924. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1925. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1926. return;
  1927. }
  1928. }
  1929. cInfo.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1930. select.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1931. cInfo.spamount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1932. cInfo.camount_expr = exprQuantity.expr;
  1933. delete cInfo.waitingLoading;
  1934. if (cInfo.id) {
  1935. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  1936. SpreadJsObj.reLoadRowData(billsSheet, row);
  1937. billsTreeSpreadObj.reCalcCamount(select);
  1938. const loadResult = { update: [select] };
  1939. const refreshNode = billsTree.loadPostData(loadResult);
  1940. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1941. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1942. }, function () {
  1943. cInfo.camount = orgValue;
  1944. cInfo.spamount = orgValue;
  1945. select.camount = orgValue;
  1946. SpreadJsObj.reLoadRowData(billsSheet, row);
  1947. });
  1948. } else {
  1949. // 更新至服务器
  1950. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  1951. changeList = result.changeList;
  1952. select.is_change = 1;
  1953. select.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  1954. select.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  1955. billsTreeSpreadObj.reCalcCamount(select);
  1956. const refreshNode = billsTree.loadPostData({ update: [select] });
  1957. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1958. SpreadJsObj.reLoadRowData(billsSheet, row);
  1959. }, function () {
  1960. cInfo[col.field] = orgValue;
  1961. cInfo.spamount = orgValue;
  1962. node[col.field] = orgValue;
  1963. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1964. });
  1965. }
  1966. return;
  1967. }
  1968. const data = {
  1969. id: select.id,
  1970. tender_id: select.tender_id,
  1971. ledger_id: select.ledger_id
  1972. };
  1973. const exprInfo = getExprInfo(field);
  1974. if (newValue !== '') {
  1975. const num = _.toNumber(newValue);
  1976. if (num) {
  1977. data[field] = num;
  1978. if (exprInfo) {
  1979. data[exprInfo.expr] = '';
  1980. }
  1981. } else {
  1982. try {
  1983. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  1984. if (exprInfo) {
  1985. data[exprInfo.expr] = newValue;
  1986. }
  1987. } catch (err) {
  1988. toastr.error('输入的表达式非法');
  1989. return;
  1990. }
  1991. }
  1992. } else {
  1993. data[field] = null;
  1994. if (exprInfo) {
  1995. data[exprInfo.expr] = '';
  1996. }
  1997. }
  1998. // 更新至服务器
  1999. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  2000. changeList = result.changeList;
  2001. const refreshNode = billsTree.loadPostData(result);
  2002. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2003. });
  2004. });
  2005. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  2006. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  2007. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  2008. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  2009. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  2010. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  2011. SpreadJsObj.Clipboard.setCopyData(copyText);
  2012. });
  2013. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  2014. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  2015. }
  2016. // 右键菜单
  2017. let batchInsertObj;
  2018. $.contextMenu.types.batchInsert = function (item, opt, root) {
  2019. const self = this;
  2020. if ($.isFunction(item.icon)) {
  2021. item._icon = item.icon.call(this, this, $t, key, item);
  2022. } else {
  2023. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  2024. // to enable font awesome
  2025. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  2026. } else {
  2027. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  2028. }
  2029. }
  2030. this.addClass(item._icon);
  2031. 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>')
  2032. .appendTo(this);
  2033. const $input = $obj.find('input');
  2034. const event = () => {
  2035. if (self.hasClass('context-menu-disabled')) return;
  2036. item.batchInsert($input[0], root);
  2037. };
  2038. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  2039. $input.click((e) => {e.stopPropagation();})
  2040. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  2041. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  2042. };
  2043. const billsContextMenuOptions = {
  2044. selector: '#bills-spread',
  2045. build: function ($trigger, e) {
  2046. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  2047. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2048. },
  2049. items: {}
  2050. };
  2051. if (!readOnly) {
  2052. billsContextMenuOptions.items.create = {
  2053. name: '新增',
  2054. icon: 'fa-sign-in',
  2055. callback: function (key, opt) {
  2056. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  2057. },
  2058. disabled: function (key, opt) {
  2059. const sheet = billsSheet;
  2060. const selection = sheet.getSelections();
  2061. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2062. const row = sel ? sel.row : -1;
  2063. const tree = sheet.zh_tree;
  2064. if (!tree) return true;
  2065. const first = sheet.zh_tree.nodes[row];
  2066. const valid = !sheet.zh_setting.readOnly;
  2067. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  2068. }
  2069. };
  2070. billsContextMenuOptions.items.delete = {
  2071. name: '删除',
  2072. icon: 'fa-remove',
  2073. callback: function (key, opt) {
  2074. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  2075. },
  2076. disabled: function (key, opt) {
  2077. const sheet = billsSheet;
  2078. const selection = sheet.getSelections();
  2079. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2080. const row = sel ? sel.row : -1;
  2081. const tree = sheet.zh_tree;
  2082. if (!tree) return true;
  2083. const first = sheet.zh_tree.nodes[row];
  2084. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  2085. if (sel.rowCount > 1 && first) {
  2086. for (let r = 1; r < sel.rowCount; r++) {
  2087. const rNode = tree.nodes[sel.row + r];
  2088. if (!rNode) {
  2089. sameParent = false;
  2090. break;
  2091. }
  2092. if (!rNode.formc) {
  2093. return true;
  2094. }
  2095. nodeUsed = nodeUsed || rNode.used;
  2096. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  2097. if (rNode.level > first.level) continue;
  2098. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  2099. sameParent = false;
  2100. break;
  2101. }
  2102. last = rNode;
  2103. }
  2104. }
  2105. const valid = !sheet.zh_setting.readOnly;
  2106. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  2107. }
  2108. };
  2109. billsContextMenuOptions.items.sprBase = '----';
  2110. }
  2111. billsContextMenuOptions.items.copyBlock = {
  2112. name: '复制整块',
  2113. icon: 'fa-files-o',
  2114. callback: function (key, opt) {
  2115. const copyBlockList = [];
  2116. const sheet = billsSheet;
  2117. const sel = sheet.getSelections()[0];
  2118. let iRow = sel.row;
  2119. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  2120. while (iRow < sel.row + sel.rowCount) {
  2121. const node = sheet.zh_tree.nodes[iRow];
  2122. if (node.ledger_pid !== pid) {
  2123. toastr.error('仅可同时选中同层节点');
  2124. return;
  2125. }
  2126. const posterity = sheet.zh_tree.getPosterity(node);
  2127. iRow += posterity.length + 1;
  2128. posterity.unshift(node);
  2129. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  2130. }
  2131. for (const cbl of copyBlockList) {
  2132. for (const b of cbl) {
  2133. const posRange = pos.getLedgerPos(b.id);
  2134. if (posRange && posRange.length > 0) b.pos = posRange;
  2135. }
  2136. }
  2137. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2138. },
  2139. visible: function (key, opt) {
  2140. const sheet = billsSheet;
  2141. const selection = sheet.getSelections();
  2142. const row = selection[0].row;
  2143. const select = billsTree.nodes[row];
  2144. return select;
  2145. },
  2146. disabled: function (key, opt) {
  2147. const sheet = billsSheet;
  2148. const selection = sheet.getSelections();
  2149. const row = selection[0].row;
  2150. const select = billsTree.nodes[row];
  2151. return select && select.level <= 1;
  2152. }
  2153. };
  2154. billsContextMenuOptions.items.copyBlockXmj = {
  2155. name: '复制整块(只复制项目节)',
  2156. icon: 'fa-files-o',
  2157. callback: function (key, opt) {
  2158. const copyBlockList = [];
  2159. const sheet = billsSheet;
  2160. const sel = sheet.getSelections()[0];
  2161. let iRow = sel.row;
  2162. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  2163. while (iRow < sel.row + sel.rowCount) {
  2164. const node = sheet.zh_tree.nodes[iRow];
  2165. if (node.ledger_pid !== pid) {
  2166. toastr.error('仅可同时选中同层节点');
  2167. return;
  2168. }
  2169. const posterity = sheet.zh_tree.getPosterity(node);
  2170. iRow += posterity.length + 1;
  2171. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  2172. copyPosterity.unshift(node);
  2173. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  2174. for (const p of copyData) {
  2175. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  2176. p.is_leaf = children.length === 0;
  2177. }
  2178. copyBlockList.push(copyData);
  2179. }
  2180. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2181. },
  2182. visible: function (key, opt) {
  2183. const sheet = billsSheet;
  2184. const selection = sheet.getSelections();
  2185. const row = selection[0].row;
  2186. const select = billsTree.nodes[row];
  2187. return select;
  2188. },
  2189. disabled: function (key, opt) {
  2190. const sheet = billsSheet;
  2191. const selection = sheet.getSelections();
  2192. const row = selection[0].row;
  2193. const select = billsTree.nodes[row];
  2194. return select && select.level <= 1;
  2195. }
  2196. };
  2197. if (!readOnly) {
  2198. billsContextMenuOptions.items.pasteBlock = {
  2199. name: '粘贴整块',
  2200. icon: 'fa-clipboard',
  2201. disabled: function (key, opt) {
  2202. //const block = treeOperationObj.block || [];
  2203. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2204. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  2205. },
  2206. callback: function (key, opt) {
  2207. //const block = treeOperationObj.block || [];
  2208. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2209. if (copyInfo.block.length > 0) {
  2210. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  2211. } else {
  2212. document.execCommand('paste');
  2213. }
  2214. },
  2215. visible: function (key, opt) {
  2216. return !readOnly;
  2217. }
  2218. };
  2219. billsContextMenuOptions.items.sprBlock = '----';
  2220. }
  2221. if (!readOnly) {
  2222. billsContextMenuOptions.items.batchInsert = {
  2223. name: '批量插入',
  2224. type: 'batchInsert',
  2225. value: '2',
  2226. icon: 'fa-sign-in',
  2227. batchInsert: function (obj, root) {
  2228. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2229. obj.value = obj.max;
  2230. toastr.warning('批量插入不可多于' + obj.max);
  2231. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2232. obj.value = obj.min;
  2233. toastr.warning('批量插入不可少于' + obj.min);
  2234. } else {
  2235. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  2236. root.$menu.trigger('contextmenu:hide');
  2237. }
  2238. },
  2239. disabled: function (key, opt) {
  2240. const sheet = billsSheet;
  2241. const selection = sheet.getSelections();
  2242. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2243. const row = sel ? sel.row : -1;
  2244. const tree = sheet.zh_tree;
  2245. if (!tree) return true;
  2246. const first = sheet.zh_tree.nodes[row];
  2247. const valid = !sheet.zh_setting.readOnly;
  2248. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  2249. }
  2250. };
  2251. billsContextMenuOptions.items.batchInsertBillsPos = {
  2252. name: '批量插入清单-计量单元',
  2253. icon: 'fa-sign-in',
  2254. visible: function (key, opt) {
  2255. return false;
  2256. },
  2257. disabled: function (key, opt) {
  2258. if (!isTz) return true;
  2259. const select = SpreadJsObj.getSelectObject(billsSheet);
  2260. if (select) {
  2261. if (select.code && select.code !== '') {
  2262. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  2263. } else {
  2264. const parent = billsTree.getParent(select);
  2265. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  2266. }
  2267. } else {
  2268. return false;
  2269. }
  2270. },
  2271. callback: function (key, opt) {
  2272. if (!batchInsertObj) {
  2273. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  2274. } else {
  2275. batchInsertObj.initView();
  2276. }
  2277. $('#batch').modal('show');
  2278. }
  2279. };
  2280. }
  2281. billsContextMenuOptions.items.sprTag = '----';
  2282. billsContextMenuOptions.items.showLast = {
  2283. name: '显示至最底层',
  2284. callback: function (key, opt, menu, e) {
  2285. const node = SpreadJsObj.getSelectObject(billsSheet);
  2286. setTimeout(() => {
  2287. showWaitingView();
  2288. billsTree.expandByCustom(x => {
  2289. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  2290. });
  2291. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  2292. closeWaitingView();
  2293. }, 100);
  2294. },
  2295. };
  2296. $.contextMenu(billsContextMenuOptions);
  2297. // 计量单元 相关方法&绑定spreadjs事件
  2298. const posSpreadObj = {
  2299. refreshOperationValid: function (sheet, selection) {
  2300. const setObjEnable = function (obj, enable) {
  2301. if (enable) {
  2302. obj.removeClass('disabled');
  2303. } else {
  2304. obj.addClass('disabled');
  2305. }
  2306. };
  2307. const invalidAll = function () {
  2308. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  2309. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  2310. };
  2311. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2312. const row = sel ? sel.row : -1;
  2313. const first = sheet.zh_data[row];
  2314. if (!first) {
  2315. invalidAll();
  2316. return;
  2317. }
  2318. let last = first;
  2319. if (sel.rowCount > 1 && first) {
  2320. for (let r = 1; r < sel.rowCount; r++) {
  2321. const rNode = sheet.zh_data[sel.row + r];
  2322. if (!rNode) break;
  2323. last = rNode;
  2324. }
  2325. }
  2326. const preNode = sheet.zh_data[row - 1];
  2327. const valid = !sheet.zh_setting.readOnly;
  2328. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  2329. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  2330. },
  2331. loadExprToInput: function () {
  2332. const sel = posSheet.getSelections()[0];
  2333. if (!sel) return;
  2334. const col = posSheet.zh_setting.cols[sel.col];
  2335. const cell = posSheet.getCell(sel.col, sel.col);
  2336. if (col && col.field === 'camount') {
  2337. const data = SpreadJsObj.getSelectObject(posSheet);
  2338. if (data) {
  2339. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  2340. if (!cInfo) {
  2341. if (posCol.readOnly.isChangeList(data)) {
  2342. $('#pos-expr').val('').attr('readOnly', true);
  2343. $('#pos-expr').removeAttr('data-row');
  2344. } else {
  2345. $('#pos-expr').val('').attr('field', col.field).attr('org', '')
  2346. .attr('readOnly', false).attr('data-row', sel.row);
  2347. }
  2348. } else {
  2349. const value = cInfo.camount_expr ? cInfo.camount_expr : cInfo.camount;
  2350. $('#pos-expr').val(value).attr('field', col.field).attr('org', cInfo.camount)
  2351. .attr('readOnly', posCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  2352. }
  2353. } else {
  2354. $('#pos-expr').val('').attr('readOnly', true);
  2355. $('#pos-expr').removeAttr('data-row');
  2356. }
  2357. } else if (col && col.type === 'Number') {
  2358. const data = SpreadJsObj.getSelectObject(posSheet);
  2359. if (data) {
  2360. const exprInfo = getExprInfo(col.field);
  2361. const value = exprInfo
  2362. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  2363. : data[col.field];
  2364. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2365. .attr('readOnly', readOnly || !data.formc || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  2366. } else {
  2367. $('#pos-expr').val('').attr('readOnly', true);
  2368. $('#pos-expr').removeAttr('data-row');
  2369. }
  2370. } else {
  2371. $('#pos-expr').val('').attr('readOnly', true);
  2372. $('#pos-expr').removeAttr('data-row');
  2373. }
  2374. },
  2375. /**
  2376. * 加载计量单元 根据当前台账选择节点
  2377. */
  2378. loadCurPosData: function () {
  2379. const node = SpreadJsObj.getSelectObject(billsSheet);
  2380. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  2381. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  2382. if (node) {
  2383. const posData = pos.getLedgerPos(node.id) || [];
  2384. console.log(posData);
  2385. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  2386. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  2387. } else {
  2388. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  2389. posSheet.zh_setting.readOnly = true;
  2390. }
  2391. SpreadJsObj.massOperationSheet(posSheet, function () {
  2392. if (posSheet.zh_setting) {
  2393. posSheet.zh_setting.cols.forEach(function (col, i) {
  2394. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  2395. if (i !== 0 && col.field !== 'camount' && col.field !== 'is_valuation') {
  2396. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  2397. } else {
  2398. let lock = false;
  2399. if (!posSheet.zh_data[iRow]) {
  2400. lock = true;
  2401. }
  2402. if (col.field === 'camount' && posCol.readOnly.isSettle(posSheet.zh_data[iRow])) {
  2403. lock = true;
  2404. }
  2405. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  2406. }
  2407. }
  2408. });
  2409. }
  2410. });
  2411. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  2412. posSpreadObj.loadExprToInput();
  2413. posSpreadObj.refreshOperationValid(posSheet);
  2414. },
  2415. baseOpr: function (sheet, type) {
  2416. const data = {
  2417. postType: 'pos',
  2418. posPostType: type === 'delete' ? type : 'update',
  2419. postData: [],
  2420. };
  2421. const selection = sheet.getSelections();
  2422. const row = selection[0].row, count = selection[0].rowCount;
  2423. const first = sheet.zh_data[row];
  2424. if (type === 'delete') {
  2425. for (let iRow = 0; iRow < count; iRow++) {
  2426. const posData = sheet.zh_data[iRow + row];
  2427. if (posData) {
  2428. if (posData.used) {
  2429. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2430. return;
  2431. }
  2432. if (posData.settle_status) {
  2433. toastr.error('"' + posData.name + '"已结算,请勿删除');
  2434. return;
  2435. }
  2436. data.postData.push(sheet.zh_data[iRow + row].id);
  2437. }
  2438. }
  2439. } else if (type === 'up-move') {
  2440. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  2441. for (let iRow = 0; iRow < count; iRow++) {
  2442. const posData = sheet.zh_data[iRow + row];
  2443. if (posData) {
  2444. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  2445. preUpdate.porder = posData.porder;
  2446. }
  2447. }
  2448. data.postData.push(preUpdate);
  2449. } else if (type === 'down-move') {
  2450. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  2451. for (let iRow = count - 1; iRow >= 0; iRow--) {
  2452. const posData = sheet.zh_data[iRow + row];
  2453. if (posData) {
  2454. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  2455. nextUpdate.porder = posData.porder;
  2456. }
  2457. }
  2458. data.postData.push(nextUpdate);
  2459. } else if (type === 'add') {
  2460. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2461. if (billsNode.settle_status === settleStatus.finish) {
  2462. toastr.warning('清单已结算,不可新增计量单元');
  2463. return;
  2464. }
  2465. }
  2466. if (data.postData.length > 0) {
  2467. postData(window.location.pathname + '/update', data, function (result) {
  2468. changeList = result.changeList;
  2469. if (type === 'delete') {
  2470. pos.removeDatas(result.pos);
  2471. sheet.deleteRows(row, count);
  2472. const loadResult = billsTree.loadPostData(result.ledger);
  2473. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2474. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2475. posSpreadObj.refreshOperationValid(posSheet);
  2476. } else {
  2477. pos.updateDatas(result.pos);
  2478. const sel = selection[0];
  2479. if (sel) {
  2480. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  2481. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  2482. }
  2483. posSpreadObj.loadCurPosData();
  2484. }
  2485. });
  2486. }
  2487. },
  2488. editStarting: function (e, info) {
  2489. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2490. const sel = info.sheet.getSelections();
  2491. if (!sel || !sel[0]) return;
  2492. const col = info.sheet.zh_setting.cols[sel[0].col];
  2493. const node = SpreadJsObj.getSelectObject(info.sheet);
  2494. const exprInfo = getExprInfo(col.field);
  2495. if (col.field === 'camount') {
  2496. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  2497. if (!cInfo) {
  2498. if (posCol.readOnly.isSettle(node)) {
  2499. toastr.error('清单数据未完善,无法编辑申请数量');
  2500. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2501. return
  2502. }
  2503. return
  2504. }
  2505. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  2506. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  2507. }
  2508. } else if (node && exprInfo) {
  2509. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2510. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2511. }
  2512. }
  2513. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  2514. info.cancel = true;
  2515. }
  2516. },
  2517. buttonClicked: function (e, info) {
  2518. if (info.sheet.zh_setting) {
  2519. const select = SpreadJsObj.getSelectObject(info.sheet);
  2520. const col = info.sheet.zh_setting.cols[info.col];
  2521. if (col.field === 'is_change') {
  2522. if (posCol.readOnly.isChangeList(select)) {
  2523. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  2524. return
  2525. }
  2526. if (info.sheet.isEditing()) {
  2527. info.sheet.endEdit(true);
  2528. }
  2529. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2530. // const valutaionCol = _.findIndex(info.sheet.zh_setting.cols, { field: 'is_valuation' });
  2531. if (is_change) {
  2532. makeGclGatherData();
  2533. const gclInfo = _.find(gclGatherData, function (item) {
  2534. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  2535. });
  2536. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  2537. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  2538. const data = {
  2539. lid: select.lid,
  2540. code: gclInfo.b_code,
  2541. name: gclInfo.name || '',
  2542. unit: gclInfo.unit || '',
  2543. unit_price: gclInfo.unit_price,
  2544. oamount: xmjInfo.quantity,
  2545. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2546. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2547. xmj_code: xmjInfo.code || '',
  2548. xmj_jldy: xmjInfo.jldy || '',
  2549. xmj_dwgc: xmjInfo.dwgc || '',
  2550. xmj_fbgc: xmjInfo.fbgc || '',
  2551. xmj_fxgc: xmjInfo.fxgc || '',
  2552. gcl_id: select.lid,
  2553. mx_id: select.id,
  2554. }
  2555. if (oldCInfo) {
  2556. data.detail = oldCInfo.detail;
  2557. data.camount = oldCInfo.camount;
  2558. data.camount_expr = oldCInfo.camount_expr;
  2559. data.spamount = oldCInfo.spamount;
  2560. data.is_valuation = oldCInfo.is_valuation;
  2561. data.delimit = oldCInfo.delimit;
  2562. }
  2563. // 更新至服务器
  2564. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  2565. changeList = result.changeList;
  2566. select.is_change = 1;
  2567. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  2568. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2569. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2570. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  2571. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2572. billsNode.is_change = 1;
  2573. billsTreeSpreadObj.reCalcCamount(billsNode);
  2574. const loadResult = { update: [billsNode] };
  2575. const refreshNode = billsTree.loadPostData(loadResult);
  2576. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2577. }
  2578. }, function () {
  2579. info.sheet.setValue(info.row, info.col, 0);
  2580. });
  2581. } else {
  2582. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  2583. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  2584. info.sheet.setValue(info.row, info.col, 1);
  2585. return
  2586. }
  2587. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2588. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  2589. toastr.warning('该计量单元已被使用,无法取消变更');
  2590. info.sheet.setValue(info.row, info.col, 1);
  2591. return
  2592. } else if (checkIsSettle(cInfo)) {
  2593. toastr.warning('该计量单元已结算,无法取消变更');
  2594. info.sheet.setValue(info.row, info.col, 1);
  2595. return
  2596. } else {
  2597. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  2598. changeList = result.changeList;
  2599. select.is_change = 0;
  2600. select.is_valuation = 0;
  2601. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2602. // info.sheet.setValue(info.row, valutaionCol, 0);
  2603. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2604. billsTreeSpreadObj.reCalcCamount(billsNode);
  2605. // 判断是否只剩一个,并同步去勾
  2606. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  2607. billsNode.is_change = 0;
  2608. }
  2609. const loadResult = { update: [billsNode] };
  2610. const refreshNode = billsTree.loadPostData(loadResult);
  2611. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2612. }, function () {
  2613. info.sheet.setValue(info.row, info.col, 1);
  2614. });
  2615. }
  2616. }
  2617. } else if (col.field === 'is_valuation') {
  2618. if (!posCol.getValue.isChange(select)) {
  2619. toastr.warning('请先勾选变更清单才能勾选计价');
  2620. info.sheet.setValue(info.row, info.col, !select || !select.is_valuation ? 0 : 1);
  2621. return;
  2622. }
  2623. if (info.sheet.isEditing()) {
  2624. info.sheet.endEdit(true);
  2625. }
  2626. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2627. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  2628. toastr.warning('该变更清单已被调用,无法更改计价');
  2629. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  2630. return;
  2631. }
  2632. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2633. // select.is_valuation = is_valuation;
  2634. cInfo.is_valuation = is_valuation;
  2635. delete cInfo.waitingLoading;
  2636. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  2637. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2638. info.sheet.setValue(info.row, info.col, is_valuation);
  2639. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2640. SpreadJsObj.reLoadRowData(billsSheet, billsTree.getNodeIndex(billsNode));
  2641. }, function () {
  2642. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2643. cInfo.is_valuation = select.is_valuation;
  2644. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2645. });
  2646. }
  2647. }
  2648. },
  2649. /**
  2650. * 编辑单元格响应事件
  2651. * @param {Object} e
  2652. * @param {Object} info
  2653. */
  2654. editEnded: function (e, info) {
  2655. if (!info.sheet.zh_setting) {
  2656. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2657. return;
  2658. }
  2659. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  2660. const node = posSpreadObj.billsNode;
  2661. const col = info.sheet.zh_setting.cols[info.col];
  2662. if (col.field === 'is_change' || col.field === 'is_valuation') {
  2663. return;
  2664. }
  2665. if (col.field === 'camount') {
  2666. if (!node) {
  2667. toastr.error('数据错误,请选择台账节点后再试');
  2668. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2669. return;
  2670. }
  2671. let cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  2672. if (!cInfo) {
  2673. if (posCol.readOnly.isSettle(posData)) {
  2674. toastr.error('清单数据未完善,无法编辑申请数量');
  2675. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2676. return
  2677. }
  2678. makeGclGatherData();
  2679. const gclInfo = _.find(gclGatherData, function (item) {
  2680. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.lid, mx_id: posData.id });
  2681. });
  2682. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.id });
  2683. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.lid, mx_id: posData.id });
  2684. const data = {
  2685. lid: posData.lid,
  2686. code: gclInfo.b_code,
  2687. name: gclInfo.name || '',
  2688. unit: gclInfo.unit || '',
  2689. unit_price: gclInfo.unit_price,
  2690. oamount: xmjInfo.quantity,
  2691. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2692. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2693. xmj_code: xmjInfo.code || '',
  2694. xmj_jldy: xmjInfo.jldy || '',
  2695. xmj_dwgc: xmjInfo.dwgc || '',
  2696. xmj_fbgc: xmjInfo.fbgc || '',
  2697. xmj_fxgc: xmjInfo.fxgc || '',
  2698. gcl_id: posData.lid,
  2699. mx_id: posData.id,
  2700. }
  2701. if (oldCInfo) {
  2702. data.detail = oldCInfo.detail;
  2703. data.camount = oldCInfo.camount;
  2704. data.camount_expr = oldCInfo.camount_expr;
  2705. data.spamount = oldCInfo.spamount;
  2706. data.is_valuation = oldCInfo.is_valuation;
  2707. data.delimit = oldCInfo.delimit;
  2708. }
  2709. cInfo = data;
  2710. // toastr.error('未勾选变更清单,无法编辑申请数量');
  2711. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2712. // return;
  2713. }
  2714. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  2715. const orgValue = validText && validText !== ''
  2716. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  2717. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  2718. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2719. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2720. return;
  2721. }
  2722. const exprQuantity = {
  2723. expr: '',
  2724. quantity: 0,
  2725. };
  2726. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  2727. if (!valid) {
  2728. toastr.error(msg);
  2729. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2730. return;
  2731. }
  2732. if (isNaN(exprQuantity.quantity)) {
  2733. toastr.error('不能输入其它非数字类型字符');
  2734. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2735. return;
  2736. }
  2737. validText = parseFloat(exprQuantity.quantity);
  2738. if (cInfo.id) {
  2739. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2740. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  2741. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2742. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2743. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2744. return;
  2745. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2746. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2747. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2748. return;
  2749. }
  2750. }
  2751. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2752. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2753. cInfo.camount_expr = exprQuantity.expr;
  2754. delete cInfo.waitingLoading;
  2755. if (cInfo.id) {
  2756. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type: 'update', updateData: cInfo }, function (result) {
  2757. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2758. const billsNode = node;
  2759. billsTreeSpreadObj.reCalcCamount(billsNode);
  2760. const loadResult = {update: [billsNode]};
  2761. const refreshNode = billsTree.loadPostData(loadResult);
  2762. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2763. }, function () {
  2764. cInfo[col.field] = orgValue;
  2765. cInfo.spamount = orgValue;
  2766. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2767. });
  2768. } else {
  2769. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  2770. changeList = result.changeList;
  2771. posData.is_change = 1;
  2772. posData.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  2773. posData.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  2774. posData.ca_tp = cInfo.camount !== undefined ? ZhCalc.mul(cInfo.camount, cInfo.unit_price, decimal.tp) : null;
  2775. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2776. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2777. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2778. if (_.findIndex(changeList, { gcl_id: posData.lid }) !== -1) {
  2779. billsNode.is_change = 1;
  2780. }
  2781. billsTreeSpreadObj.reCalcCamount(billsNode);
  2782. const loadResult = { update: [billsNode] };
  2783. const refreshNode = billsTree.loadPostData(loadResult);
  2784. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2785. }, function () {
  2786. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2787. });
  2788. }
  2789. return;
  2790. }
  2791. const orgText = posData ? posData[col.field] : null;
  2792. const newText = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  2793. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  2794. if (!node) {
  2795. toastr.error('数据错误,请选择台账节点后再试');
  2796. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2797. return;
  2798. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  2799. toastr.error('父节点不可插入计量单元');
  2800. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2801. return;
  2802. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  2803. toastr.error('项目节不可插入计量单元');
  2804. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2805. return;
  2806. }
  2807. const data = {postType: 'pos'};
  2808. if (col.field === 'name') {
  2809. if (newText === '' && posData) {
  2810. toastr.error('部位名称不可为空', 'error');
  2811. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2812. return;
  2813. } else if (!posData) {
  2814. if (newText && newText !== '') {
  2815. data.posPostType = 'add';
  2816. const sortData = info.sheet.zh_data;
  2817. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2818. data.postData = { name: newText, lid: node.id, porder: order};
  2819. if (node.settle_status === settleStatus.finish) {
  2820. toastr.error('已结算清单不可插入计量单元');
  2821. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2822. return;
  2823. }
  2824. } else {
  2825. return;
  2826. }
  2827. } else {
  2828. data.posPostType = 'update';
  2829. data.postData = {id: posData.id, name: newText};
  2830. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  2831. toastr.error('计量单元已结算,不可修改');
  2832. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2833. return;
  2834. }
  2835. }
  2836. } else if (!posData) {
  2837. toastr.warning('新增计量单元请先输入名称');
  2838. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2839. return;
  2840. } else {
  2841. data.posPostType = 'update';
  2842. data.postData = {id: posData.id};
  2843. if (col.type === 'Number') {
  2844. const exprInfo = getExprInfo(col.field);
  2845. const num = _.toNumber(newText);
  2846. if (_.isFinite(num)) {
  2847. data.postData[col.field] = num;
  2848. if (exprInfo) {
  2849. data.postData[exprInfo.expr] = '';
  2850. }
  2851. } else {
  2852. try {
  2853. data.postData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2854. if (exprInfo) {
  2855. data.postData[exprInfo.expr] = newText;
  2856. }
  2857. } catch(err) {
  2858. toastr.error('输入的表达式非法');
  2859. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2860. return;
  2861. }
  2862. }
  2863. } else if (col.field.indexOf('_expr') > 0) {
  2864. const exprInfo = getExprInfo(col.field, true);
  2865. if (!exprInfo) return;
  2866. if (newText) {
  2867. try {
  2868. data.postData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2869. data.postData[exprInfo.expr] = newText;
  2870. } catch(err) {
  2871. toastr.error('输入的表达式非法');
  2872. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2873. return;
  2874. }
  2875. } else {
  2876. data.postData[exprInfo.qty] = 0;
  2877. data.postData[exprInfo.expr] = '';
  2878. }
  2879. } else {
  2880. data.postData[col.field] = newText;
  2881. }
  2882. }
  2883. postData(window.location.pathname + '/update', data, function (result) {
  2884. changeList = result.changeList;
  2885. const updateRst = pos.updateDatas(result.pos);
  2886. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2887. if (updateRst.create.length > 0) {
  2888. posSpreadObj.loadCurPosData();
  2889. } else {
  2890. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2891. }
  2892. const loadResult = billsTree.loadPostData(result.ledger);
  2893. // 判断是否只剩一个,并同步去勾
  2894. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2895. // billsNode.is_change = ? 1 : 0;
  2896. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  2897. billsNode.is_change = 1;
  2898. } else {
  2899. billsNode.is_change = 0;
  2900. billsNode.is_valuation = 0;
  2901. billsNode.camount = null;
  2902. billsNode.ca_tp = null;
  2903. }
  2904. if (loadResult.update) {
  2905. const r = _.find(loadResult.update, { id: billsNode.id });
  2906. r.is_change = billsNode.is_change;
  2907. } else {
  2908. loadResult.update = [billsNode];
  2909. }
  2910. const refreshNode = billsTree.loadPostData(loadResult);
  2911. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2912. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2913. }, function () {
  2914. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2915. });
  2916. },
  2917. /**
  2918. * 删除按钮响应事件
  2919. * @param sheet
  2920. */
  2921. deletePress: function (sheet) {
  2922. if (!sheet.zh_setting) return;
  2923. const sortData = sheet.zh_data;
  2924. const datas = [], posSelects = [], camountDatas = [];
  2925. const sel = sheet.getSelections()[0];
  2926. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2927. let bDel = false;
  2928. const node = sortData[iRow];
  2929. if (node) {
  2930. const data = {id: node.id};
  2931. const cData = {};
  2932. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2933. const colSetting = sheet.zh_setting.cols[iCol];
  2934. if (colSetting.field === 'name') {
  2935. toastr.error('部位名称不能为空');
  2936. return;
  2937. }
  2938. const style = sheet.getStyle(iRow, iCol);
  2939. if (!style.locked) {
  2940. const colSetting = sheet.zh_setting.cols[iCol];
  2941. if (colSetting.field === 'camount') {
  2942. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  2943. if (!cInfo) continue;
  2944. cData.id = cInfo.id;
  2945. cData.camount = null;
  2946. cData.camount_expr = '';
  2947. cData.spamount = null;
  2948. } else if (colSetting.field.indexOf('_expr') > 0) {
  2949. const exprInfo = getExprInfo(colSetting.field, true);
  2950. if (!exprInfo) continue;
  2951. data[exprInfo.expr] = '';
  2952. data[exprInfo.qty] = 0;
  2953. } else {
  2954. data[colSetting.field] = null;
  2955. const exprInfo = getExprInfo(colSetting.field);
  2956. if (exprInfo) data[exprInfo.expr] = '';
  2957. }
  2958. bDel = true;
  2959. }
  2960. }
  2961. if (bDel) {
  2962. datas.push(data);
  2963. if (cData.id) camountDatas.push(cData);
  2964. posSelects.push(node);
  2965. }
  2966. }
  2967. }
  2968. if (camountDatas.length > 0) {
  2969. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  2970. changeList = result;
  2971. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2972. billsTreeSpreadObj.reCalcCamount(billsNode);
  2973. const loadResult = { update: [billsNode] };
  2974. const refreshNode = billsTree.loadPostData(loadResult);
  2975. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2976. posSpreadObj.loadCurPosData();
  2977. }, function () {
  2978. posSpreadObj.loadCurPosData();
  2979. });
  2980. return;
  2981. }
  2982. if (datas.length > 0) {
  2983. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  2984. changeList = result.changeList;
  2985. pos.updateDatas(result.pos);
  2986. posSpreadObj.loadCurPosData();
  2987. const loadResult = billsTree.loadPostData(result.ledger);
  2988. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2989. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2990. }, function () {
  2991. posSpreadObj.loadCurPosData();
  2992. });
  2993. }
  2994. },
  2995. /**
  2996. * 删除 计量单元
  2997. * @param sheet
  2998. */
  2999. deletePos: function (sheet) {
  3000. const selection = sheet.getSelections();
  3001. const data = {
  3002. postType: 'pos',
  3003. posPostType: 'delete',
  3004. postData: [],
  3005. };
  3006. const row = selection[0].row, count = selection[0].rowCount;
  3007. const sortData = sheet.zh_data;
  3008. for (let iRow = 0; iRow < count; iRow++) {
  3009. const posData = sortData[iRow + row];
  3010. if (posData) {
  3011. if (posData.used) {
  3012. toastr.error('"' + posData.name + '"已计量,请勿删除');
  3013. return;
  3014. }
  3015. if (posData.settle_status === settleStatus.finish) {
  3016. toastr.error(`"${posData.name}"已计量,请勿删除`);
  3017. return;
  3018. }
  3019. data.postData.push(sortData[iRow + row].id);
  3020. }
  3021. }
  3022. if (data.postData.length > 0) {
  3023. postData(window.location.pathname + '/update', data, function (result) {
  3024. changeList = result.changeList;
  3025. pos.removeDatas(result.pos);
  3026. sheet.deleteRows(row, count);
  3027. const loadResult = billsTree.loadPostData(result.ledger);
  3028. // 判断是否只剩一个,并同步去勾
  3029. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3030. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3031. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  3032. billsNode.is_change = 1;
  3033. } else {
  3034. billsNode.is_change = 0;
  3035. billsNode.is_valuation = 0;
  3036. billsNode.camount = null;
  3037. billsNode.ca_tp = null;
  3038. }
  3039. if (loadResult.update) {
  3040. const r = _.find(loadResult.update, { id: billsNode.id });
  3041. r.is_change = billsNode.is_change;
  3042. } else {
  3043. loadResult.update = [billsNode];
  3044. }
  3045. billsTreeSpreadObj.reCalcCamount(billsNode);
  3046. const refreshNode = billsTree.loadPostData(loadResult);
  3047. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3048. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3049. });
  3050. }
  3051. },
  3052. /**
  3053. * 粘贴单元格响应事件
  3054. * @param e
  3055. * @param info
  3056. */
  3057. clipboardPasted: function (e, info) {
  3058. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  3059. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  3060. }
  3061. const node = SpreadJsObj.getSelectObject(billsSheet);
  3062. if (node.code && (node.code !== '')) {
  3063. toastr.error('项目节不可含有节点明细');
  3064. posSpreadObj.loadCurPosData();
  3065. return;
  3066. }
  3067. if (node.children && (node.children.length > 0)) {
  3068. toastr.error('仅节点子项可以含有计量单元');
  3069. posSpreadObj.loadCurPosData();
  3070. return;
  3071. }
  3072. if (node.settle_status === settleStatus.finish) {
  3073. toastr.error('清单已结算,请勿修改计量单元数据');
  3074. posSpread.loadCurPosData();
  3075. return;
  3076. }
  3077. if (!info.sheet.zh_setting) {
  3078. posSpreadObj.loadCurPosData();
  3079. return;
  3080. }
  3081. const data = [];
  3082. const camountData = [], insertCamountData = [];
  3083. const sortData = info.sheet.zh_data || [];
  3084. const hint = {
  3085. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  3086. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  3087. };
  3088. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  3089. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  3090. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  3091. toastr.warning('新增计量单元请先输入名称');
  3092. posSpreadObj.loadCurPosData();
  3093. return;
  3094. }
  3095. }
  3096. let bHint = false;
  3097. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3098. makeGclGatherData();
  3099. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3100. let bPaste = true;
  3101. const curRow = info.cellRange.row + iRow;
  3102. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  3103. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  3104. const curCol = info.cellRange.col + iCol;
  3105. const colSetting = info.sheet.zh_setting.cols[curCol];
  3106. if (!colSetting) continue;
  3107. posData[colSetting.field] = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  3108. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  3109. bPaste = false;
  3110. toastMessageUniq(hint.settle);
  3111. continue;
  3112. }
  3113. if (colSetting.field === 'camount') {
  3114. bPaste = true;
  3115. let validText = posData[colSetting.field];
  3116. let cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  3117. if (!cInfo) {
  3118. const gclInfo = _.find(gclGatherData, function (item) {
  3119. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.lid, mx_id: posData.id });
  3120. });
  3121. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.id });
  3122. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.lid, mx_id: posData.id });
  3123. const data = {
  3124. lid: posData.lid,
  3125. code: gclInfo.b_code,
  3126. name: gclInfo.name || '',
  3127. unit: gclInfo.unit || '',
  3128. unit_price: gclInfo.unit_price,
  3129. oamount: xmjInfo.quantity,
  3130. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  3131. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  3132. xmj_code: xmjInfo.code || '',
  3133. xmj_jldy: xmjInfo.jldy || '',
  3134. xmj_dwgc: xmjInfo.dwgc || '',
  3135. xmj_fbgc: xmjInfo.fbgc || '',
  3136. xmj_fxgc: xmjInfo.fxgc || '',
  3137. gcl_id: posData.lid,
  3138. mx_id: posData.id,
  3139. }
  3140. if (oldCInfo) {
  3141. data.detail = oldCInfo.detail;
  3142. data.camount = oldCInfo.camount;
  3143. data.camount_expr = oldCInfo.camount_expr;
  3144. data.spamount = oldCInfo.spamount;
  3145. data.is_valuation = oldCInfo.is_valuation;
  3146. data.delimit = oldCInfo.delimit;
  3147. }
  3148. cInfo = data;
  3149. // bPaste = false;
  3150. // continue;
  3151. }
  3152. const exprQuantity = {
  3153. expr: '',
  3154. quantity: 0,
  3155. };
  3156. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  3157. if (!valid) {
  3158. toastMessageUniq(hint.expr);
  3159. bPaste = false;
  3160. continue;
  3161. }
  3162. if (isNaN(exprQuantity.quantity)) {
  3163. toastMessageUniq(hint.expr);
  3164. bPaste = false;
  3165. continue;
  3166. }
  3167. validText = parseFloat(exprQuantity.quantity);
  3168. if (cInfo.id) {
  3169. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3170. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  3171. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3172. toastr.error(curRow ? '计量单元第' + (curRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3173. bPaste = false;
  3174. continue;
  3175. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3176. toastr.error(curRow ? '计量单元第' + (curRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3177. bPaste = false;
  3178. continue;
  3179. }
  3180. }
  3181. if (bPaste) {
  3182. if (cInfo.id) {
  3183. 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 });
  3184. } else {
  3185. cInfo.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  3186. cInfo.camount_expr = exprQuantity.expr;
  3187. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  3188. insertCamountData.push(cInfo);
  3189. }
  3190. } else {
  3191. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  3192. }
  3193. continue;
  3194. }
  3195. if (colSetting.type === 'Number') {
  3196. const num = _.toNumber(posData[colSetting.field]);
  3197. if (num) {
  3198. posData[colSetting.field] = num;
  3199. } else {
  3200. try {
  3201. posData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(posData[colSetting.field]));
  3202. const exprInfo = getExprInfo(colSetting.field);
  3203. if (exprInfo) {
  3204. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  3205. }
  3206. } catch (err) {
  3207. if (!bHint) {
  3208. toastr.warning('粘贴了非法表达式,已过滤');
  3209. bHint = true;
  3210. }
  3211. bPaste = false;
  3212. }
  3213. }
  3214. } else if (colSetting.field.indexOf('_expr') > 0) {
  3215. try {
  3216. const exprInfo = getExprInfo(colSetting.field, true);
  3217. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  3218. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  3219. posData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(posData[exprInfo.expr]));
  3220. }
  3221. bPaste = true;
  3222. } catch (err) {
  3223. toastMessageUniq(hint.expr);
  3224. }
  3225. } else {
  3226. bPaste = true;
  3227. }
  3228. }
  3229. if (bPaste) {
  3230. data.push(posData);
  3231. }
  3232. }
  3233. if (camountData.length > 0 || insertCamountData.length > 0) {
  3234. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: insertCamountData, updateData: camountData }, function (result) {
  3235. changeList = result;
  3236. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3237. billsTreeSpreadObj.reCalcCamount(billsNode);
  3238. const loadResult = { update: [billsNode] };
  3239. const refreshNode = billsTree.loadPostData(loadResult);
  3240. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3241. posSpreadObj.loadCurPosData();
  3242. }, function () {
  3243. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3244. return;
  3245. });
  3246. return;
  3247. }
  3248. if (data.length === 0) {
  3249. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3250. return;
  3251. }
  3252. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  3253. changeList = result.changeList;
  3254. pos.updateDatas(result.pos);
  3255. posSpreadObj.loadCurPosData();
  3256. const loadResult = result.ledger;
  3257. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3258. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3259. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3260. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  3261. billsNode.is_change = 1;
  3262. } else {
  3263. billsNode.is_change = 0;
  3264. billsNode.is_valuation = 0;
  3265. billsNode.camount = null;
  3266. billsNode.ca_tp = null;
  3267. }
  3268. if (loadResult.update && loadResult.update.length > 0) {
  3269. const r = _.find(loadResult.update, { id: billsNode.id });
  3270. console.log(r, billsNode, loadResult.update);
  3271. r.is_change = billsNode.is_change;
  3272. } else {
  3273. loadResult.update = [billsNode];
  3274. }
  3275. billsTreeSpreadObj.reCalcCamount(billsNode);
  3276. const refreshNode = billsTree.loadPostData(loadResult);
  3277. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3278. posSpreadObj.loadCurPosData();
  3279. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3280. }, function () {
  3281. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3282. });
  3283. },
  3284. selectionChanged: function (e, info) {
  3285. posSpreadObj.loadExprToInput();
  3286. posSpreadObj.refreshOperationValid(posSheet);
  3287. },
  3288. addPegs: function (pegs) {
  3289. if (!pegs || pegs.length <= 0) return;
  3290. const node = SpreadJsObj.getSelectObject(billsSheet);
  3291. if (!node) return;
  3292. const sheet = posSpread.getActiveSheet();
  3293. const sortData = sheet.zh_data || [];
  3294. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3295. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  3296. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  3297. changeList = result.changeList;
  3298. pos.updateDatas(result.pos);
  3299. posSpreadObj.loadCurPosData();
  3300. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3301. });
  3302. }
  3303. };
  3304. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  3305. if (!readOnly) {
  3306. $('a[name="pos-opr"]').click(function () {
  3307. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  3308. });
  3309. $('#pos-expr').bind('change onblur', function () {
  3310. if (this.readOnly) return;
  3311. const expr = $(this);
  3312. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  3313. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  3314. if (!select) return;
  3315. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3316. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  3317. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  3318. if (field === 'camount') {
  3319. let cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  3320. if (!cInfo) {
  3321. if (posCol.readOnly.isSettle(select)) {
  3322. toastr.error('清单数据未完善,无法编辑申请数量');
  3323. SpreadJsObj.reLoadRowData(posSheet, row);
  3324. return
  3325. }
  3326. makeGclGatherData();
  3327. const gclInfo = _.find(gclGatherData, function (item) {
  3328. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  3329. });
  3330. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  3331. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  3332. const data = {
  3333. lid: select.lid,
  3334. code: gclInfo.b_code,
  3335. name: gclInfo.name || '',
  3336. unit: gclInfo.unit || '',
  3337. unit_price: gclInfo.unit_price,
  3338. oamount: xmjInfo.quantity,
  3339. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  3340. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  3341. xmj_code: xmjInfo.code || '',
  3342. xmj_jldy: xmjInfo.jldy || '',
  3343. xmj_dwgc: xmjInfo.dwgc || '',
  3344. xmj_fbgc: xmjInfo.fbgc || '',
  3345. xmj_fxgc: xmjInfo.fxgc || '',
  3346. gcl_id: select.lid,
  3347. mx_id: select.id,
  3348. }
  3349. if (oldCInfo) {
  3350. data.detail = oldCInfo.detail;
  3351. data.camount = oldCInfo.camount;
  3352. data.camount_expr = oldCInfo.camount_expr;
  3353. data.spamount = oldCInfo.spamount;
  3354. data.is_valuation = oldCInfo.is_valuation;
  3355. data.delimit = oldCInfo.delimit;
  3356. }
  3357. cInfo = data;
  3358. // toastr.error('未勾选变更清单,无法编辑申请数量');
  3359. // return;
  3360. }
  3361. const exprQuantity = {
  3362. expr: '',
  3363. quantity: 0,
  3364. };
  3365. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  3366. if (!valid) {
  3367. toastr.error(msg);
  3368. return;
  3369. }
  3370. if (isNaN(exprQuantity.quantity)) {
  3371. toastr.error('不能输入其它非数字类型字符');
  3372. return;
  3373. }
  3374. const camount = parseFloat(exprQuantity.quantity);
  3375. if (cInfo.id) {
  3376. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3377. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  3378. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3379. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3380. return;
  3381. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3382. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3383. return;
  3384. }
  3385. }
  3386. cInfo.camount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3387. cInfo.spamount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3388. cInfo.camount_expr = exprQuantity.expr;
  3389. delete cInfo.waitingLoading;
  3390. if (cInfo.id) {
  3391. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  3392. SpreadJsObj.reLoadRowData(posSheet, row);
  3393. billsTreeSpreadObj.reCalcCamount(billsNode);
  3394. const loadResult = { update: [billsNode] };
  3395. const refreshNode = billsTree.loadPostData(loadResult);
  3396. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3397. posSpreadObj.loadExprToInput(posSheet);
  3398. }, function () {
  3399. cInfo.camount = orgValue;
  3400. cInfo.spamount = orgValue;
  3401. SpreadJsObj.reLoadRowData(posSheet, row);
  3402. });
  3403. } else {
  3404. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  3405. changeList = result.changeList;
  3406. select.is_change = 1;
  3407. select.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  3408. select.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  3409. select.ca_tp = cInfo.camount !== undefined ? ZhCalc.mul(cInfo.camount, cInfo.unit_price, decimal.tp) : null;
  3410. SpreadJsObj.reLoadRowData(posSheet, row);
  3411. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3412. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  3413. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  3414. billsNode.is_change = 1;
  3415. }
  3416. billsTreeSpreadObj.reCalcCamount(billsNode);
  3417. const loadResult = { update: [billsNode] };
  3418. const refreshNode = billsTree.loadPostData(loadResult);
  3419. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3420. }, function () {
  3421. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3422. });
  3423. }
  3424. return;
  3425. }
  3426. const data = {id: select.id};
  3427. const exprInfo = getExprInfo(field);
  3428. if (newValue !== '') {
  3429. const num = _.toNumber(newValue);
  3430. if (num) {
  3431. data[field] = num;
  3432. if (exprInfo) data[exprInfo.expr] = '';
  3433. } else {
  3434. try {
  3435. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  3436. if (exprInfo) data[exprInfo.expr] = newValue;
  3437. } catch (err) {
  3438. toastr.error('输入的表达式非法');
  3439. return;
  3440. }
  3441. }
  3442. } else {
  3443. data[field] = null;
  3444. if (exprInfo) data[exprInfo.expr] = '';
  3445. }
  3446. // 更新至服务器
  3447. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  3448. changeList = result.changeList;
  3449. const updateRst = pos.updateDatas(result.pos);
  3450. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  3451. SpreadJsObj.reLoadRowData(posSheet, row);
  3452. const loadResult = billsTree.loadPostData(result.ledger);
  3453. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3454. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3455. });
  3456. });
  3457. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  3458. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  3459. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  3460. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  3461. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  3462. $.contextMenu({
  3463. selector: '#pos-spread',
  3464. build: function ($trigger, e) {
  3465. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  3466. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3467. },
  3468. items: {
  3469. 'delete': {
  3470. name: '删除',
  3471. icon: 'fa-remove',
  3472. disabled: function (key, opt) {
  3473. if (posSheet.zh_data) {
  3474. const selection = posSheet.getSelections();
  3475. const sel = selection ? selection[0] : sheet.getSelections()[0];
  3476. const row = sel ? sel.row : -1;
  3477. const rowCount = sel.rowCount;
  3478. let settleFinish = false;
  3479. for (let i = row; i < row + rowCount; i++) {
  3480. if (!posSheet.zh_data[i]) continue;
  3481. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  3482. }
  3483. 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;
  3484. } else {
  3485. return true;
  3486. }
  3487. },
  3488. callback: function (key, opt) {
  3489. posSpreadObj.deletePos(posSheet);
  3490. }
  3491. },
  3492. }
  3493. });
  3494. }
  3495. // 加载清单&计量单元数据
  3496. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  3497. let gclGatherData;
  3498. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  3499. for (const b of result.bills) {
  3500. if (!(b.is_leaf && b.b_code)) {
  3501. b.is_change = 0;
  3502. b.is_valutaion = 0;
  3503. } else {
  3504. const cInfo = _.find(changeList, { gcl_id: b.id });
  3505. b.is_change = cInfo ? 1 : 0;
  3506. b.is_valuation = cInfo ? cInfo.is_valuation : 0;
  3507. b.camount = cInfo ? cInfo.camount : 0;
  3508. }
  3509. }
  3510. billsTree.loadDatas(result.bills);
  3511. pos.loadDatas(result.pos);
  3512. treeCalc.calculateAll(billsTree);
  3513. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  3514. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  3515. checkShowLast(result.bills.length);
  3516. posSpreadObj.loadCurPosData();
  3517. SpreadJsObj.resetTopAndSelect(posSheet);
  3518. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3519. billsTreeSpreadObj.loadExprToInput(billsSheet);
  3520. checkList.loadHisCheckData();
  3521. console.log(billsTree);
  3522. }, null);
  3523. $.divResizer({
  3524. select: '#revise-resize',
  3525. callback: function () {
  3526. billsSpread.refresh();
  3527. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  3528. $(".sp-wrap").height(bcontent-30);
  3529. posSpread.refresh();
  3530. }
  3531. });
  3532. function makeGclGatherData() {
  3533. gclGatherModel.loadLedgerData(billsTree.datas);
  3534. gclGatherModel.loadPosData(pos.datas);
  3535. gclGatherData = gclGatherModel.gatherGclData();
  3536. gclGatherData = _.filter(gclGatherData, function (item) {
  3537. return item.leafXmjs && item.leafXmjs.length !== 0;
  3538. });
  3539. gclGatherData = gclGatherData.sort(sortByCode);
  3540. }
  3541. class DealBills {
  3542. constructor (selector, spreadSetting) {
  3543. const self = this;
  3544. this.loaded = false;
  3545. this.obj = $(selector)[0];
  3546. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3547. this.spreadSetting = spreadSetting;
  3548. this.spread = SpreadJsObj.createNewSpread(this.obj);
  3549. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3550. if (!readOnly) {
  3551. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3552. const dealSheet = info.sheet;
  3553. const mainSheet = billsSheet;
  3554. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3555. if (!dealBills) { return; }
  3556. const mainTree = mainSheet.zh_tree;
  3557. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3558. if (!mainNode || !mainTree) { return; }
  3559. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3560. toastr.warning('非最底层项目下,不应添加节点');
  3561. return;
  3562. }
  3563. if (mainNode.settle_status === settleStatus.finish) {
  3564. toastr.warning('已结算节点下,不应添加签约清单');
  3565. return;
  3566. }
  3567. postData(window.location.pathname + '/update', {
  3568. postType: 'add-deal',
  3569. postData: {
  3570. id: mainNode.ledger_id,
  3571. type: mainNode.code ? 'child' : 'next',
  3572. dealBills: {
  3573. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3574. unit_price: dealBills.unit_price,
  3575. }
  3576. },
  3577. }, function (result) {
  3578. changeList = result.changeList;
  3579. const refreshData = mainTree.loadPostData(result);
  3580. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3581. const sel = mainSheet.getSelections()[0];
  3582. if (sel && refreshData.create[0]) {
  3583. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3584. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3585. }
  3586. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3587. billsSpread.focus();
  3588. posSpreadObj.loadCurPosData();
  3589. });
  3590. });
  3591. }
  3592. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3593. }
  3594. loadData (callback) {
  3595. if (this.loaded) {
  3596. if (callback) callback();
  3597. return;
  3598. }
  3599. const self = this;
  3600. postData(this.url+'/get-data', {}, function (data) {
  3601. self.data = data;
  3602. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3603. self.loaded = true;
  3604. if (callback) callback();
  3605. });
  3606. }
  3607. calculateData () {
  3608. if (this.data) {
  3609. for (const d of this.data) {
  3610. d.total_price = _.multiply(d.quantity, d.unit_price);
  3611. }
  3612. }
  3613. }
  3614. }
  3615. class BatchInsertBillsPosObj {
  3616. constructor (obj) {
  3617. const self = this;
  3618. this.obj = obj;
  3619. this.billsCount = 6;
  3620. this.posCount = 1000;
  3621. this.filter = getLocalCache('zh-calc-batch-filter');
  3622. if (!this.filter) {
  3623. this.filter = '1';
  3624. }
  3625. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  3626. // 初始化 清单编号窗口 参数
  3627. this.qdSpreadSetting = {
  3628. cols: [
  3629. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3630. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  3631. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3632. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3633. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  3634. ],
  3635. emptyRows: this.billsCount,
  3636. headRows: 1,
  3637. headRowHeight: [32],
  3638. headerFont: '12px 微软雅黑',
  3639. font: '12px 微软雅黑',
  3640. };
  3641. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  3642. // 初始化 部位数量复核表 参数
  3643. this.posSpreadSetting = {
  3644. cols: [
  3645. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  3646. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  3647. ],
  3648. emptyRows: this.posCount,
  3649. headRows: 1,
  3650. headRowHeight: [32],
  3651. headerFont: '12px 微软雅黑',
  3652. font: '12px 微软雅黑',
  3653. };
  3654. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  3655. this.posSpreadSetting.cols.push(
  3656. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  3657. )
  3658. }
  3659. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  3660. // 初始化 签约节点 参数
  3661. this.dealSpreadSetting = {
  3662. cols: [
  3663. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  3664. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  3665. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3666. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  3667. ],
  3668. emptyRows: 0,
  3669. headRows: 1,
  3670. headRowHeight: [32],
  3671. headerFont: '12px 微软雅黑',
  3672. font: '12px 微软雅黑',
  3673. };
  3674. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  3675. // 初始化 清单编号、部位数量复核表 表格
  3676. this.initView();
  3677. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  3678. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  3679. // 拉取签约节点数据
  3680. dealBills.loadData(() => {
  3681. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3682. });
  3683. // 双击签约节点,自动添加到清单编号窗口
  3684. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  3685. const deal = info.sheet.zh_data[info.row];
  3686. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  3687. const sel = qdSheet.getSelections()[0];
  3688. qdSheet.getCell(sel.row, 0).value(deal.code);
  3689. qdSheet.getCell(sel.row, 1).value(deal.name);
  3690. qdSheet.getCell(sel.row, 2).value(deal.unit);
  3691. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  3692. if (sel.row + 1 === qdSheet.getRowCount()) {
  3693. const count = sel.row + 2;
  3694. qdSheet.setRowCount(count);
  3695. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  3696. const colCount = posSheet.getColumnCount() + 1;
  3697. posSheet.setColumnCount(colCount);
  3698. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  3699. }
  3700. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  3701. qdSheet.getParent().focus();
  3702. });
  3703. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3704. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  3705. const count = posSheet.getColumnCount() - 2;
  3706. if (billsCount > count) {
  3707. posSheet.setColumnCount(billsCount + 2);
  3708. for (let i = count + 1; i <= billsCount; i++) {
  3709. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3710. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3711. }
  3712. }
  3713. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  3714. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3715. if (dealBills && dealBills.length > 0) {
  3716. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3717. const curRow = iRow + info.cellRange.row;
  3718. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  3719. if (bills) {
  3720. info.sheet.getCell(curRow, 1).value(bills.name);
  3721. info.sheet.getCell(curRow, 2).value(bills.unit);
  3722. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  3723. }
  3724. }
  3725. }
  3726. }
  3727. });
  3728. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3729. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  3730. const count = qdSheet.getRowCount();
  3731. if (billsCount > count) {
  3732. qdSheet.setRowCount(billsCount);
  3733. for (let i = count + 1; i <= billsCount; i++) {
  3734. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3735. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3736. }
  3737. }
  3738. });
  3739. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  3740. if (info.col === 0) {
  3741. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3742. if (dealBills && dealBills.length > 0) {
  3743. const bills = _.find(dealBills, {code: info.editingText});
  3744. if (bills) {
  3745. info.sheet.getCell(info.row, 1).value(bills.name);
  3746. info.sheet.getCell(info.row, 2).value(bills.unit);
  3747. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  3748. }
  3749. }
  3750. }
  3751. });
  3752. this.obj.bind('shown.bs.modal', function () {
  3753. self.qdSpread.refresh();
  3754. self.posSpread.refresh();
  3755. self.dealSpread.refresh();
  3756. });
  3757. $('#batch-ok').click(function () {
  3758. const selection = billsSheet.getSelections();
  3759. const sel = selection[0];
  3760. const row = selection[0].row;
  3761. const select = billsTree.nodes[row];
  3762. if (select) {
  3763. const insertData = {};
  3764. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3765. insertData.id = select[billsTree.setting.id];
  3766. insertData.batchData = self.getBatchData();
  3767. if (insertData.batchData.length > 0) {
  3768. postData(window.location.pathname + '/update', {
  3769. postType: 'batch-insert',
  3770. postData: insertData
  3771. }, function (data) {
  3772. changeList = result.changeList;
  3773. pos.updateDatas(data.pos);
  3774. const result = billsTree.loadPostData(data.ledger);
  3775. billsTreeSpreadObj.refreshTree(billsSheet, result);
  3776. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3777. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  3778. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  3779. posSpreadObj.loadCurPosData();
  3780. self.obj.modal('hide');
  3781. }, null, true);
  3782. } else {
  3783. self.obj.modal('hide');
  3784. }
  3785. }
  3786. });
  3787. $('input[name=batch-filter]').change(function () {
  3788. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3789. });
  3790. $.contextMenu({
  3791. selector: '.batch-l-t',
  3792. build: function ($trigger, e) {
  3793. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  3794. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3795. },
  3796. items: {
  3797. 'create': {
  3798. name: '新增行',
  3799. icon: 'fa-sign-in',
  3800. callback: function (key, opt) {
  3801. const qdSheet = self.qdSpread.getActiveSheet();
  3802. const posSheet = self.posSpread.getActiveSheet();
  3803. qdSheet.addRows(qdSheet.getRowCount(), 1);
  3804. const index = qdSheet.getRowCount();
  3805. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  3806. posSheet.addColumns(posSheet.getColumnCount(), 1);
  3807. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  3808. },
  3809. },
  3810. 'delete': {
  3811. name: '删除行',
  3812. icon: 'fa-remove',
  3813. callback: function (key, opt) {
  3814. const qdSheet = self.qdSpread.getActiveSheet();
  3815. const posSheet = self.posSpread.getActiveSheet();
  3816. const sel = qdSheet.getSelections()[0];
  3817. qdSheet.deleteRows(sel.row, sel.rowCount);
  3818. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  3819. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  3820. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  3821. }
  3822. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  3823. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  3824. }
  3825. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  3826. },
  3827. },
  3828. }
  3829. });
  3830. }
  3831. // 初始化左侧表格
  3832. initView () {
  3833. // 初始化 清单编号
  3834. const qdSheet = this.qdSpread.getActiveSheet();
  3835. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3836. SpreadJsObj.refreshColumnAlign(qdSheet);
  3837. // 清理原有数据
  3838. SpreadJsObj.beginMassOperation(qdSheet);
  3839. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3840. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3841. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3842. }
  3843. qdSheet.setSelection(0, 0, 1 ,1);
  3844. SpreadJsObj.endMassOperation(qdSheet);
  3845. // 初始化 部位数量复核表
  3846. const posSheet = this.posSpread.getActiveSheet();
  3847. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3848. SpreadJsObj.refreshColumnAlign(posSheet);
  3849. // 清理原有数据
  3850. SpreadJsObj.beginMassOperation(posSheet);
  3851. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3852. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3853. posSheet.setSelection(0, 0, 1 ,1);
  3854. SpreadJsObj.endMassOperation(posSheet);
  3855. // 检查签约节点数据,以工具栏数据为准
  3856. if (dealBills) {
  3857. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3858. }
  3859. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3860. }
  3861. // 获取界面数据
  3862. getBatchData () {
  3863. const result = [];
  3864. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3865. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3866. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3867. const qd = {
  3868. b_code: qdSheet.getText(iRow, 0),
  3869. name: qdSheet.getText(iRow, 1),
  3870. unit: qdSheet.getText(iRow, 2),
  3871. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3872. pos: [],
  3873. };
  3874. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3875. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3876. if (value !== 0 && !isNaN(value)) {
  3877. qd.pos.push({
  3878. name: posSheet.getText(iPosRow, 0),
  3879. drawing_code: posSheet.getText(iPosRow, 1),
  3880. quantity: value, porder: qd.pos.length + 1,
  3881. });
  3882. }
  3883. }
  3884. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  3885. }
  3886. return result;
  3887. }
  3888. }
  3889. const dealBills = new DealBills('#deal-bills-spread', {
  3890. cols: [
  3891. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  3892. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3893. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3894. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  3895. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  3896. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  3897. ],
  3898. emptyRows: 0,
  3899. headRows: 1,
  3900. headRowHeight: [32],
  3901. headColWidth: [30],
  3902. defaultRowHeight: 21,
  3903. headerFont: '12px 微软雅黑',
  3904. font: '12px 微软雅黑',
  3905. selectedBackColor: '#fffacd',
  3906. });
  3907. class Jlzf {
  3908. constructor (selector, spreadSetting) {
  3909. const self = this;
  3910. this.loaded = false;
  3911. this.obj = $(selector);
  3912. const relaSelect = {
  3913. showLevel: `cb-${spreadSetting.stdType}-sl`,
  3914. searchText: `cb-${spreadSetting.stdType}-st`,
  3915. searchResult: `cb-${spreadSetting.stdType}-sr`,
  3916. searchPre: `cb-${spreadSetting.stdType}-sp`,
  3917. searchNext: `cb-${spreadSetting.stdType}-sn`,
  3918. searchClose: `cb-${spreadSetting.stdType}-sc`,
  3919. };
  3920. this.obj.html(
  3921. '<div class="sjs-bar d-flex">\n' +
  3922. ' <div class="ml-1">\n' +
  3923. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  3924. ' <div class="d-inline-block">\n' +
  3925. ' <div class="input-group input-group-sm mr-1">' +
  3926. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  3927. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  3928. ' <div class="input-group-append" >\n' +
  3929. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  3930. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  3931. ' </div>\n' +
  3932. ' </div>\n' +
  3933. ' </div>\n' +
  3934. ` <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` +
  3935. ' </div>\n' +
  3936. ' </div>' +
  3937. '</div>\n' +
  3938. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  3939. );
  3940. autoFlashHeight();
  3941. const sh = `.cb-${spreadSetting.stdType}-sh`;
  3942. function getObjHeight(select) {
  3943. return select.length > 0 ? select.height() : 0;
  3944. }
  3945. const cHeader = getObjHeight($(".c-header"));
  3946. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  3947. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3948. this.spreadSetting = spreadSetting;
  3949. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  3950. const searchSheet = this.spread.getActiveSheet();
  3951. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  3952. if (!readOnly) {
  3953. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3954. const dealSheet = info.sheet;
  3955. const mainSheet = billsSheet;
  3956. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3957. if (!dealBills) { return; }
  3958. const mainTree = mainSheet.zh_tree;
  3959. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3960. if (!mainNode || !mainTree) { return; }
  3961. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3962. toastr.warning('非最底层项目下,不应添加节点');
  3963. return;
  3964. }
  3965. if (mainNode.settle_status === settleStatus.finish) {
  3966. toastr.warning('已结算节点下,不应添加签约清单');
  3967. return;
  3968. }
  3969. postData(window.location.pathname + '/update', {
  3970. postType: 'add-deal',
  3971. postData: {
  3972. id: mainNode.ledger_id,
  3973. type: mainNode.code ? 'child' : 'next',
  3974. dealBills: {
  3975. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3976. unit_price: dealBills.unit_price,
  3977. }
  3978. },
  3979. }, function (result) {
  3980. changeList = result.changeList;
  3981. const refreshData = mainTree.loadPostData(result);
  3982. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3983. const sel = mainSheet.getSelections()[0];
  3984. if (sel && refreshData.create[0]) {
  3985. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3986. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3987. }
  3988. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3989. billsSpread.focus();
  3990. posSpreadObj.loadCurPosData();
  3991. });
  3992. });
  3993. }
  3994. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3995. const searchObj = {
  3996. result: [],
  3997. cur: 0,
  3998. searchStdNode: function() {
  3999. const keyword = $(`#${relaSelect.searchText}`).val();
  4000. const sortData = SpreadJsObj.getSortData(searchSheet);
  4001. searchObj.result = keyword ? sortData.filter(x => {
  4002. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  4003. }) : [];
  4004. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  4005. searchObj.cur = 0;
  4006. if (searchObj.result.length > 0) {
  4007. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4008. }
  4009. },
  4010. searchPre: function () {
  4011. if (searchObj.result.length === 0) return;
  4012. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  4013. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4014. },
  4015. searchNext: function () {
  4016. if (searchObj.result.length === 0) return;
  4017. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  4018. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4019. },
  4020. clear: function () {
  4021. $(`#${relaSelect.searchText}`).val('');
  4022. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  4023. searchObj.result = [];
  4024. searchObj.cur = 0;
  4025. }
  4026. };
  4027. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  4028. $(`#${relaSelect.searchPre}`).click(function (e) {
  4029. searchObj.searchPre();
  4030. e.stopPropagation();
  4031. });
  4032. $(`#${relaSelect.searchNext}`).click(function (e) {
  4033. searchObj.searchNext();
  4034. e.stopPropagation();
  4035. });
  4036. $(`#${relaSelect.searchClose}`).click(function (e) {
  4037. searchObj.clear();
  4038. e.stopPropagation();
  4039. });
  4040. };
  4041. loadData (callback) {
  4042. // if (this.loaded) {
  4043. // if (callback) callback();
  4044. // return;
  4045. // }
  4046. const self = this;
  4047. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  4048. const showDatas = [];
  4049. for (const d of datas) {
  4050. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  4051. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  4052. }
  4053. }
  4054. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  4055. // self.loaded = true;
  4056. if (callback) callback();
  4057. }
  4058. }
  4059. const jlzfBills = new Jlzf('#jlzf-spread', {
  4060. cols: [
  4061. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  4062. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  4063. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  4064. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4065. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4066. ],
  4067. emptyRows: 0,
  4068. headRows: 1,
  4069. headRowHeight: [32],
  4070. headColWidth: [30],
  4071. defaultRowHeight: 21,
  4072. headerFont: '12px 微软雅黑',
  4073. font: '12px 微软雅黑',
  4074. selectedBackColor: '#fffacd',
  4075. readOnly: true,
  4076. stdType: 'jlzf',
  4077. });
  4078. class Dsk {
  4079. constructor (selector, spreadSetting) {
  4080. const self = this;
  4081. this.loaded = false;
  4082. this.obj = $(selector);
  4083. const dskProjectHtml = spreadSetting.libs.map(l => {
  4084. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  4085. });
  4086. const relaSelect = {
  4087. showLevel: `cb-${spreadSetting.stdType}-sl`,
  4088. searchText: `cb-${spreadSetting.stdType}-st`,
  4089. searchResult: `cb-${spreadSetting.stdType}-sr`,
  4090. searchPre: `cb-${spreadSetting.stdType}-sp`,
  4091. searchNext: `cb-${spreadSetting.stdType}-sn`,
  4092. searchClose: `cb-${spreadSetting.stdType}-sc`,
  4093. };
  4094. this.obj.html(
  4095. '<div class="sjs-bar d-flex">\n' +
  4096. ' <div class="dropdown mr-1">\n' +
  4097. ' <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' +
  4098. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  4099. ' </button>\n' +
  4100. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  4101. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  4102. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  4103. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  4104. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  4105. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  4106. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  4107. ' </div>\n' +
  4108. ' </div>' +
  4109. ` <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` +
  4110. ` <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` +
  4111. ' <div class="ml-1">\n' +
  4112. ' <div class="dropdown">\n' +
  4113. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  4114. ' <i class="fa fa-search"></i>\n' +
  4115. ' </button>\n' +
  4116. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  4117. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  4118. ' <div class="d-inline-block">\n' +
  4119. ' <div class="input-group input-group-sm mr-1">' +
  4120. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  4121. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  4122. ' <div class="input-group-append" >\n' +
  4123. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  4124. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  4125. ' </div>\n' +
  4126. ' </div>\n' +
  4127. ' </div>\n' +
  4128. ` <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` +
  4129. ' </div>\n' +
  4130. ' </div>\n' +
  4131. ' </div>\n' +
  4132. ' </div>' +
  4133. '</div>\n' +
  4134. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  4135. );
  4136. autoFlashHeight();
  4137. const sh = `.cb-${spreadSetting.stdType}-sh`;
  4138. function getObjHeight(select) {
  4139. return select.length > 0 ? select.height() : 0;
  4140. }
  4141. const cHeader = getObjHeight($(".c-header"));
  4142. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  4143. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  4144. this.spreadSetting = spreadSetting;
  4145. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  4146. const searchSheet = this.spread.getActiveSheet();
  4147. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  4148. (function (select, sheet) {
  4149. $(select).click(function () {
  4150. if (!sheet.zh_tree) return;
  4151. const tag = $(this).attr('tag');
  4152. const tree = sheet.zh_tree;
  4153. setTimeout(() => {
  4154. switch (tag) {
  4155. case "1":
  4156. case "2":
  4157. case "3":
  4158. case "4":
  4159. case "5":
  4160. tree.expandByLevel(parseInt(tag));
  4161. SpreadJsObj.refreshTreeRowVisible(sheet);
  4162. break;
  4163. case "last":
  4164. tree.expandByCustom(() => { return true; });
  4165. SpreadJsObj.refreshTreeRowVisible(sheet);
  4166. break;
  4167. }
  4168. }, 100);
  4169. });
  4170. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  4171. if (!readOnly) {
  4172. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  4173. const dealSheet = info.sheet;
  4174. const mainSheet = billsSheet;
  4175. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  4176. if (!dealBills) { return; }
  4177. const mainTree = mainSheet.zh_tree;
  4178. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  4179. if (!mainNode || !mainTree) { return; }
  4180. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4181. toastr.warning('非最底层项目下,不应添加节点');
  4182. return;
  4183. }
  4184. if (mainNode.settle_status === settleStatus.finish) {
  4185. toastr.warning('已结算节点下,不应添加签约清单');
  4186. return;
  4187. }
  4188. const is_bill = dealBills.kind === 4;
  4189. // 判断dealBills.code以-开头,是则向上判断是否需要拼接code名称
  4190. function makeCode(dealBills) {
  4191. const originalCode = dealBills.code;
  4192. if (!originalCode || originalCode.charAt(0) !== '-') {
  4193. return originalCode;
  4194. }
  4195. const parents = dealSheet.zh_tree.getAllParents(dealBills);
  4196. if (!parents || parents.length === 0) {
  4197. return originalCode;
  4198. }
  4199. const kind4Parents = _.filter(parents, { kind: 4 });
  4200. if (!kind4Parents || kind4Parents.length === 0) {
  4201. return originalCode;
  4202. }
  4203. const firstParentCode = kind4Parents[0].code;
  4204. if (firstParentCode.charAt(0) === '-') {
  4205. return originalCode;
  4206. }
  4207. const codeParts = [];
  4208. for (const parent of kind4Parents.reverse()) {
  4209. codeParts.push(parent.code);
  4210. if (parent.code.charAt(0) !== '-') {
  4211. break;
  4212. }
  4213. }
  4214. if (codeParts.length > 0) {
  4215. return codeParts.reverse().join('') + originalCode;
  4216. }
  4217. return originalCode;
  4218. }
  4219. const oneBills = {
  4220. b_code: is_bill ? makeCode(dealBills) : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  4221. unit_price: is_bill ? dealBills.unitPrice : null, quantity: null, total_price: null,
  4222. sgfh_qty: null, sgfh_tp: null,
  4223. };
  4224. postData(window.location.pathname + '/update', {
  4225. postType: 'add-deal',
  4226. postData: {
  4227. id: mainNode.ledger_id,
  4228. type: mainNode.code ? 'child' : 'next',
  4229. dealBills: oneBills,
  4230. },
  4231. }, function (result) {
  4232. changeList = result.changeList;
  4233. const refreshData = mainTree.loadPostData(result);
  4234. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  4235. const sel = mainSheet.getSelections()[0];
  4236. if (sel && refreshData.create[0]) {
  4237. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  4238. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  4239. }
  4240. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4241. billsSpread.focus();
  4242. posSpreadObj.loadCurPosData();
  4243. });
  4244. });
  4245. }
  4246. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  4247. const searchObj = {
  4248. result: [],
  4249. cur: 0,
  4250. searchStdNode: function() {
  4251. const keyword = $(`#${relaSelect.searchText}`).val();
  4252. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  4253. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  4254. }) : [];
  4255. // searchObj.result = [];
  4256. // for (const x of pathTree.nodes) {
  4257. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  4258. // searchObj.result.push(x);
  4259. // }
  4260. // }
  4261. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  4262. searchObj.cur = 0;
  4263. if (searchObj.result.length > 0) {
  4264. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  4265. }
  4266. },
  4267. searchPre: function () {
  4268. if (searchObj.result.length === 0) return;
  4269. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  4270. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  4271. },
  4272. searchNext: function () {
  4273. if (searchObj.result.length === 0) return;
  4274. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  4275. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  4276. },
  4277. clear: function () {
  4278. $(`#${relaSelect.searchText}`).val('');
  4279. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  4280. searchObj.result = [];
  4281. searchObj.cur = 0;
  4282. }
  4283. };
  4284. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  4285. $(`#${relaSelect.searchPre}`).click(function (e) {
  4286. searchObj.searchPre();
  4287. e.stopPropagation();
  4288. });
  4289. $(`#${relaSelect.searchNext}`).click(function (e) {
  4290. searchObj.searchNext();
  4291. e.stopPropagation();
  4292. });
  4293. $(`#${relaSelect.searchClose}`).click(function (e) {
  4294. searchObj.clear();
  4295. e.stopPropagation();
  4296. });
  4297. };
  4298. loadData (callback) {
  4299. if (this.loaded) {
  4300. if (callback) callback();
  4301. return;
  4302. }
  4303. const self = this;
  4304. if (dskAccountData && dskAccountData.select_project) {
  4305. self.loaded = true;
  4306. changeDskProject(dskAccountData.select_project);
  4307. } else {
  4308. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  4309. self.loaded = true;
  4310. }
  4311. if (callback) callback();
  4312. }
  4313. }
  4314. $('body').on('change', '#change-dsk-project', function () {
  4315. const pid = $(this).val();
  4316. changeDskProject(pid);
  4317. });
  4318. $('body').on('change', '#change-dsk-project-tree', function () {
  4319. const treeId = $(this).val();
  4320. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  4321. changeDskProjectTree(projectInfo, treeId);
  4322. });
  4323. function setDskProjectTreeSelect(trees) {
  4324. let html = '';
  4325. for (const tree of trees) {
  4326. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  4327. }
  4328. $('#change-dsk-project-tree').html(html);
  4329. }
  4330. function changeDskProject(pid) {
  4331. const projectInfo = _.find(dskProjects, { pid });
  4332. if (!projectInfo) {
  4333. dskAccountData.select_project = null;
  4334. dskAccountData.select_tree = null;
  4335. const tree = dskProjectBills2Tree.convert([]);
  4336. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4337. return;
  4338. }
  4339. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  4340. const trees = _.filter(datas, x => x.type === 4);
  4341. dskAccountData.select_project = projectInfo.pid;
  4342. setDskProjectTreeSelect(trees);
  4343. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  4344. });
  4345. }
  4346. function changeDskProjectTree(projectInfo, treeId) {
  4347. dskAccountData.select_tree = treeId;
  4348. if (!treeId) {
  4349. const tree = dskProjectBills2Tree.convert([]);
  4350. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4351. return;
  4352. }
  4353. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  4354. const tree = dskProjectBills2Tree.convert(result);
  4355. console.log(tree);
  4356. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4357. });
  4358. }
  4359. const dskBills = new Dsk('#dsk-spread', {
  4360. cols: [
  4361. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  4362. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  4363. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4364. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  4365. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  4366. ],
  4367. emptyRows: 0,
  4368. headRows: 1,
  4369. headRowHeight: [32],
  4370. headColWidth: [30],
  4371. defaultRowHeight: 21,
  4372. headerFont: '12px 微软雅黑',
  4373. font: '12px 微软雅黑',
  4374. selectedBackColor: '#fffacd',
  4375. readOnly: true,
  4376. stdType: 'dsk',
  4377. libs: dskProjects,
  4378. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  4379. });
  4380. const dskProjectBills2Tree = (function () {
  4381. const treeSetting = {
  4382. id: 'dpb_id',
  4383. pid: 'dpb_pid',
  4384. order: 'seq',
  4385. level: 'level',
  4386. rootId: '-1',
  4387. fullPath: 'full_path',
  4388. };
  4389. const tenderTree = createNewPathTree('gather', treeSetting);
  4390. function setChildrenNode(node, dxs, files, tenders) {
  4391. const dxchildren = _.filter(dxs, { parentID: node.bid });
  4392. const children = _.filter(files, { parentID: node.bid });
  4393. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  4394. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  4395. for (const t of checkChildren) {
  4396. const child = {
  4397. bid: t.ID,
  4398. parentID: t.parentID,
  4399. name: t.name,
  4400. kind: t.kind,
  4401. code: t.code,
  4402. quantity: t.quantity,
  4403. quantity2: t.quantity2,
  4404. unit: t.unit,
  4405. unitPrice: t.unitPrice,
  4406. totalPrice: t.totalPrice,
  4407. formulaCode: t.formulaCode,
  4408. flag: t.flag,
  4409. remark: t.remark,
  4410. };
  4411. tenderTree.addNode(child, node);
  4412. setChildrenNode(child, dxs, files, tenders);
  4413. }
  4414. }
  4415. function convert (projects) {
  4416. tenderTree.clearDatas();
  4417. // 区分文件夹及项目
  4418. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  4419. const dxs = _.filter(projects, { kind: 1 });
  4420. const files = _.filter(projects, { kind: 4 });
  4421. const tenders = _.filter(projects, { kind: 8 });
  4422. for (const t of topLevel) {
  4423. const node = {
  4424. bid: t.ID,
  4425. parentID: t.parentID,
  4426. name: t.name,
  4427. kind: t.kind,
  4428. code: t.code,
  4429. quantity: t.quantity,
  4430. quantity2: t.quantity2,
  4431. unit: t.unit,
  4432. unitPrice: t.unitPrice,
  4433. totalPrice: t.totalPrice,
  4434. formulaCode: t.formulaCode,
  4435. flag: t.flag,
  4436. remark: t.remark,
  4437. };
  4438. tenderTree.addNode(node, null);
  4439. setChildrenNode(node, dxs, files, tenders);
  4440. }
  4441. tenderTree.sortTreeNode(true);
  4442. return tenderTree;
  4443. }
  4444. return { tenderTree, convert }
  4445. })();
  4446. $.divResizer({
  4447. select: '#revise-right-spr',
  4448. callback: function () {
  4449. billsSpread.refresh();
  4450. if (posSpread) posSpread.refresh();
  4451. if (stdXmj) stdXmj.spread.refresh();
  4452. if (stdGcl) stdGcl.spread.refresh();
  4453. if (dealBills) dealBills.spread.refresh();
  4454. if (searchLedger) searchLedger.spread.refresh();
  4455. if (errorList) errorList.spread.refresh();
  4456. if (checkList) checkList.spread.refresh();
  4457. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4458. if (jlzfBills) jlzfBills.spread.refresh();
  4459. if (dskBills) dskBills.spread.refresh();
  4460. }
  4461. });
  4462. $.subMenu({
  4463. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  4464. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  4465. key: 'menu.1.0.0',
  4466. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  4467. callback: function (info) {
  4468. if (info.mini) {
  4469. $('.panel-title').addClass('fluid');
  4470. $('#sub-menu').removeClass('panel-sidebar');
  4471. } else {
  4472. $('.panel-title').removeClass('fluid');
  4473. $('#sub-menu').addClass('panel-sidebar');
  4474. }
  4475. autoFlashHeight();
  4476. billsSpread.refresh();
  4477. if (posSpread) posSpread.refresh();
  4478. if (stdXmj) stdXmj.spread.refresh();
  4479. if (stdGcl) stdGcl.spread.refresh();
  4480. if (dealBills) dealBills.spread.refresh();
  4481. if (searchLedger) searchLedger.spread.refresh();
  4482. if (errorList) errorList.spread.refresh();
  4483. if (checkList) checkList.spread.refresh();
  4484. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4485. if (jlzfBills) jlzfBills.spread.refresh();
  4486. if (dskBills) dskBills.spread.refresh();
  4487. }
  4488. });
  4489. // showSideTools(true);
  4490. billsSpread.refresh();
  4491. if (posSpread) posSpread.refresh();
  4492. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  4493. const mainSheet = billsSheet;
  4494. if (!stdTree || !mainSheet.zh_tree) { return; }
  4495. const mainTree = mainSheet.zh_tree;
  4496. const sel = mainSheet.getSelections()[0];
  4497. const mainNode = mainTree.nodes[sel.row];
  4498. if (!stdNode) return;
  4499. if (updateData.postData.stdType === 'gcl') {
  4500. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4501. toastr.warning('非最底层项目下,不应添加节点');
  4502. return;
  4503. }
  4504. if (mainNode.settle_status === settleStatus.finish) {
  4505. toastr.warning('已结算节点下,不可添加工程量清单');
  4506. return;
  4507. }
  4508. } else {
  4509. const stdNodes = stdTree.getAllParents(stdNode);
  4510. for (const node of stdNodes) {
  4511. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  4512. if (parent && parent.settle_status === settleStatus.finish) {
  4513. toastr.warning('项目节父项已结算,不可添加节点');
  4514. return;
  4515. }
  4516. }
  4517. }
  4518. postData(window.location.pathname + '/update', {
  4519. postType: 'add-std',
  4520. postData: {
  4521. id: mainTree.getNodeKey(mainNode),
  4522. tender_id: mainNode.tender_id,
  4523. stdType: updateData.postData.stdType,
  4524. stdLibId: stdNode.list_id,
  4525. stdNode: stdTree.getNodeKey(stdNode)
  4526. }
  4527. }, function (result) {
  4528. changeList = result.changeList;
  4529. const refreshNode = mainTree.loadPostData(result);
  4530. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  4531. if (sel) {
  4532. if (refreshNode.create && refreshNode.create.length > 0) {
  4533. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  4534. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  4535. } else {
  4536. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  4537. if (node) {
  4538. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  4539. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  4540. }
  4541. }
  4542. }
  4543. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4544. billsSpread.focus();
  4545. posSpreadObj.loadCurPosData();
  4546. });
  4547. };
  4548. const stdXmjSetting = {
  4549. selector: '#std-xmj',
  4550. stdType: 'xmj',
  4551. libs: stdChapters,
  4552. treeSetting: {
  4553. id: 'chapter_id',
  4554. pid: 'pid',
  4555. order: 'order',
  4556. level: 'level',
  4557. rootId: -1,
  4558. keys: ['id', 'list_id', 'chapter_id'],
  4559. },
  4560. spreadSetting: {
  4561. cols: [
  4562. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4563. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4564. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4565. ],
  4566. treeCol: 0,
  4567. emptyRows: 0,
  4568. headRows: 1,
  4569. headRowHeight: [32],
  4570. defaultRowHeight: 21,
  4571. headerFont: '12px 微软雅黑',
  4572. font: '12px 微软雅黑',
  4573. headColWidth: [30],
  4574. selectedBackColor: '#fffacd',
  4575. },
  4576. cellDoubleClick: stdLibCellDoubleClick,
  4577. page: 'revise',
  4578. tid: window.location.pathname.split('/')[2],
  4579. };
  4580. const stdGclSetting = {
  4581. selector: '#std-gcl',
  4582. stdType: 'gcl',
  4583. libs: stdBills,
  4584. treeSetting: {
  4585. id: 'bill_id',
  4586. pid: 'pid',
  4587. order: 'order',
  4588. level: 'level',
  4589. rootId: -1,
  4590. keys: ['id', 'list_id', 'bill_id']
  4591. },
  4592. spreadSetting: {
  4593. cols: [
  4594. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4595. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4596. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4597. ],
  4598. treeCol: 0,
  4599. emptyRows: 0,
  4600. headRows: 1,
  4601. headRowHeight: [32],
  4602. defaultRowHeight: 21,
  4603. headerFont: '12px 微软雅黑',
  4604. font: '12px 微软雅黑',
  4605. headColWidth: [30],
  4606. selectedBackColor: '#fffacd',
  4607. },
  4608. cellDoubleClick: stdLibCellDoubleClick,
  4609. page: 'revise',
  4610. tid: window.location.pathname.split('/')[2],
  4611. };
  4612. // 展开收起标准节点
  4613. $('a', '#side-menu').bind('click', function (e) {
  4614. e.preventDefault();
  4615. const tab = $(this), tabPanel = $(tab.attr('content'));
  4616. // 展开工具栏、切换标签
  4617. if (!tab.hasClass('active')) {
  4618. const close = $('.active', '#side-menu').length === 0;
  4619. $('a', '#side-menu').removeClass('active');
  4620. tab.addClass('active');
  4621. $('.tab-content .tab-pane').removeClass('active');
  4622. tabPanel.addClass('active');
  4623. showSideTools(tab.hasClass('active'));
  4624. if (tab.attr('content') === '#std-xmj') {
  4625. if (!stdXmj) {
  4626. stdXmj = $.stdLib(stdXmjSetting);
  4627. }
  4628. stdXmj.spread.refresh();
  4629. } else if (tab.attr('content') === '#std-gcl') {
  4630. if (!stdGcl) {
  4631. stdGcl = $.stdLib(stdGclSetting);
  4632. }
  4633. stdGcl.spread.refresh();
  4634. } else if (tab.attr('content') === '#deal-bills') {
  4635. dealBills.loadData();
  4636. dealBills.spread.refresh();
  4637. } else if (tab.attr('content') === '#search') {
  4638. if (!searchLedger) {
  4639. searchLedger = $.ledgerSearch({
  4640. selector: '#search',
  4641. ledger: { billsTree: billsTree, pos: pos },
  4642. searchOver: true,
  4643. searchEmpty: true,
  4644. resultSpreadSetting: {
  4645. cols: [
  4646. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4647. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4648. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4649. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4650. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4651. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4652. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4653. ],
  4654. emptyRows: 0,
  4655. headRows: 1,
  4656. headRowHeight: [32],
  4657. headColWidth: [30],
  4658. defaultRowHeight: 21,
  4659. headerFont: '12px 微软雅黑',
  4660. font: '12px 微软雅黑',
  4661. selectedBackColor: '#fffacd',
  4662. readOnly: true,
  4663. },
  4664. locate: function(cur) {
  4665. if (!cur.lid) return;
  4666. SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
  4667. posSpreadObj.loadCurPosData();
  4668. if (cur.pid && cur.pid !== -1) {
  4669. const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4670. SpreadJsObj.locateRow(posSheet, pIndex);
  4671. }
  4672. },
  4673. customSearch: [
  4674. {
  4675. key: 'revise', title: '新增部位', valid: true, parent: true,
  4676. check: function (node) {
  4677. if (node.formc || node.cid) {
  4678. return true;
  4679. } else {
  4680. return false;
  4681. }
  4682. }
  4683. }
  4684. ],
  4685. });
  4686. }
  4687. searchLedger.spread.refresh();
  4688. } else if (tab.attr('content') === '#error-list') {
  4689. errorList.spread.refresh();
  4690. } else if (tab.attr('content') === '#check-list') {
  4691. checkList.spread.refresh();
  4692. } else if (tab.attr('content') === '#sum-load-miss') {
  4693. sumLoadMiss.spread.refresh();
  4694. } else if (tab.attr('content') === '#dsk-list') {
  4695. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  4696. $(dskActiveTab).addClass('active');
  4697. if (dskActiveTab === '#jlzf-spread') {
  4698. $('#get-dsk-btn').hide();
  4699. $('#get-dsk-bills-btn').hide();
  4700. jlzfBills.loadData();
  4701. jlzfBills.spread.refresh();
  4702. } else if (dskActiveTab === '#dsk-spread') {
  4703. $('#get-dsk-btn').show();
  4704. $('#get-dsk-bills-btn').show();
  4705. dskBills.loadData();
  4706. dskBills.spread.refresh();
  4707. }
  4708. }
  4709. }
  4710. else {// 收起工具栏
  4711. tab.removeClass('active');
  4712. tabPanel.removeClass('active');
  4713. showSideTools(tab.hasClass('active'));
  4714. }
  4715. billsSpread.refresh();
  4716. if (posSpread) posSpread.refresh();
  4717. });
  4718. // 新增清单切换tab
  4719. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  4720. e.preventDefault();
  4721. const dskActiveTab = $(this).attr('href');
  4722. if (dskActiveTab === '#jlzf-spread') {
  4723. $('#get-dsk-btn').hide();
  4724. $('#get-dsk-bills-btn').hide();
  4725. jlzfBills.loadData();
  4726. jlzfBills.spread.refresh();
  4727. } else if (dskActiveTab === '#dsk-spread') {
  4728. $('#get-dsk-btn').show();
  4729. $('#get-dsk-bills-btn').show();
  4730. dskBills.loadData();
  4731. dskBills.spread.refresh();
  4732. }
  4733. });
  4734. // 显示层次
  4735. (function (select, sheet) {
  4736. $(select).click(function () {
  4737. if (!sheet.zh_tree) return;
  4738. const tag = $(this).attr('tag');
  4739. const tree = sheet.zh_tree;
  4740. setTimeout(() => {
  4741. showWaitingView();
  4742. switch (tag) {
  4743. case "1":
  4744. case "2":
  4745. case "3":
  4746. case "4":
  4747. case "5":
  4748. tree.expandByLevel(parseInt(tag));
  4749. SpreadJsObj.refreshTreeRowVisible(sheet);
  4750. break;
  4751. case "last":
  4752. tree.expandByCustom(() => { return true; });
  4753. SpreadJsObj.refreshTreeRowVisible(sheet);
  4754. break;
  4755. case "leafXmj":
  4756. tree.expandToLeafXmj();
  4757. SpreadJsObj.refreshTreeRowVisible(sheet);
  4758. break;
  4759. }
  4760. closeWaitingView();
  4761. }, 100);
  4762. });
  4763. })('a[name=showLevel]', billsSheet);
  4764. const dataChecker = DataChecker({
  4765. checkUrl: window.location.pathname + '/check',
  4766. completeData: function (data) {
  4767. pos.updateDatas({update: data.source.pos});
  4768. const loadResult = billsTree.loadPostData({update: data.source.bills});
  4769. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  4770. posSpreadObj.loadCurPosData();
  4771. for (const e of data.error) {
  4772. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  4773. }
  4774. },
  4775. errorList: errorList,
  4776. });
  4777. $('#ledger-check2').click(() => {
  4778. ledgerCheck2({
  4779. ledgerTree: billsTree,
  4780. ledgerPos: pos,
  4781. checkList: checkList,
  4782. decimal: decimal,
  4783. checkOption: checkOption,
  4784. }).then(result => {
  4785. check2Viewing({
  4786. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  4787. randomWait: true,
  4788. prefix: 'check2-',
  4789. checks: result,
  4790. checkList: checkList,
  4791. });
  4792. });
  4793. });
  4794. if (isYb) {
  4795. let compilationList = [];
  4796. $('#get-dsk-btn').click(function () {
  4797. // 判断是否已绑定dsk用户
  4798. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  4799. if (result === 1) {
  4800. $('#error-dsk .modal-body').find('h5').eq(0).show();
  4801. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  4802. $('#error-dsk').modal('show');
  4803. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  4804. } else if (result === 2) {
  4805. $('#error-dsk .modal-body').find('h5').eq(1).show();
  4806. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  4807. $('#error-dsk').modal('show');
  4808. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  4809. } else {
  4810. postData('/profile/dsk/api', {
  4811. type: 'compilation',
  4812. getProject: 1,
  4813. compilationId: getLocalCache(dskCompilation)
  4814. }, function (result) {
  4815. let html = '';
  4816. for (const data of result.compilation) {
  4817. if (data.ID !== '5c66649650da2d000d8d37ba' && data.ID !== '5b52b027fd3bb0000b257cf8') {
  4818. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  4819. }
  4820. }
  4821. dskAccountData = result.dskAccountData;
  4822. compilationList = result.compilation;
  4823. console.log(compilationList);
  4824. $('#dsk-compilation-list').html(html);
  4825. $('#add-dsk').modal('show');
  4826. setLocalCache(dskCompilation, result.select_compilation);
  4827. makeDskProjectSjsHtml(result.project);
  4828. });
  4829. }
  4830. })
  4831. });
  4832. $('#get-dsk-bills-btn').click(function () {
  4833. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  4834. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  4835. });
  4836. $('body').on('change', '#dsk-compilation-list', function () {
  4837. const compilationId = $(this).val();
  4838. setLocalCache(dskCompilation, compilationId);
  4839. dskProjectSpreadObj.refreshSourceTree();
  4840. });
  4841. $('.hide-dsk-modal').click(function () {
  4842. $('#error-dsk').modal('hide');
  4843. });
  4844. let dp = false;
  4845. let gsObj = {
  4846. setting: null,
  4847. gsSheet: null,
  4848. grSheet: null,
  4849. tenderSourceTree: null,
  4850. grArray: dskProjects ? dskProjects : [],
  4851. orgSelect: null,
  4852. };
  4853. function makeDskProjectSjsHtml(datas) {
  4854. if (!dp) {
  4855. initDskProjectTree();
  4856. dp = true;
  4857. }
  4858. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  4859. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  4860. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  4861. if (datas.length === 0) {
  4862. $('#show-project-0').show();
  4863. } else {
  4864. $('#show-project-0').hide();
  4865. }
  4866. }
  4867. const dskProjectSpreadObj = {
  4868. _addTender: function (tender) {
  4869. const gr = gsObj.grArray.find(function (x) {
  4870. return x.pid === tender.pid;
  4871. });
  4872. const c_id = getLocalCache(dskCompilation);
  4873. const t = {
  4874. pid: tender.pid,
  4875. name: tender.name,
  4876. compilationId: c_id,
  4877. compilationName: _.find(compilationList, {ID: c_id}).name
  4878. };
  4879. if (!gr) gsObj.grArray.push(t);
  4880. return t;
  4881. },
  4882. _removeTender: function (tender) {
  4883. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  4884. return x.pid === tender.pid;
  4885. });
  4886. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  4887. },
  4888. reloadResultData: function () {
  4889. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  4890. },
  4891. refreshSourceTree: function () {
  4892. const c_id = getLocalCache(dskCompilation);
  4893. if (c_id) {
  4894. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  4895. makeDskProjectSjsHtml(result);
  4896. });
  4897. }
  4898. },
  4899. gsButtonClicked: function (e, info) {
  4900. if (!info.sheet.zh_setting) return;
  4901. const col = info.sheet.zh_setting.cols[info.col];
  4902. if (col.field !== 'selected') return;
  4903. const node = SpreadJsObj.getSelectObject(info.sheet);
  4904. node.selected = !node.selected;
  4905. if (node.children && node.children.length > 0) {
  4906. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  4907. for (const p of posterity) {
  4908. p.selected = node.selected;
  4909. if ((!p.children || p.children.length === 0) && p.type === 2) {
  4910. if (p.selected) {
  4911. dskProjectSpreadObj._addTender(p);
  4912. } else {
  4913. dskProjectSpreadObj._removeTender(p);
  4914. }
  4915. }
  4916. }
  4917. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  4918. } else if (node.type === 2) {
  4919. if (node.selected) {
  4920. dskProjectSpreadObj._addTender(node);
  4921. } else {
  4922. dskProjectSpreadObj._removeTender(node);
  4923. }
  4924. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  4925. }
  4926. dskProjectSpreadObj.reloadResultData();
  4927. },
  4928. deleteGr: function () {
  4929. if (gsObj.grArray.length === 0) return;
  4930. if (gsObj.grSheet.getSelections().length === 0) return;
  4931. const selections = gsObj.grSheet.getSelections();
  4932. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  4933. const row = sel && sel.row !== undefined ? sel.row : -1;
  4934. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  4935. return false;
  4936. }
  4937. const delList = [];
  4938. for (let r = 0; r < sel.rowCount; r++) {
  4939. const select = gsObj.grArray[row + r];
  4940. delList.push(select);
  4941. }
  4942. _.pullAll(gsObj.grArray, delList);
  4943. dskProjectSpreadObj.reloadResultData();
  4944. dskProjectSpreadObj.refreshSourceTree();
  4945. },
  4946. };
  4947. const initDskProjectTree = function () {
  4948. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  4949. gsObj.gsSheet = gsSpread.getActiveSheet();
  4950. const gsSpreadSetting = {
  4951. cols: [
  4952. {
  4953. title: '选择',
  4954. field: 'selected',
  4955. hAlign: 1,
  4956. width: 40,
  4957. formatter: '@',
  4958. cellType: 'checkbox',
  4959. readOnly: true,
  4960. },
  4961. {
  4962. title: '名称',
  4963. field: 'name',
  4964. hAlign: 0,
  4965. width: 400,
  4966. formatter: '@',
  4967. readOnly: true,
  4968. folderCell: true,
  4969. cellType: 'tree'
  4970. },
  4971. ],
  4972. emptyRows: 0,
  4973. headRows: 1,
  4974. headRowHeight: [32],
  4975. defaultRowHeight: 21,
  4976. headerFont: '12px 微软雅黑',
  4977. font: '12px 微软雅黑',
  4978. headColWidth: [0],
  4979. selectedBackColor: '#fffacd',
  4980. };
  4981. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  4982. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  4983. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  4984. gsObj.grSheet = grSpread.getActiveSheet();
  4985. const grSpreadSetting = {
  4986. cols: [
  4987. {
  4988. title: '名称',
  4989. colSpan: '1',
  4990. rowSpan: '1',
  4991. field: 'name',
  4992. hAlign: 0,
  4993. width: 250,
  4994. formatter: '@',
  4995. readOnly: true,
  4996. cellType: 'ellipsisAutoTip',
  4997. scrollHeightClass: '.modal-height-500'
  4998. },
  4999. {
  5000. title: '所属编办',
  5001. colSpan: '1',
  5002. rowSpan: '1',
  5003. field: 'compilationName',
  5004. hAlign: 0,
  5005. width: 150,
  5006. formatter: '@',
  5007. readOnly: true
  5008. },
  5009. ],
  5010. emptyRows: 0,
  5011. headRows: 1,
  5012. headRowHeight: [32],
  5013. defaultRowHeight: 21,
  5014. headerFont: '12px 微软雅黑',
  5015. font: '12px 微软雅黑',
  5016. headColWidth: []
  5017. };
  5018. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  5019. // 右键删除已选项目
  5020. const gsContextMenuOptions = {
  5021. selector: '#dsk-project-result-spread',
  5022. build: function ($trigger, e) {
  5023. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  5024. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  5025. },
  5026. items: {
  5027. delete: {
  5028. name: '删除',
  5029. icon: 'fa-remove',
  5030. callback: function (key, opt) {
  5031. dskProjectSpreadObj.deleteGr();
  5032. },
  5033. disabled: function (key, opt) {
  5034. const selection = gsObj.grSheet.getSelections();
  5035. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  5036. const row = sel && sel.row !== undefined ? sel.row : -1;
  5037. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  5038. return true;
  5039. }
  5040. return false;
  5041. }
  5042. },
  5043. }
  5044. };
  5045. $.contextMenu(gsContextMenuOptions);
  5046. $('#add-dsk').bind('shown.bs.modal', function () {
  5047. if (gsSpread) gsSpread.refresh();
  5048. if (grSpread) grSpread.refresh();
  5049. });
  5050. };
  5051. const dskProject2Tree = (function () {
  5052. const treeSetting = {
  5053. id: 'tmt_id',
  5054. pid: 'tmt_pid',
  5055. order: 'seq',
  5056. level: 'level',
  5057. rootId: '-1',
  5058. fullPath: 'full_path',
  5059. };
  5060. const tenderTree = createNewPathTree('gather', treeSetting);
  5061. function setChildrenNode(node, files, tenders) {
  5062. const children = _.filter(files, {parentID: node.pid});
  5063. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  5064. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  5065. for (const c of checkChildren) {
  5066. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  5067. // // 判断文件夹下有无东西,没有就不插入
  5068. // continue;
  5069. // }
  5070. const child = {
  5071. pid: c.ID,
  5072. parentID: c.parentID,
  5073. name: c.name,
  5074. type: c.type,
  5075. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  5076. };
  5077. tenderTree.addNode(child, node);
  5078. if (c.type === 1) setChildrenNode(child, files, tenders);
  5079. }
  5080. }
  5081. function convert(projects) {
  5082. tenderTree.clearDatas();
  5083. const result = filterFolders(projects);
  5084. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  5085. const files = _.filter(result, {type: 1});
  5086. const tenders = _.filter(result, {type: 2});
  5087. for (const t of topLevel) {
  5088. const node = {
  5089. pid: t.ID,
  5090. parentID: t.parentID,
  5091. name: t.name,
  5092. type: t.type,
  5093. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  5094. };
  5095. tenderTree.addNode(node, null);
  5096. if (t.type === 1) setChildrenNode(node, files, tenders);
  5097. }
  5098. tenderTree.sortTreeNode(true);
  5099. return tenderTree;
  5100. }
  5101. return {tenderTree, convert}
  5102. })();
  5103. function filterFolders(data) {
  5104. // 构建ID到节点的映射
  5105. const idMap = data.reduce((map, node) => {
  5106. map[node.ID] = node;
  5107. return map;
  5108. }, {});
  5109. // 建立父子关系映射
  5110. const parentMap = data.reduce((map, node) => {
  5111. if (node.parentID !== '-1') {
  5112. if (!map[node.parentID]) {
  5113. map[node.parentID] = [];
  5114. }
  5115. map[node.parentID].push(node.ID);
  5116. }
  5117. return map;
  5118. }, {});
  5119. // 检查节点及其子节点是否包含清单(type=1)
  5120. const hasChecklist = (id) => {
  5121. const node = idMap[id];
  5122. if (node.type === 2) {
  5123. return true;
  5124. }
  5125. if (!parentMap[id]) {
  5126. return false;
  5127. }
  5128. return parentMap[id].some(childID => hasChecklist(childID));
  5129. };
  5130. // 过滤节点
  5131. const filteredIDs = new Set();
  5132. data.forEach(node => {
  5133. if (node.type === 2 || hasChecklist(node.ID)) {
  5134. let currentID = node.ID;
  5135. while (currentID !== '-1') {
  5136. filteredIDs.add(currentID);
  5137. currentID = idMap[currentID].parentID;
  5138. }
  5139. }
  5140. });
  5141. // 返回过滤后的数据
  5142. return data.filter(node => filteredIDs.has(node.ID));
  5143. }
  5144. $('#set-dsk-project').click(function () {
  5145. postData('/profile/dsk/api', {
  5146. type: 'save_projects',
  5147. tid: window.location.pathname.split('/')[2],
  5148. project_list: gsObj.grArray
  5149. }, function (result) {
  5150. // dskAccountData.select_project = result;
  5151. dskProjects = gsObj.grArray;
  5152. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  5153. dskAccountData.select_project = result;
  5154. changeDskProject(result);
  5155. dskBills.spread.refresh();
  5156. }
  5157. setDskProjectSelect(gsObj.grArray);
  5158. $('#add-dsk').modal('hide');
  5159. });
  5160. });
  5161. $('#add-dsk').on('hide.bs.modal', function () {
  5162. $('#autoTip').hide();
  5163. });
  5164. function setDskProjectSelect(projects) {
  5165. let html = '';
  5166. for (const project of projects) {
  5167. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  5168. }
  5169. $('#change-dsk-project').html(html);
  5170. }
  5171. // 选中所有新增部位/清单
  5172. $('#add-all-revise').click(function() {
  5173. const this_cid = window.location.pathname.split('/')[4];
  5174. makeGclGatherData();
  5175. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  5176. type: 'get-revise-list',
  5177. }, function (result) {
  5178. const addDatas = [];
  5179. for (const ggd in gclGatherData) {
  5180. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  5181. let hadcid = 0;
  5182. for (const xmj of gclGatherData[ggd].leafXmjs) {
  5183. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  5184. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  5185. if (changeLedger || changePos) {
  5186. xmj.cid = 1;
  5187. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  5188. hadcid = 1;
  5189. }
  5190. }
  5191. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  5192. }
  5193. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  5194. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  5195. if (leafXmjs.length > 0) {
  5196. gclInfo.is_change = 1;
  5197. for (const xmj of leafXmjs) {
  5198. if (_.findIndex(changeList, function (item) {
  5199. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  5200. }) === -1) {
  5201. addDatas.push({
  5202. lid: xmj.gcl_id,
  5203. code: gclInfo.code,
  5204. name: gclInfo.name || '',
  5205. unit: gclInfo.unit || '',
  5206. unit_price: gclInfo.unit_price,
  5207. oamount: xmj.quantity,
  5208. oamount2: xmj.quantity,
  5209. bwmx: xmj.bwmx || xmj.jldy || '',
  5210. xmj_code: xmj.code || '',
  5211. xmj_jldy: xmj.jldy || '',
  5212. xmj_dwgc: xmj.dwgc || '',
  5213. xmj_fbgc: xmj.fbgc || '',
  5214. xmj_fxgc: xmj.fxgc || '',
  5215. gcl_id: xmj.gcl_id,
  5216. mx_id: xmj.mx_id || '',
  5217. });
  5218. }
  5219. }
  5220. }
  5221. }
  5222. console.log(addDatas);
  5223. if (addDatas.length > 0) {
  5224. // 更新至服务器
  5225. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  5226. type: 'add-change-list',
  5227. postData: addDatas,
  5228. }, function (result) {
  5229. toastr.success('已新增当前变更令新增的所有部位/清单');
  5230. changeList = result.changeList;
  5231. const sortData = SpreadJsObj.getSortData(billsSheet);
  5232. const billsNodes = _.filter(sortData, function (item) {
  5233. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  5234. });
  5235. for (const billsNode of billsNodes) {
  5236. billsNode.is_change = 1;
  5237. }
  5238. const loadResult = { update: billsNodes };
  5239. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  5240. posSpreadObj.loadCurPosData();
  5241. });
  5242. } else {
  5243. toastr.warning('未存在当前变更令新增的部位/清单');
  5244. }
  5245. });
  5246. });
  5247. }
  5248. });
  5249. function findDecimal(unit) {
  5250. let value = precision.other.value;
  5251. const changeUnits = precision;
  5252. for (const d in changeUnits) {
  5253. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  5254. value = changeUnits[d].value;
  5255. break;
  5256. }
  5257. }
  5258. return value;
  5259. }
  5260. // 编号排序,多重判断
  5261. function sortByCode(a, b, code = 'b_code') {
  5262. let code1 = a[code].split('-');
  5263. let code2 = b[code].split('-');
  5264. let code1length = code1.length;
  5265. let code2length = code2.length;
  5266. for (let i = 0; i < code1length; i ++) {
  5267. if (i+1 <= code2length) {
  5268. if (code1[i] != code2[i]) {
  5269. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  5270. return parseInt(code1[i]) - parseInt(code2[i]);
  5271. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  5272. return 1;
  5273. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  5274. return -1;
  5275. } else {
  5276. const str1length = code1[i].length;
  5277. const str2length = code2[i].length;
  5278. for (let j = 0; j < str1length; j++) {
  5279. if (j+1 <= str2length) {
  5280. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  5281. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  5282. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  5283. if (str1length == str2length) {
  5284. return 0;
  5285. } else {
  5286. return str1length - str2length;
  5287. }
  5288. }
  5289. } else {
  5290. if (j+1 >= str1length) {
  5291. return 1;
  5292. } else {
  5293. return -1;
  5294. }
  5295. }
  5296. }
  5297. }
  5298. } else if (i+1 == code1length && code1[i] == code2[i]) {
  5299. if (code1length == code2length) {
  5300. return 0;
  5301. } else {
  5302. return code1length - code2length;
  5303. }
  5304. }
  5305. } else {
  5306. if (i+1 >= code1length) {
  5307. return 1;
  5308. } else {
  5309. return -1;
  5310. }
  5311. }
  5312. }
  5313. }