change_revise.js 279 KB

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