ledger.js 264 KB

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