stage.js 279 KB

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