ledger.js 269 KB

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