stage.js 279 KB

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