change_revise.js 249 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060
  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', 'ex_tp1'],
  288. autoExpand: 3,
  289. markExpandKey: 'change-bills-expand',
  290. markExpandSubKey: window.location.pathname.split('/')[2],
  291. };
  292. if (!isTz) {
  293. treeSetting.calcFields.push('deal_tp');
  294. }
  295. treeSetting.calcFun = function (node) {
  296. if (node && node.b_code) {
  297. const posData = pos.getLedgerPos(node.id) || [];
  298. let camount = ZhCalc.round(node.camount, findDecimal(node.unit)) || 0;
  299. if (posData.length > 0) {
  300. let sgfh_qty = 0;
  301. let sjcl_qty = 0;
  302. let qtcl_qty = 0;
  303. let ex_qty1 = 0;
  304. camount = 0;
  305. for (const np of posData) {
  306. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  307. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  308. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  309. ex_qty1 = ZhCalc.add(ex_qty1, np.ex_qty1);
  310. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  311. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(node.unit))) : camount;
  312. }
  313. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  314. node.sgfh_qty = sgfh_qty;
  315. node.sjcl_qty = sjcl_qty;
  316. node.qtcl_qty = qtcl_qty;
  317. node.ex_qty1 = ex_qty1;
  318. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  319. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  320. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  321. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  322. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  323. }
  324. if (!_.isEqual(node.ex_qty1, ex_qty1)) {
  325. node.ex_qty1 = ex_qty1;
  326. node.ex_tp1 = ZhCalc.mul(node.ex_qty1, node.unit_price, decimal.tp) || 0;
  327. }
  328. }
  329. node.camount = camount;
  330. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  331. }
  332. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  333. };
  334. const billsTree = createNewPathTree('revise', treeSetting);
  335. console.log(billsTree, treeSetting);
  336. // 初始化 计量单元
  337. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  338. // 清单 相关方法&绑定spreadjs事件
  339. const billsTreeSpreadObj = {
  340. loadExprToInput(sheet) {
  341. const sel = sheet.getSelections()[0];
  342. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  343. if (col && col.field === 'camount') {
  344. const data = SpreadJsObj.getSelectObject(sheet);
  345. if (data) {
  346. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  347. if (!cInfo) {
  348. $('#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] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  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 = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  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 = colSetting.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 = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  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 = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1771. select.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  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. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1782. }, function () {
  1783. cInfo.camount = orgValue;
  1784. cInfo.spamount = orgValue;
  1785. select.camount = orgValue;
  1786. SpreadJsObj.reLoadRowData(billsSheet, row);
  1787. });
  1788. return;
  1789. }
  1790. const data = {
  1791. id: select.id,
  1792. tender_id: select.tender_id,
  1793. ledger_id: select.ledger_id
  1794. };
  1795. const exprInfo = getExprInfo(field);
  1796. if (newValue !== '') {
  1797. const num = _.toNumber(newValue);
  1798. if (num) {
  1799. data[field] = num;
  1800. if (exprInfo) {
  1801. data[exprInfo.expr] = '';
  1802. }
  1803. } else {
  1804. try {
  1805. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  1806. if (exprInfo) {
  1807. data[exprInfo.expr] = newValue;
  1808. }
  1809. } catch (err) {
  1810. toastr.error('输入的表达式非法');
  1811. return;
  1812. }
  1813. }
  1814. } else {
  1815. data[field] = null;
  1816. if (exprInfo) {
  1817. data[exprInfo.expr] = '';
  1818. }
  1819. }
  1820. // 更新至服务器
  1821. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1822. changeList = result.changeList;
  1823. const refreshNode = billsTree.loadPostData(result);
  1824. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1825. });
  1826. });
  1827. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  1828. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  1829. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  1830. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  1831. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1832. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1833. SpreadJsObj.Clipboard.setCopyData(copyText);
  1834. });
  1835. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  1836. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  1837. }
  1838. // 右键菜单
  1839. let batchInsertObj;
  1840. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1841. const self = this;
  1842. if ($.isFunction(item.icon)) {
  1843. item._icon = item.icon.call(this, this, $t, key, item);
  1844. } else {
  1845. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1846. // to enable font awesome
  1847. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1848. } else {
  1849. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1850. }
  1851. }
  1852. this.addClass(item._icon);
  1853. 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>')
  1854. .appendTo(this);
  1855. const $input = $obj.find('input');
  1856. const event = () => {
  1857. if (self.hasClass('context-menu-disabled')) return;
  1858. item.batchInsert($input[0], root);
  1859. };
  1860. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1861. $input.click((e) => {e.stopPropagation();})
  1862. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1863. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1864. };
  1865. const billsContextMenuOptions = {
  1866. selector: '#bills-spread',
  1867. build: function ($trigger, e) {
  1868. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  1869. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1870. },
  1871. items: {}
  1872. };
  1873. if (!readOnly) {
  1874. billsContextMenuOptions.items.create = {
  1875. name: '新增',
  1876. icon: 'fa-sign-in',
  1877. callback: function (key, opt) {
  1878. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  1879. },
  1880. disabled: function (key, opt) {
  1881. const sheet = billsSheet;
  1882. const selection = sheet.getSelections();
  1883. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1884. const row = sel ? sel.row : -1;
  1885. const tree = sheet.zh_tree;
  1886. if (!tree) return true;
  1887. const first = sheet.zh_tree.nodes[row];
  1888. const valid = !sheet.zh_setting.readOnly;
  1889. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1890. }
  1891. };
  1892. billsContextMenuOptions.items.delete = {
  1893. name: '删除',
  1894. icon: 'fa-remove',
  1895. callback: function (key, opt) {
  1896. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  1897. },
  1898. disabled: function (key, opt) {
  1899. const sheet = billsSheet;
  1900. const selection = sheet.getSelections();
  1901. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1902. const row = sel ? sel.row : -1;
  1903. const tree = sheet.zh_tree;
  1904. if (!tree) return true;
  1905. const first = sheet.zh_tree.nodes[row];
  1906. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  1907. if (sel.rowCount > 1 && first) {
  1908. for (let r = 1; r < sel.rowCount; r++) {
  1909. const rNode = tree.nodes[sel.row + r];
  1910. if (!rNode) {
  1911. sameParent = false;
  1912. break;
  1913. }
  1914. if (!rNode.formc) {
  1915. return true;
  1916. }
  1917. nodeUsed = nodeUsed || rNode.used;
  1918. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  1919. if (rNode.level > first.level) continue;
  1920. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1921. sameParent = false;
  1922. break;
  1923. }
  1924. last = rNode;
  1925. }
  1926. }
  1927. const valid = !sheet.zh_setting.readOnly;
  1928. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  1929. }
  1930. };
  1931. billsContextMenuOptions.items.sprBase = '----';
  1932. }
  1933. billsContextMenuOptions.items.copyBlock = {
  1934. name: '复制整块',
  1935. icon: 'fa-files-o',
  1936. callback: function (key, opt) {
  1937. const copyBlockList = [];
  1938. const sheet = billsSheet;
  1939. const sel = sheet.getSelections()[0];
  1940. let iRow = sel.row;
  1941. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1942. while (iRow < sel.row + sel.rowCount) {
  1943. const node = sheet.zh_tree.nodes[iRow];
  1944. if (node.ledger_pid !== pid) {
  1945. toastr.error('仅可同时选中同层节点');
  1946. return;
  1947. }
  1948. const posterity = sheet.zh_tree.getPosterity(node);
  1949. iRow += posterity.length + 1;
  1950. posterity.unshift(node);
  1951. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1952. }
  1953. for (const cbl of copyBlockList) {
  1954. for (const b of cbl) {
  1955. const posRange = pos.getLedgerPos(b.id);
  1956. if (posRange && posRange.length > 0) b.pos = posRange;
  1957. }
  1958. }
  1959. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1960. },
  1961. visible: function (key, opt) {
  1962. const sheet = billsSheet;
  1963. const selection = sheet.getSelections();
  1964. const row = selection[0].row;
  1965. const select = billsTree.nodes[row];
  1966. return select;
  1967. },
  1968. disabled: function (key, opt) {
  1969. const sheet = billsSheet;
  1970. const selection = sheet.getSelections();
  1971. const row = selection[0].row;
  1972. const select = billsTree.nodes[row];
  1973. return select && select.level <= 1;
  1974. }
  1975. };
  1976. billsContextMenuOptions.items.copyBlockXmj = {
  1977. name: '复制整块(只复制项目节)',
  1978. icon: 'fa-files-o',
  1979. callback: function (key, opt) {
  1980. const copyBlockList = [];
  1981. const sheet = billsSheet;
  1982. const sel = sheet.getSelections()[0];
  1983. let iRow = sel.row;
  1984. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1985. while (iRow < sel.row + sel.rowCount) {
  1986. const node = sheet.zh_tree.nodes[iRow];
  1987. if (node.ledger_pid !== pid) {
  1988. toastr.error('仅可同时选中同层节点');
  1989. return;
  1990. }
  1991. const posterity = sheet.zh_tree.getPosterity(node);
  1992. iRow += posterity.length + 1;
  1993. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1994. copyPosterity.unshift(node);
  1995. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1996. for (const p of copyData) {
  1997. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1998. p.is_leaf = children.length === 0;
  1999. }
  2000. copyBlockList.push(copyData);
  2001. }
  2002. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2003. },
  2004. visible: function (key, opt) {
  2005. const sheet = billsSheet;
  2006. const selection = sheet.getSelections();
  2007. const row = selection[0].row;
  2008. const select = billsTree.nodes[row];
  2009. return select;
  2010. },
  2011. disabled: function (key, opt) {
  2012. const sheet = billsSheet;
  2013. const selection = sheet.getSelections();
  2014. const row = selection[0].row;
  2015. const select = billsTree.nodes[row];
  2016. return select && select.level <= 1;
  2017. }
  2018. };
  2019. if (!readOnly) {
  2020. billsContextMenuOptions.items.pasteBlock = {
  2021. name: '粘贴整块',
  2022. icon: 'fa-clipboard',
  2023. disabled: function (key, opt) {
  2024. //const block = treeOperationObj.block || [];
  2025. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2026. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  2027. },
  2028. callback: function (key, opt) {
  2029. //const block = treeOperationObj.block || [];
  2030. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2031. if (copyInfo.block.length > 0) {
  2032. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  2033. } else {
  2034. document.execCommand('paste');
  2035. }
  2036. },
  2037. visible: function (key, opt) {
  2038. return !readOnly;
  2039. }
  2040. };
  2041. billsContextMenuOptions.items.sprBlock = '----';
  2042. }
  2043. if (!readOnly) {
  2044. billsContextMenuOptions.items.batchInsert = {
  2045. name: '批量插入',
  2046. type: 'batchInsert',
  2047. value: '2',
  2048. icon: 'fa-sign-in',
  2049. batchInsert: function (obj, root) {
  2050. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2051. obj.value = obj.max;
  2052. toastr.warning('批量插入不可多于' + obj.max);
  2053. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2054. obj.value = obj.min;
  2055. toastr.warning('批量插入不可少于' + obj.min);
  2056. } else {
  2057. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  2058. root.$menu.trigger('contextmenu:hide');
  2059. }
  2060. },
  2061. disabled: function (key, opt) {
  2062. const sheet = billsSheet;
  2063. const selection = sheet.getSelections();
  2064. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2065. const row = sel ? sel.row : -1;
  2066. const tree = sheet.zh_tree;
  2067. if (!tree) return true;
  2068. const first = sheet.zh_tree.nodes[row];
  2069. const valid = !sheet.zh_setting.readOnly;
  2070. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  2071. }
  2072. };
  2073. billsContextMenuOptions.items.batchInsertBillsPos = {
  2074. name: '批量插入清单-计量单元',
  2075. icon: 'fa-sign-in',
  2076. visible: function (key, opt) {
  2077. return false;
  2078. },
  2079. disabled: function (key, opt) {
  2080. if (!isTz) return true;
  2081. const select = SpreadJsObj.getSelectObject(billsSheet);
  2082. if (select) {
  2083. if (select.code && select.code !== '') {
  2084. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  2085. } else {
  2086. const parent = billsTree.getParent(select);
  2087. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  2088. }
  2089. } else {
  2090. return false;
  2091. }
  2092. },
  2093. callback: function (key, opt) {
  2094. if (!batchInsertObj) {
  2095. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  2096. } else {
  2097. batchInsertObj.initView();
  2098. }
  2099. $('#batch').modal('show');
  2100. }
  2101. };
  2102. }
  2103. billsContextMenuOptions.items.sprTag = '----';
  2104. billsContextMenuOptions.items.showLast = {
  2105. name: '显示至最底层',
  2106. callback: function (key, opt, menu, e) {
  2107. const node = SpreadJsObj.getSelectObject(billsSheet);
  2108. setTimeout(() => {
  2109. showWaitingView();
  2110. billsTree.expandByCustom(x => {
  2111. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  2112. });
  2113. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  2114. closeWaitingView();
  2115. }, 100);
  2116. },
  2117. };
  2118. $.contextMenu(billsContextMenuOptions);
  2119. // 计量单元 相关方法&绑定spreadjs事件
  2120. const posSpreadObj = {
  2121. refreshOperationValid: function (sheet, selection) {
  2122. const setObjEnable = function (obj, enable) {
  2123. if (enable) {
  2124. obj.removeClass('disabled');
  2125. } else {
  2126. obj.addClass('disabled');
  2127. }
  2128. };
  2129. const invalidAll = function () {
  2130. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  2131. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  2132. };
  2133. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2134. const row = sel ? sel.row : -1;
  2135. const first = sheet.zh_data[row];
  2136. if (!first) {
  2137. invalidAll();
  2138. return;
  2139. }
  2140. let last = first;
  2141. if (sel.rowCount > 1 && first) {
  2142. for (let r = 1; r < sel.rowCount; r++) {
  2143. const rNode = sheet.zh_data[sel.row + r];
  2144. if (!rNode) break;
  2145. last = rNode;
  2146. }
  2147. }
  2148. const preNode = sheet.zh_data[row - 1];
  2149. const valid = !sheet.zh_setting.readOnly;
  2150. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  2151. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  2152. },
  2153. loadExprToInput: function () {
  2154. const sel = posSheet.getSelections()[0];
  2155. if (!sel) return;
  2156. const col = posSheet.zh_setting.cols[sel.col];
  2157. const cell = posSheet.getCell(sel.col, sel.col);
  2158. if (col && col.field === 'camount') {
  2159. const data = SpreadJsObj.getSelectObject(posSheet);
  2160. if (data) {
  2161. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  2162. if (!cInfo) {
  2163. $('#pos-expr').val('').attr('readOnly', true);
  2164. $('#pos-expr').removeAttr('data-row');
  2165. } else {
  2166. const value = cInfo.camount_expr ? cInfo.camount_expr : cInfo.camount;
  2167. $('#pos-expr').val(value).attr('field', col.field).attr('org', cInfo.camount)
  2168. .attr('readOnly', posCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  2169. }
  2170. } else {
  2171. $('#pos-expr').val('').attr('readOnly', true);
  2172. $('#pos-expr').removeAttr('data-row');
  2173. }
  2174. } else if (col && col.type === 'Number') {
  2175. const data = SpreadJsObj.getSelectObject(posSheet);
  2176. if (data) {
  2177. const exprInfo = getExprInfo(col.field);
  2178. const value = exprInfo
  2179. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  2180. : data[col.field];
  2181. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2182. .attr('readOnly', readOnly || !data.formc || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  2183. } else {
  2184. $('#pos-expr').val('').attr('readOnly', true);
  2185. $('#pos-expr').removeAttr('data-row');
  2186. }
  2187. } else {
  2188. $('#pos-expr').val('').attr('readOnly', true);
  2189. $('#pos-expr').removeAttr('data-row');
  2190. }
  2191. },
  2192. /**
  2193. * 加载计量单元 根据当前台账选择节点
  2194. */
  2195. loadCurPosData: function () {
  2196. const node = SpreadJsObj.getSelectObject(billsSheet);
  2197. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  2198. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  2199. if (node) {
  2200. const posData = pos.getLedgerPos(node.id) || [];
  2201. console.log(posData);
  2202. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  2203. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  2204. } else {
  2205. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  2206. posSheet.zh_setting.readOnly = true;
  2207. }
  2208. SpreadJsObj.massOperationSheet(posSheet, function () {
  2209. if (posSheet.zh_setting) {
  2210. posSheet.zh_setting.cols.forEach(function (col, i) {
  2211. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  2212. if (i !== 0 && col.field !== 'camount' && col.field !== 'is_valuation') {
  2213. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  2214. } else {
  2215. let lock = false;
  2216. if (!posSheet.zh_data[iRow]) {
  2217. lock = true;
  2218. }
  2219. if (col.field === 'camount' && posCol.readOnly.isSettle(posSheet.zh_data[iRow])) {
  2220. lock = true;
  2221. }
  2222. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  2223. }
  2224. }
  2225. });
  2226. }
  2227. });
  2228. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  2229. posSpreadObj.loadExprToInput();
  2230. posSpreadObj.refreshOperationValid(posSheet);
  2231. },
  2232. baseOpr: function (sheet, type) {
  2233. const data = {
  2234. postType: 'pos',
  2235. posPostType: type === 'delete' ? type : 'update',
  2236. postData: [],
  2237. };
  2238. const selection = sheet.getSelections();
  2239. const row = selection[0].row, count = selection[0].rowCount;
  2240. const first = sheet.zh_data[row];
  2241. if (type === 'delete') {
  2242. for (let iRow = 0; iRow < count; iRow++) {
  2243. const posData = sheet.zh_data[iRow + row];
  2244. if (posData) {
  2245. if (posData.used) {
  2246. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2247. return;
  2248. }
  2249. if (posData.settle_status) {
  2250. toastr.error('"' + posData.name + '"已结算,请勿删除');
  2251. return;
  2252. }
  2253. data.postData.push(sheet.zh_data[iRow + row].id);
  2254. }
  2255. }
  2256. } else if (type === 'up-move') {
  2257. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  2258. for (let iRow = 0; iRow < count; iRow++) {
  2259. const posData = sheet.zh_data[iRow + row];
  2260. if (posData) {
  2261. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  2262. preUpdate.porder = posData.porder;
  2263. }
  2264. }
  2265. data.postData.push(preUpdate);
  2266. } else if (type === 'down-move') {
  2267. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  2268. for (let iRow = count - 1; iRow >= 0; iRow--) {
  2269. const posData = sheet.zh_data[iRow + row];
  2270. if (posData) {
  2271. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  2272. nextUpdate.porder = posData.porder;
  2273. }
  2274. }
  2275. data.postData.push(nextUpdate);
  2276. } else if (type === 'add') {
  2277. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2278. if (billsNode.settle_status === settleStatus.finish) {
  2279. toastr.warning('清单已结算,不可新增计量单元');
  2280. return;
  2281. }
  2282. }
  2283. if (data.postData.length > 0) {
  2284. postData(window.location.pathname + '/update', data, function (result) {
  2285. changeList = result.changeList;
  2286. if (type === 'delete') {
  2287. pos.removeDatas(result.pos);
  2288. sheet.deleteRows(row, count);
  2289. const loadResult = billsTree.loadPostData(result.ledger);
  2290. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2291. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2292. posSpreadObj.refreshOperationValid(posSheet);
  2293. } else {
  2294. pos.updateDatas(result.pos);
  2295. const sel = selection[0];
  2296. if (sel) {
  2297. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  2298. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  2299. }
  2300. posSpreadObj.loadCurPosData();
  2301. }
  2302. });
  2303. }
  2304. },
  2305. editStarting: function (e, info) {
  2306. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2307. const sel = info.sheet.getSelections();
  2308. if (!sel || !sel[0]) return;
  2309. const col = info.sheet.zh_setting.cols[sel[0].col];
  2310. const node = SpreadJsObj.getSelectObject(info.sheet);
  2311. const exprInfo = getExprInfo(col.field);
  2312. if (col.field === 'camount') {
  2313. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  2314. if (!cInfo) {
  2315. toastr.error('未勾选变更清单,无法编辑申请数量');
  2316. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2317. return;
  2318. }
  2319. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  2320. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  2321. }
  2322. } else if (node && exprInfo) {
  2323. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2324. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2325. }
  2326. }
  2327. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  2328. info.cancel = true;
  2329. }
  2330. },
  2331. buttonClicked: function (e, info) {
  2332. if (info.sheet.zh_setting) {
  2333. const select = SpreadJsObj.getSelectObject(info.sheet);
  2334. const col = info.sheet.zh_setting.cols[info.col];
  2335. if (col.field === 'is_change') {
  2336. if (posCol.readOnly.isChangeList(select)) {
  2337. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  2338. return
  2339. }
  2340. if (info.sheet.isEditing()) {
  2341. info.sheet.endEdit(true);
  2342. }
  2343. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2344. // const valutaionCol = _.findIndex(info.sheet.zh_setting.cols, { field: 'is_valuation' });
  2345. if (is_change) {
  2346. makeGclGatherData();
  2347. const gclInfo = _.find(gclGatherData, function (item) {
  2348. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  2349. });
  2350. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  2351. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  2352. const data = {
  2353. lid: select.lid,
  2354. code: gclInfo.b_code,
  2355. name: gclInfo.name || '',
  2356. unit: gclInfo.unit || '',
  2357. unit_price: gclInfo.unit_price,
  2358. oamount: xmjInfo.quantity,
  2359. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2360. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2361. xmj_code: xmjInfo.code || '',
  2362. xmj_jldy: xmjInfo.jldy || '',
  2363. xmj_dwgc: xmjInfo.dwgc || '',
  2364. xmj_fbgc: xmjInfo.fbgc || '',
  2365. xmj_fxgc: xmjInfo.fxgc || '',
  2366. gcl_id: select.lid,
  2367. mx_id: select.id,
  2368. }
  2369. if (oldCInfo) {
  2370. data.detail = oldCInfo.detail;
  2371. data.camount = oldCInfo.camount;
  2372. data.camount_expr = oldCInfo.camount_expr;
  2373. data.spamount = oldCInfo.spamount;
  2374. data.is_valuation = oldCInfo.is_valuation;
  2375. data.delimit = oldCInfo.delimit;
  2376. }
  2377. // 更新至服务器
  2378. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  2379. changeList = result.changeList;
  2380. select.is_change = 1;
  2381. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  2382. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2383. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2384. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  2385. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2386. billsNode.is_change = 1;
  2387. billsTreeSpreadObj.reCalcCamount(billsNode);
  2388. const loadResult = { update: [billsNode] };
  2389. const refreshNode = billsTree.loadPostData(loadResult);
  2390. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2391. }
  2392. }, function () {
  2393. info.sheet.setValue(info.row, info.col, 0);
  2394. });
  2395. } else {
  2396. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  2397. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  2398. info.sheet.setValue(info.row, info.col, 1);
  2399. return
  2400. }
  2401. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2402. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  2403. toastr.warning('该计量单元已被使用,无法取消变更');
  2404. info.sheet.setValue(info.row, info.col, 1);
  2405. return
  2406. } else if (checkIsSettle(cInfo)) {
  2407. toastr.warning('该计量单元已结算,无法取消变更');
  2408. info.sheet.setValue(info.row, info.col, 1);
  2409. return
  2410. } else {
  2411. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  2412. changeList = result.changeList;
  2413. select.is_change = 0;
  2414. select.is_valuation = 0;
  2415. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2416. // info.sheet.setValue(info.row, valutaionCol, 0);
  2417. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2418. billsTreeSpreadObj.reCalcCamount(billsNode);
  2419. // 判断是否只剩一个,并同步去勾
  2420. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  2421. billsNode.is_change = 0;
  2422. }
  2423. const loadResult = { update: [billsNode] };
  2424. const refreshNode = billsTree.loadPostData(loadResult);
  2425. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2426. }, function () {
  2427. info.sheet.setValue(info.row, info.col, 1);
  2428. });
  2429. }
  2430. }
  2431. } else if (col.field === 'is_valuation') {
  2432. if (!posCol.getValue.isChange(select)) {
  2433. toastr.warning('请先勾选变更清单才能勾选计价');
  2434. info.sheet.setValue(info.row, info.col, !select || !select.is_valuation ? 0 : 1);
  2435. return;
  2436. }
  2437. if (info.sheet.isEditing()) {
  2438. info.sheet.endEdit(true);
  2439. }
  2440. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2441. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  2442. toastr.warning('该变更清单已被调用,无法更改计价');
  2443. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  2444. return;
  2445. }
  2446. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2447. // select.is_valuation = is_valuation;
  2448. cInfo.is_valuation = is_valuation;
  2449. delete cInfo.waitingLoading;
  2450. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  2451. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2452. info.sheet.setValue(info.row, info.col, is_valuation);
  2453. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2454. SpreadJsObj.reLoadRowData(billsSheet, billsTree.getNodeIndex(billsNode));
  2455. }, function () {
  2456. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2457. cInfo.is_valuation = select.is_valuation;
  2458. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2459. });
  2460. }
  2461. }
  2462. },
  2463. /**
  2464. * 编辑单元格响应事件
  2465. * @param {Object} e
  2466. * @param {Object} info
  2467. */
  2468. editEnded: function (e, info) {
  2469. if (!info.sheet.zh_setting) {
  2470. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2471. return;
  2472. }
  2473. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  2474. const node = posSpreadObj.billsNode;
  2475. const col = info.sheet.zh_setting.cols[info.col];
  2476. if (col.field === 'is_change' || col.field === 'is_valuation') {
  2477. return;
  2478. }
  2479. if (col.field === 'camount') {
  2480. if (!node) {
  2481. toastr.error('数据错误,请选择台账节点后再试');
  2482. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2483. return;
  2484. }
  2485. const cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  2486. if (!cInfo) {
  2487. toastr.error('未勾选变更清单,无法编辑申请数量');
  2488. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2489. return;
  2490. }
  2491. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  2492. const orgValue = validText && validText !== ''
  2493. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  2494. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  2495. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2496. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2497. return;
  2498. }
  2499. const exprQuantity = {
  2500. expr: '',
  2501. quantity: 0,
  2502. };
  2503. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  2504. if (!valid) {
  2505. toastr.error(msg);
  2506. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2507. return;
  2508. }
  2509. if (isNaN(exprQuantity.quantity)) {
  2510. toastr.error('不能输入其它非数字类型字符');
  2511. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2512. return;
  2513. }
  2514. validText = parseFloat(exprQuantity.quantity);
  2515. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2516. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  2517. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2518. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2519. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2520. return;
  2521. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2522. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2523. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2524. return;
  2525. }
  2526. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2527. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2528. cInfo.camount_expr = exprQuantity.expr;
  2529. delete cInfo.waitingLoading;
  2530. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  2531. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2532. const billsNode = node;
  2533. billsTreeSpreadObj.reCalcCamount(billsNode);
  2534. const loadResult = { update: [billsNode] };
  2535. const refreshNode = billsTree.loadPostData(loadResult);
  2536. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2537. }, function () {
  2538. cInfo[col.field] = orgValue;
  2539. cInfo.spamount = orgValue;
  2540. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2541. });
  2542. return;
  2543. }
  2544. const orgText = posData ? posData[col.field] : null;
  2545. const newText = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  2546. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  2547. if (!node) {
  2548. toastr.error('数据错误,请选择台账节点后再试');
  2549. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2550. return;
  2551. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  2552. toastr.error('父节点不可插入计量单元');
  2553. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2554. return;
  2555. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  2556. toastr.error('项目节不可插入计量单元');
  2557. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2558. return;
  2559. }
  2560. const data = {postType: 'pos'};
  2561. if (col.field === 'name') {
  2562. if (newText === '' && posData) {
  2563. toastr.error('部位名称不可为空', 'error');
  2564. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2565. return;
  2566. } else if (!posData) {
  2567. if (newText && newText !== '') {
  2568. data.posPostType = 'add';
  2569. const sortData = info.sheet.zh_data;
  2570. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2571. data.postData = { name: newText, lid: node.id, porder: order};
  2572. if (node.settle_status === settleStatus.finish) {
  2573. toastr.error('已结算清单不可插入计量单元');
  2574. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2575. return;
  2576. }
  2577. } else {
  2578. return;
  2579. }
  2580. } else {
  2581. data.posPostType = 'update';
  2582. data.postData = {id: posData.id, name: newText};
  2583. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  2584. toastr.error('计量单元已结算,不可修改');
  2585. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2586. return;
  2587. }
  2588. }
  2589. } else if (!posData) {
  2590. toastr.warning('新增计量单元请先输入名称');
  2591. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2592. return;
  2593. } else {
  2594. data.posPostType = 'update';
  2595. data.postData = {id: posData.id};
  2596. if (col.type === 'Number') {
  2597. const exprInfo = getExprInfo(col.field);
  2598. const num = _.toNumber(newText);
  2599. if (_.isFinite(num)) {
  2600. data.postData[col.field] = num;
  2601. if (exprInfo) {
  2602. data.postData[exprInfo.expr] = '';
  2603. }
  2604. } else {
  2605. try {
  2606. data.postData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2607. if (exprInfo) {
  2608. data.postData[exprInfo.expr] = newText;
  2609. }
  2610. } catch(err) {
  2611. toastr.error('输入的表达式非法');
  2612. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2613. return;
  2614. }
  2615. }
  2616. } else if (col.field.indexOf('_expr') > 0) {
  2617. const exprInfo = getExprInfo(col.field, true);
  2618. if (!exprInfo) return;
  2619. if (newText) {
  2620. try {
  2621. data.postData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2622. data.postData[exprInfo.expr] = newText;
  2623. } catch(err) {
  2624. toastr.error('输入的表达式非法');
  2625. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2626. return;
  2627. }
  2628. } else {
  2629. data.postData[exprInfo.qty] = 0;
  2630. data.postData[exprInfo.expr] = '';
  2631. }
  2632. } else {
  2633. data.postData[col.field] = newText;
  2634. }
  2635. }
  2636. postData(window.location.pathname + '/update', data, function (result) {
  2637. changeList = result.changeList;
  2638. const updateRst = pos.updateDatas(result.pos);
  2639. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2640. if (updateRst.create.length > 0) {
  2641. posSpreadObj.loadCurPosData();
  2642. } else {
  2643. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2644. }
  2645. const loadResult = billsTree.loadPostData(result.ledger);
  2646. // 判断是否只剩一个,并同步去勾
  2647. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2648. // billsNode.is_change = ? 1 : 0;
  2649. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  2650. billsNode.is_change = 1;
  2651. } else {
  2652. billsNode.is_change = 0;
  2653. billsNode.is_valuation = 0;
  2654. billsNode.camount = null;
  2655. billsNode.ca_tp = null;
  2656. }
  2657. if (loadResult.update) {
  2658. const r = _.find(loadResult.update, { id: billsNode.id });
  2659. r.is_change = billsNode.is_change;
  2660. } else {
  2661. loadResult.update = [billsNode];
  2662. }
  2663. const refreshNode = billsTree.loadPostData(loadResult);
  2664. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2665. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2666. }, function () {
  2667. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2668. });
  2669. },
  2670. /**
  2671. * 删除按钮响应事件
  2672. * @param sheet
  2673. */
  2674. deletePress: function (sheet) {
  2675. if (!sheet.zh_setting) return;
  2676. const sortData = sheet.zh_data;
  2677. const datas = [], posSelects = [], camountDatas = [];
  2678. const sel = sheet.getSelections()[0];
  2679. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2680. let bDel = false;
  2681. const node = sortData[iRow];
  2682. if (node) {
  2683. const data = {id: node.id};
  2684. const cData = {};
  2685. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2686. const colSetting = sheet.zh_setting.cols[iCol];
  2687. if (colSetting.field === 'name') {
  2688. toastr.error('部位名称不能为空');
  2689. return;
  2690. }
  2691. const style = sheet.getStyle(iRow, iCol);
  2692. if (!style.locked) {
  2693. const colSetting = sheet.zh_setting.cols[iCol];
  2694. if (colSetting.field === 'camount') {
  2695. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  2696. if (!cInfo) continue;
  2697. cData.id = cInfo.id;
  2698. cData.camount = null;
  2699. cData.camount_expr = '';
  2700. cData.spamount = null;
  2701. } else if (colSetting.field.indexOf('_expr') > 0) {
  2702. const exprInfo = getExprInfo(colSetting.field, true);
  2703. if (!exprInfo) continue;
  2704. data[exprInfo.expr] = '';
  2705. data[exprInfo.qty] = 0;
  2706. } else {
  2707. data[colSetting.field] = null;
  2708. const exprInfo = getExprInfo(colSetting.field);
  2709. if (exprInfo) data[exprInfo.expr] = '';
  2710. }
  2711. bDel = true;
  2712. }
  2713. }
  2714. if (bDel) {
  2715. datas.push(data);
  2716. if (cData.id) camountDatas.push(cData);
  2717. posSelects.push(node);
  2718. }
  2719. }
  2720. }
  2721. if (camountDatas.length > 0) {
  2722. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  2723. changeList = result;
  2724. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2725. billsTreeSpreadObj.reCalcCamount(billsNode);
  2726. const loadResult = { update: [billsNode] };
  2727. const refreshNode = billsTree.loadPostData(loadResult);
  2728. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2729. posSpreadObj.loadCurPosData();
  2730. }, function () {
  2731. posSpreadObj.loadCurPosData();
  2732. });
  2733. return;
  2734. }
  2735. if (datas.length > 0) {
  2736. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  2737. changeList = result.changeList;
  2738. pos.updateDatas(result.pos);
  2739. posSpreadObj.loadCurPosData();
  2740. const loadResult = billsTree.loadPostData(result.ledger);
  2741. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2742. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2743. }, function () {
  2744. posSpreadObj.loadCurPosData();
  2745. });
  2746. }
  2747. },
  2748. /**
  2749. * 删除 计量单元
  2750. * @param sheet
  2751. */
  2752. deletePos: function (sheet) {
  2753. const selection = sheet.getSelections();
  2754. const data = {
  2755. postType: 'pos',
  2756. posPostType: 'delete',
  2757. postData: [],
  2758. };
  2759. const row = selection[0].row, count = selection[0].rowCount;
  2760. const sortData = sheet.zh_data;
  2761. for (let iRow = 0; iRow < count; iRow++) {
  2762. const posData = sortData[iRow + row];
  2763. if (posData) {
  2764. if (posData.used) {
  2765. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2766. return;
  2767. }
  2768. if (posData.settle_status === settleStatus.finish) {
  2769. toastr.error(`"${posData.name}"已计量,请勿删除`);
  2770. return;
  2771. }
  2772. data.postData.push(sortData[iRow + row].id);
  2773. }
  2774. }
  2775. if (data.postData.length > 0) {
  2776. postData(window.location.pathname + '/update', data, function (result) {
  2777. changeList = result.changeList;
  2778. pos.removeDatas(result.pos);
  2779. sheet.deleteRows(row, count);
  2780. const loadResult = billsTree.loadPostData(result.ledger);
  2781. // 判断是否只剩一个,并同步去勾
  2782. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2783. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  2784. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  2785. billsNode.is_change = 1;
  2786. } else {
  2787. billsNode.is_change = 0;
  2788. billsNode.is_valuation = 0;
  2789. billsNode.camount = null;
  2790. billsNode.ca_tp = null;
  2791. }
  2792. if (loadResult.update) {
  2793. const r = _.find(loadResult.update, { id: billsNode.id });
  2794. r.is_change = billsNode.is_change;
  2795. } else {
  2796. loadResult.update = [billsNode];
  2797. }
  2798. billsTreeSpreadObj.reCalcCamount(billsNode);
  2799. const refreshNode = billsTree.loadPostData(loadResult);
  2800. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2801. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2802. });
  2803. }
  2804. },
  2805. /**
  2806. * 粘贴单元格响应事件
  2807. * @param e
  2808. * @param info
  2809. */
  2810. clipboardPasted: function (e, info) {
  2811. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2812. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2813. }
  2814. const node = SpreadJsObj.getSelectObject(billsSheet);
  2815. if (node.code && (node.code !== '')) {
  2816. toastr.error('项目节不可含有节点明细');
  2817. posSpreadObj.loadCurPosData();
  2818. return;
  2819. }
  2820. if (node.children && (node.children.length > 0)) {
  2821. toastr.error('仅节点子项可以含有计量单元');
  2822. posSpreadObj.loadCurPosData();
  2823. return;
  2824. }
  2825. if (node.settle_status === settleStatus.finish) {
  2826. toastr.error('清单已结算,请勿修改计量单元数据');
  2827. posSpread.loadCurPosData();
  2828. return;
  2829. }
  2830. if (!info.sheet.zh_setting) {
  2831. posSpreadObj.loadCurPosData();
  2832. return;
  2833. }
  2834. const data = [];
  2835. const camountData = [];
  2836. const sortData = info.sheet.zh_data || [];
  2837. const hint = {
  2838. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2839. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  2840. };
  2841. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  2842. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  2843. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  2844. toastr.warning('新增计量单元请先输入名称');
  2845. posSpreadObj.loadCurPosData();
  2846. return;
  2847. }
  2848. }
  2849. let bHint = false;
  2850. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2851. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2852. let bPaste = true;
  2853. const curRow = info.cellRange.row + iRow;
  2854. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2855. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2856. const curCol = info.cellRange.col + iCol;
  2857. const colSetting = info.sheet.zh_setting.cols[curCol];
  2858. if (!colSetting) continue;
  2859. posData[colSetting.field] = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  2860. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  2861. bPaste = false;
  2862. toastMessageUniq(hint.settle);
  2863. continue;
  2864. }
  2865. if (colSetting.field === 'camount') {
  2866. bPaste = true;
  2867. let validText = posData[colSetting.field];
  2868. const cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  2869. if (!cInfo) {
  2870. bPaste = false;
  2871. continue;
  2872. }
  2873. const exprQuantity = {
  2874. expr: '',
  2875. quantity: 0,
  2876. };
  2877. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  2878. if (!valid) {
  2879. toastMessageUniq(hint.expr);
  2880. bPaste = false;
  2881. continue;
  2882. }
  2883. if (isNaN(exprQuantity.quantity)) {
  2884. toastMessageUniq(hint.expr);
  2885. bPaste = false;
  2886. continue;
  2887. }
  2888. validText = parseFloat(exprQuantity.quantity);
  2889. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2890. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  2891. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2892. toastr.error(curRow ? '计量单元第' + (curRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2893. bPaste = false;
  2894. continue;
  2895. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2896. toastr.error(curRow ? '计量单元第' + (curRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2897. bPaste = false;
  2898. continue;
  2899. }
  2900. if (bPaste) {
  2901. 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 });
  2902. } else {
  2903. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  2904. }
  2905. continue;
  2906. }
  2907. if (colSetting.type === 'Number') {
  2908. const num = _.toNumber(posData[colSetting.field]);
  2909. if (num) {
  2910. posData[colSetting.field] = num;
  2911. } else {
  2912. try {
  2913. posData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(posData[colSetting.field]));
  2914. const exprInfo = getExprInfo(colSetting.field);
  2915. if (exprInfo) {
  2916. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2917. }
  2918. } catch (err) {
  2919. if (!bHint) {
  2920. toastr.warning('粘贴了非法表达式,已过滤');
  2921. bHint = true;
  2922. }
  2923. bPaste = false;
  2924. }
  2925. }
  2926. } else if (colSetting.field.indexOf('_expr') > 0) {
  2927. try {
  2928. const exprInfo = getExprInfo(colSetting.field, true);
  2929. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2930. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  2931. posData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(posData[exprInfo.expr]));
  2932. }
  2933. bPaste = true;
  2934. } catch (err) {
  2935. toastMessageUniq(hint.expr);
  2936. }
  2937. } else {
  2938. bPaste = true;
  2939. }
  2940. }
  2941. if (bPaste) {
  2942. data.push(posData);
  2943. }
  2944. }
  2945. if (camountData.length > 0) {
  2946. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountData }, function (result) {
  2947. changeList = result;
  2948. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2949. billsTreeSpreadObj.reCalcCamount(billsNode);
  2950. const loadResult = { update: [billsNode] };
  2951. const refreshNode = billsTree.loadPostData(loadResult);
  2952. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2953. posSpreadObj.loadCurPosData();
  2954. }, function () {
  2955. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2956. return;
  2957. });
  2958. return;
  2959. }
  2960. if (data.length === 0) {
  2961. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2962. return;
  2963. }
  2964. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  2965. changeList = result.changeList;
  2966. pos.updateDatas(result.pos);
  2967. posSpreadObj.loadCurPosData();
  2968. const loadResult = result.ledger;
  2969. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2970. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  2971. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  2972. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  2973. billsNode.is_change = 1;
  2974. } else {
  2975. billsNode.is_change = 0;
  2976. billsNode.is_valuation = 0;
  2977. billsNode.camount = null;
  2978. billsNode.ca_tp = null;
  2979. }
  2980. if (loadResult.update) {
  2981. const r = _.find(loadResult.update, { id: billsNode.id });
  2982. r.is_change = billsNode.is_change;
  2983. } else {
  2984. loadResult.update = [billsNode];
  2985. }
  2986. billsTreeSpreadObj.reCalcCamount(billsNode);
  2987. const refreshNode = billsTree.loadPostData(loadResult);
  2988. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2989. posSpreadObj.loadCurPosData();
  2990. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2991. }, function () {
  2992. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2993. });
  2994. },
  2995. selectionChanged: function (e, info) {
  2996. posSpreadObj.loadExprToInput();
  2997. posSpreadObj.refreshOperationValid(posSheet);
  2998. },
  2999. addPegs: function (pegs) {
  3000. if (!pegs || pegs.length <= 0) return;
  3001. const node = SpreadJsObj.getSelectObject(billsSheet);
  3002. if (!node) return;
  3003. const sheet = posSpread.getActiveSheet();
  3004. const sortData = sheet.zh_data || [];
  3005. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3006. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  3007. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  3008. changeList = result.changeList;
  3009. pos.updateDatas(result.pos);
  3010. posSpreadObj.loadCurPosData();
  3011. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3012. });
  3013. }
  3014. };
  3015. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  3016. if (!readOnly) {
  3017. $('a[name="pos-opr"]').click(function () {
  3018. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  3019. });
  3020. $('#pos-expr').bind('change onblur', function () {
  3021. if (this.readOnly) return;
  3022. const expr = $(this);
  3023. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  3024. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  3025. if (!select) return;
  3026. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3027. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  3028. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  3029. if (field === 'camount') {
  3030. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  3031. if (!cInfo) {
  3032. toastr.error('未勾选变更清单,无法编辑申请数量');
  3033. return;
  3034. }
  3035. const exprQuantity = {
  3036. expr: '',
  3037. quantity: 0,
  3038. };
  3039. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  3040. if (!valid) {
  3041. toastr.error(msg);
  3042. return;
  3043. }
  3044. if (isNaN(exprQuantity.quantity)) {
  3045. toastr.error('不能输入其它非数字类型字符');
  3046. return;
  3047. }
  3048. const camount = parseFloat(exprQuantity.quantity);
  3049. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3050. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  3051. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3052. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3053. return;
  3054. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3055. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3056. return;
  3057. }
  3058. cInfo.camount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3059. cInfo.spamount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3060. cInfo.camount_expr = exprQuantity.expr;
  3061. delete cInfo.waitingLoading;
  3062. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  3063. SpreadJsObj.reLoadRowData(posSheet, row);
  3064. billsTreeSpreadObj.reCalcCamount(billsNode);
  3065. const loadResult = { update: [billsNode] };
  3066. const refreshNode = billsTree.loadPostData(loadResult);
  3067. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3068. posSpreadObj.loadExprToInput(posSheet);
  3069. }, function () {
  3070. cInfo.camount = orgValue;
  3071. cInfo.spamount = orgValue;
  3072. SpreadJsObj.reLoadRowData(posSheet, row);
  3073. });
  3074. return;
  3075. }
  3076. const data = {id: select.id};
  3077. const exprInfo = getExprInfo(field);
  3078. if (newValue !== '') {
  3079. const num = _.toNumber(newValue);
  3080. if (num) {
  3081. data[field] = num;
  3082. if (exprInfo) data[exprInfo.expr] = '';
  3083. } else {
  3084. try {
  3085. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  3086. if (exprInfo) data[exprInfo.expr] = newValue;
  3087. } catch (err) {
  3088. toastr.error('输入的表达式非法');
  3089. return;
  3090. }
  3091. }
  3092. } else {
  3093. data[field] = null;
  3094. if (exprInfo) data[exprInfo.expr] = '';
  3095. }
  3096. // 更新至服务器
  3097. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  3098. changeList = result.changeList;
  3099. const updateRst = pos.updateDatas(result.pos);
  3100. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  3101. SpreadJsObj.reLoadRowData(posSheet, row);
  3102. const loadResult = billsTree.loadPostData(result.ledger);
  3103. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3104. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3105. });
  3106. });
  3107. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  3108. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  3109. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  3110. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  3111. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  3112. $.contextMenu({
  3113. selector: '#pos-spread',
  3114. build: function ($trigger, e) {
  3115. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  3116. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3117. },
  3118. items: {
  3119. 'delete': {
  3120. name: '删除',
  3121. icon: 'fa-remove',
  3122. disabled: function (key, opt) {
  3123. if (posSheet.zh_data) {
  3124. const selection = posSheet.getSelections();
  3125. const sel = selection ? selection[0] : sheet.getSelections()[0];
  3126. const row = sel ? sel.row : -1;
  3127. const rowCount = sel.rowCount;
  3128. let settleFinish = false;
  3129. for (let i = row; i < row + rowCount; i++) {
  3130. if (!posSheet.zh_data[i]) continue;
  3131. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  3132. }
  3133. 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;
  3134. } else {
  3135. return true;
  3136. }
  3137. },
  3138. callback: function (key, opt) {
  3139. posSpreadObj.deletePos(posSheet);
  3140. }
  3141. },
  3142. }
  3143. });
  3144. }
  3145. // 加载清单&计量单元数据
  3146. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  3147. let gclGatherData;
  3148. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  3149. for (const b of result.bills) {
  3150. if (!(b.is_leaf && b.b_code)) {
  3151. b.is_change = 0;
  3152. b.is_valutaion = 0;
  3153. } else {
  3154. const cInfo = _.find(changeList, { gcl_id: b.id });
  3155. b.is_change = cInfo ? 1 : 0;
  3156. b.is_valuation = cInfo ? cInfo.is_valuation : 0;
  3157. b.camount = cInfo ? cInfo.camount : 0;
  3158. }
  3159. }
  3160. billsTree.loadDatas(result.bills);
  3161. pos.loadDatas(result.pos);
  3162. treeCalc.calculateAll(billsTree);
  3163. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  3164. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  3165. checkShowLast(result.bills.length);
  3166. posSpreadObj.loadCurPosData();
  3167. SpreadJsObj.resetTopAndSelect(posSheet);
  3168. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3169. billsTreeSpreadObj.loadExprToInput(billsSheet);
  3170. checkList.loadHisCheckData();
  3171. console.log(billsTree);
  3172. }, null);
  3173. $.divResizer({
  3174. select: '#revise-resize',
  3175. callback: function () {
  3176. billsSpread.refresh();
  3177. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  3178. $(".sp-wrap").height(bcontent-30);
  3179. posSpread.refresh();
  3180. }
  3181. });
  3182. function makeGclGatherData() {
  3183. gclGatherModel.loadLedgerData(billsTree.datas);
  3184. gclGatherModel.loadPosData(pos.datas);
  3185. gclGatherData = gclGatherModel.gatherGclData();
  3186. gclGatherData = _.filter(gclGatherData, function (item) {
  3187. return item.leafXmjs && item.leafXmjs.length !== 0;
  3188. });
  3189. gclGatherData = gclGatherData.sort(sortByCode);
  3190. }
  3191. class DealBills {
  3192. constructor (selector, spreadSetting) {
  3193. const self = this;
  3194. this.loaded = false;
  3195. this.obj = $(selector)[0];
  3196. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3197. this.spreadSetting = spreadSetting;
  3198. this.spread = SpreadJsObj.createNewSpread(this.obj);
  3199. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3200. if (!readOnly) {
  3201. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3202. const dealSheet = info.sheet;
  3203. const mainSheet = billsSheet;
  3204. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3205. if (!dealBills) { return; }
  3206. const mainTree = mainSheet.zh_tree;
  3207. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3208. if (!mainNode || !mainTree) { return; }
  3209. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3210. toastr.warning('非最底层项目下,不应添加节点');
  3211. return;
  3212. }
  3213. if (mainNode.settle_status === settleStatus.finish) {
  3214. toastr.warning('已结算节点下,不应添加签约清单');
  3215. return;
  3216. }
  3217. postData(window.location.pathname + '/update', {
  3218. postType: 'add-deal',
  3219. postData: {
  3220. id: mainNode.ledger_id,
  3221. type: mainNode.code ? 'child' : 'next',
  3222. dealBills: {
  3223. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3224. unit_price: dealBills.unit_price,
  3225. }
  3226. },
  3227. }, function (result) {
  3228. changeList = result.changeList;
  3229. const refreshData = mainTree.loadPostData(result);
  3230. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3231. const sel = mainSheet.getSelections()[0];
  3232. if (sel && refreshData.create[0]) {
  3233. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3234. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3235. }
  3236. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3237. billsSpread.focus();
  3238. posSpreadObj.loadCurPosData();
  3239. });
  3240. });
  3241. }
  3242. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3243. }
  3244. loadData (callback) {
  3245. if (this.loaded) {
  3246. if (callback) callback();
  3247. return;
  3248. }
  3249. const self = this;
  3250. postData(this.url+'/get-data', {}, function (data) {
  3251. self.data = data;
  3252. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3253. self.loaded = true;
  3254. if (callback) callback();
  3255. });
  3256. }
  3257. calculateData () {
  3258. if (this.data) {
  3259. for (const d of this.data) {
  3260. d.total_price = _.multiply(d.quantity, d.unit_price);
  3261. }
  3262. }
  3263. }
  3264. }
  3265. class BatchInsertBillsPosObj {
  3266. constructor (obj) {
  3267. const self = this;
  3268. this.obj = obj;
  3269. this.billsCount = 6;
  3270. this.posCount = 1000;
  3271. this.filter = getLocalCache('zh-calc-batch-filter');
  3272. if (!this.filter) {
  3273. this.filter = '1';
  3274. }
  3275. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  3276. // 初始化 清单编号窗口 参数
  3277. this.qdSpreadSetting = {
  3278. cols: [
  3279. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3280. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  3281. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3282. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3283. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  3284. ],
  3285. emptyRows: this.billsCount,
  3286. headRows: 1,
  3287. headRowHeight: [32],
  3288. headerFont: '12px 微软雅黑',
  3289. font: '12px 微软雅黑',
  3290. };
  3291. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  3292. // 初始化 部位数量复核表 参数
  3293. this.posSpreadSetting = {
  3294. cols: [
  3295. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  3296. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  3297. ],
  3298. emptyRows: this.posCount,
  3299. headRows: 1,
  3300. headRowHeight: [32],
  3301. headerFont: '12px 微软雅黑',
  3302. font: '12px 微软雅黑',
  3303. };
  3304. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  3305. this.posSpreadSetting.cols.push(
  3306. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  3307. )
  3308. }
  3309. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  3310. // 初始化 签约节点 参数
  3311. this.dealSpreadSetting = {
  3312. cols: [
  3313. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  3314. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  3315. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3316. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  3317. ],
  3318. emptyRows: 0,
  3319. headRows: 1,
  3320. headRowHeight: [32],
  3321. headerFont: '12px 微软雅黑',
  3322. font: '12px 微软雅黑',
  3323. };
  3324. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  3325. // 初始化 清单编号、部位数量复核表 表格
  3326. this.initView();
  3327. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  3328. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  3329. // 拉取签约节点数据
  3330. dealBills.loadData(() => {
  3331. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3332. });
  3333. // 双击签约节点,自动添加到清单编号窗口
  3334. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  3335. const deal = info.sheet.zh_data[info.row];
  3336. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  3337. const sel = qdSheet.getSelections()[0];
  3338. qdSheet.getCell(sel.row, 0).value(deal.code);
  3339. qdSheet.getCell(sel.row, 1).value(deal.name);
  3340. qdSheet.getCell(sel.row, 2).value(deal.unit);
  3341. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  3342. if (sel.row + 1 === qdSheet.getRowCount()) {
  3343. const count = sel.row + 2;
  3344. qdSheet.setRowCount(count);
  3345. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  3346. const colCount = posSheet.getColumnCount() + 1;
  3347. posSheet.setColumnCount(colCount);
  3348. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  3349. }
  3350. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  3351. qdSheet.getParent().focus();
  3352. });
  3353. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3354. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  3355. const count = posSheet.getColumnCount() - 2;
  3356. if (billsCount > count) {
  3357. posSheet.setColumnCount(billsCount + 2);
  3358. for (let i = count + 1; i <= billsCount; i++) {
  3359. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3360. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3361. }
  3362. }
  3363. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  3364. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3365. if (dealBills && dealBills.length > 0) {
  3366. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3367. const curRow = iRow + info.cellRange.row;
  3368. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  3369. if (bills) {
  3370. info.sheet.getCell(curRow, 1).value(bills.name);
  3371. info.sheet.getCell(curRow, 2).value(bills.unit);
  3372. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  3373. }
  3374. }
  3375. }
  3376. }
  3377. });
  3378. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3379. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  3380. const count = qdSheet.getRowCount();
  3381. if (billsCount > count) {
  3382. qdSheet.setRowCount(billsCount);
  3383. for (let i = count + 1; i <= billsCount; i++) {
  3384. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3385. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3386. }
  3387. }
  3388. });
  3389. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  3390. if (info.col === 0) {
  3391. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3392. if (dealBills && dealBills.length > 0) {
  3393. const bills = _.find(dealBills, {code: info.editingText});
  3394. if (bills) {
  3395. info.sheet.getCell(info.row, 1).value(bills.name);
  3396. info.sheet.getCell(info.row, 2).value(bills.unit);
  3397. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  3398. }
  3399. }
  3400. }
  3401. });
  3402. this.obj.bind('shown.bs.modal', function () {
  3403. self.qdSpread.refresh();
  3404. self.posSpread.refresh();
  3405. self.dealSpread.refresh();
  3406. });
  3407. $('#batch-ok').click(function () {
  3408. const selection = billsSheet.getSelections();
  3409. const sel = selection[0];
  3410. const row = selection[0].row;
  3411. const select = billsTree.nodes[row];
  3412. if (select) {
  3413. const insertData = {};
  3414. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3415. insertData.id = select[billsTree.setting.id];
  3416. insertData.batchData = self.getBatchData();
  3417. if (insertData.batchData.length > 0) {
  3418. postData(window.location.pathname + '/update', {
  3419. postType: 'batch-insert',
  3420. postData: insertData
  3421. }, function (data) {
  3422. changeList = result.changeList;
  3423. pos.updateDatas(data.pos);
  3424. const result = billsTree.loadPostData(data.ledger);
  3425. billsTreeSpreadObj.refreshTree(billsSheet, result);
  3426. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3427. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  3428. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  3429. posSpreadObj.loadCurPosData();
  3430. self.obj.modal('hide');
  3431. }, null, true);
  3432. } else {
  3433. self.obj.modal('hide');
  3434. }
  3435. }
  3436. });
  3437. $('input[name=batch-filter]').change(function () {
  3438. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3439. });
  3440. $.contextMenu({
  3441. selector: '.batch-l-t',
  3442. build: function ($trigger, e) {
  3443. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  3444. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3445. },
  3446. items: {
  3447. 'create': {
  3448. name: '新增行',
  3449. icon: 'fa-sign-in',
  3450. callback: function (key, opt) {
  3451. const qdSheet = self.qdSpread.getActiveSheet();
  3452. const posSheet = self.posSpread.getActiveSheet();
  3453. qdSheet.addRows(qdSheet.getRowCount(), 1);
  3454. const index = qdSheet.getRowCount();
  3455. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  3456. posSheet.addColumns(posSheet.getColumnCount(), 1);
  3457. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  3458. },
  3459. },
  3460. 'delete': {
  3461. name: '删除行',
  3462. icon: 'fa-remove',
  3463. callback: function (key, opt) {
  3464. const qdSheet = self.qdSpread.getActiveSheet();
  3465. const posSheet = self.posSpread.getActiveSheet();
  3466. const sel = qdSheet.getSelections()[0];
  3467. qdSheet.deleteRows(sel.row, sel.rowCount);
  3468. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  3469. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  3470. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  3471. }
  3472. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  3473. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  3474. }
  3475. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  3476. },
  3477. },
  3478. }
  3479. });
  3480. }
  3481. // 初始化左侧表格
  3482. initView () {
  3483. // 初始化 清单编号
  3484. const qdSheet = this.qdSpread.getActiveSheet();
  3485. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3486. SpreadJsObj.refreshColumnAlign(qdSheet);
  3487. // 清理原有数据
  3488. SpreadJsObj.beginMassOperation(qdSheet);
  3489. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3490. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3491. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3492. }
  3493. qdSheet.setSelection(0, 0, 1 ,1);
  3494. SpreadJsObj.endMassOperation(qdSheet);
  3495. // 初始化 部位数量复核表
  3496. const posSheet = this.posSpread.getActiveSheet();
  3497. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3498. SpreadJsObj.refreshColumnAlign(posSheet);
  3499. // 清理原有数据
  3500. SpreadJsObj.beginMassOperation(posSheet);
  3501. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3502. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3503. posSheet.setSelection(0, 0, 1 ,1);
  3504. SpreadJsObj.endMassOperation(posSheet);
  3505. // 检查签约节点数据,以工具栏数据为准
  3506. if (dealBills) {
  3507. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3508. }
  3509. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3510. }
  3511. // 获取界面数据
  3512. getBatchData () {
  3513. const result = [];
  3514. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3515. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3516. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3517. const qd = {
  3518. b_code: qdSheet.getText(iRow, 0),
  3519. name: qdSheet.getText(iRow, 1),
  3520. unit: qdSheet.getText(iRow, 2),
  3521. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3522. pos: [],
  3523. };
  3524. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3525. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3526. if (value !== 0 && !isNaN(value)) {
  3527. qd.pos.push({
  3528. name: posSheet.getText(iPosRow, 0),
  3529. drawing_code: posSheet.getText(iPosRow, 1),
  3530. quantity: value, porder: qd.pos.length + 1,
  3531. });
  3532. }
  3533. }
  3534. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  3535. }
  3536. return result;
  3537. }
  3538. }
  3539. const dealBills = new DealBills('#deal-bills-spread', {
  3540. cols: [
  3541. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  3542. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3543. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3544. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  3545. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  3546. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  3547. ],
  3548. emptyRows: 0,
  3549. headRows: 1,
  3550. headRowHeight: [32],
  3551. headColWidth: [30],
  3552. defaultRowHeight: 21,
  3553. headerFont: '12px 微软雅黑',
  3554. font: '12px 微软雅黑',
  3555. selectedBackColor: '#fffacd',
  3556. });
  3557. class Jlzf {
  3558. constructor (selector, spreadSetting) {
  3559. const self = this;
  3560. this.loaded = false;
  3561. this.obj = $(selector);
  3562. const relaSelect = {
  3563. showLevel: `cb-${spreadSetting.stdType}-sl`,
  3564. searchText: `cb-${spreadSetting.stdType}-st`,
  3565. searchResult: `cb-${spreadSetting.stdType}-sr`,
  3566. searchPre: `cb-${spreadSetting.stdType}-sp`,
  3567. searchNext: `cb-${spreadSetting.stdType}-sn`,
  3568. searchClose: `cb-${spreadSetting.stdType}-sc`,
  3569. };
  3570. this.obj.html(
  3571. '<div class="sjs-bar d-flex">\n' +
  3572. ' <div class="ml-1">\n' +
  3573. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  3574. ' <div class="d-inline-block">\n' +
  3575. ' <div class="input-group input-group-sm mr-1">' +
  3576. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  3577. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  3578. ' <div class="input-group-append" >\n' +
  3579. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  3580. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  3581. ' </div>\n' +
  3582. ' </div>\n' +
  3583. ' </div>\n' +
  3584. ` <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` +
  3585. ' </div>\n' +
  3586. ' </div>' +
  3587. '</div>\n' +
  3588. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  3589. );
  3590. autoFlashHeight();
  3591. const sh = `.cb-${spreadSetting.stdType}-sh`;
  3592. function getObjHeight(select) {
  3593. return select.length > 0 ? select.height() : 0;
  3594. }
  3595. const cHeader = getObjHeight($(".c-header"));
  3596. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  3597. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3598. this.spreadSetting = spreadSetting;
  3599. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  3600. const searchSheet = this.spread.getActiveSheet();
  3601. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  3602. if (!readOnly) {
  3603. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3604. const dealSheet = info.sheet;
  3605. const mainSheet = billsSheet;
  3606. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3607. if (!dealBills) { return; }
  3608. const mainTree = mainSheet.zh_tree;
  3609. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3610. if (!mainNode || !mainTree) { return; }
  3611. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3612. toastr.warning('非最底层项目下,不应添加节点');
  3613. return;
  3614. }
  3615. if (mainNode.settle_status === settleStatus.finish) {
  3616. toastr.warning('已结算节点下,不应添加签约清单');
  3617. return;
  3618. }
  3619. postData(window.location.pathname + '/update', {
  3620. postType: 'add-deal',
  3621. postData: {
  3622. id: mainNode.ledger_id,
  3623. type: mainNode.code ? 'child' : 'next',
  3624. dealBills: {
  3625. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3626. unit_price: dealBills.unit_price,
  3627. }
  3628. },
  3629. }, function (result) {
  3630. changeList = result.changeList;
  3631. const refreshData = mainTree.loadPostData(result);
  3632. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3633. const sel = mainSheet.getSelections()[0];
  3634. if (sel && refreshData.create[0]) {
  3635. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3636. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3637. }
  3638. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3639. billsSpread.focus();
  3640. posSpreadObj.loadCurPosData();
  3641. });
  3642. });
  3643. }
  3644. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3645. const searchObj = {
  3646. result: [],
  3647. cur: 0,
  3648. searchStdNode: function() {
  3649. const keyword = $(`#${relaSelect.searchText}`).val();
  3650. const sortData = SpreadJsObj.getSortData(searchSheet);
  3651. searchObj.result = keyword ? sortData.filter(x => {
  3652. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  3653. }) : [];
  3654. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  3655. searchObj.cur = 0;
  3656. if (searchObj.result.length > 0) {
  3657. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  3658. }
  3659. },
  3660. searchPre: function () {
  3661. if (searchObj.result.length === 0) return;
  3662. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  3663. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  3664. },
  3665. searchNext: function () {
  3666. if (searchObj.result.length === 0) return;
  3667. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  3668. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  3669. },
  3670. clear: function () {
  3671. $(`#${relaSelect.searchText}`).val('');
  3672. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  3673. searchObj.result = [];
  3674. searchObj.cur = 0;
  3675. }
  3676. };
  3677. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  3678. $(`#${relaSelect.searchPre}`).click(function (e) {
  3679. searchObj.searchPre();
  3680. e.stopPropagation();
  3681. });
  3682. $(`#${relaSelect.searchNext}`).click(function (e) {
  3683. searchObj.searchNext();
  3684. e.stopPropagation();
  3685. });
  3686. $(`#${relaSelect.searchClose}`).click(function (e) {
  3687. searchObj.clear();
  3688. e.stopPropagation();
  3689. });
  3690. };
  3691. loadData (callback) {
  3692. // if (this.loaded) {
  3693. // if (callback) callback();
  3694. // return;
  3695. // }
  3696. const self = this;
  3697. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  3698. const showDatas = [];
  3699. for (const d of datas) {
  3700. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  3701. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  3702. }
  3703. }
  3704. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  3705. // self.loaded = true;
  3706. if (callback) callback();
  3707. }
  3708. }
  3709. const jlzfBills = new Jlzf('#jlzf-spread', {
  3710. cols: [
  3711. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  3712. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  3713. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  3714. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3715. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3716. ],
  3717. emptyRows: 0,
  3718. headRows: 1,
  3719. headRowHeight: [32],
  3720. headColWidth: [30],
  3721. defaultRowHeight: 21,
  3722. headerFont: '12px 微软雅黑',
  3723. font: '12px 微软雅黑',
  3724. selectedBackColor: '#fffacd',
  3725. readOnly: true,
  3726. stdType: 'jlzf',
  3727. });
  3728. class Dsk {
  3729. constructor (selector, spreadSetting) {
  3730. const self = this;
  3731. this.loaded = false;
  3732. this.obj = $(selector);
  3733. const dskProjectHtml = spreadSetting.libs.map(l => {
  3734. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  3735. });
  3736. const relaSelect = {
  3737. showLevel: `cb-${spreadSetting.stdType}-sl`,
  3738. searchText: `cb-${spreadSetting.stdType}-st`,
  3739. searchResult: `cb-${spreadSetting.stdType}-sr`,
  3740. searchPre: `cb-${spreadSetting.stdType}-sp`,
  3741. searchNext: `cb-${spreadSetting.stdType}-sn`,
  3742. searchClose: `cb-${spreadSetting.stdType}-sc`,
  3743. };
  3744. this.obj.html(
  3745. '<div class="sjs-bar d-flex">\n' +
  3746. ' <div class="dropdown mr-1">\n' +
  3747. ' <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' +
  3748. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  3749. ' </button>\n' +
  3750. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  3751. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  3752. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  3753. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  3754. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  3755. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  3756. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  3757. ' </div>\n' +
  3758. ' </div>' +
  3759. ` <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` +
  3760. ` <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` +
  3761. ' <div class="ml-1">\n' +
  3762. ' <div class="dropdown">\n' +
  3763. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  3764. ' <i class="fa fa-search"></i>\n' +
  3765. ' </button>\n' +
  3766. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  3767. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  3768. ' <div class="d-inline-block">\n' +
  3769. ' <div class="input-group input-group-sm mr-1">' +
  3770. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  3771. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  3772. ' <div class="input-group-append" >\n' +
  3773. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  3774. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  3775. ' </div>\n' +
  3776. ' </div>\n' +
  3777. ' </div>\n' +
  3778. ` <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` +
  3779. ' </div>\n' +
  3780. ' </div>\n' +
  3781. ' </div>\n' +
  3782. ' </div>' +
  3783. '</div>\n' +
  3784. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  3785. );
  3786. autoFlashHeight();
  3787. const sh = `.cb-${spreadSetting.stdType}-sh`;
  3788. function getObjHeight(select) {
  3789. return select.length > 0 ? select.height() : 0;
  3790. }
  3791. const cHeader = getObjHeight($(".c-header"));
  3792. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  3793. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3794. this.spreadSetting = spreadSetting;
  3795. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  3796. const searchSheet = this.spread.getActiveSheet();
  3797. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  3798. (function (select, sheet) {
  3799. $(select).click(function () {
  3800. if (!sheet.zh_tree) return;
  3801. const tag = $(this).attr('tag');
  3802. const tree = sheet.zh_tree;
  3803. setTimeout(() => {
  3804. switch (tag) {
  3805. case "1":
  3806. case "2":
  3807. case "3":
  3808. case "4":
  3809. case "5":
  3810. tree.expandByLevel(parseInt(tag));
  3811. SpreadJsObj.refreshTreeRowVisible(sheet);
  3812. break;
  3813. case "last":
  3814. tree.expandByCustom(() => { return true; });
  3815. SpreadJsObj.refreshTreeRowVisible(sheet);
  3816. break;
  3817. }
  3818. }, 100);
  3819. });
  3820. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  3821. if (!readOnly) {
  3822. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3823. const dealSheet = info.sheet;
  3824. const mainSheet = billsSheet;
  3825. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3826. if (!dealBills) { return; }
  3827. const mainTree = mainSheet.zh_tree;
  3828. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3829. if (!mainNode || !mainTree) { return; }
  3830. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3831. toastr.warning('非最底层项目下,不应添加节点');
  3832. return;
  3833. }
  3834. if (mainNode.settle_status === settleStatus.finish) {
  3835. toastr.warning('已结算节点下,不应添加签约清单');
  3836. return;
  3837. }
  3838. const is_bill = dealBills.kind === 4;
  3839. const oneBills = {
  3840. b_code: is_bill ? dealBills.code : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  3841. unit_price: is_bill ? dealBills.unitPrice : null, quantity: is_bill ? dealBills.quantity : null, total_price: is_bill ? dealBills.totalPrice : null,
  3842. sgfh_qty: is_bill ? dealBills.quantity : null, sgfh_tp: is_bill ? dealBills.totalPrice : null,
  3843. };
  3844. postData(window.location.pathname + '/update', {
  3845. postType: 'add-deal',
  3846. postData: {
  3847. id: mainNode.ledger_id,
  3848. type: mainNode.code ? 'child' : 'next',
  3849. dealBills: oneBills,
  3850. },
  3851. }, function (result) {
  3852. changeList = result.changeList;
  3853. const refreshData = mainTree.loadPostData(result);
  3854. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3855. const sel = mainSheet.getSelections()[0];
  3856. if (sel && refreshData.create[0]) {
  3857. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3858. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3859. }
  3860. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3861. billsSpread.focus();
  3862. posSpreadObj.loadCurPosData();
  3863. });
  3864. });
  3865. }
  3866. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3867. const searchObj = {
  3868. result: [],
  3869. cur: 0,
  3870. searchStdNode: function() {
  3871. const keyword = $(`#${relaSelect.searchText}`).val();
  3872. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  3873. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  3874. }) : [];
  3875. // searchObj.result = [];
  3876. // for (const x of pathTree.nodes) {
  3877. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  3878. // searchObj.result.push(x);
  3879. // }
  3880. // }
  3881. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  3882. searchObj.cur = 0;
  3883. if (searchObj.result.length > 0) {
  3884. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  3885. }
  3886. },
  3887. searchPre: function () {
  3888. if (searchObj.result.length === 0) return;
  3889. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  3890. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3891. },
  3892. searchNext: function () {
  3893. if (searchObj.result.length === 0) return;
  3894. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  3895. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3896. },
  3897. clear: function () {
  3898. $(`#${relaSelect.searchText}`).val('');
  3899. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  3900. searchObj.result = [];
  3901. searchObj.cur = 0;
  3902. }
  3903. };
  3904. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  3905. $(`#${relaSelect.searchPre}`).click(function (e) {
  3906. searchObj.searchPre();
  3907. e.stopPropagation();
  3908. });
  3909. $(`#${relaSelect.searchNext}`).click(function (e) {
  3910. searchObj.searchNext();
  3911. e.stopPropagation();
  3912. });
  3913. $(`#${relaSelect.searchClose}`).click(function (e) {
  3914. searchObj.clear();
  3915. e.stopPropagation();
  3916. });
  3917. };
  3918. loadData (callback) {
  3919. if (this.loaded) {
  3920. if (callback) callback();
  3921. return;
  3922. }
  3923. const self = this;
  3924. if (dskAccountData && dskAccountData.select_project) {
  3925. self.loaded = true;
  3926. changeDskProject(dskAccountData.select_project);
  3927. } else {
  3928. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  3929. self.loaded = true;
  3930. }
  3931. if (callback) callback();
  3932. }
  3933. }
  3934. $('body').on('change', '#change-dsk-project', function () {
  3935. const pid = $(this).val();
  3936. changeDskProject(pid);
  3937. });
  3938. $('body').on('change', '#change-dsk-project-tree', function () {
  3939. const treeId = $(this).val();
  3940. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  3941. changeDskProjectTree(projectInfo, treeId);
  3942. });
  3943. function setDskProjectTreeSelect(trees) {
  3944. let html = '';
  3945. for (const tree of trees) {
  3946. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  3947. }
  3948. $('#change-dsk-project-tree').html(html);
  3949. }
  3950. function changeDskProject(pid) {
  3951. const projectInfo = _.find(dskProjects, { pid });
  3952. if (!projectInfo) {
  3953. dskAccountData.select_project = null;
  3954. dskAccountData.select_tree = null;
  3955. const tree = dskProjectBills2Tree.convert([]);
  3956. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3957. return;
  3958. }
  3959. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  3960. const trees = _.filter(datas, x => x.type === 4);
  3961. dskAccountData.select_project = projectInfo.pid;
  3962. setDskProjectTreeSelect(trees);
  3963. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  3964. });
  3965. }
  3966. function changeDskProjectTree(projectInfo, treeId) {
  3967. dskAccountData.select_tree = treeId;
  3968. if (!treeId) {
  3969. const tree = dskProjectBills2Tree.convert([]);
  3970. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3971. return;
  3972. }
  3973. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  3974. const tree = dskProjectBills2Tree.convert(result);
  3975. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3976. });
  3977. }
  3978. const dskBills = new Dsk('#dsk-spread', {
  3979. cols: [
  3980. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  3981. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  3982. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3983. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  3984. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  3985. ],
  3986. emptyRows: 0,
  3987. headRows: 1,
  3988. headRowHeight: [32],
  3989. headColWidth: [30],
  3990. defaultRowHeight: 21,
  3991. headerFont: '12px 微软雅黑',
  3992. font: '12px 微软雅黑',
  3993. selectedBackColor: '#fffacd',
  3994. readOnly: true,
  3995. stdType: 'dsk',
  3996. libs: dskProjects,
  3997. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  3998. });
  3999. const dskProjectBills2Tree = (function () {
  4000. const treeSetting = {
  4001. id: 'dpb_id',
  4002. pid: 'dpb_pid',
  4003. order: 'seq',
  4004. level: 'level',
  4005. rootId: '-1',
  4006. fullPath: 'full_path',
  4007. };
  4008. const tenderTree = createNewPathTree('gather', treeSetting);
  4009. function setChildrenNode(node, dxs, files, tenders) {
  4010. const dxchildren = _.filter(dxs, { parentID: node.bid });
  4011. const children = _.filter(files, { parentID: node.bid });
  4012. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  4013. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  4014. for (const t of checkChildren) {
  4015. const child = {
  4016. bid: t.ID,
  4017. parentID: t.parentID,
  4018. name: t.name,
  4019. kind: t.kind,
  4020. code: t.code,
  4021. quantity: t.quantity,
  4022. quantity2: t.quantity2,
  4023. unit: t.unit,
  4024. unitPrice: t.unitPrice,
  4025. totalPrice: t.totalPrice,
  4026. formulaCode: t.formulaCode,
  4027. flag: t.flag,
  4028. remark: t.remark,
  4029. };
  4030. tenderTree.addNode(child, node);
  4031. setChildrenNode(child, dxs, files, tenders);
  4032. }
  4033. }
  4034. function convert (projects) {
  4035. tenderTree.clearDatas();
  4036. // 区分文件夹及项目
  4037. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  4038. const dxs = _.filter(projects, { kind: 1 });
  4039. const files = _.filter(projects, { kind: 4 });
  4040. const tenders = _.filter(projects, { kind: 8 });
  4041. for (const t of topLevel) {
  4042. const node = {
  4043. bid: t.ID,
  4044. parentID: t.parentID,
  4045. name: t.name,
  4046. kind: t.kind,
  4047. code: t.code,
  4048. quantity: t.quantity,
  4049. quantity2: t.quantity2,
  4050. unit: t.unit,
  4051. unitPrice: t.unitPrice,
  4052. totalPrice: t.totalPrice,
  4053. formulaCode: t.formulaCode,
  4054. flag: t.flag,
  4055. remark: t.remark,
  4056. };
  4057. tenderTree.addNode(node, null);
  4058. setChildrenNode(node, dxs, files, tenders);
  4059. }
  4060. tenderTree.sortTreeNode(true);
  4061. return tenderTree;
  4062. }
  4063. return { tenderTree, convert }
  4064. })();
  4065. $.divResizer({
  4066. select: '#revise-right-spr',
  4067. callback: function () {
  4068. billsSpread.refresh();
  4069. if (posSpread) posSpread.refresh();
  4070. if (stdXmj) stdXmj.spread.refresh();
  4071. if (stdGcl) stdGcl.spread.refresh();
  4072. if (dealBills) dealBills.spread.refresh();
  4073. if (searchLedger) searchLedger.spread.refresh();
  4074. if (errorList) errorList.spread.refresh();
  4075. if (checkList) checkList.spread.refresh();
  4076. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4077. if (jlzfBills) jlzfBills.spread.refresh();
  4078. if (dskBills) dskBills.spread.refresh();
  4079. }
  4080. });
  4081. $.subMenu({
  4082. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  4083. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  4084. key: 'menu.1.0.0',
  4085. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  4086. callback: function (info) {
  4087. if (info.mini) {
  4088. $('.panel-title').addClass('fluid');
  4089. $('#sub-menu').removeClass('panel-sidebar');
  4090. } else {
  4091. $('.panel-title').removeClass('fluid');
  4092. $('#sub-menu').addClass('panel-sidebar');
  4093. }
  4094. autoFlashHeight();
  4095. billsSpread.refresh();
  4096. if (posSpread) posSpread.refresh();
  4097. if (stdXmj) stdXmj.spread.refresh();
  4098. if (stdGcl) stdGcl.spread.refresh();
  4099. if (dealBills) dealBills.spread.refresh();
  4100. if (searchLedger) searchLedger.spread.refresh();
  4101. if (errorList) errorList.spread.refresh();
  4102. if (checkList) checkList.spread.refresh();
  4103. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4104. if (jlzfBills) jlzfBills.spread.refresh();
  4105. if (dskBills) dskBills.spread.refresh();
  4106. }
  4107. });
  4108. // showSideTools(true);
  4109. billsSpread.refresh();
  4110. if (posSpread) posSpread.refresh();
  4111. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  4112. const mainSheet = billsSheet;
  4113. if (!stdTree || !mainSheet.zh_tree) { return; }
  4114. const mainTree = mainSheet.zh_tree;
  4115. const sel = mainSheet.getSelections()[0];
  4116. const mainNode = mainTree.nodes[sel.row];
  4117. if (!stdNode) return;
  4118. if (updateData.postData.stdType === 'gcl') {
  4119. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4120. toastr.warning('非最底层项目下,不应添加节点');
  4121. return;
  4122. }
  4123. if (mainNode.settle_status === settleStatus.finish) {
  4124. toastr.warning('已结算节点下,不可添加工程量清单');
  4125. return;
  4126. }
  4127. } else {
  4128. const stdNodes = stdTree.getAllParents(stdNode);
  4129. for (const node of stdNodes) {
  4130. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  4131. if (parent && parent.settle_status === settleStatus.finish) {
  4132. toastr.warning('项目节父项已结算,不可添加节点');
  4133. return;
  4134. }
  4135. }
  4136. }
  4137. postData(window.location.pathname + '/update', {
  4138. postType: 'add-std',
  4139. postData: {
  4140. id: mainTree.getNodeKey(mainNode),
  4141. tender_id: mainNode.tender_id,
  4142. stdType: updateData.postData.stdType,
  4143. stdLibId: stdNode.list_id,
  4144. stdNode: stdTree.getNodeKey(stdNode)
  4145. }
  4146. }, function (result) {
  4147. changeList = result.changeList;
  4148. const refreshNode = mainTree.loadPostData(result);
  4149. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  4150. if (sel) {
  4151. if (refreshNode.create && refreshNode.create.length > 0) {
  4152. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  4153. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  4154. } else {
  4155. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  4156. if (node) {
  4157. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  4158. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  4159. }
  4160. }
  4161. }
  4162. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4163. billsSpread.focus();
  4164. posSpreadObj.loadCurPosData();
  4165. });
  4166. };
  4167. const stdXmjSetting = {
  4168. selector: '#std-xmj',
  4169. stdType: 'xmj',
  4170. libs: stdChapters,
  4171. treeSetting: {
  4172. id: 'chapter_id',
  4173. pid: 'pid',
  4174. order: 'order',
  4175. level: 'level',
  4176. rootId: -1,
  4177. keys: ['id', 'list_id', 'chapter_id'],
  4178. },
  4179. spreadSetting: {
  4180. cols: [
  4181. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4182. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4183. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4184. ],
  4185. treeCol: 0,
  4186. emptyRows: 0,
  4187. headRows: 1,
  4188. headRowHeight: [32],
  4189. defaultRowHeight: 21,
  4190. headerFont: '12px 微软雅黑',
  4191. font: '12px 微软雅黑',
  4192. headColWidth: [30],
  4193. selectedBackColor: '#fffacd',
  4194. },
  4195. cellDoubleClick: stdLibCellDoubleClick,
  4196. page: 'revise',
  4197. tid: window.location.pathname.split('/')[2],
  4198. };
  4199. const stdGclSetting = {
  4200. selector: '#std-gcl',
  4201. stdType: 'gcl',
  4202. libs: stdBills,
  4203. treeSetting: {
  4204. id: 'bill_id',
  4205. pid: 'pid',
  4206. order: 'order',
  4207. level: 'level',
  4208. rootId: -1,
  4209. keys: ['id', 'list_id', 'bill_id']
  4210. },
  4211. spreadSetting: {
  4212. cols: [
  4213. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4214. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4215. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4216. ],
  4217. treeCol: 0,
  4218. emptyRows: 0,
  4219. headRows: 1,
  4220. headRowHeight: [32],
  4221. defaultRowHeight: 21,
  4222. headerFont: '12px 微软雅黑',
  4223. font: '12px 微软雅黑',
  4224. headColWidth: [30],
  4225. selectedBackColor: '#fffacd',
  4226. },
  4227. cellDoubleClick: stdLibCellDoubleClick,
  4228. page: 'revise',
  4229. tid: window.location.pathname.split('/')[2],
  4230. };
  4231. // 展开收起标准节点
  4232. $('a', '#side-menu').bind('click', function (e) {
  4233. e.preventDefault();
  4234. const tab = $(this), tabPanel = $(tab.attr('content'));
  4235. // 展开工具栏、切换标签
  4236. if (!tab.hasClass('active')) {
  4237. const close = $('.active', '#side-menu').length === 0;
  4238. $('a', '#side-menu').removeClass('active');
  4239. tab.addClass('active');
  4240. $('.tab-content .tab-pane').removeClass('active');
  4241. tabPanel.addClass('active');
  4242. showSideTools(tab.hasClass('active'));
  4243. if (tab.attr('content') === '#std-xmj') {
  4244. if (!stdXmj) {
  4245. stdXmj = $.stdLib(stdXmjSetting);
  4246. }
  4247. stdXmj.spread.refresh();
  4248. } else if (tab.attr('content') === '#std-gcl') {
  4249. if (!stdGcl) {
  4250. stdGcl = $.stdLib(stdGclSetting);
  4251. }
  4252. stdGcl.spread.refresh();
  4253. } else if (tab.attr('content') === '#deal-bills') {
  4254. dealBills.loadData();
  4255. dealBills.spread.refresh();
  4256. } else if (tab.attr('content') === '#search') {
  4257. if (!searchLedger) {
  4258. searchLedger = $.ledgerSearch({
  4259. selector: '#search',
  4260. ledger: { billsTree: billsTree, pos: pos },
  4261. searchOver: true,
  4262. searchEmpty: true,
  4263. resultSpreadSetting: {
  4264. cols: [
  4265. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4266. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4267. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4268. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4269. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4270. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4271. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4272. ],
  4273. emptyRows: 0,
  4274. headRows: 1,
  4275. headRowHeight: [32],
  4276. headColWidth: [30],
  4277. defaultRowHeight: 21,
  4278. headerFont: '12px 微软雅黑',
  4279. font: '12px 微软雅黑',
  4280. selectedBackColor: '#fffacd',
  4281. readOnly: true,
  4282. },
  4283. locate: function(cur) {
  4284. if (!cur.lid) return;
  4285. SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
  4286. posSpreadObj.loadCurPosData();
  4287. if (cur.pid && cur.pid !== -1) {
  4288. const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4289. SpreadJsObj.locateRow(posSheet, pIndex);
  4290. }
  4291. },
  4292. customSearch: [
  4293. {
  4294. key: 'revise', title: '新增部位', valid: true, parent: true,
  4295. check: function (node) {
  4296. if (node.formc || node.cid) {
  4297. return true;
  4298. } else {
  4299. return false;
  4300. }
  4301. }
  4302. }
  4303. ],
  4304. });
  4305. }
  4306. searchLedger.spread.refresh();
  4307. } else if (tab.attr('content') === '#error-list') {
  4308. errorList.spread.refresh();
  4309. } else if (tab.attr('content') === '#check-list') {
  4310. checkList.spread.refresh();
  4311. } else if (tab.attr('content') === '#sum-load-miss') {
  4312. sumLoadMiss.spread.refresh();
  4313. } else if (tab.attr('content') === '#dsk-list') {
  4314. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  4315. $(dskActiveTab).addClass('active');
  4316. if (dskActiveTab === '#jlzf-spread') {
  4317. $('#get-dsk-btn').hide();
  4318. $('#get-dsk-bills-btn').hide();
  4319. jlzfBills.loadData();
  4320. jlzfBills.spread.refresh();
  4321. } else if (dskActiveTab === '#dsk-spread') {
  4322. $('#get-dsk-btn').show();
  4323. $('#get-dsk-bills-btn').show();
  4324. dskBills.loadData();
  4325. dskBills.spread.refresh();
  4326. }
  4327. }
  4328. }
  4329. else {// 收起工具栏
  4330. tab.removeClass('active');
  4331. tabPanel.removeClass('active');
  4332. showSideTools(tab.hasClass('active'));
  4333. }
  4334. billsSpread.refresh();
  4335. if (posSpread) posSpread.refresh();
  4336. });
  4337. // 新增清单切换tab
  4338. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  4339. e.preventDefault();
  4340. const dskActiveTab = $(this).attr('href');
  4341. if (dskActiveTab === '#jlzf-spread') {
  4342. $('#get-dsk-btn').hide();
  4343. $('#get-dsk-bills-btn').hide();
  4344. jlzfBills.loadData();
  4345. jlzfBills.spread.refresh();
  4346. } else if (dskActiveTab === '#dsk-spread') {
  4347. $('#get-dsk-btn').show();
  4348. $('#get-dsk-bills-btn').show();
  4349. dskBills.loadData();
  4350. dskBills.spread.refresh();
  4351. }
  4352. });
  4353. // 显示层次
  4354. (function (select, sheet) {
  4355. $(select).click(function () {
  4356. if (!sheet.zh_tree) return;
  4357. const tag = $(this).attr('tag');
  4358. const tree = sheet.zh_tree;
  4359. setTimeout(() => {
  4360. showWaitingView();
  4361. switch (tag) {
  4362. case "1":
  4363. case "2":
  4364. case "3":
  4365. case "4":
  4366. case "5":
  4367. tree.expandByLevel(parseInt(tag));
  4368. SpreadJsObj.refreshTreeRowVisible(sheet);
  4369. break;
  4370. case "last":
  4371. tree.expandByCustom(() => { return true; });
  4372. SpreadJsObj.refreshTreeRowVisible(sheet);
  4373. break;
  4374. case "leafXmj":
  4375. tree.expandToLeafXmj();
  4376. SpreadJsObj.refreshTreeRowVisible(sheet);
  4377. break;
  4378. }
  4379. closeWaitingView();
  4380. }, 100);
  4381. });
  4382. })('a[name=showLevel]', billsSheet);
  4383. const dataChecker = DataChecker({
  4384. checkUrl: window.location.pathname + '/check',
  4385. completeData: function (data) {
  4386. pos.updateDatas({update: data.source.pos});
  4387. const loadResult = billsTree.loadPostData({update: data.source.bills});
  4388. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  4389. posSpreadObj.loadCurPosData();
  4390. for (const e of data.error) {
  4391. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  4392. }
  4393. },
  4394. errorList: errorList,
  4395. });
  4396. $('#ledger-check2').click(() => {
  4397. ledgerCheck2({
  4398. ledgerTree: billsTree,
  4399. ledgerPos: pos,
  4400. checkList: checkList,
  4401. decimal: decimal,
  4402. checkOption: checkOption,
  4403. }).then(result => {
  4404. check2Viewing({
  4405. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  4406. randomWait: true,
  4407. prefix: 'check2-',
  4408. checks: result,
  4409. checkList: checkList,
  4410. });
  4411. });
  4412. });
  4413. if (isYb) {
  4414. let compilationList = [];
  4415. $('#get-dsk-btn').click(function () {
  4416. // 判断是否已绑定dsk用户
  4417. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  4418. if (result === 1) {
  4419. $('#error-dsk .modal-body').find('h5').eq(0).show();
  4420. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  4421. $('#error-dsk').modal('show');
  4422. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  4423. } else if (result === 2) {
  4424. $('#error-dsk .modal-body').find('h5').eq(1).show();
  4425. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  4426. $('#error-dsk').modal('show');
  4427. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  4428. } else {
  4429. postData('/profile/dsk/api', {
  4430. type: 'compilation',
  4431. getProject: 1,
  4432. compilationId: getLocalCache(dskCompilation)
  4433. }, function (result) {
  4434. let html = '';
  4435. for (const data of result.compilation) {
  4436. if (data.ID !== '5c66649650da2d000d8d37ba' && data.ID !== '5b52b027fd3bb0000b257cf8') {
  4437. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  4438. }
  4439. }
  4440. dskAccountData = result.dskAccountData;
  4441. compilationList = result.compilation;
  4442. console.log(compilationList);
  4443. $('#dsk-compilation-list').html(html);
  4444. $('#add-dsk').modal('show');
  4445. setLocalCache(dskCompilation, result.select_compilation);
  4446. makeDskProjectSjsHtml(result.project);
  4447. });
  4448. }
  4449. })
  4450. });
  4451. $('#get-dsk-bills-btn').click(function () {
  4452. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  4453. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  4454. });
  4455. $('body').on('change', '#dsk-compilation-list', function () {
  4456. const compilationId = $(this).val();
  4457. setLocalCache(dskCompilation, compilationId);
  4458. dskProjectSpreadObj.refreshSourceTree();
  4459. });
  4460. $('.hide-dsk-modal').click(function () {
  4461. $('#error-dsk').modal('hide');
  4462. });
  4463. let dp = false;
  4464. let gsObj = {
  4465. setting: null,
  4466. gsSheet: null,
  4467. grSheet: null,
  4468. tenderSourceTree: null,
  4469. grArray: dskProjects ? dskProjects : [],
  4470. orgSelect: null,
  4471. };
  4472. function makeDskProjectSjsHtml(datas) {
  4473. if (!dp) {
  4474. initDskProjectTree();
  4475. dp = true;
  4476. }
  4477. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  4478. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  4479. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  4480. if (datas.length === 0) {
  4481. $('#show-project-0').show();
  4482. } else {
  4483. $('#show-project-0').hide();
  4484. }
  4485. }
  4486. const dskProjectSpreadObj = {
  4487. _addTender: function (tender) {
  4488. const gr = gsObj.grArray.find(function (x) {
  4489. return x.pid === tender.pid;
  4490. });
  4491. const c_id = getLocalCache(dskCompilation);
  4492. const t = {
  4493. pid: tender.pid,
  4494. name: tender.name,
  4495. compilationId: c_id,
  4496. compilationName: _.find(compilationList, {ID: c_id}).name
  4497. };
  4498. if (!gr) gsObj.grArray.push(t);
  4499. return t;
  4500. },
  4501. _removeTender: function (tender) {
  4502. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  4503. return x.pid === tender.pid;
  4504. });
  4505. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  4506. },
  4507. reloadResultData: function () {
  4508. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  4509. },
  4510. refreshSourceTree: function () {
  4511. const c_id = getLocalCache(dskCompilation);
  4512. if (c_id) {
  4513. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  4514. makeDskProjectSjsHtml(result);
  4515. });
  4516. }
  4517. },
  4518. gsButtonClicked: function (e, info) {
  4519. if (!info.sheet.zh_setting) return;
  4520. const col = info.sheet.zh_setting.cols[info.col];
  4521. if (col.field !== 'selected') return;
  4522. const node = SpreadJsObj.getSelectObject(info.sheet);
  4523. node.selected = !node.selected;
  4524. if (node.children && node.children.length > 0) {
  4525. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  4526. for (const p of posterity) {
  4527. p.selected = node.selected;
  4528. if ((!p.children || p.children.length === 0) && p.type === 2) {
  4529. if (p.selected) {
  4530. dskProjectSpreadObj._addTender(p);
  4531. } else {
  4532. dskProjectSpreadObj._removeTender(p);
  4533. }
  4534. }
  4535. }
  4536. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  4537. } else if (node.type === 2) {
  4538. if (node.selected) {
  4539. dskProjectSpreadObj._addTender(node);
  4540. } else {
  4541. dskProjectSpreadObj._removeTender(node);
  4542. }
  4543. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  4544. }
  4545. dskProjectSpreadObj.reloadResultData();
  4546. },
  4547. deleteGr: function () {
  4548. if (gsObj.grArray.length === 0) return;
  4549. if (gsObj.grSheet.getSelections().length === 0) return;
  4550. const selections = gsObj.grSheet.getSelections();
  4551. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  4552. const row = sel && sel.row !== undefined ? sel.row : -1;
  4553. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  4554. return false;
  4555. }
  4556. const delList = [];
  4557. for (let r = 0; r < sel.rowCount; r++) {
  4558. const select = gsObj.grArray[row + r];
  4559. delList.push(select);
  4560. }
  4561. _.pullAll(gsObj.grArray, delList);
  4562. dskProjectSpreadObj.reloadResultData();
  4563. dskProjectSpreadObj.refreshSourceTree();
  4564. },
  4565. };
  4566. const initDskProjectTree = function () {
  4567. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  4568. gsObj.gsSheet = gsSpread.getActiveSheet();
  4569. const gsSpreadSetting = {
  4570. cols: [
  4571. {
  4572. title: '选择',
  4573. field: 'selected',
  4574. hAlign: 1,
  4575. width: 40,
  4576. formatter: '@',
  4577. cellType: 'checkbox',
  4578. readOnly: true,
  4579. },
  4580. {
  4581. title: '名称',
  4582. field: 'name',
  4583. hAlign: 0,
  4584. width: 400,
  4585. formatter: '@',
  4586. readOnly: true,
  4587. folderCell: true,
  4588. cellType: 'tree'
  4589. },
  4590. ],
  4591. emptyRows: 0,
  4592. headRows: 1,
  4593. headRowHeight: [32],
  4594. defaultRowHeight: 21,
  4595. headerFont: '12px 微软雅黑',
  4596. font: '12px 微软雅黑',
  4597. headColWidth: [0],
  4598. selectedBackColor: '#fffacd',
  4599. };
  4600. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  4601. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  4602. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  4603. gsObj.grSheet = grSpread.getActiveSheet();
  4604. const grSpreadSetting = {
  4605. cols: [
  4606. {
  4607. title: '名称',
  4608. colSpan: '1',
  4609. rowSpan: '1',
  4610. field: 'name',
  4611. hAlign: 0,
  4612. width: 250,
  4613. formatter: '@',
  4614. readOnly: true,
  4615. cellType: 'ellipsisAutoTip',
  4616. scrollHeightClass: '.modal-height-500'
  4617. },
  4618. {
  4619. title: '所属编办',
  4620. colSpan: '1',
  4621. rowSpan: '1',
  4622. field: 'compilationName',
  4623. hAlign: 0,
  4624. width: 150,
  4625. formatter: '@',
  4626. readOnly: true
  4627. },
  4628. ],
  4629. emptyRows: 0,
  4630. headRows: 1,
  4631. headRowHeight: [32],
  4632. defaultRowHeight: 21,
  4633. headerFont: '12px 微软雅黑',
  4634. font: '12px 微软雅黑',
  4635. headColWidth: []
  4636. };
  4637. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  4638. // 右键删除已选项目
  4639. const gsContextMenuOptions = {
  4640. selector: '#dsk-project-result-spread',
  4641. build: function ($trigger, e) {
  4642. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  4643. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4644. },
  4645. items: {
  4646. delete: {
  4647. name: '删除',
  4648. icon: 'fa-remove',
  4649. callback: function (key, opt) {
  4650. dskProjectSpreadObj.deleteGr();
  4651. },
  4652. disabled: function (key, opt) {
  4653. const selection = gsObj.grSheet.getSelections();
  4654. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  4655. const row = sel && sel.row !== undefined ? sel.row : -1;
  4656. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  4657. return true;
  4658. }
  4659. return false;
  4660. }
  4661. },
  4662. }
  4663. };
  4664. $.contextMenu(gsContextMenuOptions);
  4665. $('#add-dsk').bind('shown.bs.modal', function () {
  4666. if (gsSpread) gsSpread.refresh();
  4667. if (grSpread) grSpread.refresh();
  4668. });
  4669. };
  4670. const dskProject2Tree = (function () {
  4671. const treeSetting = {
  4672. id: 'tmt_id',
  4673. pid: 'tmt_pid',
  4674. order: 'seq',
  4675. level: 'level',
  4676. rootId: '-1',
  4677. fullPath: 'full_path',
  4678. };
  4679. const tenderTree = createNewPathTree('gather', treeSetting);
  4680. function setChildrenNode(node, files, tenders) {
  4681. const children = _.filter(files, {parentID: node.pid});
  4682. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  4683. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  4684. for (const c of checkChildren) {
  4685. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  4686. // // 判断文件夹下有无东西,没有就不插入
  4687. // continue;
  4688. // }
  4689. const child = {
  4690. pid: c.ID,
  4691. parentID: c.parentID,
  4692. name: c.name,
  4693. type: c.type,
  4694. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  4695. };
  4696. tenderTree.addNode(child, node);
  4697. if (c.type === 1) setChildrenNode(child, files, tenders);
  4698. }
  4699. }
  4700. function convert(projects) {
  4701. tenderTree.clearDatas();
  4702. const result = filterFolders(projects);
  4703. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  4704. const files = _.filter(result, {type: 1});
  4705. const tenders = _.filter(result, {type: 2});
  4706. for (const t of topLevel) {
  4707. const node = {
  4708. pid: t.ID,
  4709. parentID: t.parentID,
  4710. name: t.name,
  4711. type: t.type,
  4712. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  4713. };
  4714. tenderTree.addNode(node, null);
  4715. if (t.type === 1) setChildrenNode(node, files, tenders);
  4716. }
  4717. tenderTree.sortTreeNode(true);
  4718. return tenderTree;
  4719. }
  4720. return {tenderTree, convert}
  4721. })();
  4722. function filterFolders(data) {
  4723. // 构建ID到节点的映射
  4724. const idMap = data.reduce((map, node) => {
  4725. map[node.ID] = node;
  4726. return map;
  4727. }, {});
  4728. // 建立父子关系映射
  4729. const parentMap = data.reduce((map, node) => {
  4730. if (node.parentID !== '-1') {
  4731. if (!map[node.parentID]) {
  4732. map[node.parentID] = [];
  4733. }
  4734. map[node.parentID].push(node.ID);
  4735. }
  4736. return map;
  4737. }, {});
  4738. // 检查节点及其子节点是否包含清单(type=1)
  4739. const hasChecklist = (id) => {
  4740. const node = idMap[id];
  4741. if (node.type === 2) {
  4742. return true;
  4743. }
  4744. if (!parentMap[id]) {
  4745. return false;
  4746. }
  4747. return parentMap[id].some(childID => hasChecklist(childID));
  4748. };
  4749. // 过滤节点
  4750. const filteredIDs = new Set();
  4751. data.forEach(node => {
  4752. if (node.type === 2 || hasChecklist(node.ID)) {
  4753. let currentID = node.ID;
  4754. while (currentID !== '-1') {
  4755. filteredIDs.add(currentID);
  4756. currentID = idMap[currentID].parentID;
  4757. }
  4758. }
  4759. });
  4760. // 返回过滤后的数据
  4761. return data.filter(node => filteredIDs.has(node.ID));
  4762. }
  4763. $('#set-dsk-project').click(function () {
  4764. postData('/profile/dsk/api', {
  4765. type: 'save_projects',
  4766. tid: window.location.pathname.split('/')[2],
  4767. project_list: gsObj.grArray
  4768. }, function (result) {
  4769. // dskAccountData.select_project = result;
  4770. dskProjects = gsObj.grArray;
  4771. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  4772. dskAccountData.select_project = result;
  4773. changeDskProject(result);
  4774. dskBills.spread.refresh();
  4775. }
  4776. setDskProjectSelect(gsObj.grArray);
  4777. $('#add-dsk').modal('hide');
  4778. });
  4779. });
  4780. $('#add-dsk').on('hide.bs.modal', function () {
  4781. $('#autoTip').hide();
  4782. });
  4783. function setDskProjectSelect(projects) {
  4784. let html = '';
  4785. for (const project of projects) {
  4786. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  4787. }
  4788. $('#change-dsk-project').html(html);
  4789. }
  4790. // 选中所有新增部位/清单
  4791. $('#add-all-revise').click(function() {
  4792. const this_cid = window.location.pathname.split('/')[4];
  4793. makeGclGatherData();
  4794. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  4795. type: 'get-revise-list',
  4796. }, function (result) {
  4797. const addDatas = [];
  4798. for (const ggd in gclGatherData) {
  4799. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  4800. let hadcid = 0;
  4801. for (const xmj of gclGatherData[ggd].leafXmjs) {
  4802. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  4803. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  4804. if (changeLedger || changePos) {
  4805. xmj.cid = 1;
  4806. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  4807. hadcid = 1;
  4808. }
  4809. }
  4810. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  4811. }
  4812. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  4813. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  4814. if (leafXmjs.length > 0) {
  4815. gclInfo.is_change = 1;
  4816. for (const xmj of leafXmjs) {
  4817. if (_.findIndex(changeList, function (item) {
  4818. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  4819. }) === -1) {
  4820. addDatas.push({
  4821. lid: xmj.gcl_id,
  4822. code: gclInfo.code,
  4823. name: gclInfo.name || '',
  4824. unit: gclInfo.unit || '',
  4825. unit_price: gclInfo.unit_price,
  4826. oamount: xmj.quantity,
  4827. oamount2: xmj.quantity,
  4828. bwmx: xmj.bwmx || xmj.jldy || '',
  4829. xmj_code: xmj.code || '',
  4830. xmj_jldy: xmj.jldy || '',
  4831. xmj_dwgc: xmj.dwgc || '',
  4832. xmj_fbgc: xmj.fbgc || '',
  4833. xmj_fxgc: xmj.fxgc || '',
  4834. gcl_id: xmj.gcl_id,
  4835. mx_id: xmj.mx_id || '',
  4836. });
  4837. }
  4838. }
  4839. }
  4840. }
  4841. console.log(addDatas);
  4842. if (addDatas.length > 0) {
  4843. // 更新至服务器
  4844. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  4845. type: 'add-change-list',
  4846. postData: addDatas,
  4847. }, function (result) {
  4848. toastr.success('已新增当前变更令新增的所有部位/清单');
  4849. changeList = result.changeList;
  4850. const sortData = SpreadJsObj.getSortData(billsSheet);
  4851. const billsNodes = _.filter(sortData, function (item) {
  4852. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  4853. });
  4854. for (const billsNode of billsNodes) {
  4855. billsNode.is_change = 1;
  4856. }
  4857. const loadResult = { update: billsNodes };
  4858. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  4859. posSpreadObj.loadCurPosData();
  4860. });
  4861. } else {
  4862. toastr.warning('未存在当前变更令新增的部位/清单');
  4863. }
  4864. });
  4865. });
  4866. }
  4867. });
  4868. function findDecimal(unit) {
  4869. let value = precision.other.value;
  4870. const changeUnits = precision;
  4871. for (const d in changeUnits) {
  4872. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  4873. value = changeUnits[d].value;
  4874. break;
  4875. }
  4876. }
  4877. return value;
  4878. }
  4879. // 编号排序,多重判断
  4880. function sortByCode(a, b, code = 'b_code') {
  4881. let code1 = a[code].split('-');
  4882. let code2 = b[code].split('-');
  4883. let code1length = code1.length;
  4884. let code2length = code2.length;
  4885. for (let i = 0; i < code1length; i ++) {
  4886. if (i+1 <= code2length) {
  4887. if (code1[i] != code2[i]) {
  4888. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  4889. return parseInt(code1[i]) - parseInt(code2[i]);
  4890. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  4891. return 1;
  4892. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  4893. return -1;
  4894. } else {
  4895. const str1length = code1[i].length;
  4896. const str2length = code2[i].length;
  4897. for (let j = 0; j < str1length; j++) {
  4898. if (j+1 <= str2length) {
  4899. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  4900. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  4901. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  4902. if (str1length == str2length) {
  4903. return 0;
  4904. } else {
  4905. return str1length - str2length;
  4906. }
  4907. }
  4908. } else {
  4909. if (j+1 >= str1length) {
  4910. return 1;
  4911. } else {
  4912. return -1;
  4913. }
  4914. }
  4915. }
  4916. }
  4917. } else if (i+1 == code1length && code1[i] == code2[i]) {
  4918. if (code1length == code2length) {
  4919. return 0;
  4920. } else {
  4921. return code1length - code2length;
  4922. }
  4923. }
  4924. } else {
  4925. if (i+1 >= code1length) {
  4926. return 1;
  4927. } else {
  4928. return -1;
  4929. }
  4930. }
  4931. }
  4932. }