change_revise.js 246 KB

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