change_revise.js 248 KB

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