change_revise.js 271 KB

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