1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644 |
- 'use strict';
- /**
- * 期计量 - 本期计量台账页面 js
- *
- * @author Mai
- * @date 2018/12/7
- * @version
- */
- const ckBillsSpread = window.location.pathname + '-billsSelect';
- function checkTzMeasureType () {
- return tender.measure_type === measureType.tz.value;
- }
- function transExpr(expr) {
- return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
- }
- function getExprInfo (field, converse = false) {
- const exprField = [
- {qty: 'sgfh_qty', expr: 'sgfh_expr'},
- {qty: 'sjcl_qty', expr: 'sjcl_expr'},
- {qty: 'qtcl_qty', expr: 'qtcl_expr'},
- {qty: 'contract_qty', expr: 'contract_expr'},
- ];
- if (converse) return _.find(exprField, { expr: field });
- return _.find(exprField, {qty: field});
- }
- /**
- * 从cookie中读取缓存的列显示设置,没有则取默认
- * @returns {*[]}
- */
- function customColDisplay () {
- const defaultSetting = [
- { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
- { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl', 'qc_minus_qty'], visible: true },
- { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
- { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
- { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl', 'end_qc_minus_qty'], visible: true },
- { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent', 'end_final_1_precent'], visible: true },
- { title: '本期批注', fields: ['postil'], visible: true },
- { title: '图册号', fields: ['drawing_code'], visible: true },
- { title: '备注', fields: ['memo'], visible: true },
- { title: '总额计量', fields: ['is_tp'], visible: true},
- ];
- if (!checkTzMeasureType()) {
- defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
- }
- const settingStr = Cookies.get(ckColSetting);
- if (settingStr) {
- const customSetting = JSON.parse(settingStr);
- for (const ds of defaultSetting) {
- const cs = customSetting.find(x => {return x.title === ds.title});
- if (cs) ds.visible = cs.visible;
- }
- }
- return defaultSetting;
- }
- /**
- * 根据列显示设置,调整setting中的列是否显示
- * @param setting
- * @param customDisplay
- */
- function customizeStageTreeSetting(setting, customDisplay) {
- for (const cd of customDisplay) {
- for (const c of setting.cols) {
- if (cd.fields.indexOf(c.field) !== -1) {
- c.visible = c.defaultVisible === undefined ? cd.visible : c.defaultVisible && cd.visible;
- }
- }
- }
- }
- /**
- * 初始化 树结构 列事件
- * @param setting
- */
- function initTreeColSettingEvents(setting) {
- const Events = {
- readOnly: {
- measureData: function (node) {
- return node.children && node.children.length > 0;
- },
- },
- };
- const getEvent = function (eventName) {
- const names = eventName.split('.');
- let event = Events;
- for (let name of names) {
- if (event[name]) {
- event = event[name];
- } else {
- return null;
- }
- }
- if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
- return null;
- } else {
- return event;
- }
- };
- for (const col of setting.cols) {
- if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
- col.readOnly = getEvent(col.readOnly);
- }
- }
- }
- // 生成所有附件列表
- function getAllList(currPageNum = 1) {
- // 每页最多几个附件
- const pageCount = 20;
- // 附件总数
- const total = attData.length;
- // 总页数
- const pageNum = Math.ceil(total/pageCount);
- $('#totalPage').text(pageNum);
- $('#currentPage').text(total === 0 ? 0 : currPageNum);
- // 当前页附件内容
- const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
- currPageFileData = currPageAttData;
- let html = '';
- // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
- for(const att of currPageAttData) {
- const delHtml = deleteFilePermission && parseInt(cur_uid) === att.uid
- ? `<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>`
- : '';
- html += `<tr>
- <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
- <td>
- <div class="d-flex">
- <a href="javascript:void(0)" class="pl-0 col-10 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
- <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>
- </div>
- </td><td>${att.username}</td></tr>`
- }
- $('#alllist-table').html(html);
- $('#alllist-table').on('click', 'tr', function() {
- $('#alllist-table tr').removeClass('bg-light')
- $(this).addClass('bg-light')
- });
- }
- // 生成当前节点列表
- function getNodeList(node) {
- let html = '';
- for(const att of attData) {
- if (node === att.lid) {
- const delHtml = deleteFilePermission && parseInt(cur_uid) === att.uid
- ? `<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>`
- : '';
- // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
- html += `<tr>
- <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
- <td>
- <div class="d-flex">
- <a href="javascript:void(0)" class="pl-0 col-10 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
- <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>
- </div>
- </td><td>${att.username}</td></tr>`
- }
- }
- $('#nodelist-table').html(html);
- $('#nodelist-table').on('click', 'tr', function() {
- $('#nodelist-table tr').removeClass('bg-light');
- $(this).addClass('bg-light');
- })
- }
- function getGxbyText(data) {
- const def = thirdParty.gxby.find(function (x) {
- return x.value === data.gxby_status;
- });
- return def ? def.name : '';
- }
- function getDaglText(data) {
- const def = thirdParty.dagl.find(function (x) {
- return x.value === data.dagl_status;
- });
- return def ? def.name : '';
- }
- function getHintMsg () {
- return {
- invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
- disableChange: {type: 'error', msg: '不可修改此数据'},
- }
- }
- let ledgerData, posData = '';
- $(document).ready(() => {
- const completePerField = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
- const exportExcelSetting = {
- cols: [
- {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
- {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
- {title: '本期数量变更|数量', colSpan: '3|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
- {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
- {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
- {title: '截止本期数量变更|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
- {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'end_qc_minus_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
- {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_final_1_percent', hAlign: 2, width: 80, type: 'Number'},
- {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
- {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
- {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
- {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
- {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
- {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
- {title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 80, formatter: '@'},
- ],
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: 'bold 10px 微软雅黑',
- font: '10px 微软雅黑'
- };
- let detail, searchLedger, checkedChanges;
- const checkOption = {
- sibling: { enable: 0 },
- empty_code: { enable: 0 },
- calc: {
- enable: 1,
- fields: ['contract_qty', 'qc_qty', 'qc_minus_qty'],
- },
- zero: { enable: 0 },
- tp: {
- enable: 1,
- fields: [
- {qty: 'contract_qty', tp: 'contract_tp'},
- {qty: 'qc_qty', tp: 'qc_tp'},
- ],
- filter: function (node) {
- return node.is_tp;
- }
- },
- over: { enable: 1, isTz: checkTzMeasureType(), checkInfo: tenderInfo.checkOverInfo },
- limit3f: { enable: 1, checkType: [], status: thirdParty, },
- minus_cb: { enable: hintMinusCb },
- // change_over: { enable: 1 },
- };
- if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');
- if (tender.s2b_dagl_check) checkOption.limit3f.checkType.push('dagl');
- // 界面布局
- autoFlashHeight();
- let featureDisplay;
- const changeFeaturesDisplay = function (show, init = false) {
- $('#features-show').html(show ? '<i class="fa fa-eye-slash"></i> 隐藏特征' : '<i class="fa fa-eye"></i> 显示特征');
- const featureCols = ledgerSpreadSetting.cols.find(x => { return x.field === 'features'; });
- if (!featureCols) return;
- featureCols.visible = show ? true : false;
- if (!init) {
- featureDisplay = show;
- setLocalCache(featureShowCache, show ? 1 : 0);
- SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet(), 1);
- }
- };
- const reloadFeaturesDisplayCache = function () {
- const featureCols = ledgerSpreadSetting.cols.find(x => { return x.field === 'features'; });
- if (featureCols) {
- $('#features-show').show();
- featureDisplay = getLocalCache(featureShowCache);
- featureDisplay = featureDisplay ? parseInt(featureDisplay) : 1;
- changeFeaturesDisplay(featureDisplay, true);
- } else {
- $('#features-show').hide();
- }
- };
- reloadFeaturesDisplayCache();
- $('#features-show').click(function() {
- changeFeaturesDisplay(!featureDisplay);
- });
- // 初始化 台账树结构 数据结构
- removeLocalCache('bills-fold');
- const stageTreeSetting = {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tender_id', 'ledger_id'],
- stageId: 'id',
- autoExpand: 3,
- // markFoldKey: 'bills-fold',
- // markFoldSubKey: window.location.pathname.split('/')[2],
- markExpandKey: 'stage-bills-expand',
- markExpandSubKey: window.location.pathname.split('/')[2],
- };
- // 台账树结构计算相关设置
- stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'postil', 'used', 'contract_expr', 'ex_stage_qty1', 'ex_stage_tp1'];
- stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp',
- 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp',
- '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'];
- stageTreeSetting.calcFun = function (node) {
- if (!node.children || node.children.length === 0) {
- node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
- node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
- node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
- node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
- node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
- node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty);
- node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity);
- node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp);
- node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty);
- node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
- node.due_final_qty = ZhCalc.add(node.quantity, node.due_qc_qty);
- node.end_ex_stage_qty1 = ZhCalc.add(node.ex_stage_qty1, node.pre_ex_stage_qty1);
- node.tz2_qty = ZhCalc.sum([node.quantity, node.tz_qc_qty, node.tz_qc_minus_qty]);
- }
- node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
- node.gather_tp = ZhCalc.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
- node.end_contract_tp = ZhCalc.sum([node.pre_contract_tp, node.contract_tp, node.contract_pc_tp]);
- node.end_qc_tp = ZhCalc.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
- node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
- node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
- node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
- node.due_final_tp = ZhCalc.add(node.total_price, node.due_qc_tp);
- node.end_ex_stage_tp1 = ZhCalc.add(node.ex_stage_tp1, node.pre_ex_stage_tp1);
- if (!node.children || node.children.length === 0) {
- if (node.end_contract_qty) {
- node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
- } else {
- node.end_correct_tp = node.end_gather_tp;
- }
- }
- node.tz2_tp = ZhCalc.sum([node.total_price, node.tz_qc_tp, node.tz_qc_minus_tp]);
- node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
- node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
- 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);
- node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
- node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
- };
- const stageTree = createNewPathTree('stage', stageTreeSetting);
- // 初始化 计量单元 数据结构
- const stagePosSetting = {
- id: 'id', ledgerId: 'lid',
- updateFields: ['contract_qty', 'qc_qty', 'qc_minus_qty', 'postil', 'contract_expr', 'ex_stage_qty1'],
- };
- stagePosSetting.calcFun = function (pos) {
- pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
- pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
- pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
- pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
- pos.end_qc_minus_qty = ZhCalc.add(pos.pre_qc_minus_qty, pos.qc_minus_qty);
- pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
- pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
- pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
- pos.end_contract_percent = ZhCalc.mul(ZhCalc.div(pos.end_contract_qty, pos.quantity), 100, 2);
- pos.estimate_qty = !checkZero(pos.real_qty)
- ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
- : null;
- pos.final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.quantity);
- pos.deal_final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.deal_qty);
- pos.end_final_1_qty = ZhCalc.add(pos.end_qc_qty, pos.final_1_qty);
- pos.end_ex_stage_qty1 = ZhCalc.add(pos.pre_ex_stage_qty1, pos.ex_stage_qty1);
- pos.due_final_qty = ZhCalc.add(pos.quantity, pos.due_qc_qty);
- pos.tz2_qty = ZhCalc.sum([pos.quantity, pos.tz_qc_qty, pos.tz_qc_minus_qty]);
- };
- const stagePos = new StagePosData(stagePosSetting);
- function checkUsed(tree, pos, node) {
- if (node.children && node.children.length > 0) {
- const posterity = tree.getPosterity(node);
- for (const p of posterity) {
- if (p.children && p.children.length > 0) continue;
- if (!checkZero(p.contract_qty) || !checkZero(p.contract_tp) ||
- !checkZero(p.qc_qty) || !checkZero(p.qc_tp) || !checkZero(p.qc_minus_qty))
- return true;
- const pPos = pos.getLedgerPos(p.id);
- if (!pPos || pPos.length === 0) continue;
- for (const pp of pPos) {
- if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
- }
- }
- return false;
- } else {
- if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp) ||
- !checkZero(node.qc_qty) || !checkZero(node.qc_tp) || !checkZero(node.qc_minus_qty))
- return true;
- const pPos = pos.getLedgerPos(node.id);
- if (!pPos || pPos.length === 0) return false;
- for (const pp of pPos) {
- if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
- }
- }
- };
- class Changes {
- constructor(obj) {
- const self = this;
- this.obj = obj;
- // 初始化 清单编号窗口 参数
- this.spreadSetting = {
- cols: [
- {title: '已用', field: 'select', width: 45, formatter: '@', cellType: 'checkbox', hAlign: 1, indent: 14, getValue: function (data) {return data.uamount && !checkZero(data.uamount);}},
- {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
- {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
- {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
- {title: '批复数量', field: 'b_amount', width: 60, readOnly: true, hAlign: 2, },
- {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, type: 'Number', getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
- {title: '本期计量', field: 'uamount', width: 60, hAlign: 2, type: 'Number', },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- getColor: function (sheet, data, row, col, defaultColor) {
- if (col.field === 'uamount') {
- if (data.bamount > 0) {
- const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
- return usedAmount < 0 || usedAmount > data.limitAmount ? spreadColor.stage.over : defaultColor;
- } else if (data.bamount < 0) {
- const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
- return usedAmount > 0 || usedAmount < data.limitAmount ? spreadColor.stage.over : defaultColor;
- } else {
- return data.uamount ? spreadColor.stage.over : defaultColor;
- }
- } else {
- return defaultColor;
- }
- }
- };
- this.curChangeId = '';
- this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
- this.firstView = true;
- SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
- // 初次显示,需刷新spread界面,保证界面绘制正确
- this.obj.bind('shown.bs.modal', function () {
- if (self.firstView) {
- self.firstView = false;
- self.spread.refresh();
- }
- });
- // 切换变更令,加载右侧明细数据
- this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- const change = SpreadJsObj.getSelectObject(info.sheet);
- if(change) self._loadChangeDetail(change);
- });
- // 填写本期计量
- this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
- if (info.sheet.zh_setting) {
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.cellType === 'checkbox') return;
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const node = sortData[info.row];
- if (col.type === 'Number') {
- const num = _.toNumber(info.editingText);
- if (_.isFinite(num)) {
- node[col.field] = num;
- } else {
- try {
- node[col.field] = ZhCalc.mathCalcExpr(transExpr(info.editingText));
- } catch(err) {
- toastr.error('输入的表达式非法');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- } else {
- node[col.field] = info.editingText;
- }
- // 刷新界面
- SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
- }
- });
- this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
- if (info.sheet.zh_setting) {
- const sortData = SpreadJsObj.getSortData(info.sheet);
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = iRow + info.cellRange.row;
- const curCol = info.cellRange.col;
- const col = info.sheet.zh_setting.cols[info.cellRange.col];
- if (col.type === 'Number') {
- const num = _.toNumber(info.sheet.getText(curRow, curCol));
- if (_.isFinite(num)) {
- sortData[curRow][col.field] = num;
- } else {
- try {
- sortData[curRow][col.field] = ZhCalc.mathCalcExpr(transExpr(info.sheet.getText(curRow, curCol)));
- } catch(err) {
- // toastr.error('输入的表达式非法');
- }
- }
- } else {
- sortData[curRow][col.field] = info.sheet.getText(curRow, curCol);
- }
- }
- SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
- }
- });
- this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
- if (!info.sheet.zh_setting) return;
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.cellType === 'checkbox') {
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- const select = info.sheet.zh_data[info.row];
- select.uamount = select.uamount ? 0 : select.vamount;
- SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
- }
- });
- SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
- if (sheet.zh_setting) {
- const sel = sheet.getSelections()[0];
- const sortData = SpreadJsObj.getSortData(sheet);
- // 仅本期计量可删除
- if (sel.col === 5 && sel.colCount === 1) {
- const col = sheet.zh_setting.cols[sel.col];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const data = sortData[iRow];
- data[col.field] = null;
- }
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- }
- }
- });
- // 过滤可变更数量为0
- $('#filterEmpty').click(function () {
- self._filterChange(!this.checked, $('#matchPos')[0].checked);
- });
- // 匹配编号
- $('#matchPos').click(function () {
- self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
- });
- // 展开收起 变更令详细信息
- $('#show-bgl-detail').bind('click', function () {
- const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
- if (detail.hasClass('col-4')) {
- detail.attr('class', 'col').hide();
- bgl.attr('class', 'col-12');
- $('a', obj).attr('title', '展开侧栏');
- $('i', obj).attr('class', 'fa fa-chevron-left');
- self.spread.refresh();
- } else {
- detail.attr('class', 'col-4').show();
- bgl.attr('class', 'col-8');
- $('a', obj).attr('title', '收起侧栏');
- $('i', obj).attr('class', 'fa fa-chevron-right');
- self.spread.refresh();
- }
- });
- // 添加调用变更令
- $('#usg-bg-ok').click(function () {
- const data = { target: self.callData, change: [] };
- for (const c of self.displayChanges) {
- if (c.uamount) {
- if (c.bamount > 0) {
- const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
- if (usedAmount < 0 || usedAmount > c.limitAmount) {
- toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
- return;
- }
- } else if (c.bamount < 0) {
- const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
- if (usedAmount > 0 || usedAmount < c.limitAmount) {
- toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
- return;
- }
- } else {
- toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
- return;
- }
- data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount, minus: c.bamount < 0 });
- }
- }
- // 提交数据到后端
- postData(window.location.pathname + '/use-change', data, function(result) {
- if (result.pos) {
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.bills);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStageChangeUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateChangeData(result, nodes)
- }
- self.obj.modal('hide');
- });
- })
- }
- findDecimal(unit) {
- let value = 3;
- if (unit !== '') {
- value = precision.other.value;
- const changeUnits = precision;
- for (const d in changeUnits) {
- if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
- value = changeUnits[d].value;
- break;
- }
- }
- }
- return value;
- }
- _calculateAmount() {
- for (const c of this.changes) {
- c.bamount = _.toNumber(c.b_amount);
- const qtyDecimal = this.findDecimal(c.b_unit);
- c.limitAmount = ZhCalc.mul(c.bamount, ZhCalc.div(c.delimit, 100, 2), qtyDecimal);
- c.vamount = ZhCalc.sub(ZhCalc.sub(c.limitAmount, c.used_amount), c.stage_used_amount);
- const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid, no_value: this.callData.noValue});
- if (uc) {
- c.org_uamount = uc.qty;
- c.uamount = uc.qty;
- c.vamount = ZhCalc.add(c.vamount, uc.qty);
- }
- c.pre_amount = ZhCalc.sub(ZhCalc.add(c.used_amount, c.stage_used_amount), c.uamount);
- }
- }
- _loadChangeDetail(change) {
- if (change) {
- if (change.cid === this.curChangeId) { return; }
- this.curChangeId = change.cid;
- const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
- for (const i of inputs) {
- const field = $(i).attr('name');
- const text = (field && change[field]) ? change[field] : '';
- $(i).val(text);
- }
- const textareas = $('textarea', this.obj);
- for (const ta of textareas) {
- const field = $(ta).attr('name');
- const text = (field && change[field]) ? change[field].replace(/<br><br>/g, '\r\n') : '';
- ta.textContent = text;
- }
- const html = [];
- for (const a of change.attachments) {
- html.push('<tr>');
- html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
- html.push('<td>', a.u_name, '</td>');
- html.push('</tr>');
- }
- // 变更类型
- if (change.type) {
- const cType = change.type.split(',');
- $('input[name="type"]').prop("checked", false);
- for (const c of cType) {
- $('input[name="type"][value='+ c +']').prop("checked", true);
- }
- }
- // 变更类别
- $('select[name=class]').val(change.class);
- // 变更性质
- $('select[name=quality]').val(change.quality);
- // 变更单位
- $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
- // 费用承担方
- $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
- // 附件
- $('#attachment').html(html.join(''));
- } else {
- const inputs = $('input', this.obj);
- for (const i of inputs) {
- $(i).val('');
- }
- const textareas = $('textarea', this.obj);
- for (const ta of textareas) {
- ta.innerText = '';
- }
- $('#attachment').html('');
- }
- }
- _viewChanges() {
- const sheet = this.spread.getActiveSheet();
- if (this.changes) {
- sheet.setSelection(0, 0, 1, 1);
- this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
- this._loadChangeDetail(this.displayChanges[0]);
- } else {
- toastr.error('查询变更令有误,请刷新页面后重试');
- }
- }
- _matchPos(match, change) {
- return match && this.callData.pos
- ? (change.gcl_id === this.callData.bills.id && change.b_bwmx === this.callData.pos.name)
- : true;
- }
- _matchBillsParent(match, change) {
- return match ? (!change.b_bwmx || change.b_bwmx === (this.callData.leafXmj ? this.callData.leafXmj.name : '')) : true;
- }
- _filterChange(filterEmpty, matchPosName) {
- this.displayChanges = [];
- for (const c of this.changes) {
- const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
- const matchVisible = this.callData.pos ? this._matchPos(matchPosName, c) : this._matchBillsParent(matchPosName, c);
- if ((filterVisible && matchVisible) || (c.org_uamount)) {
- this.displayChanges.push(c);
- }
- }
- SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
- this._loadChangeDetail(this.displayChanges[0]);
- }
- loadChanges(data) {
- this.callData = data;
- // if (this.callData.pos) {
- // $('#matchPos').parent().show();
- // } else {
- // $('#matchPos').parent().hide();
- // }
- $('#matchPos').parent().show();
- const self = this;
- $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
- postData(window.location.pathname + '/valid-change', data, function (result) {
- self.changes = result.changes;
- self.useChanges = result.useChanges;
- self._calculateAmount();
- self._viewChanges();
- self.obj.modal('show');
- });
- }
- }
- const changesObj = new Changes($('#use-bg'));
- // 初始化 台账 spread
- const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
- const slSheet = slSpread.getActiveSheet();
- customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
- // 数量变更列,添加按钮
- const qcColShowImage = function (data) {
- if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
- return false;
- } else {
- const nodePos = stagePos.getLedgerPos(data.id);
- return !(nodePos && nodePos.length > 0);
- }
- };
- sjsSettingObj.setQcCols(ledgerSpreadSetting.cols, [
- {field: 'qc_qty', showImage: qcColShowImage},
- {field: 'qc_minus_qty', showImage: qcColShowImage},
- ]);
- sjsSettingObj.setOrgPriceCol(ledgerSpreadSetting.cols, [ {field: 'org_price'} ]);
- // const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
- // if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
- const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
- if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
- ledgerSpreadSetting.imageClick = function (data, hitinfo) {
- const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
- switch (col.field) {
- case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
- case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
- case 'qc_qty':
- case 'qc_minus_qty':
- if (data.children && data.children.length > 0 || data.lock || data.is_import || data.settle_status === settleStatus.finish) return;
- const nodePos = stagePos.getLedgerPos(data.id);
- if (nodePos && nodePos.length > 0) return;
- const minus = col.field === 'qc_minus_qty' ? 1 : 0;
- const leafXmj = stageTree.getLeafXmjParent(data);
- changesObj.loadChanges({bills: data, minus, noValue: minus, leafXmj: leafXmj});
- break;
- default: return;
- }
- };
- ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
- ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
- if (data) {
- if (col.field === 'gxby') {
- const def = thirdParty.gxby.find(function (x) {
- return x.value === data.gxby_status;
- });
- if (def && def.color) return def.color;
- } else if (col.field === 'dagl') {
- const def = thirdParty.dagl.find(function (x) {
- return x.value === data.dagl_status;
- });
- if (def && def.color) return def.color;
- }
- if (data.settle_status === settleStatus.finish) {
- return spreadColor.stage.settle;
- }
- return hintOver && checkUtils.billsOver(data, stagePos, tenderInfo.checkOverInfo) ? spreadColor.stage.over : defaultColor;
- } else {
- return defaultColor;
- }
- };
- sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- sjsSettingObj.set3FCols(ledgerSpreadSetting.cols, [
- {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
- {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
- ]);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
- ledgerSpreadSetting.headColWidth = [50];
- ledgerSpreadSetting.rowHeader = [
- {
- rowHeaderType: 'tag',
- setting: {
- indent: 14,
- tagSize: 0.8,
- tagFont: '8px 微软雅黑',
- getColor: function (index, data) {
- if (!data) return;
- return billsTag.getBillsTagsColor(data.id);
- },
- getTagHtml: function (index, data) {
- if (!data) return;
- const getHtml = function (list) {
- if (!list || list.length === 0) return '';
- const html = [];
- for (const l of list) {
- html.push('<div class="mr-1">');
- html.push(`<div class="float-left ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
- html.push('<div class="ml-4">', '<p style="word-wrap: break-word">', l.comment, '</p>', '</div>');
- html.push('</div>');
- }
- return html.join('');
- };
- return getHtml(billsTag.getBillsTagsInfo(data.id));
- }
- },
- },
- ];
- sjsSettingObj.setIsTpCol(ledgerSpreadSetting.cols, [ {field: 'is_tp'} ]);
- ledgerSpreadSetting.readOnly = function (data) {
- if (!data) return false;
- return data.lock || stageTreeSpreadObj.assistReadOnly;
- };
- SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
- //初始化所有附件列表
- getAllList();
- // 初始化 计量单元 Spread
- const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
- const spSheet = spSpread.getActiveSheet();
- const posQcColShowImage = function (data) {
- return data !== undefined && data !== null;
- };
- sjsSettingObj.setQcCols(posSpreadSetting.cols, [
- { field: 'qc_qty', showImage: posQcColShowImage },
- { field: 'qc_minus_qty', showImage: posQcColShowImage }
- ]);
- posSpreadSetting.imageClick = function (data, hitinfo) {
- const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
- switch (col.field) {
- case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
- case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
- case 'qc_qty':
- case 'qc_minus_qty':
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (node.lock || node.settle_status === settleStatus.finish) return;
- const minus = col.field === 'qc_minus_qty' ? 1 : 0;
- changesObj.loadChanges({bills: node, pos: data, minus, noValue: minus});
- break;
- default: return;
- }
- };
- posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
- if (data) {
- if (col.field === 'gxby') {
- const def = thirdParty.gxby.find(function (x) {
- return x.value === data.gxby_status;
- });
- if (def && def.color) return def.color;
- } else if (col.field === 'dagl') {
- const def = thirdParty.dagl.find(function (x) {
- return x.value === data.dagl_status;
- });
- if (def && def.color) return def.color;
- }
- if (data.settle_status === settleStatus.finish) {
- return spreadColor.stage.settle;
- }
- }
- return hintOver && checkUtils.posOver(data, tenderInfo.checkOverInfo) ? spreadColor.stage.over : defaultColor;
- };
- sjsSettingObj.setGridSelectStyle(posSpreadSetting);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
- sjsSettingObj.set3FCols(posSpreadSetting.cols, [
- {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
- {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
- ]);
- SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
- const billsTag = $.billsTag({
- relaTree: stageTree,
- selector: '#bills-tag',
- relaSpread: slSpread,
- updateUrl: window.location.pathname + '/tag',
- afterModify: function (nodes) {
- SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
- },
- afterLocated: function () {
- stagePosSpreadObj.loadCurPosData();
- },
- afterShow: function () {
- slSpread.refresh();
- if (spSpread) spSpread.refresh();
- },
- });
- const errorList = $.cs_errorList({
- tabSelector: '#error-list-tab',
- selector: '#error-list',
- relaSpread: slSpread,
- storeKey: 'stage-error-' + stage.id,
- afterLocated: function () {
- stagePosSpreadObj.loadCurPosData();
- },
- afterShow: function () {
- slSpread.refresh();
- if (spSpread) spSpread.refresh();
- },
- });
- const checkList = $.ledger_checkList({
- id: 'check-list',
- tabSelector: '#check-list-tab',
- selector: '#check-list',
- relaSpread: slSpread,
- storeKey: 'stage-check-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
- checkType: getCheckType(checkOption),
- afterLocated: function () {
- stagePosSpreadObj.loadCurPosData();
- },
- afterShow: function () {
- slSpread.refresh();
- if (spSpread) spSpread.refresh();
- },
- });
- const sumLoadMiss = $.sumLoadMiss({
- tabSelector: '#sum-load-miss-tab',
- selector: '#sum-load-miss',
- relaSpread: slSpread,
- storeKey: 'stage-slm-' + stage.id,
- id: 'stage-slm',
- type: 'stage',
- afterLocated: function () {
- stagePosSpreadObj.loadCurPosData();
- },
- afterShow: function () {
- slSpread.refresh();
- if (spSpread) spSpread.refresh();
- },
- });
- const stageTreeSpreadObj = {
- cut: function (sheet, sel, callback) {
- callback(true);
- },
- loadExprToInput(sheet) {
- const sel = sheet.getSelections()[0];
- const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
- if (col.type === 'Number') {
- const data = SpreadJsObj.getSelectObject(sheet);
- if (!data) {
- $('#bills-expr').val('').attr('readOnly', true);
- $('#bills-expr').removeAttr('data-row');
- return;
- }
- const nodePos = stagePos.getLedgerPos(data.id);
- if (nodePos && nodePos.length > 0) {
- $('#bills-expr').val('').attr('readOnly', true);
- } else {
- if ((!data.is_tp && col.field.indexOf('tp') >= 0) || (data.is_tp && col.field.indexOf('tp') < 0)) {
- $('#bills-expr').val('').attr('readOnly', true);
- $('#bills-expr').removeAttr('data-row');
- return;
- }
- const exprInfo = getExprInfo(col.field);
- const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
- $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
- if (col.field.indexOf('tp') >= 0) {
- $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
- } else {
- $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
- }
- }
- $('#bills-expr').attr('data-row', sel.row);
- } else {
- $('#bills-expr').val('').attr('readOnly', true);
- $('#bills-expr').removeAttr('data-row');
- }
- },
- refreshTreeNodes: function (sheet, nodes) {
- const tree = sheet.zh_tree;
- if (!tree) { return }
- const rows = [];
- for (const node of nodes) {
- rows.push(tree.nodes.indexOf(node));
- }
- SpreadJsObj.reLoadRowsData(sheet, rows);
- },
- editEnded: function (e, info) {
- if (info.sheet.zh_setting) {
- const col = info.sheet.zh_setting.cols[info.col];
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const node = sortData[info.row], updateData = {};
- const orgValue = node[col.field];
- let newValue = trimInvalidChar(info.editingText);
- if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
- return;
- }
- if (col.type === 'Number' && newValue && newValue !== '') {
- const num = _.toNumber(newValue);
- if (_.isFinite(num)) {
- newValue = num;
- } else {
- try {
- newValue = ZhCalc.mathCalcExpr(transExpr(newValue));
- } catch(err) {
- toastr.error('输入的表达式非法');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- if (col.field.indexOf('_dgn_') > 0) {
- if (node.b_code && node.b_code !== '') {
- toastr.error('仅项目节可输入项目节数量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
- if (node.children && node.children.length > 0) {
- toastr.error('清单父项不可计量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else {
- const nodePos = stagePos.getLedgerPos(node.id);
- if (nodePos && nodePos.length > 0) {
- toastr.error('该清单有计量单元,请在计量单元处计量');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
- updateData.main = {
- id: node.id
- };
- updateData.main[col.field] = newValue;
- } else if (col.field.indexOf('_dgn_') > 0) {
- updateData.dgn = {
- id: node.id
- };
- updateData.dgn[col.field] = newValue;
- } else if (col.field !== 'is_tp') {
- updateData.stage = {
- lid: node.id
- };
- updateData.stage[col.field] = newValue;
- const exprInfo = getExprInfo(col.field);
- if (exprInfo) {
- updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
- }
- }
- postData(window.location.href + '/update', {bills: updateData}, function (data) {
- // tag update
- const nodes = stageTree.loadPostStageData(data);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(data, nodes);
- } else {
- stageIm.loadUpdateLedgerData(data, nodes);
- }
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- }
- },
- loadRelaData: function () {
- const billsSheet = slSpread.getActiveSheet();
- SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
- const posSheet = spSpread.getActiveSheet();
- SpreadJsObj.resetTopAndSelect(posSheet);
- stagePosSpreadObj.loadCurPosData();
- if (posSearch) posSearch.search();
- },
- selectionChanged: function (e, info) {
- if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
- stageTreeSpreadObj.loadRelaData();
- // 全选去除
- $('#dqjiedian').find('.check-all-file').prop('checked', false);
- }
- stageTreeSpreadObj.loadExprToInput(info.sheet);
- },
- deletePress(sheet) {
- if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
- const tree = sheet.zh_tree;
- if (!tree) { return; }
- const sel = sheet.getSelections()[0];
- const validCols = [];
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
- validCols.push(iCol);
- }
- }
- if (validCols.length === 0) { return; }
- const sortData = sheet.zh_tree.nodes;
- const datas = [], dgnDatas = [], mainDatas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const node = sortData[iRow];
- if (node && !node.lock) {
- const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
- let filter = true, filterDgn = true, filterMain = true;
- for (const iCol of validCols) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
- if (node.b_code && node.b_code !== '') continue;
- } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) < 0) {
- if (colSetting.field === 'contract_qty') {
- if (node.is_tp || node.settle_status === settleStatus.finish) continue;
- } else if (colSetting.field === 'contract_tp') {
- if (!node.is_tp || node.settle_status === settleStatus.finish) continue;
- }
- if (node.children && node.children.length > 0) {
- continue;
- }
- const nodePos = stagePos.getLedgerPos(node.id);
- if (nodePos && nodePos.length > 0) {
- continue;
- }
- }
- if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
- if (node[colSetting.field] && node[colSetting.field] !== 0) {
- dgnData[colSetting.field] = 0;
- filterDgn = false;
- }
- } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) >= 0) {
- mainData[colSetting.field] = null;
- filterMain = false;
- } else {
- data[colSetting.field] = colSetting.type === 'Number' ? 0 : '';
- const exprInfo = getExprInfo(colSetting.field);
- if (exprInfo) {
- data[exprInfo.expr] = '';
- }
- filter = false;
- }
- }
- if (!filter) datas.push(data);
- if (!filterDgn) dgnDatas.push(dgnData);
- if (!filterMain) mainDatas.push(mainData);
- }
- }
- if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
- const bills = {};
- if (datas.length > 0) bills.stage = datas;
- if (dgnDatas.length > 0) bills.dgn = dgnDatas;
- if (mainDatas.length > 0) bills.main = mainDatas;
- postData(window.location.href + '/update', {bills: bills}, function (result) {
- const nodes = stageTree.loadPostStageData(result);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateLedgerData(result, nodes);
- }
- stageTreeSpreadObj.loadExprToInput(sheet);
- });
- }
- }
- },
- clipboardPasting(e, info) {
- if (info.sheet.zh_setting) {
- const setting = info.sheet.zh_setting;
- const range = info.cellRange;
- 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);
- for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
- const col = info.sheet.zh_setting.cols[iCol];
- if ((validField.indexOf(col.field) === -1)) {
- toastr.error('不可修改此数据');
- info.cancel = true;
- return;
- }
- }
- }
- },
- clipboardPasted(e, info) {
- const pasteHint = getHintMsg();
- if (info.sheet.zh_setting && info.sheet.zh_tree) {
- const sheet = info.sheet, setting = info.sheet.zh_setting;
- const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = iRow + info.cellRange.row;
- const node = sheet.zh_tree.getItemsByIndex(curRow);
- const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
- let filter = true, filterDgn = true, filterMain = true;
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const col = info.sheet.zh_setting.cols[curCol];
- if (col.field === 'contract_tp') {
- if (!node.is_tp || node.settle_status === settleStatus.finish) continue;
- } else if (col.field === 'contract_qty') {
- if (node.is_tp || node.settle_status === settleStatus.finish) continue;
- }
- if (setting.dgnUpFields.indexOf(col.field) !== -1) {
- if (node.b_code && node.b_code !== '') continue;
- } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
- if (node.children && node.children.length > 0) continue;
- const nodePos = stagePos.getLedgerPos(node.id);
- if (nodePos && nodePos.length > 0) continue;
- }
- const text = trimInvalidChar(sheet.getText(curRow, curCol));
- if (setting.dgnUpFields.indexOf(col.field) !== -1) {
- const num = _.toNumber(text);
- if (num) {
- dgnData[col.field] = num;
- filterDgn = false;
- } else {
- try {
- dgnData[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
- filterDgn = false;
- } catch(err) {
- toastMessageUniq(pasteHint.invalidExpr);
- }
- }
- } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
- mainData[col.field] = text;
- filterMain = false;
- } else {
- if (col.type === 'Number') {
- const exprInfo = getExprInfo(col.field);
- if (text) {
- const num = _.toNumber(text);
- data[col.field] = num;
- if (exprInfo) data[exprInfo.expr] = '';
- if (_.isFinite(num)) {
- filter = false;
- } else {
- try {
- data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
- if (exprInfo) data[exprInfo.expr] = text;
- filter = false;
- } catch(err) {
- toastMessageUniq(pasteHint.invalidExpr);
- }
- }
- } else {
- data[col.field] = null;
- if (exprInfo) data[exprInfo.expr] = '';
- filter = false;
- }
- } else {
- data[col.field] = text;
- }
- }
- }
- if (filter && filterDgn && filterMain) {
- filterNodes.push(node);
- } else {
- if (!filter) datas.push(data);
- if (!filterDgn) dgnDatas.push(dgnData);
- if (!filterMain) mainDatas.push(mainData);
- }
- }
- if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
- const updateData = {};
- if (datas.length > 0) updateData.stage = datas;
- if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
- if (mainDatas.length > 0) updateData.main = mainDatas;
- postData(window.location.href + '/update', {bills: updateData}, function (data) {
- const nodes = stageTree.loadPostStageData(data);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
- if (detail) {
- detail.loadStageLedgerUpdateData(data, nodes);
- } else {
- stageIm.loadUpdateLedgerData(data, nodes);
- }
- stageTreeSpreadObj.loadExprToInput(sheet);
- }, function () {
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
- });
- } else {
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
- }
- }
- },
- measureAllPosInNode(node, ratio = 1) {
- const posterity = stageTree.getPosterity(node);
- const data = {updateType: 'update', updateData: []};
- for (const p of posterity) {
- if (p.children && p.children.length > 0) continue;
- const posRange = stagePos.getLedgerPos(p.id);
- if (posRange && posRange.length > 0) {
- for (const pr of posRange) {
- if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
- const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
- if (validValue <= 0) continue;
- const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
- const pData = {
- pid: pr.id,
- lid: pr.lid,
- contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
- };
- data.updateData.push(pData);
- }
- }
- if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
- toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
- break;
- }
- }
- if (data.updateData.length === 0) {
- toastr.info('其下全部计量单元均已计量');
- return;
- }
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStagePosUpdateData(result, nodes);
- } else {
- stageIm.loadUpdatePosData(result, nodes);
- }
- toastr.success('已计量' + data.updateData.length + '条');
- }, function () {
- stagePosSpreadObj.loadCurPosData();
- });
- },
- topRowChanged(e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
- },
- editStarting(e, info) {
- if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
- const col = info.sheet.zh_setting.cols[info.col];
- const node = info.sheet.zh_tree.nodes[info.row];
- switch (col.field) {
- case 'contract_qty':
- case 'qc_qty':
- case 'qc_minus_qty':
- info.cancel = node.is_tp || node.settle_status === settleStatus.finish;
- break;
- case 'ex_stage_qty1':
- info.cancel = node.is_tp;
- break;
- case 'contract_tp':
- info.cancel = !node.is_tp || node.settle_status === settleStatus.finish;
- break;
- case 'is_tp':
- info.cancel = true;
- break;
- }
- if (!info.cancel) {
- const exprInfo = getExprInfo(col.field);
- if (exprInfo) {
- if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
- info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
- }
- }
- }
- },
- buttonClicked: function (e, info) {
- if (info.sheet.zh_setting) {
- const node = SpreadJsObj.getSelectObject(info.sheet);
- const col = info.sheet.zh_setting.cols[info.col];
- const posRange = stagePos.getLedgerPos(node.id);
- const tpUnit = ['总额', '元', '台', '个', '处', '月', '棵', '套', '组', '辆', '项', '座', '根', '块', '系统'];
- if (node.pre_used === 1 ||
- (node.children && node.children.length > 0) ||
- (tpUnit.indexOf(node.unit) < 0) ||
- (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const postIsTp = function () {
- const data = { calcType: {id: node.id} };
- data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
- // 更新至服务器
- postData(window.location.pathname + '/update', {bills: data}, function (result) {
- const nodes = stageTree.loadPostStageData(result);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateLedgerData(result, nodes);
- }
- });
- };
- if (col.field === 'is_tp') {
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp) || !checkZero(node.ex_stage_qty1) || !checkZero(node.ex_stage_tp1)) {
- $.msgBox({
- id: 'calc-type',
- title: '提示',
- message: '切换计量模式,已计量数据会被清空。',
- ok: {
- caption: '确定',
- callback: postIsTp,
- },
- cancel: {
- caption: '取消',
- callback: function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- }
- }
- });
- } else {
- postIsTp();
- }
- }
- }
- },
- measureByBatch: function (posNames, ratio, apply2sibling) {
- if (posNames.length <= 0) return;
- if (ratio <= 0) return;
- const fRatio = ZhCalc.div(ratio, 100);
- const sheet = slSpread.getActiveSheet();
- const node = SpreadJsObj.getSelectObject(sheet);
- const parent = stageTree.getParent(node);
- const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
- const data = {updateType: 'batchUpdate', updateData: []};
- for (const node of nodes) {
- const posRange = stagePos.getLedgerPos(node.id);
- if (!posRange || posRange <= 0) continue;
- for (const p of posRange) {
- if (posNames.indexOf(p.name) < 0) continue;
- data.updateData.push({
- pid: p.id, lid: p.lid,
- contract_qty: ZhCalc.mul(p.quantity, fRatio),
- contract_expr: `${p.quantity}*${ratio}%`,
- });
- }
- }
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStagePosUpdateData(result, nodes);
- } else {
- stageIm.loadUpdatePosData(result, nodes);
- }
- $('#calc-by-ratio').modal('hide');
- }, function () {
- stagePosSpreadObj.loadCurPosData();
- $('#calc-by-ratio').modal('hide');
- });
- },
- exportExcel: function (filename, nodes, withPos = true) {
- stageTree.recursiveExe(function(node) {
- if (node.children && node.children.length > 0) {
- node._export_group = _.sum(node.children.map(x => { return x._export_group; })) + node.children.length;
- } else {
- const posRange = stagePos.getLedgerPos(node.id);
- node._export_group = posRange ? posRange.length : 0;
- }
- });
- const exportNodesData = function (data, nodes, groupData) {
- for (const node of nodes) {
- data.push({
- code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
- unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
- contract_qty: node.contract_qty, contract_tp: node.contract_tp,
- qc_qty: node.qc_qty, qc_tp: node.qc_tp, qc_minus_qty: node.qc_minus_qty,
- gather_qty: node.gather_qty, gather_tp: node.gather_tp,
- end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
- end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp, end_qc_minus_qty: node.end_qc_minus_qty,
- end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_final_1_percent: node.end_final_1_percent,
- deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
- c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
- final_dgn_price: node.final_dgn_price,
- postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
- contract_expr_str: node.calc_expr ? TreeExprCalc.expr2ExprStr(node.calc_expr) : '',
- });
- if (node.children && node.children.length > 0) {
- exportNodesData(data, node.children, groupData);
- } else {
- if (!withPos) continue;
- const posRange = stagePos.getLedgerPos(node.id);
- if (!posRange || posRange.length === 0) continue;
- if (node._export_group) groupData.push({ code: node.code, b_code: node.b_code, start: data.length, count: node._export_group });
- for (const [i, p] of posRange.entries()) {
- data.push({
- pos_code: (i + 1) + '', name: p.name,
- quantity: p.quantity,
- contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
- end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
- qc_minus_qty: p.qc_minus_qty, end_qc_minus_qty: p.end_qc_minus_qty,
- drawing_code: p.drawing_code, memo: p.memo, postil: p.postil, position: p.position,
- });
- }
- }
- }
- };
- const data = [], groupData = [];
- exportNodesData(data, nodes ? nodes : stageTree.children, groupData);
- SpreadExcelObj.exportSimpleXlsxSheet(exportExcelSetting, data, filename, groupData);
- },
- loadChangeData: function(tree, pos, changes) {
- const findEmptyBills = function(tree, change, changeBills) {
- const cb = {
- b_code: changeBills.code || '',
- name: changeBills.name || '',
- unit: changeBills.unit || '',
- unit_price: changeBills.unit_price || 0,
- };
- for (const node of tree.nodes) {
- if (node.children && node.children.length > 0) continue;
- const b = {
- b_code: node.b_code || '',
- name: node.name || '',
- unit: node.unit || '',
- unit_price: node.unit_price || 0,
- };
- if (_.isMatch(cb, b)) return node;
- }
- return null;
- };
- for (const change of changes) {
- for (const changeBills of change.bills) {
- const node = changeBills.gcl_id
- ? tree.nodes.find(x => {return x.id === changeBills.gcl_id})
- : findEmptyBills(tree, change, changeBills);
- if (!node) continue;
- node.tz_qc_qty = ZhCalc.add(node.tz_qc_qty, changeBills.checked_amount);
- node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.checked_price);
- const posData = pos.getLedgerPos(node.id);
- if (posData && posData.length > 0) {
- for (const p of changeBills.pos) {
- const changePos = p.bwmx ? posData.find(x => { return x.name === p.bwmx; }) : posData[0];
- if (changePos) changePos.tz_qc_qty = ZhCalc.add(changePos.tz_qc_qty, p.checked_amount);
- }
- }
- }
- }
- }
- };
- slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
- slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
- slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
- slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
- slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
- slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
- slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
- SpreadJsObj.addCutEvents(slSpread, stageTreeSpreadObj.cut);
- SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
- if (!readOnly) {
- $('#bills-expr').bind('change onblur', function () {
- if (this.readOnly) return;
- const expr = $(this);
- const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
- const select = stageTree.getItemsByIndex(row);
- if (!select) return;
- const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
- let newValue = expr.val();
- const num = _.toNumber(newValue);
- if (_.isFinite(num)) {
- newValue = num;
- } else {
- try {
- newValue = ZhCalc.mathCalcExpr(transExpr(newValue));
- } catch(err) {
- toastr.error('输入的表达式非法');
- return;
- }
- }
- if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
- if (field.indexOf('_dgn_') > 0) {
- updateData.dgn = {
- id: select.id
- };
- updateData.dgn[field] = newValue;
- } else {
- updateData.stage = {
- lid: select.id
- };
- updateData.stage[field] = newValue;
- const exprInfo = getExprInfo(field);
- if (exprInfo) {
- updateData.stage[exprInfo.expr] = expr.val();
- }
- }
- // 更新至服务器
- postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
- const nodes = stageTree.loadPostStageData(result);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateLedgerData(result, nodes);
- }
- });
- });
- }
- stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
- const addTag = newTag({ledgerSheet: slSpread.getActiveSheet(), billsTag});
- const tenderSelect = TenderSelect({
- type: 'stage',
- afterLoad: function (result, select) {
- const nodes = stageTree.loadPostStageData(result);
- const posterity = stageTree.getPosterity(select);
- for (const p of posterity) {
- p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
- }
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateLedgerData(result, nodes);
- }
- if (result.sumLoadHis.errors.length > 0) {
- sumLoadMiss.loadMissData(result.sumLoadHis.errors);
- sumLoadMiss.show();
- } else {
- sumLoadMiss.clearMissData();
- }
- // todo 优化,仅加载需要刷新的变更令
- if (checkedChanges) checkedChanges.reloadChangeData();
- }
- });
- const batchImport = BatchImportStageGcl({
- stageTree,
- afterLoad: function (result, select) {
- const nodes = stageTree.loadPostStageData(result);
- const posterity = stageTree.getPosterity(select);
- for (const p of posterity) {
- p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
- }
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateLedgerData(result, nodes);
- }
- if (checkedChanges) checkedChanges.reloadChangeData();
- }
- });
- $.contextMenu({
- selector: '#stage-ledger',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
- stageTreeSpreadObj.loadRelaData();
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'remainCur': {
- name: '填剩余量',
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return readOnly || !node || node.lock;
- },
- callback: function (key, opt) {
- const sheet = spSpread.getActiveSheet();
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const updateStage = [];
- const posterity = stageTree.getPosterity(node);
- posterity.unshift(node);
- for (const p of posterity) {
- if (p.children && p.children.length > 0) continue;
- if (!p.b_code) continue;
- const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
- if (posRange.length > 0) continue;
- if (!p.is_tp) {
- const qty = ZhCalc.sub(p.quantity, p.pre_contract_qty);
- const differ = ZhCalc.sub(p.quantity, p.end_contract_qty);
- if (differ) updateStage.push({ lid: p.id, contract_qty: qty, contract_expr: '' });
- } else {
- const tp = ZhCalc.sub(p.total_price, p.pre_contract_tp);
- const differ = ZhCalc.sub(p.quantity, p.end_contract_qty);
- if (differ) updateStage.push({ lid: p.id, contract_tp: tp });
- }
- }
- if (updateStage.length === 0) {
- toastr.warning('所选节点及子项已全部计量');
- return;
- }
- if (updateStage.length > 0) {
- if (updateStage.length > 1000) {
- toastr.warning('提交的数据太大,仅提交1000条数据');
- updateStage.length = 1000;
- }
- postData(window.location.pathname + '/update', {bills: { stage: updateStage }}, function (result) {
- const nodes = stageTree.loadPostStageData(result);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateLedgerData(result, nodes);
- }
- stageTreeSpreadObj.loadExprToInput(sheet);
- });
- }
- }
- },
- 'remainCurPos': {
- name: '填剩余量(计量单元)',
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return readOnly || !node || node.lock;
- },
- callback: function (key, opt) {
- const sheet = spSpread.getActiveSheet();
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const data = { updateType: 'batchUpdate', updateData: [] };
- const posterity = stageTree.getPosterity(node);
- posterity.unshift(node);
- for (const p of posterity) {
- if (p.children && p.children.length > 0) continue;
- if (!p.b_code) continue;
- const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
- if (posRange.length === 0) continue;
- for (const pr of posRange) {
- const qty = ZhCalc.sub(pr.quantity, pr.pre_contract_qty);
- const differ = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
- if (differ) data.updateData.push({ lid: pr.lid, pid: pr.id, contract_qty: qty, contract_expr: '' });
- }
- }
- if (data.updateData.length === 0) {
- toastr.warning('所选节点及子项已全部计量');
- return;
- }
- if (data.updateData.length > 0) {
- if (data.updateData.length > 1000) {
- toastr.warning('提交的数据太大,仅提交1000条数据');
- data.updateData.length = 1000;
- }
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStagePosUpdateData(result, nodes);
- } else {
- stageIm.loadUpdatePosData(result, nodes);
- }
- stageTreeSpreadObj.loadExprToInput(sheet);
- });
- }
- }
- },
- 'remainXmjQty': {
- name: '填项目节数量',
- callback: function(key, opt) {
- const sheet = spSpread.getActiveSheet();
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const updateDgn = [];
- const posterity = stageTree.getPosterity(node);
- posterity.unshift(node);
- for (const p of posterity) {
- if (p.b_code) continue;
- const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
- if (posRange.length > 0) continue;
- 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 });
- }
- if (updateDgn.length === 0) {
- toastr.warning('所选项目节及子项的项目节数量已与台账相等');
- return;
- }
- if (updateDgn.length > 1000) {
- toastr.warning('提交的数据太大,仅提交1000条数据');
- updateDgn.length = 1000;
- }
- postData(window.location.pathname + '/update', {bills: { dgn: updateDgn }}, function (result) {
- const nodes = stageTree.loadPostStageData(result);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateLedgerData(result, nodes);
- }
- stageTreeSpreadObj.loadExprToInput(sheet);
- });
- // postData(window.location.pathname + '/update', { dgn: 'all' }, function (result) {
- // const nodes = stageTree.loadPostStageData(result);
- // stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- // if (detail) {
- // detail.loadStageLedgerUpdateData(result, nodes);
- // } else {
- // stageIm.loadUpdateLedgerData(result, nodes);
- // }
- // stageTreeSpreadObj.loadExprToInput(sheet);
- // });
- },
- visible: function(key, opt) {
- return !readOnly;
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return !node || !!node.b_code;
- }
- },
- 'remainByExprAll': {
- name: '计算本期合同计量',
- icon: 'fa-forward',
- callback: function(key, opt) {
- const sheet = spSpread.getActiveSheet();
- TreeExprCalc.setCalcType(TreeExprCalc.calcType.sortCache);
- const calcExpr = stageTree.nodes.filter(x => {
- if (x.children && x.children.length > 0) return false;
- const posRange = stagePos.getLedgerPos(x.id);
- if (posRange && posRange.length > 0) return false;
- return !!x.calc_expr;
- }).map(x => { return { id: x.id, expr: x.calc_expr, unit: x.unit, unit_price: x.unit_price, calcField: x.is_tp ? 'tp' : 'qty' }});
- if (calcExpr.length === 0) {
- toastr.warning('沒有可计算的公式');
- return;
- }
- TreeExprCalc.calcAllExpr(calcExpr);
- const updateData = calcExpr.map(x => {
- const data = { lid: x.id, contract_expr: x.formula };
- const field = x.calcField === 'qty' ? 'contract_qty' : 'contract_tp';
- data[field] = x.value;
- return data;
- });
- postData(window.location.pathname + '/update', {bills: { stage: updateData }}, function (result) {
- const nodes = stageTree.loadPostStageData(result);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStageLedgerUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateLedgerData(result, nodes);
- }
- stageTreeSpreadObj.loadExprToInput(sheet);
- });
- },
- visible: function(key, opt) {
- return !readOnly && contractExpr;
- },
- },
- zjjlSpr: '----',
- 'locateZjjl': {
- name: '定位至中间计量',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- if (!detail) {
- detail = new Detail($('#detail-spread'));
- }
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
- if (leafUsedBills) {
- if (!$('#zhongjian').hasClass('active')) {
- const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
- $('a', '.side-menu').removeClass('active');
- $('.tab-content .tab-select-show').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('active');
- showSideTools(tab.hasClass('active'));
- slSpread.refresh();
- spSpread.refresh();
- }
- const relaXmj = stageIm.getRelaXmj(leafUsedBills);
- const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
- SpreadJsObj.locateData(detail.sheet, im);
- detail.spread.refresh();
- $('#zhongjian .sjs-bottom').height('400px');
- $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
- detail.reLoadDetailData();
- } else {
- toastr.error('无可定位中间计量');
- }
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return !node;
- }
- },
- tagSpr: '----',
- tag: {
- name: '书签',
- callback: function (key, opt, menu, e) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- addTag.do(node);
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return !node;
- }
- },
- showSpr: '----',
- showLast: {
- name: '显示至最底层',
- callback: function (key, opt, menu, e) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- setTimeout(() => {
- showWaitingView();
- stageTree.expandByCustom(x => {
- return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
- });
- SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
- closeWaitingView();
- }, 100);
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return !node;
- }
- },
- exportSpr: '----',
- exportSelectNodeXlsx: {
- name: '导出选中节点至Excel',
- callback: function (key, opt, menu, e) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return !node;
- }
- },
- exportContractExprXlsx: {
- name: '导出本期合同计量公式',
- callback: function(key, opt, menu, e) {
- exportExcelSetting.cols.push({title: '本期合同计量计算式', colSpan: '1', rowSpan: '2', field: 'contract_expr_str', hAlign: 0, width: 140, formatter: '@'});
- stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + '本期合同计量公式.xlsx', null, false);
- exportExcelSetting.cols.splice(exportExcelSetting.cols.length - 1, 1);
- },
- visible: function(key, opt) {
- return contractExpr;
- }
- },
- dealLoadSpr: '---',
- exportDealData: {
- name: '导出本期合同计量',
- callback: function (key, opt, menu, e) {
- window.open(window.location.pathname + '/cpd');
- },
- },
- importDealData: {
- name: '导入本期合同计量',
- callback: function (key, opt, menu, e) {
- BaseImportFile.show({
- validList: ['.cpd'],
- url: window.location.pathname + '/cpd/load',
- afterImport: function() {
- window.location.reload();
- }
- });
- },
- disabled: function(key, opt) {
- return readOnly || stage.revising || stage.status !== auditConst.status.uncheck;
- },
- },
- sumLoadSpr: '---',
- importStageGcl: {
- name: '导入(其他标段)工程量清单计量数据',
- icon: 'fa-link',
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return readOnly || !node || !stageTree.isLeafXmj(node);
- },
- callback: function (key, opt) {
- tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
- }
- },
- batchImportStageGcl: {
- name: '批量导入(其他标段)工程量清单计量数据',
- icon: 'fa-link',
- disabled: function (key, opt) {
- return readOnly;
- },
- callback: function (key, opt){
- batchImport.show();
- }
- },
- shoufangdanSpr: '---',
- shoufangdan: {
- name: '生成收方单',
- visible: function(key, opt) {
- if (cur_uid === stage.user_id) return true;
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
- },
- callback: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- $('#shoufang-lid').val(node.id);
- $('#shoufang-pid').val('');
- $('#shoufang-ledger').text('清单:' + node.b_code);
- $('#shoufang-pos').text('').hide();
- $('#addshoufang').modal('show');
- }
- },
- lockedSpr: '----',
- lockedHint: {
- name: '检查审批状态',
- visible: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return node.locked;
- },
- callback: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const lockedInfo = stageTree.getLockedInfo(node);
- toastr.warning(`审批人 ${lockedInfo.map(x => { return x.name; }).join(',')} 审批通过,如需修改,请联系审批人重新审批`);
- }
- },
- }
- });
- const stagePosSpreadObj = {
- loadExprToInput(sheet) {
- const sel = sheet.getSelections()[0];
- if (!sel) return;
- const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
- if (col && col.type === 'Number') {
- const data = SpreadJsObj.getSelectObject(sheet);
- if (data) {
- const exprInfo = getExprInfo(col.field);
- const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
- $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
- .attr('readOnly', readOnly || cell.locked());
- $('#pos-expr').attr('data-row', sel.row);
- } else {
- $('#pos-expr').val('').attr('readOnly', true);
- $('#pos-expr').removeAttr('data-row');
- }
- } else {
- $('#pos-expr').val('').attr('readOnly', true);
- $('#pos-expr').removeAttr('data-row');
- }
- },
- /**
- * 加载计量单元 根据当前台账选择节点
- */
- loadCurPosData: function () {
- const sheet = slSpread.getActiveSheet();
- const node = SpreadJsObj.getSelectObject(sheet);
- if (node) {
- const posReadOnly = node.lock || (node.children && node.children.length > 0) || !node.b_code;
- spSpread.getActiveSheet().zh_setting.readOnly = posReadOnly;
- const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
- const posMeasure = $('#pos-measure')[0].checked;
- const posUnMeasure = $('#pos-un-measure')[0].checked;
- posData.forEach(x => {
- x.visible = true;
- if (posMeasure && x.visible) {
- x.visible = !!x.contract_qty || !!x.qc_qty || !!x.qc_minus_qty;
- }
- if (posUnMeasure && x.visible) {
- // 不考虑不计价
- x.visible = !x.end_contract_qty && !x.end_qc_qty && !x.end_gather_qty; // && !x.qc_minus_qty;
- }
- });
- SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
- getNodeList(node.id);
- } else {
- spSpread.getActiveSheet().zh_setting.readOnly = true;
- SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
- }
- stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
- },
- editEnded: function (e, info) {
- if (info.sheet.zh_setting) {
- // 未改变过,则直接跳过
- const sortData = info.sheet.zh_data;
- const posData = sortData ? sortData[info.row] : null;
- const col = info.sheet.zh_setting.cols[info.col];
- const orgText = posData ? posData[col.field] : null;
- const newText = trimInvalidChar(info.editingText);
- if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
- return;
- }
- // 台账模式下,不可新增
- if (checkTzMeasureType() && !posData) {
- toastr.error('台账模式不可新增计量单元数据');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return ;
- }
- // 不同节点下,计量单元检查输入
- //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const node = stagePosSpreadObj.stageTreeNode;
- if (!node) {
- toastr.warning('数据错误, 请刷新页面后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (newText !== '' && node.children && node.children.length > 0) {
- toastr.error('父节点不可插入计量单元');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (newText !== '' && !node.b_code || node.b_code === '') {
- toastr.error('项目节不可插入计量单元');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- // 生成提交数据
- const data = {};
- if (col.field === 'name') {
- if ((!newText || newText === '') && posData) {
- toastr.error('部位名称不可为空');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (!posData) {
- if (newText !== '') {
- data.updateType = 'add';
- if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
- toastr.error('无计量单元的清单,计量后,不可新增计量单元');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
- data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- } else {
- data.updateType = 'update';
- data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
- }
- } else if (!posData) {
- toastr.warning('新增计量单元请先输入名称');
- } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
- data.updateType = 'update';
- data.updateData = {pid: posData.id, lid: posData.lid};
- data.updateData[col.field] = newText;
- } else {
- data.updateType = 'update';
- data.updateData = {pid: posData.id, lid: posData.lid};
- if (col.type === 'Number') {
- const exprInfo = getExprInfo(col.field);
- const num = _.toNumber(newText);
- if (_.isFinite(num)) {
- data.updateData[col.field] = num;
- if (exprInfo) {
- data.updateData[exprInfo.expr] = '';
- }
- } else {
- try {
- data.updateData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
- if (exprInfo) {
- data.updateData[exprInfo.expr] = newText;
- }
- } catch(err) {
- toastr.error('输入的表达式非法');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- } else if (col.field.indexOf('_expr') > 0) {
- const exprInfo = getExprInfo(col.field, true);
- if (!exprInfo) return;
- if (newText) {
- try {
- data.updateData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
- data.updateData[exprInfo.expr] = newText;
- } catch(err) {
- toastr.error('输入的表达式非法');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- } else {
- data.updateData[exprInfo.qty] = 0;
- data.updateData[exprInfo.expr] = '';
- }
- } else {
- data.updateData[col.field] = newText;
- }
- }
- // 提交数据到服务器
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const refreshData = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStagePosUpdateData(result, refreshData);
- } else {
- stageIm.loadUpdatePosData(result, refreshData);
- }
- }, function () {
- stagePosSpreadObj.loadCurPosData();
- });
- }
- },
- editStarting: function (e, info) {
- stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const sel = info.sheet.getSelections();
- if (!sel || !sel[0]) return;
- const col = info.sheet.zh_setting.cols[sel[0].col];
- const node = SpreadJsObj.getSelectObject(info.sheet);
- const exprInfo = getExprInfo(col.field);
- if (exprInfo && node) {
- if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
- info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
- }
- }
- switch (col.field) {
- case 'contract_qty':
- case 'contract_expr':
- case 'qc_qty':
- case 'qc_minus_qty':
- info.cancel = node.settle_status === settleStatus.finish;
- break;
- }
- },
- clipboardPasting: function (e, info) {
- if (info.sheet.zh_setting) {
- const sortData = info.sheet.zh_data;
- const range = info.cellRange;
- const validField = ['contract_qty', 'contract_expr', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3', 'ex_stage_qty1'];
- if (!checkTzMeasureType()) {
- validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
- }
- for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
- const col = info.sheet.zh_setting.cols[iCol];
- if (validField.indexOf(col.field) === -1) {
- if (checkTzMeasureType()) {
- toastr.error('不可修改此数据');
- info.cancel = true;
- return;
- } else {
- for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
- const pos = sortData(iRow);
- if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
- toastr.error('不可修改此数据');
- info.cancel = true;
- return;
- }
- }
- }
- }
- }
- }
- },
- clipboardPasted: function (e, info) {
- const hint = {
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- if (info.sheet.zh_setting) {
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const data = { updateType: '', updateData: [], };
- const sortData = info.sheet.zh_data;
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (node.children && node.children.length > 0) return;
- if (sortData && (info.cellRange.row >= sortData.length)) {
- data.updateType = 'add';
- if (info.cellRange.col !== 0) {
- toastr.warning('新增计量单元请先输入名称');
- stagePosSpreadObj.loadCurPosData();
- return;
- }
- if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
- toastr.error('无计量单元的清单,计量后,不可新增计量单元');
- stagePosSpreadObj.loadCurPosData();
- return;
- }
- const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = info.cellRange.row + iRow;
- const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- if (!colSetting) continue;
- const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
- if (colSetting.type === 'Number') {
- const exprInfo = getExprInfo(colSetting.field);
- if (newValue) {
- const num = _.toNumber(newValue);
- if (num) {
- newData[colSetting.field] = num;
- if (exprInfo) {
- newData[exprInfo.expr] = '';
- }
- } else {
- try {
- newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
- if (exprInfo) {
- newData[exprInfo.expr] = newValue;
- }
- } catch(err) {
- toastr.error('输入的表达式非法');
- stagePosSpreadObj.loadCurPosData();
- return;
- }
- }
- } else {
- newData[colSetting.field] = null;
- if (exprInfo) newData[exprInfo.expr] = '';
- }
- } else if (colSetting.field.indexOf('_expr') > 0) {
- try {
- const exprInfo = getExprInfo(colSetting.field, true);
- newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
- if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
- newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
- }
- } catch (err) {
- toastMessageUniq(hint.expr);
- }
- } else {
- newData[colSetting.field] = newValue;
- }
- }
- data.updateData.push(newData);
- }
- } else {
- data.updateType = 'update';
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = info.cellRange.row + iRow;
- const curPos = sortData[curRow];
- if (curPos) {
- const newData = {pid: curPos.id, lid: curPos.lid};
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
- if (colSetting.type === 'Number') {
- if (curPos.settle_status === settleStatus.finish) {
- newData.error = 1;
- continue;
- }
- const exprInfo = getExprInfo(colSetting.field);
- if (!newValue) {
- newData[colSetting.field] = newValue;
- if (exprInfo) newData[exprInfo.expr] = '';
- continue;
- }
- const num = _.toNumber(newValue);
- if (num) {
- newData[colSetting.field] = num;
- if (exprInfo) newData[exprInfo.expr] = '';
- } else {
- try {
- newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
- const exprInfo = getExprInfo(colSetting.field);
- if (exprInfo) newData[exprInfo.expr] = newValue;
- } catch(err) {
- toastr.error('输入的表达式非法');
- stagePosSpreadObj.loadCurPosData();
- return;
- }
- }
- } else if (colSetting.field.indexOf('_expr') > 0) {
- try {
- const exprInfo = getExprInfo(colSetting.field, true);
- newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
- if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
- newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
- }
- } catch (err) {
- toastMessageUniq(hint.expr);
- }
- } else {
- newData[colSetting.field] = newValue;
- }
- }
- if (newData.error === undefined) data.updateData.push(newData);
- }
- }
- }
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStagePosUpdateData(result, nodes);
- } else {
- stageIm.loadUpdatePosData(result, nodes);
- }
- }, function () {
- stagePosSpreadObj.loadCurPosData();
- });
- }
- },
- deletePress: function (sheet) {
- if (sheet.zh_setting.readOnly) return;
- if (sheet.zh_setting && sheet.zh_data) {
- const sortData = sheet.zh_data;
- if (!sortData || sortData.length === 0) { return; }
- const sel = sheet.getSelections()[0];
- const validCols = [];
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
- validCols.push(iCol);
- }
- }
- if (validCols.length === 0) { return; }
- const datas = [], posSelects = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const node = sortData[iRow];
- if (node) {
- const data = {pid: node.id, lid: node.lid};
- for (const iCol of validCols) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (colSetting.field === 'name') {
- toastr.error('部位名称不能为空');
- return;
- }
- if (colSetting.Type === 'Number' && node.settle_status === settleStatus.finish) {
- toastr.error('已结算节点不可计量');
- return;
- }
- if (colSetting.field.indexOf('_expr') > 0) {
- const exprInfo = getExprInfo(colSetting.field, true);
- if (!exprInfo) continue;
- data[exprInfo.expr] = '';
- data[exprInfo.qty] = 0;
- } else {
- data[colSetting.field] = null;
- const exprInfo = getExprInfo(colSetting.field);
- if (exprInfo) {
- data[exprInfo.expr] = '';
- }
- }
- }
- datas.push(data);
- posSelects.push(node);
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- if (detail) {
- detail.loadStagePosUpdateData(result, nodes);
- } else {
- stageIm.loadUpdatePosData(result, nodes);
- }
- // todo 只加载改变项
- stagePosSpreadObj.loadCurPosData();
- });
- }
- }
- },
- deletePos: function (sheet) {
- const sels = sheet.getSelections();
- const sel = sels ? sels[0] : null;
- if (sheet.zh_data && sel) {
- const data = {updateType: 'delete', updateData: []};
- for (let iRow = 0; iRow < sel.rowCount; iRow++) {
- const posData = sheet.zh_data[sel.row + iRow];
- if (posData) {
- data.updateData.push(posData.id);
- }
- }
- if (data.updateData.length > 0) {
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- stagePos.removeDatas(result.pos.pos);
- const refreshData = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStagePosUpdateData(result, refreshData);
- } else {
- stageIm.loadUpdatePosData(result, refreshData);
- }
- });
- }
- }
- },
- selectionChanged: function (e, info) {
- stagePosSpreadObj.loadExprToInput(info.sheet);
- },
- addPegs: function (pegs) {
- if (!pegs || pegs.length <= 0) return;
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (!node) return;
- const sheet = spSpread.getActiveSheet();
- const sortData = sheet.zh_data || [];
- let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
- pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
- postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- }
- stagePosSpreadObj.loadCurPosData();
- });
- }
- };
- $('#pos-measure').click(stagePosSpreadObj.loadCurPosData);
- $('#pos-un-measure').click(stagePosSpreadObj.loadCurPosData);
- // 加载上下窗口resizer
- $.divResizer({
- select: '#main-resize',
- callback: function () {
- slSpread.refresh();
- let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-30);
- spSpread.refresh();
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
- postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag;reCalcChange' }, function (result) {
- // 加载树结构
- stageTree.loadDatas(result.ledgerData, result.locked);
- if (stage.assist) {
- stageTree.loadFilter(stage.assist.ass_ledger_id);
- } else if (stage.relaAuditor && stage.relaAuditor.audit_ledger_id) {
- stageTree.loadFilter(stage.relaAuditor.audit_ledger_id);
- }
- // 加载部位明细
- stagePos.loadDatas(result.posData);
- stageTreeSpreadObj.loadChangeData(stageTree, stagePos, result.reCalcChange);
- checkShowLast(result.ledgerData.length);
- treeCalc.calculateAll(stageTree);
- for (const t of result.tags) {
- t.node = stageTree.datas.find(x => {return x.id === t.lid});
- }
- billsTag.loadDatas(result.tags);
- stagePos.calculateAll();
- SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
- SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
- stagePosSpreadObj.loadCurPosData();
- SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
- TreeExprCalc.init({
- tree: stageTree,
- decimal: tenderInfo.decimal,
- precision: tenderInfo.precision,
- calcField: { qty: 'contract_qty', tp: 'contract_tp' }, calcType: TreeExprCalc.calcType.sortCache,
- exprFieldsIndex: {
- tzsl: 'quantity', tzje: 'total_price', qysl: 'deal_qty', qyje: 'deal_tp',
- bqhtje: 'contract_tp',
- },
- exprCacheKey: ['bqhtje'],
- });
- // 加载中间计量
- stageIm.init(tenderInfo, stage, imType, tenderInfo.decimal);
- stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.stageChange, result.import_change, result.detailAtt);
- if (stage.assist) {
- stageIm.loadFilter(stage.assist.ass_ledger_id);
- } else if (stage.relaAuditor) {
- stageIm.loadFilter(stage.relaAuditor.audit_ledger_id);
- }
- errorList.loadHisErrorData();
- checkList.loadHisCheckData();
- sumLoadMiss.loadHisMissData();
- // 收方单赋值
- ledgerData = result.ledgerData;
- posData = result.posData;
- makeShouFang();
- }, null, true);
- spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
- spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
- spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
- spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
- spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
- SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
- if (!readOnly) {
- $('#pos-expr').bind('change onblur', function () {
- if (this.readOnly) return;
- const expr = $(this);
- const posSheet = spSpread.getActiveSheet();
- const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
- const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
- if (!select) return;
- const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
- if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
- const data = {pid: select.id, lid: select.lid};
- const exprInfo = getExprInfo(field);
- if (newValue !== '') {
- const num = _.toNumber(newValue);
- if (num) {
- data[field] = num;
- if (exprInfo) data[exprInfo.expr] = '';
- } else {
- try {
- data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
- if (exprInfo) data[exprInfo.expr] = newValue;
- } catch (err) {
- toastr.error('输入的表达式非法');
- return;
- }
- }
- } else {
- data[field] = null;
- if (exprInfo) data[exprInfo.expr] = '';
- }
- // 提交数据到服务器
- postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
- }
- const refreshData = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
- if (detail) {
- detail.loadStagePosUpdateData(result, refreshData);
- } else {
- stageIm.loadUpdatePosData(result, refreshData);
- }
- });
- });
- }
- const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
- $.contextMenu({
- selector: '#stage-pos',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'del': {
- name: '删除',
- icon: 'fa-remove',
- visible: function (key, opt) {
- return !checkTzMeasureType();
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (!node || node.lock) return true;
- const sheet = spSpread.getActiveSheet();
- if (sheet.zh_data && !readOnly) {
- const selection = sheet.getSelections();
- if (selection && selection[0]) {
- let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
- for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
- const posData = sheet.zh_data[selection[0].row + iRow];
- if (posData) {
- if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
- valid = true;
- break;
- }
- } else {
- valid = true;
- break;
- }
- }
- return valid;
- } else {
- return true;
- }
- } else {
- return true;
- }
- },
- callback: function (key, opt) {
- stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
- }
- },
- 'sort': {
- name: '排序',
- items: {
- "addStageReverse": {
- name: '按新增期倒序',
- icon: 'fa-sort-amount-desc',
- callback: function (key, opt) {
- stagePos.sort = [['add_stage_order', 'desc'], ['porder', 'asc']];
- const spSheet = spSpread.getActiveSheet();
- if (spSheet.zh_data) {
- spSheet.zh_data.sort((x, y) => { return y.add_stage_order - x.add_stage_order || x.porder - y.porder; });
- SpreadJsObj.reLoadSheetData(spSheet);
- }
- }
- }
- }
- },
- 'merge-peg': {
- name: '合并起讫桩号',
- visible: function (key, opt) {
- return !checkTzMeasureType();
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
- },
- callback: function (key, opt) {
- mergePeg.show();
- }
- },
- 'calcByRatio': {
- name: '按比例计量',
- visible: function (key, opt) {
- const data = spSpread.getActiveSheet().zh_data;
- return checkTzMeasureType() && data && data.length > 0;
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return node.lock;
- },
- callback: function (key, opt) {
- $('#cbr-ratio').val('');
- $('#apply2sibling')[0].checked = false;
- $('#cbr-check-all')[0].checked = false;
- const html = [];
- for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
- html.push('<tr>');
- html.push('<td>', i+1, '</td>');
- html.push('<td>', p.name, '</td>');
- html.push('<td>', p.quantity, '</td>');
- html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
- html.push('</tr>');
- }
- $('#cbr-pos-list').html(html.join(''));
- $('#calc-by-ratio').modal('show');
- }
- },
- 'remainCur': {
- name: '填剩余量(选中行)',
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
- return readOnly || node.lock || !curPos;
- },
- callback: function (key, opt) {
- const sheet = spSpread.getActiveSheet();
- const sels = sheet.getSelections();
- if (!sels || !sels[0]) return;
- const data = { updateType: 'update', updateData: [] };
- for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
- const curRow = iRow + sels[0].row;
- const curPos = SpreadJsObj.getRowObject(sheet, curRow);
- if (!curPos) continue;
- const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
- const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
- if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
- }
- if (data.updateData.length > 0) {
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStagePosUpdateData(result, nodes);
- } else {
- stageIm.loadUpdatePosData(result, nodes);
- }
- });
- }
- },
- visible: function(key, opt) {
- return checkTzMeasureType();
- },
- },
- 'remainAll': {
- name: '填剩余量(全部行)',
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
- return readOnly || node.lock || !curPos;
- },
- callback: function (key, opt) {
- const sheet = spSpread.getActiveSheet();
- if (!sheet.zh_data || sheet.zh_data.length === 0) return;
- const data = { updateType: 'update', updateData: [] };
- for (const curPos of sheet.zh_data) {
- const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
- const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
- if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
- }
- if (data.updateData.length > 0) {
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStagePosUpdateData(result, nodes);
- } else {
- stageIm.loadUpdatePosData(result, nodes);
- }
- });
- }
- },
- visible: function(key, opt) {
- return checkTzMeasureType();
- },
- },
- 'shoufangdan': {
- name: '生成收方单',
- visible: function(key, opt) {
- if (cur_uid === stage.user_id) return true;
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
- if (!node || cur_uid !== stage.user_id) return true;
- },
- callback: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
- const ledgerNode = _.find(ledgerData, { id: node.lid });
- $('#shoufang-lid').val(node.lid);
- $('#shoufang-pid').val(node.id);
- $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
- $('#shoufang-pos').text('计量单元:' + node.name).show();
- $('#addshoufang').modal('show');
- }
- }
- }
- });
- $.subMenu({
- menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
- toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
- key: 'menu.1.0.0',
- miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
- callback: function (info) {
- if (info.mini) {
- $('.panel-title').addClass('fluid');
- $('#sub-menu').removeClass('panel-sidebar');
- } else {
- $('.panel-title').removeClass('fluid');
- $('#sub-menu').addClass('panel-sidebar');
- }
- autoFlashHeight();
- slSpread.refresh();
- spSpread.refresh();
- if (searchLedger) searchLedger.spread.refresh();
- if (detail) detail.spread.refresh();
- if (checkedChanges) checkedChanges.refresh();
- if (errorList && errorList.spread) errorList.spread.refresh();
- if (checkList) checkList.spread.refresh();
- if (sumLoadMiss) sumLoadMiss.spread.refresh();
- }
- });
- $('#row-view').on('show.bs.modal', function () {
- const html = [], customDisplay = customColDisplay();
- for (const cd of customDisplay) {
- html.push('<tr>');
- html.push('<td>', cd.title, '</td>');
- html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
- html.push('</tr>');
- }
- $('#row-view-list').html(html.join(''));
- });
- $('#row-view-ok').click(function () {
- const customDisplay = customColDisplay();
- const cvl = $('#row-view-list').children();
- for (const cv of cvl) {
- const title = $(cv).children()[0].innerHTML;
- const check = $('input', cv)[0].checked;
- const cd = customDisplay.find(function (c) {
- return c.title === title;
- });
- cd.visible = check;
- }
- customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
- SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
- Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
- $('#row-view').modal('hide');
- });
- const posSearch = (function () {
- let resultArr = [];
- const search = function () {
- resultArr = [];
- const keyword = $('#pos-search-keyword').val();
- const checkOver = $('#pos-over-search')[0].checked;
- const checkEmpty = $('#pos-empty-search')[0].checked;
- const sortData = spSpread.getActiveSheet().zh_data;
- if (checkOver || checkEmpty) {
- if (sortData) {
- for (let i = 0, iLength = sortData.length; i < iLength; i++) {
- const sd = sortData[i];
- let match = false;
- if (checkOver) {
- if (sd.end_gather_qty) {
- if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
- }
- }
- if (checkEmpty) {
- if (sd.quantity) {
- if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
- }
- }
- if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
- if (match) {
- resultArr.push({index: i, data: sd});
- }
- }
- }
- } else if (keyword && keyword !== '') {
- if (sortData) {
- for (let i = 0, iLength = sortData.length; i < iLength; i++) {
- const sd = sortData[i];
- if (sd.name && sd.name.indexOf(keyword) > -1) {
- resultArr.push({index: i, data: sd});
- }
- }
- }
- }
- $('#pos-search-result').html('结果:' + resultArr.length);
- };
- const searchAndLocate = function () {
- search();
- if (resultArr.length > 0) {
- const sheet = spSpread.getActiveSheet();
- const sel = sheet.getSelections()[0];
- const curRow = sel ? sel.row : 0;
- const pos = resultArr[0];
- if (pos.index !== curRow) {
- sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
- sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
- }
- }
- };
- const locateNext = function () {
- if (resultArr.length > 0) {
- const sheet = spSpread.getActiveSheet();
- const sel = sheet.getSelections()[0];
- const curRow = sel ? sel.row : 0;
- let next = _.find(resultArr, function (d) {
- return d.index > curRow;
- });
- if (!next) next = resultArr[0];
- if (next.index !== curRow) {
- sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
- sheet.showRow(next.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
- }
- }
- };
- const locatePre = function () {
- if (resultArr.length > 0) {
- const sheet = spSpread.getActiveSheet();
- const sel = sheet.getSelections()[0];
- const curRow = sel ? sel.row : 0;
- let next = _.findLast(resultArr, function (d) {
- return d.index < curRow;
- });
- if (!next) next = resultArr[resultArr.length - 1];
- if (next.index !== curRow) {
- sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
- sheet.showRow(next.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
- }
- }
- };
- return {search, searchAndLocate, locateNext, locatePre};
- })();
- $('#pos-search-keyword').bind('keydown', function(e){
- if (e.keyCode == 13) posSearch.searchAndLocate();
- });
- $('#pos-empty-search').click(function () {
- if (this.checked) {
- $('[for=' + this.id +']').addClass('text-warning');
- } else {
- $('[for=' + this.id +']').removeClass('text-warning');
- }
- if (this.checked) {
- if ($('#pos-over-search')[0].checked) {
- $('#pos-search-keyword').attr('placeholder', '按名称查询');
- } else {
- $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
- }
- } else {
- if ($('#pos-over-search')[0].checked) {
- $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
- } else {
- $('#pos-search-keyword').attr('placeholder', '按名称查询');
- }
- }
- posSearch.searchAndLocate();
- });
- $('#pos-over-search').click(function () {
- if (this.checked) {
- $('[for=' + this.id +']').addClass('text-danger');
- } else {
- $('[for=' + this.id +']').removeClass('text-danger');
- }
- if (this.checked) {
- if ($('#pos-empty-search')[0].checked) {
- $('#pos-search-keyword').attr('placeholder', '按名称查询');
- } else {
- $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
- }
- } else {
- if ($('#pos-empty-search')[0].checked) {
- $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
- } else {
- $('#pos-search-keyword').attr('placeholder', '按名称查询');
- }
- }
- posSearch.searchAndLocate();
- });
- $('#pos-search-next').click(() => {posSearch.locateNext()});
- $('#pos-search-pre').click(() => {posSearch.locatePre()});
- $.divResizer({
- select: '#right-spr',
- callback: function () {
- slSpread.refresh();
- spSpread.refresh();
- if (searchLedger) {
- searchLedger.spread.refresh();
- }
- if (detail) {
- detail.spread.refresh();
- }
- if (checkedChanges) checkedChanges.refresh();
- if (errorList && errorList.spread) errorList.spread.refresh();
- if (checkList) checkList.spread.refresh();
- if (sumLoadMiss) sumLoadMiss.spread.refresh();
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- // 中间计量加载上下窗口resizer
- $.divResizer({
- select: '#zhongjian-spr',
- callback: function () {
- if (detail) {
- detail.spread.refresh();
- }
- $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- // 附件加载上下窗口resizer
- $.divResizer({
- select: '#file-spr',
- callback: function () {
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- // 变更令加载上下窗口resizer
- $.divResizer({
- select: '#change-spr',
- callback: function () {
- if (checkedChanges) checkedChanges.refresh();
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- class Detail {
- constructor (obj) {
- const self = this;
- this.spreadSetting = {
- cols: [
- {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 80, formatter: '@', readOnly: true},
- {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
- {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
- {
- title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
- colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
- },
- {
- title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
- normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
- return data.attachment ? data.attachment.length : 0;
- }
- },
- ],
- headRows: 1,
- emptyRows: 0,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: readOnly,
- selectedBackColor: '#fffacd',
- imageClick: function (data) {
- self.makeAttTable(data);
- $('#im-file').modal('show');
- }
- };
- this.spread = SpreadJsObj.createNewSpread(obj[0]);
- this.sheet = this.spread.getActiveSheet();
- this.spread.options.allowUserDragFill = true;
- this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
- SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
- this.detailObj = {
- selectionChanged: function (e, info) {
- self.reLoadDetailData();
- if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
- self.loadLocateInfo();
- }
- },
- editEnded: function(e, info) {
- if (info.sheet.zh_setting) {
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field !== 'doc_code') {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const data = SpreadJsObj.getSelectObject(info.sheet);
- if (data) {
- const updateData = {lid: data.lid, pid: data.pid};
- if (data.uuid) {
- updateData.uuid = data.uuid;
- } else {
- updateData.code = data.code;
- updateData.name = data.name;
- updateData.unit = data.unit;
- updateData.unit_price = data.unit_price;
- updateData.pid = data.pid;
- updateData.pos_name = data.pos_name;
- updateData.im_type = data.im_type;
- }
- if (data.custom_define.indexOf('doc_code') === -1) {
- updateData.custom_define = data.custom_define;
- updateData.custom_define.push('doc_code');
- updateData.custom_define = updateData.custom_define.join(',');
- }
- updateData.doc_code = info.editingText === null ? '' : info.editingText;
- postData(window.location.pathname + '/detail/save', updateData, function (result) {
- stageIm.loadUpdateDetailData(result);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- }
- }
- },
- clipboardPasted: function (e, info) {
- if (info.sheet.zh_setting && info.sheet.zh_data) {
- const col = info.sheet.zh_setting.cols[info.cellRange.col];
- if (info.cellRange.colCount > 1) {
- toastr.warning('请勿同时复制粘贴多列数据');
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
- return;
- }
- if (col.field !== 'doc_code') {
- SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
- return;
- }
- const datas = [];
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = info.cellRange.row + iRow;
- const data = info.sheet.zh_data[curRow];
- if (data) {
- const updateData = {lid: data.lid, pid: data.pid};
- if (data.uuid) {
- updateData.uuid = data.uuid;
- } else {
- updateData.code = data.code;
- updateData.name = data.name;
- updateData.unit = data.unit;
- updateData.unit_price = data.unit_price;
- updateData.pid = data.pid;
- updateData.pos_name = data.pos_name;
- updateData.im_type = data.im_type;
- }
- if (data.custom_define.indexOf('doc_code') === -1) {
- updateData.custom_define = data.custom_define;
- updateData.custom_define.push('doc_code');
- updateData.custom_define = updateData.custom_define.join(',');
- }
- updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
- datas.push(updateData);
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/detail/save', datas, function (result) {
- stageIm.loadUpdateDetailData(result);
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- })
- }
- }
- },
- deletePress: function (sheet) {
- if (sheet.zh_setting) {
- const datas = [];
- const sel = sheet.getSelections()[0];
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const data = sheet.zh_data[iRow];
- if (col.field === 'doc_code') {
- const updateData = {lid: data.lid};
- if (data.uuid) {
- updateData.uuid = data.uuid;
- updateData.doc_code = '';
- datas.push(updateData);
- }
- }
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/detail/save', datas, function (result) {
- stageIm.loadUpdateDetailData(result);
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- }, function () {
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- });
- }
- }
- },
- dragFillBlock: function (e, info) {
- info.cancel = true;
- if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
- const sel = info.sheet.getSelections()[0];
- const col = info.sheet.zh_setting.cols[info.fillRange.col];
- if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
- const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
- if (text === '') return;
- const regRst = /(\d+)$/g.exec(text), datas = [];
- for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
- const curRow = info.fillRange.row + iRow;
- const data = info.sheet.zh_data[curRow];
- if (data) {
- const updateData = {lid: data.lid};
- if (data.uuid) {
- updateData.uuid = data.uuid;
- } else {
- updateData.code = data.code;
- updateData.name = data.name;
- updateData.unit = data.unit;
- updateData.unit_price = data.unit_price;
- updateData.pid = data.pid;
- updateData.pos_name = data.pos_name;
- updateData.im_type = data.im_type;
- }
- if (regRst) {
- updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
- } else {
- updateData.doc_code = text.replace('\n', '');
- }
- if (data.custom_define.indexOf('doc_code') === -1) {
- updateData.custom_define = data.custom_define;
- updateData.custom_define.push('doc_code');
- updateData.custom_define = updateData.custom_define.join(',');
- }
- datas.push(updateData);
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/detail/save', datas, function (result) {
- stageIm.loadUpdateDetailData(result);
- SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
- })
- }
- },
- };
- this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
- if (!readOnly) {
- this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
- this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
- this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
- SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
- }
- this._initImTypeSetRela();
- this._initModifyDetail();
- this._initLocateRela();
- this._initAttRela();
- // 草图相关
- this._initImageRela();
- this.reBuildImData();
- }
- makeAttTable (data) {
- let html = [];
- if (data.attachment) {
- for (const att of data.attachment) {
- const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked || deleteFilePermission))
- ? '<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>'
- : '';
- const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
- 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>';
- 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>',
- '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
- }
- }
- $('#im-attList').html(html.join(''));
- }
- _initAttRela() {
- // 上传附件
- const self = this;
- $('#upload-im-file').change(function () {
- const files = this.files;
- const sels = self.sheet.getSelections();
- const select = SpreadJsObj.getSelectObject(self.sheet);
- if (!select) return;
- const formData = new FormData();
- const baseInfo = {};
- if (select.att_uuid) {
- baseInfo.uuid = select.att_uuid;
- } else {
- baseInfo.im_type = select.im_type;
- baseInfo.lid = select.lid;
- baseInfo.pid = select.pid;
- baseInfo.code = select.code;
- baseInfo.name = select.name;
- baseInfo.unit = select.unit;
- baseInfo.unit_price = select.unit_price;
- baseInfo.pos_name = select.pos_name;
- }
- formData.append('base', JSON.stringify(baseInfo));
- for (const file of files) {
- if (file === undefined) {
- toast('未选择上传文件!', 'error');
- return false;
- }
- const filesize = file.size;
- if (filesize > 50 * 1024 * 1024) {
- toast('存在上传文件大小过大!', 'error');
- return false;
- }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toast('只能上传指定格式的附件!', 'error');
- return false;
- }
- formData.append('size', filesize);
- formData.append('file[]', file);
- }
- postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
- stageIm.loadUpdateDetailAtt(data);
- SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
- self.makeAttTable(select);
- $('#upload-im-file').val('');
- });
- });
- // 删除附件
- $('body').on('click', '.delete-att' ,function () {
- const sels = self.sheet.getSelections();
- const select = SpreadJsObj.getSelectObject(self.sheet);
- if (!select) return;
- const uuid = $(this).attr('data-imid');
- const file_id = $(this).attr('data-attid');
- const att = select.attachment.find(x => {
- return x.file_id === file_id;
- });
- deleteAfterHint(function () {
- postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
- stageIm.loadUpdateDetailAtt(result);
- SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
- self.makeAttTable(select);
- });
- }, `确认删除附件「${att.filename}」?`);
- });
- // 预览附件
- $('body').on('click', '.preview-att', function () {
- const uuid = $(this).attr('data-imid');
- const file_id = $(this).attr('data-attid');
- postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
- const { filepath } = result;
- $('#load-file').attr('href', filepath);
- $('#load-file')[0].click();
- });
- });
- $('#batch-download-im-file').click(function() {
- const select = $('[name=sia-check]:checked');
- if (select.length === 0) {
- toastr.warning('请选择需要批量下载的文件');
- return;
- }
- const files = [];
- const curIm = SpreadJsObj.getSelectObject(self.sheet);
- for (const s of select) {
- const att = curIm.attachment.find(x => { return x.file_id === s.getAttribute('fid')});
- if (att) files.push(att);
- }
- if (files.length === 0) return;
- AliOss.zipFiles(files, `中间计量[${curIm.code}].zip`, (fails) => {
- $(self).removeAttr('disabled');
- if (fails.length === 0) {
- toastr.success('下载成功');
- } else {
- toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
- }
- }, () => {
- $(self).removeAttr('disabled');
- toastr.error('批量下载失败');
- });
- });
- }
- _initImTypeSetRela() {
- const self = this;
- const gatherConfirmPopover = {
- reBind: function (obj, eventName, fun) {
- obj.unbind(eventName);
- obj.bind(eventName, fun);
- },
- check: function (pos, hint, okCallback) {
- const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
- const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
- this.reBind(cancelObj, 'click', function () {
- confirmObj.hide();
- });
- this.reBind(okObj, 'click', function () {
- okCallback();
- confirmObj.hide();
- });
- hintObj.text(hint);
- confirmObj.css("top", pos.y).css("left", pos.x).show();
- }
- };
- this.gsTree = stageIm.getGsTree();
- if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
- const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
- jlCol.title = '本期计量金额';
- SpreadJsObj.reLoadSheetHeader(self.sheet);
- $('[name=type-title-contract]').text('本期合同计量金额');
- $('[name=type-title-qc]').text('本期变更计量金额');
- if ($('#show-qc-minus-jl').length > 0) {
- $('#show-qc-minus-jl').parent().hide();
- $('#qc-minus-jl').parent().hide();
- }
- } else {
- const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
- jlCol.title = '本期计量数量';
- SpreadJsObj.reLoadSheetHeader(self.sheet);
- $('[name=type-title-contract]').text('本期合同计量数量');
- $('[name=type-title-qc]').text('本期变更计量数量');
- if ($('#show-qc-minus-jl').length > 0) {
- $('#show-qc-minus-jl').parent().show();
- $('#qc-minus-jl').parent().show();
- }
- }
- if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
- $('#show-jldy').parent().show();
- $('#jldy').parent().show();
- $('#show-xm-name').parent().hide();
- $('#xm-name').parent().hide();
- } else {
- $('#show-jldy').parent().hide();
- $('#jldy').parent().hide();
- $('#show-xm-name').parent().show();
- $('#xm-name').parent().show();
- }
- // 选择中间计量模式
- $('div[name="im-type"]').click(function () {
- function chooseType(obj) {
- obj.style.cursor = 'default';
- $(obj).children().addClass('text-primary');
- $(obj).addClass('border-primary');
- $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
- }
- function validType(obj) {
- obj.style.cursor = 'pointer';
- $(obj).children().removeClass('text-primary');
- $(obj).removeClass('border-primary');
- $('i', obj).remove();
- }
- if (this.style.cursor === 'pointer') {
- const typeArr = $('div[name="im-type"]');
- for (const t of typeArr) {
- if ($(t).attr('im-type') === $(this).attr('im-type')) {
- chooseType(t);
- } else {
- validType(t)
- }
- }
- }
- });
- $('#choose').on('show.bs.modal', function () {
- function chooseType(obj) {
- obj.style.cursor = 'default';
- $(obj).children().addClass('text-primary');
- $('i', obj).remove();
- $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
- }
- function validType(obj) {
- obj.style.cursor = 'pointer';
- $(obj).children().removeClass('text-primary');
- $('i', obj).remove();
- }
- $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
- $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
- const typeArr = $('div[name="im-type"]');
- for (const t of typeArr) {
- if (parseInt($(t).attr('im-type')) === stage.im_type) {
- chooseType(t);
- } else {
- validType(t)
- }
- }
- });
- // 提交 中间计量模式
- $('#choose-ok').click(() => {
- let startNum;
- try {
- startNum = parseInt($('#im-start-num').val());
- if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
- } catch (err) {
- toastr.error("起始编号请输入正整数");
- return;
- }
- const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
- return it.style.cursor !== 'pointer';
- });
- const data = {
- im_type: parseInt($(chooseType).attr('im-type')),
- im_pre: $('#im-pre').val(),
- im_start_num: startNum,
- };
- postData(window.location.pathname + '/detail/build', data, function (result) {
- stage.im_type = data.im_type;
- stage.im_pre = data.im_pre;
- stage.im_start_num = data.im_start_num;
- if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
- const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
- jlCol.title = '本期计量金额';
- SpreadJsObj.reLoadSheetHeader(self.sheet);
- $('[name=type-title-contract]').text('本期合同计量金额');
- $('[name=type-title-qc]').text('本期变更计量金额');
- if ($('#show-qc-minus-jl').length > 0) {
- $('#show-qc-minus-jl').parent().hide();
- $('#qc-minus-jl').parent().hide();
- }
- } else {
- const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
- jlCol.title = '本期计量数量';
- SpreadJsObj.reLoadSheetHeader(self.sheet);
- $('[name=type-title-contract]').text('本期合同计量数量');
- $('[name=type-title-qc]').text('本期变更计量数量');
- if ($('#show-qc-minus-jl').length > 0) {
- $('#show-qc-minus-jl').parent().show();
- $('#qc-minus-jl').parent().show();
- }
- }
- if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
- $('#show-jldy').parent().show();
- $('#jldy').parent().show();
- $('#show-xm-name').parent().hide();
- $('#xm-name').parent().hide();
- } else {
- $('#show-jldy').parent().hide();
- $('#jldy').parent().hide();
- $('#show-xm-name').parent().show();
- $('#xm-name').parent().show();
- }
- // 加载生成数据
- self.reBuildImData();
- $('#choose').modal('hide');
- });
- });
- // 显示树结构信息
- $('#choose2').on('shown.bs.modal', function () {
- if (!self.gsSpread) {
- self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
- const setting = {
- cols: [
- {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
- {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
- {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
- {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
- ],
- headRows: 1,
- emptyRows: 0,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- };
- sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
- SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
- self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
- function checkParent(node) {
- const parent = self.gsTree.getParent(node);
- if (parent) {
- return parent.check ? parent.check : checkParent(parent);
- } else {
- return false;
- }
- }
- function checkChildren(node) {
- for (const child of node.children) {
- if (child.check) {
- return true;
- } else if (checkChildren(child)) {
- return true;
- }
- }
- return false;
- }
- if (!$('#im-gather-check')[0].checked) { return; }
- const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
- if (cellType instanceof spreadNS.CellTypes.CheckBox) {
- if (sheet.isEditing()) {
- sheet.endEdit(true);
- }
- }
- if (info.sheet.zh_setting) {
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field !== 'check') {
- return;
- }
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const node = sortData[info.row];
- if (!node.check) {
- if (checkParent(node)) {
- const rect = info.sheet.getCellRect(info.row, info.col);
- gatherConfirmPopover.check({
- x: rect.x + rect.width / 2 + 25,
- y: rect.y + rect.height / 2 + 3,
- }, '父项已勾选,继续将取消父项勾选。', function () {
- node.check = true;
- const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
- const rows = [self.gsTree.nodes.indexOf(node)];
- for (const p of parents) {
- if (p.check) {
- p.check = false;
- rows.push(self.gsTree.nodes.indexOf(p));
- }
- }
- SpreadJsObj.reLoadRowsData(info.sheet, rows);
- });
- } else if (checkChildren(node)) {
- const rect = info.sheet.getCellRect(info.row, info.col);
- gatherConfirmPopover.check({
- x: rect.x + rect.width / 2 + 25,
- y: rect.y + rect.height / 2 + 3,
- }, '子项已勾选,继续将取消子项勾选。', function () {
- node.check = true;
- const posterity = self.gsTree.getPosterity(node);
- const rows = [self.gsTree.nodes.indexOf(node)];
- for (const p of posterity) {
- if (p.check) {
- rows.push(self.gsTree.nodes.indexOf(p));
- p.check = false;
- }
- }
- SpreadJsObj.reLoadRowsData(info.sheet, rows);
- });
- } else {
- node.check = true;
- SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
- }
- } else {
- node.check = false;
- SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
- }
- }
- });
- const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
- for (const node of self.gsTree.datas) {
- node.check = gatherNodes.indexOf(node.id + '') !== -1;
- }
- SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
- self.gsTree.expandByLevel(4);
- SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
- SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
- } else {
- const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
- for (const node of self.gsTree.datas) {
- node.check = gatherNodes.indexOf(node.id + '') !== -1;
- }
- SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
- }
- });
- // 提交 高级设置
- $('#choose2-ok').click(() => {
- if (!self.gsTree) { return; }
- const nodes = [];
- for (const node of self.gsTree.datas) {
- if (node.check) {
- nodes.push(node.id);
- }
- }
- const data = {
- im_gather: $('#im-gather-check')[0].checked,
- im_gather_node: nodes.join(','),
- };
- postData(window.location.pathname + '/detail/adv', data, function (result) {
- stage.im_gather = data.im_gather;
- stage.im_gather_node = data.im_gather_node;
- $('#choose2').modal('hide');
- });
- });
- }
- _initLocateRela() {
- const self = this;
- $('#im-locate2bills').click(function () {
- const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
- const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- if (select && select.source) {
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
- stagePosSpreadObj.loadCurPosData();
- if (select.source[curIndex-1].pos_id) {
- SpreadJsObj.locateDataBy(spSpread.getActiveSheet(), function(data){ return data.id === select.source[curIndex-1].pos_id});
- }
- }
- });
- $('#im-locate-pre').click(function () {
- const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
- const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- if (select && select.source) {
- const targetIndex = Math.max(curIndex-1, 1);
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
- stagePosSpreadObj.loadCurPosData();
- $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
- }
- });
- $('#im-locate-next').click(function () {
- const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
- const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- if (select && select.source) {
- const targetIndex = Math.min(curIndex+1, select.source.length);
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
- stagePosSpreadObj.loadCurPosData();
- $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
- }
- });
- }
- _initModifyDetail() {
- const self = this;
- // 重置
- $('#reset-detail-ok').click(function () {
- const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- if (!data.uuid) return;
- const updateData = {
- lid: data.lid, pid: data.pid,
- uuid: data.uuid,
- custom_define: [],
- };
- for (const f of data.custom_define) {
- if (stageIm.resetFields.indexOf(f) >= 0) {
- updateData[f] = null;
- } else {
- updateData.custom_define.push(f);
- }
- }
- updateData.custom_define = updateData.custom_define.join(',');
- $('#reset-detail-modal').modal('hide');
- postData(window.location.pathname + '/detail/save', updateData, function (result) {
- stageIm.loadUpdateDetailData(result);
- self.reLoadDetailData();
- });
- });
- // 编辑
- $('#edit-detail').click(function () {
- $(this).hide();
- $('#save-detail').show();
- $('#cancel-detail').show();
- $('#detail-show').hide();
- $('#detail-edit').show();
- self.updateImageData = null;
- });
- // 保存
- $('#save-detail').click(() => {
- function check(field, obj, org, update) {
- const newValue = obj.val();
- if (!org[field]) {
- if (newValue !== '') {
- update[field] = newValue;
- if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
- return true;
- }
- } else if (newValue !== org[field]){
- update[field] = newValue;
- if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
- return true;
- }
- return false;
- }
- const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- const updateData = {lid: data.lid, pid: data.pid};
- if (data.uuid) {
- updateData.uuid = data.uuid;
- updateData.custom_define = data.custom_define;
- } else {
- updateData.code = data.code;
- updateData.name = data.name;
- updateData.unit = data.unit;
- updateData.unit_price = data.unit_price;
- updateData.pid = data.pid;
- updateData.pos_name = data.pos_name;
- updateData.im_type = data.im_type;
- updateData.custom_define = [];
- }
- let infoUpdate = false;
- infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
- infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
- infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
- infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
- infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
- infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
- infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
- updateData.custom_define = updateData.custom_define.join(',');
- if (infoUpdate) {
- postData(window.location.pathname + '/detail/save', updateData, function (result) {
- stageIm.loadUpdateDetailData(result);
- self.reLoadDetailData();
- if (!self.updateImageData) return;
- if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
- postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
- stageIm.loadUpdateDetailData(result);
- self.reLoadDetailData();
- });
- });
- } else if (self.updateImageData) {
- postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
- stageIm.loadUpdateDetailData(result);
- self.reLoadDetailData();
- });
- } else {
- self.reLoadDetailData();
- }
- });
- // 取消
- $('#cancel-detail').click(() => {
- self.reLoadDetailData();
- });
- }
- _initImageRela() {
- const self = this;
- $('#edit-detail').click(function () {
- loadImageItem();
- });
- function setdraggrable(){
- $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
- }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
- stop: function( event, ui ) {
- }
- });
- }
- function upload(formData) {
- if (formData.length < 1) {
- return;
- }
- postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
- const html = [];
- html.push('<div class="img-item">');
- html.push('<div class="img-bar">');
- html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
- html.push('</div>');
- html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
- html.push('</div>');
- $('.img-view').append(html.join(''));
- $('.img-bar').click(removeImageItem);
- setdraggrable();
- $('#upload-img-file').val('');
- });
- }
- function dragFile(e) {
- var file = null,
- data = e.dataTransfer.types;
- for (var i = 0; i < data.length; i += 1) {
- if (data[i] === 'Files') {
- file = e.dataTransfer.files; //获取文件
- break;
- }
- }
- if (file && file[0].type.indexOf('image') !== -1) {
- var formData = new FormData();
- formData.append('file', file[0]); //上传单个文件的添加方式
- upload(formData); //upload 异步上传
- }
- }
- // 移动图片
- const moveImageItem = function (ev) {
- const item = this;
- const view = $('.img-view')[0];
- let oEvent = ev;
- // 浏览器有一些图片的默认事件,这里要阻止
- oEvent.preventDefault();
- let disX = oEvent.clientX - item.offsetLeft;
- let disY = oEvent.clientY - item.offsetTop;
- view.onmousemove = function (ev) {
- oEvent = ev;
- oEvent.preventDefault();
- let x = oEvent.clientX -disX;
- let y = oEvent.clientY -disY;
- // 图形移动的边界判断
- x = x <= 0 ? 0 : x;
- x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
- y = y <= 0 ? 0 : y;
- y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
- item.style.left = x + 'px';
- item.style.top = y + 'px';
- };
- // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
- view.onmouseleave = function () {
- view.onmousemove = null;
- view.onmouseup = null;
- };
- // 鼠标弹起后停止移动
- view.onmouseup=function() {
- view.onmousemove = null;
- view.onmouseup = null;
- };
- };
- const removeImageItem = function () {
- $(this).parent().remove();
- };
- // 加载草图组成
- const loadImageItem = function () {
- self.updateImageData = null;
- const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
- const html = [];
- for (const item of items) {
- const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
- html.push('<div class="img-item" style="' + itemStyle + '">');
- html.push('<div class="img-bar">');
- html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
- html.push('</div>');
- html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
- html.push('</div>');
- }
- $('.img-view').html(html.join(''));
- $('.img-bar').click(removeImageItem);
- setdraggrable();
- };
- // 上传图片
- $('#upload-img').click(function () {
- $('#upload-img-file').trigger('click');
- });
- // 拖拽上传
- //拖拽上传文件
- const dragbox = document.querySelector('#upload-img');
- dragbox.addEventListener('dragover', function(e) {
- e.preventDefault(); // 必须阻止默认事件
- }, false);
- dragbox.addEventListener('drop', function(e) {
- e.preventDefault(); // 阻止默认事件
- dragFile(e);
- }, false);
- //拖拽上传文件
- const dragbox2 = document.querySelector('.img-view');
- dragbox2.addEventListener('dragover', function(e) {
- e.preventDefault(); // 必须阻止默认事件
- }, false);
- dragbox2.addEventListener('drop', function(e) {
- e.preventDefault(); // 阻止默认事件
- dragFile(e);
- }, false);
- // 粘贴上传
- $(".img-view").on('paste', function(ev) {
- let file = null;
- const data = (event.clipboardData || window.clipboardData).items;
- for (let i = 0; i < data.length; i += 1) {
- if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
- file = data[i].getAsFile(); //读取图片文件
- break;
- }
- }
- if (file) {
- const formData = new FormData();
- formData.append('file', file); //上传单个文件的添加方式
- upload(formData); //异步上传文件
- }
- });
- $('#upload-img-file').change(function () {
- const file = this.files[0];
- const ext = file.name.toLowerCase().split('.').splice(-1)[0];
- const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
- if (!imgStr.test(ext)) {
- toastr.error('请上传正确的图片格式文件');
- return
- }
- if ($(this).val()) {
- const formData = new FormData();
- formData.append('file', this.files[0]);
- upload(formData);
- }
- });
- // 保存草图修改结果
- $('#edit-img-ok').click(function () {
- // 记录上传的图片的信息
- const items = $('.img-item');
- const img_remark = $('#text-edit').val();
- const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- // 生成上传数据
- const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
- if (data.uuid) {
- updateData.uuid = data.uuid;
- } else {
- updateData.code = data.code;
- updateData.name = data.name;
- updateData.unit = data.unit;
- updateData.unit_price = data.unit_price;
- updateData.pid = data.pid;
- updateData.pos_name = data.pos_name;
- updateData.im_type = data.im_type;
- }
- if (items.length > 0) {
- const itemInfo = [];
- for (const item of items) {
- const itemData = {
- src: $('img', item).attr('src'),
- left: item.style.left,
- top: item.style.top,
- width: item.style.width,
- height: item.style.height,
- };
- itemInfo.push(itemData);
- }
- // 获取合并好的图片数据
- const canvas = document.createElement('canvas');
- const view = $('.img-view')[0];
- canvas.height = view.clientHeight;
- canvas.width = view.clientWidth;
- const ctx = canvas.getContext('2d');
- ctx.fillStyle = '#ffffff';
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- for (const b of $('.img-item')) {
- const pos = $(b).position();
- const img = $('img', b)[0];
- ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
- }
- updateData.img = canvas.toDataURL('image/png');
- updateData.imgInfo = itemInfo;
- self.updateImageData = updateData;
- $('#calc-img').attr('src', updateData.img);
- $('#calc-remark').html(img_remark);
- $('#view-calc-img').attr('src', updateData.img);
- $('#show-calc-img').attr('src', updateData.img);
- $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
- $('#view-calc-remark').text(img_remark);
- $('#edit-img').modal('hide');
- // });
- } else if (data.calc_img) {
- self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
- $('#show-calc-img').attr('src', '');
- $('#show-calc-remark').html('');
- $('#calc-img').attr('src', '');
- $('#calc-remark').html(img_remark);
- $('#view-calc-img').attr('src', '');
- $('#view-calc-remark').val(img_remark);
- $('#text-edit').val(img_remark);
- $('#edit-img').modal('hide');
- } else {
- self.updateImageData = updateData;
- $('#show-calc-img').attr('src', '');
- $('#show-calc-remark').html('');
- $('#calc-img').attr('src', '');
- $('#calc-remark').html(img_remark);
- $('#view-calc-img').attr('src', '');
- $('#view-calc-remark').val(img_remark);
- $('#text-edit').val(img_remark);
- $('#edit-img').modal('hide');
- }
- });
- }
- reBuildImData() {
- const imData = stageIm.buildImData();
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
- this.reLoadDetailData();
- this.loadLocateInfo();
- }
- loadStageLedgerUpdateData(data, nodes) {
- const imData = stageIm.loadUpdateLedgerData(data, nodes);
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
- this.reLoadDetailData();
- }
- loadStagePosUpdateData(data, nodes) {
- const imData = stageIm.loadUpdatePosData(data, nodes);
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
- this.reLoadDetailData();
- }
- loadStageChangeUpdateData(data, nodes) {
- const imData = stageIm.loadUpdateChangeData(data, nodes);
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
- this.reLoadDetailData();
- }
- loadLocateInfo() {
- const select = SpreadJsObj.getSelectObject(this.sheet);
- if (select && select.source.length > 1) {
- $('#im-locate2bills').next().show();
- } else {
- $('#im-locate2bills').next().hide();
- }
- $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
- }
- reLoadDetailData() {
- const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
- $('#reset-detail').hide();
- if (data) {
- for (const f of data.custom_define) {
- if (stageIm.resetFields.indexOf(f) >= 0) {
- $('#reset-detail').show();
- break;
- }
- }
- $('#edit-detail').show();
- $('#modify-img').show();
- } else {
- $('#edit-detail').hide();
- $('#modify-img').hide();
- }
- $('#save-detail').hide();
- $('#cancel-detail').hide();
- $('#detail-show').show();
- $('#detail-edit').hide();
- const contractJl = data && data.contract_jl ? data.contract_jl : '';
- $('#show-contract-jl').text(contractJl);
- $('#contract-jl').val(contractJl);
- const qcJl = data && data.qc_jl ? data.qc_jl : '';
- $('#show-qc-jl').text(qcJl);
- $('#qc-jl').val(qcJl);
- const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
- $('#show-qc-minus-jl').text(qcMinusJl);
- $('#qc-minus-jl').val(qcMinusJl);
- const bglCode = data && data.bgl_code ? data.bgl_code : '';
- $('#show-bgl-code').text(bglCode);
- $('#bgl-code').val(bglCode);
- const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
- $('#show-bgl-drawing-code').text(bglDrawingCode);
- $('#bgl-drawing-code').val(bglDrawingCode);
- const bwName = data && data.bw ? data.bw : '';
- $('#show-bw-name').text(bwName);
- $('#bw-name').val(bwName);
- const position = data && data.position ? data.position : '';
- $('#show-position').text(position);
- $('#position').val(position);
- const peg = data && data.peg ? data.peg : '';
- $('#show-peg').text(peg);
- $('#peg').val(peg);
- const xmName = data && data.xm ? data.xm: '';
- $('#show-xm-name').text(xmName);
- $('#xm-name').val(xmName);
- const jldy = data && data.jldy ? data.jldy: '';
- $('#show-jldy').text(jldy);
- $('#jldy').val(jldy);
- const drawingCode = data && data.drawing_code ? data.drawing_code: '';
- $('#show-drawing-code').text(drawingCode);
- $('#drawing-code').val(drawingCode);
- const calcMemo = data && data.calc_memo ? data.calc_memo: '';
- $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
- $('#calc-memo').val(calcMemo);
- const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
- $('#show-calc-img').attr('src', calcImgSrc);
- $('#calc-img').attr('src', calcImgSrc);
- $('#view-calc-img').attr('src', calcImgSrc);
- const calcImgRemark = data && data.calc_img_remark || '';
- $('#view-calc-remark').val(calcImgRemark);
- $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
- $('#calc-remark').html(calcImgRemark);
- $("#view-calc-remark").attr('readonly', true);
- // 处理 编辑 -> 添加草图中textarea多余的空格
- $('#text-edit').val(calcImgRemark)
- }
- }
- class CheckedChange {
- constructor (setting) {
- const self = this;
- this.changeSpreadSetting = {
- cols: [
- {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}` : ''; }},
- {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
- {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
- {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- getColor: function (sheet, data, row, col, defaultColor) {
- if (data && data.is_import) {
- return '#eee';
- } else {
- return defaultColor;
- }
- }
- };
- this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
- this.changeSheet = this.changeSpread.getActiveSheet();
- SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
- const getTipText = function (data) {
- if (!data) return '';
- const tips = [];
- if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
- if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
- if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
- if (data.xmj_jldy) tips.push(data.xmj_jldy);
- return tips.join('-');
- };
- this.changeBillsSpreadSetting = {
- cols: [
- {title: '计价', colSpan: '1', rowSpan: '1', field: 'is_valuation', hAlign: 1, width: 30, cellType: 'checkbox'},
- {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, cellType: 'delayTip', getTip: getTipText},
- {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
- {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
- {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
- {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true
- };
- this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
- this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
- SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
- this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- const change = SpreadJsObj.getSelectObject(self.changeSheet);
- if (change) self.refreshChangeDetailData(change);
- });
- this.changes = null;
- this.reloadChangeData();
- setting.reloadObj.click(function() {
- self.reloadChangeData();
- });
- $.contextMenu({
- selector: '#' + setting.changeBillsObj.attr('id'),
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'locateZjjl': {
- name: '定位至台账',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- const change = SpreadJsObj.getSelectObject(self.changeSheet);
- const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
- if (change.is_import) {
- if (changeBills.pos && changeBills.pos.length > 0) {
- const node = stageTree.getItems(changeBills.pos[0].ledger_id);
- if (!node || node.filter) return;
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
- SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
- stagePosSpreadObj.loadCurPosData();
- }
- } else if (changeBills.gcl_id) {
- const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
- if (!node || node.filter) return;
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id, true);
- SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
- stagePosSpreadObj.loadCurPosData();
- const posData = spSpread.getActiveSheet().zh_data;
- if (!posData || posData.length === 0) return;
- const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
- if (changePos) SpreadJsObj.locateData(spSpread.getActiveSheet(), changePos);
- } else {
- const cb = {
- b_code: changeBills.code || '',
- name: changeBills.name || '',
- unit: changeBills.unit || '',
- unit_price: changeBills.unit_price || 0,
- };
- for (const node of stageTree.nodes) {
- if (node.children && node.children.length > 0) continue;
- if (node.filter) continue;
- const b = {
- b_code: node.b_code || '',
- name: node.name || '',
- unit: node.unit || '',
- unit_price: node.unit_price || 0,
- };
- if (_.isMatch(cb, b)) {
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
- SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
- stagePosSpreadObj.loadCurPosData();
- return;
- }
- }
- }
- },
- disabled: function (key, opt) {
- const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
- return !changeBills;
- }
- },
- 'autoUse': {
- name: '调用',
- icon: 'fa-play',
- callback: function (key, opt) {
- const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
- const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
- const billsPos = self.findBillsPos(curChange, changeBills);
- if (!billsPos) {
- toastr.warning('无可调用的清单或计量单元');
- return;
- }
- const data = { autoType: 'bills', bills: [{ ...billsPos, cid: changeBills.cid, cbid: changeBills.id }] };
- postData(window.location.pathname + '/auto-use-change', data, function(result) {
- if (result.pos) {
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.bills);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStageChangeUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateChangeData(result, nodes)
- }
- });
- },
- disabled: function (key, opt) {
- const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
- const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
- return !changeBills || curChange.is_import;
- },
- visible: function (key, opt) {
- return stage.status === 1 && stage.isCheckFirst && !stage.assist;
- }
- },
- }
- });
- $.contextMenu({
- selector: '#' + setting.changeObj.attr('id'),
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeSpread);
- const change = target.cellTypeHintInfo ? self.changes[target.cellTypeHitInfo.row] : null;
- if (change) self.refreshChangeDetailData(change);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'autoUseCur': {
- name: '自动调用',
- icon: 'fa-play',
- callback: function (key, opt) {
- const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
- const changeBills = self.changeBillsSheet.zh_data;
- const data = { bills: [], autoType: 'bills' };
- for (const cb of changeBills) {
- const billsPos = self.findBillsPos(curChange, cb);
- if (billsPos) data.bills.push({ ...billsPos, cid: cb.cid, cbid: cb.id })
- }
- if (data.bills.length === 0) {
- toastr.warning('无可调用的清单或计量单元');
- return;
- }
- postData(window.location.pathname + '/auto-use-change', data, function(result) {
- if (result.pos) {
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.bills);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- if (detail) {
- detail.loadStageChangeUpdateData(result, nodes);
- } else {
- stageIm.loadUpdateChangeData(result, nodes)
- }
- });
- },
- disabled: function (key, opt) {
- const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
- const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
- return !curChange || !changeBills || curChange.is_import;
- },
- visible: function (key, opt) {
- return stage.status === 1 && stage.isCheckFirst && !stage.assist;
- }
- },
- 'autoUseAll': {
- name: '自动调用(全部变更令)',
- icon: 'fa-play',
- callback: function (key, opt) {
- postData(window.location.pathname + '/auto-use-change', { autoType: 'all' }, function(result) {
- window.location.reload();
- });
- },
- disabled: function (key, opt) {
- const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
- return !curChange || curChange.is_import;
- },
- visible: function (key, opt) {
- return stage.status === 1 && stage.isCheckFirst && !stage.assist;
- }
- }
- }
- });
- }
- refreshChangeDetailData(data) {
- const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
- if (change.cid === this.curChangeId) return;
- this.curChangeId = change.cid;
- const self = this;
- if (change.detail) {
- self.loadChangeDetailData();
- } else {
- postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
- change.detail = result;
- self.analyzeChange(change);
- self.loadChangeDetailData();
- });
- }
- }
- loadChangeDetailData(data) {
- const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
- if (change) {
- SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
- } else {
- SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
- }
- }
- refresh() {
- this.changeSpread.refresh();
- this.changeBillsSpread.refresh();
- }
- reloadChangeData() {
- const self = this;
- postData(window.location.pathname + '/change/data', null, function (result) {
- self.changes = [];
- result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
- result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
- if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
- if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
- SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
- self.changeSheet.setSelection(0, 0, 1, 1);
- self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
- self.loadChangeDetailData();
- });
- }
- _analyzeCommon(change) {
- for (const b of change.bills) {
- const eub = change.detail.endUsedBills.find(function (x) {
- return x.cbid === b.id;
- });
- if (eub) b.used_qty = eub.qty;
- b.qty = _.toNumber(b.samount);
- b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
- b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
- b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
- b.cur_qty = 0;
- for (const p of b.pos) {
- p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
- b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
- }
- }
- }
- _analyzeImport(change) {
- for (const b of change.bills) {
- const eub = change.detail.endUsedBills.find(function (x) {
- return x.rela_cbid === b.id;
- });
- if (eub) b.used_qty = eub.rela_qty;
- b.qty = _.toNumber(b.samount);
- delete b.unit_price;
- // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
- b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
- b.cur_qty = 0;
- for (const p of b.pos) {
- p.qty = p.rela_qty;
- const node = stageTree.datas.find(x => { return x.id === p.lid; });
- p.ledger_id = node.ledger_id;
- p.f_qty = node.quantity;
- b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
- }
- }
- }
- analyzeChange(change) {
- change.bills = change.detail.bills;
- if (change.is_import) {
- this._analyzeImport(change);
- } else {
- this._analyzeCommon(change);
- }
- }
- findBillsPos(change, changeBills) {
- if (change.is_import) {
- return null;
- } else if (changeBills.gcl_id) {
- const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
- if (node.filter) return null;
- if (node.settle_status === settleStatus.finish) return null;
- posData = stagePos.getLedgerPos(node.id) || [];
- const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
- if (changePos && changePos.settle_status) return null;
- let defaultPos;
- if (posData.length > 0) {
- defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
- if (!defaultPos) return null;
- } else {
- defaultPos = { id: '-1' };
- }
- return { lid: node.id, pid: changePos ? changePos.id : defaultPos.id };
- } else {
- const cb = {
- b_code: changeBills.code || '',
- name: changeBills.name || '',
- unit: changeBills.unit || '',
- unit_price: changeBills.unit_price || 0,
- };
- for (const node of stageTree.nodes) {
- if (node.children && node.children.length > 0) continue;
- if (node.filter) continue;
- if (node.settle_status === settleStatus.finish) continue;
- const b = {
- b_code: node.b_code || '',
- name: node.name || '',
- unit: node.unit || '',
- unit_price: node.unit_price || 0,
- };
- if (_.isMatch(cb, b)) {
- posData = stagePos.getLedgerPos(node.id) || [];
- let defaultPos;
- if (posData.length > 0) {
- defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
- if (!defaultPos) return null;
- } else {
- defaultPos = { id: '-1' };
- }
- return { lid: node.id, pid: defaultPos.id };
- }
- }
- return null;
- }
- }
- }
- // 展开收起附件
- $('a', '.right-nav').bind('click', function () {
- //const main = $('#main-view'), tool = $('#tools-view');
- const tab = $(this), tabPanel = $(tab.attr('content'));
- if (!tab.hasClass('active')) {
- $('a', '.side-menu').removeClass('active');
- $('.tab-content .tab-select-show').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('active');
- showSideTools(tab.hasClass('active'));
- if (tab.attr('content') === '#search' && !searchLedger) {
- searchLedger = $.ledgerSearch({
- selector: '#search',
- ledger: { billsTree: stageTree, pos: stagePos },
- searchOver: true,
- searchEmpty: true,
- resultSpreadSetting: {
- cols: [
- {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
- {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- {title: '数量', field: 'quantity', hAlign: 2, width: 50},
- {title: '完成率(%)', field: completePerField, hAlign: 2, width: 70},
- {title: '部位', field: 'bw', hAlign: 2, width: 90},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- },
- locate: function(cur) {
- if (!cur.lid) return;
- SpreadJsObj.locateTreeNode(slSheet, cur.lid, true);
- stageTreeSpreadObj.loadRelaData();
- if (cur.pid && cur.pid !== -1) {
- const pIndex = spSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
- SpreadJsObj.locateRow(spSheet, pIndex);
- }
- },
- customSearch: [
- {
- key: 'less', title: '漏计', valid: true,
- check: function (node) {
- if (node.quantity) {
- return ZhCalc.sub(ZhCalc.sum([node.quantity, node.end_qc_qty, node.end_qc_minus_qty]), node.end_gather_qty) > 0;
- } else if (node.total_price) {
- return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
- }
- }
- }, {
- key: 'over', title: '超计', valid: true,
- check: function (node) {
- return checkUtils.billsOver(node, stagePos, tenderInfo.checkOverInfo);
- }
- }, {
- key: 'empty', title: '漏计', valid: false,
- check: function (node) {
- if (node.quantity) {
- return !node.end_gather_qty || checkZero(node.end_gather_qty);
- } else if (node.total_price) {
- return !node.end_gather_tp || checkZero(node.end_gather_tp);
- }
- }
- }, {
- key: 'estimate', title: '预计变更', valid: true,
- check: function (node) {
- const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
- if (posRange.length > 0) {
- for (const p of posRange) {
- if (!checkZero(p.estimate_qty)) return true;
- }
- return false;
- } else {
- return false;
- }
- }
- }
- ],
- });
- searchLedger.spread.refresh();
- }
- if (tab.attr('content') === '#fujian') {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- node && getNodeList(node.id);
- }
- if (tab.attr('content') === '#zhongjian') {
- if (!detail) {
- detail = new Detail($('#detail-spread'));
- detail.spread.refresh();
- $('#zhongjian .sjs-bottom').height('400px');
- $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
- } else {
- detail.spread.refresh();
- }
- }
- if (tab.attr('content') === '#checked-change') {
- if (!checkedChanges) {
- checkedChanges = new CheckedChange({
- changeObj: $('#cc-spread'),
- changeBillsObj: $('#ccb-spread'),
- reloadObj: $('#refresh-cc'),
- });
- checkedChanges.refresh();
- } else {
- $('#ccb-spread').height('400px');
- checkedChanges.refresh();
- }
- }
- if (tab.attr('content') === '#error-list') {
- errorList.spread.refresh();
- }
- if (tab.attr('content') === '#check-list') {
- checkList.spread.refresh();
- }
- if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
- } else {
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showSideTools(tab.hasClass('active'));
- }
- slSpread.refresh();
- spSpread.refresh();
- });
- // 切换附件里节点和所有附件
- $('#fujian .nav-link').on('click', function () {
- const tabPanel = $(this).attr('fujian-content');
- if (tabPanel !== 'syfujian') {
- $('#showPage').hide();
- $('#bach-download').prop('type', 'curr');
- } else {
- $('#showPage').show();
- $('#bach-download').prop('type', 'all')
- }
- $('#showAttachment').hide();
- });
- // 上传附件
- $('#upload-file-btn').click(function () {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (!node) return
- const files = $('#upload-file')[0].files;
- const formData = new FormData();
- formData.append('lid', node.id);
- for (const file of files) {
- if (file === undefined) {
- toastr.error('未选择上传文件!');
- return false;
- }
- const filesize = file.size;
- if (filesize > 50 * 1024 * 1024) {
- toastr.error('存在上传文件大小过大!');
- return false;
- }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toastr.error('只能上传指定格式的附件!');
- return false;
- }
- formData.append('size', filesize);
- formData.append('file[]', file);
- }
- postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
- $('#upload').modal('hide');
- // 插入到attData中
- attData = data.concat(attData);
- // 重新生成List
- getAllList();
- getNodeList(node.id);
- }, function () {
- toastr.error('附件上传失败');
- });
- $('#upload-file').val('');
- });
- // 获取附件信息
- $('.list-table').on('click', '.att-file-name', function () {
- const fid = $(this).attr('file-id');
- if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
- return;
- }
- const att = attData.find(function (item) {
- return item.id === parseInt(fid);
- });
- $('#edit-att').hide();
- $('#show-att').show();
- if (att !== undefined) {
- // 进来先把编辑功能隐藏
- $('#btn-att a').eq(3).hide()
- $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
- const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
- $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
- // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
- // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
- $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
- $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
- $('#show-att tr').eq(3).children('td').text(att.remark);
- // 附件uid等于当前用户id, 附件上传本人
- if (parseInt(cur_uid) === att.uid) {
- $('#btn-att').show();
- const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
- if (showDel) $('#btn-att a').eq(3).show();
- // $('#btn-att a').eq(3).show();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(4).hide();
- $('#btn-att a').eq(5).hide();
- } else {
- $('#btn-att').hide();
- $('#btn-att a').eq(3).hide();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(4).hide();
- $('#btn-att a').eq(5).hide();
- }
- $('#showAttachment').attr('file-id', fid);
- $('#showAttachment').show();
- } else {
- $('#showAttachment').hide();
- $('#showAttachment').attr('file-id', '');
- toastr.error('附件信息获取失败');
- }
- });
- // $('body').on('click', '.alllist-table a', handleFileList);
- $('body').on('click', '#btn-att a', function () {
- const content = $(this).attr('content');
- const fid = $('#showAttachment').attr('file-id');
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (content === 'edit') {
- $('#btn-att a').eq(3).hide();
- $('#btn-att a').eq(2).show();
- $('#btn-att a').eq(4).show();
- $('#btn-att a').eq(5).show();
- $('#show-att').hide();
- $('#edit-att').show();
- const att = attData.find(function (item) {
- return item.id === parseInt(fid);
- });
- $('#edit-att .form-group').eq(0).find('input').val(att.filename);
- $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
- const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
- $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
- $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
- $('#edit-att .form-group').eq(3).find('input').val(att.remark);
- } else if (content === 'cancel') {
- $('#show-att').show();
- $('#edit-att').hide();
- $('#btn-att a').eq(3).show();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(4).hide();
- $('#btn-att a').eq(5).hide();
- } else if (content === 'save') {
- const formData = new FormData();
- formData.append('id', fid);
- formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
- formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
- formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
- const file = $('#change-att-btn')[0];
- if (file.files[0] !== undefined) {
- const filesize = file.files[0].size;
- formData.append('size', filesize);
- formData.append('file', file.files[0]);
- }
- postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
- // 替换到attData中
- const att_index = attData.findIndex(function (item) {
- return item.id === parseInt(fid);
- });
- attData.splice(att_index, 1, data);
- // 重新生成List
- getAllList(parseInt($('#currentPage').text()));
- getNodeList(node.id);
- $('#show-att').show();
- $('#edit-att').hide();
- $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
- const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
- $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
- // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
- $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
- $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
- $('#show-att tr').eq(4).children('td').text(data.remark);
- $('#btn-att a').eq(3).show();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(4).hide();
- $('#btn-att a').eq(5).hide();
- }, function () {
- toastr.error('附件上传失败');
- });
- $('#change-att-btn').val('');
- } else if (content === 'del') {
- const data = {id: fid};
- postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
- // 删除到attData中
- const att_index = attData.findIndex(function (item) {
- return item.id === parseInt(fid);
- });
- attData.splice(att_index, 1);
- // 重新生成List
- if ($('#alllist-table tr').length === 1) {
- getAllList(parseInt($('#currentPage').text()) - 1);
- } else {
- getAllList(parseInt($('#currentPage').text()));
- }
- getNodeList(node.id);
- $('#showAttachment').hide();
- $('#showAttachment').attr('file-id', '');
- });
- } else if (content === 'view') {
- const data = {id: fid};
- postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
- const { filepath } = result
- $('#load-file').attr('href', filepath);
- $('#load-file')[0].click();
- // $('#show-att tr').eq(2).find('a').attr('href', filepath)
- // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
- });
- } else if (content === 'location') {
- const att = attData.find(item => item.id === parseInt(fid));
- if (Object.keys(att).length) {
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
- stagePosSpreadObj.loadCurPosData();
- }
- }
- });
- // 替换附件
- $('#change-att-btn').on('change', function () {
- const file = $('#change-att-btn')[0].files[0];
- const name = file.name;
- const filename = name.substring(0, name.lastIndexOf("."));
- const fileext = name.substr(name.indexOf("."));
- const filesize = file.size;
- if (filesize > 50 * 1024 * 1024) {
- toastr.error('文件大小过大!');
- $('#change-att-btn').val('');
- return false;
- }
- if (whiteList.indexOf(fileext) === -1) {
- toastr.error('只能上传指定格式的附件!');
- $('#change-att-btn').val('');
- return false;
- }
- $('#edit-att .form-group').eq(0).find('input').val(filename);
- $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
- });
- // 切换页数
- $('.page-select').on('click', function () {
- const totalPageNum = parseInt($('#totalPage').text());
- const lastPageNum = parseInt($('#currentPage').text());
- const status = $(this).attr('content');
- if (status === 'pre' && lastPageNum > 1) {
- getAllList(lastPageNum-1);
- $('#showAttachment').hide();
- $('#syfujian .check-all-file').prop('checked', false)
- } else if (status === 'next' && lastPageNum < totalPageNum) {
- getAllList(lastPageNum+1);
- $('#showAttachment').hide();
- $('#syfujian .check-all-file').prop('checked', false)
- }
- });
- // 批量下载
- $('#bach-download').click(function() {
- const fileIds = [];
- const type = $(this).attr('type');
- let node = ''
- if (type === 'curr') {
- node = '#nodelist-table .check-file:checked'
- } else {
- node = '#alllist-table .check-file:checked'
- }
- $(node).each(function() {
- const fileId = $(this).attr('file-id');
- fileId && fileIds.push(fileId);
- });
- if (fileIds.length) {
- if (fileIds.length > 20) {
- return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
- }
- toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
- $(this).attr('disabled', "true")
- const btn = $(this);
- const fileArr = [];
- for (const id of fileIds) {
- const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
- fileArr.push({
- url: fileInfo.orginpath, //文件的oss存储路径 (必填)
- name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
- foldPath: '' // (可选, 文件在压缩包中的存储路径)
- });
- }
- const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
- try {
- zipOss.downloadFromAliOss(fileArr, packageName, btn);
- } catch (e) {
- btn.removeAttr('disabled');
- toastr.clear();
- toastr.error('批量下载失败');
- }
- // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
- // toastr.clear()
- // toastr.success('压缩文件成功')
- // btn.removeAttr('disabled')
- // const href = window.URL.createObjectURL(result)
- // $('#zipDown').attr('href', href);
- // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
- // $("#zipDown")[0].click();
- // }, () => {
- // btn.removeAttr('disabled')
- // toastr.clear()
- // toastr.error('批量下载失败')
- // });
- // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
- // $('#zipDown').attr('href', url);
- // $("#zipDown")[0].click();
- }
- });
- // 监听附件check是否选中
- $('.list-table').on('click', '.check-file', function() {
- const checkedList = $(this).parents('.list-table').children().find('input:checked');
- const childs = $(this).parents('.list-table').children().length;
- const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
- if (checkedList.length === childs) {
- checkBox.prop("checked", true);
- } else {
- checkBox.prop("checked", false);
- }
- });
- $('.check-all-file').click(function() {
- const isCheck = $(this).is(':checked');
- $(this).parents('table').find('.list-table').each(function() {
- $(this).find('input:checkbox').prop("checked", isCheck);
- })
- });
- // 显示层次
- (function (select, sheet) {
- $(select).click(function () {
- if (!sheet.zh_tree) return;
- const tag = $(this).attr('tag');
- const tree = sheet.zh_tree;
- setTimeout(() => {
- showWaitingView();
- switch (tag) {
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- tree.expandByLevel(parseInt(tag));
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "last":
- tree.expandByCustom(() => { return true; });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "leafXmj":
- tree.expandToLeafXmj();
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "curMeasure":
- tree.expandByCustom(function (node) {
- for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
- if (node[field]) {
- return true;
- }
- }
- return false;
- });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "endMeasure":
- tree.expandByCustom(function (node) {
- 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']) {
- if (node[field]) {
- return true;
- }
- }
- return false;
- });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- }
- closeWaitingView();
- }, 100);
- });
- })('a[name=showLevel]', slSpread.getActiveSheet());
- const stageCheckerSetting = {
- ledgerTree: stageTree,
- ledgerPos: stagePos,
- checkList: checkList,
- decimal: tenderInfo.decimal,
- checkOption: checkOption,
- };
- if (!checkTzMeasureType()) {
- stageCheckerSetting.checkOption.tp.fields.push(
- {qty: 'sgfh_qty', tp: 'sgfh_tp'},
- {qty: 'sjcl_qty', tp: 'sjcl_tp'},
- {qty: 'qtcl_qty', tp: 'qtcl_tp'},
- {qty: 'quantity', tp: 'total_price'},
- );
- }
- $('#ledger-check2').click(() => {
- ledgerCheck2(stageCheckerSetting).then(result => {
- check2Viewing({
- extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
- randomWait: true,
- prefix: 'check2-',
- checks: result,
- checkList: checkList,
- });
- });
- });
- const dataChecker = DataChecker({
- checkUrl: window.location.pathname + '/check',
- completeData: function (data) {
- stagePos.updateDatas({pos: data.source.pos});
- const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
- stagePosSpreadObj.loadCurPosData();
- for (const e of data.error) {
- e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
- }
- },
- errorList: errorList,
- });
- $('[name=stage-start]').submit(function (e) {
- if (checkAuditorFrom()) {
- // 再检查多人协同确认情况
- const list = stage.relaAssists.find(x => {return !x.confirm });
- if(list) {
- toastr.error('请检查多人协同确认情况再上报');
- $('#hide-all').hide();
- return false;
- }
- $(this).parent().parent().parent().modal('hide');
- dataChecker.checkAndPost(this.action, {});
- $('#hide-all').hide();
- }
- return false;
- });
- $('#audit-check0').submit(function (e) {
- // 再检查多人协同确认情况
- const list = stage.relaAssists.find(x => {return !x.confirm && stageAssistRela.checkAssistPartUsed(x) });
- if(list) {
- toastr.error('请检查多人协同确认情况再审批通过');
- $('#hide-all').hide();
- return false;
- }
- const checkType = parseInt($('[name=checkType]').val());
- const noUsed = stage.relaAssists.filter(x => {return !stageAssistRela.checkAssistPartUsed(x) });
- const data = {
- opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
- coop_noUsed: noUsed && noUsed.length > 0 ? noUsed.map(x => { return x.ass_ledger_id; }) : [],
- checkType,
- };
- $('#sp-done').modal('hide');
- checkType && dataChecker.checkAndPost(this.action, data);
- $('#hide-all').hide();
- return false;
- });
- $('#audit-check1').submit(function (e) {
- const checkType = parseInt($('[name=checkType]:checked').val());
- const confirm = stage.relaAssists.filter(x => { return x.confirm });
- const data = {
- opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
- coop_checked: confirm && confirm.length > 0 ? confirm.map(x => { return x.id; }) : [],
- checkType,
- };
- if ($('#warning-text').length) $('#warning-text').remove();
- if (!checkType && !$('#warning-text').length) {
- $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
- return false
- }
- $('#sp-back').modal('hide');
- checkType && dataChecker.checkAndPost(this.action, data);
- $('#hide-all').hide();
- return false;
- });
- $('#exportExcel').click(function () {
- stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
- });
- $('#cbr-check-all').click(function () {
- if (this.checked) {
- $('input', '#cbr-pos-list').attr('checked', 'checked');
- } else {
- $('input', '#cbr-pos-list').removeAttr('checked');
- }
- });
- $('#cbr-ok').click(() => {
- const ratio = parseInt($('#cbr-ratio').val());
- if (!ratio) {
- toastr.warning('请输入计量比例');
- return;
- } else if (ratio < 1) {
- toastr.warning('计量比例不可小于1');
- return;
- } else if (ratio > 100) {
- toastr.warning('计量比例不可大于100');
- return;
- }
- const apply2sibling = $('#apply2sibling')[0].checked;
- const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
- if (posName.length === 0) {
- toastr.warning('请勾选需要按计量比例的计量单元');
- return;
- }
- stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
- });
- // 收方单生成
- $('#setshoufang').click(function () {
- const lid = $('#shoufang-lid').val();
- const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
- // 修改线上
- postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
- // 收方单tab打开并显示在最新
- if (!$('#shoufang-tab').hasClass('active')) {
- $('#shoufang-tab').click();
- }
- const data = makeOneShouFang(result);
- data.filenum = 0;
- sfData = _.concat(data, sfData);
- getShouFangList();
- });
- });
- $('body').on('click', '.del-shoufang', function () {
- const id = $(this).attr('data-id');
- $('#del-shoufang-id').val(id);
- const name = $(this).parents('tr').children('td').eq(0).text();
- const ledger_code = name.split(' / ')[0];
- const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
- $('#del-shoufang-ledger').text('清单:' + ledger_code);
- if (pos_name) {
- $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
- } else {
- $('#del-shoufang-pos').text('').hide();
- }
- });
- // 收方单删除
- $('#delshoufang').click(function () {
- const sfid = $('#del-shoufang-id').val();
- // 修改线上
- postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
- // 删除到sfData中
- const att_index = sfData.findIndex(function (item) {
- return item.id === parseInt(sfid);
- });
- sfData.splice(att_index, 1);
- // 重新生成List
- if ($('#shoufang-table tr').length === 1) {
- getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
- } else {
- getShouFangList(parseInt($('#shoufang-currentPage').text()));
- }
- $('#shoufangdelete').modal('hide');
- });
- });
- // 切换页数
- $('.shoufang-page-select').on('click', function () {
- const totalPageNum = parseInt($('#shoufang-totalPage').text());
- const lastPageNum = parseInt($('#shoufang-currentPage').text());
- const status = $(this).attr('content');
- if (status === 'pre' && lastPageNum > 1) {
- getShouFangList(lastPageNum-1);
- } else if (status === 'next' && lastPageNum < totalPageNum) {
- getShouFangList(lastPageNum+1);
- }
- });
- // 获取单个收方单附件列表
- $('body').on('click', '.show-shoufang-att', function () {
- const id = parseInt($(this).attr('data-id'));
- let html = '';
- $('#shoufang-flie-list').html(html);
- postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
- for (const att of result) {
- html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
- `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
- `<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>`;
- }
- $('#shoufang-flie-list').html(html);
- $('[data-toggle="tooltip"]').tooltip()
- });
- function makeViewHtml(viewpath) {
- 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>` : '';
- }
- function makeDelHtml(fid, extra_upload) {
- return sfAttDelPower &&
- (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
- '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
- '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
- }
- });
- function makeEditHtml(fid, filename, fileext, extra_upload) {
- return sfAttDelPower &&
- (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
- '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
- '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
- }
- // 修改收方单附件文件名
- $('body').on('click', '.edit-shoufang-att', function () {
- $(this).children('i').tooltip('hide');
- const fid = $(this).data('id');
- const filename = $(this).data('filename');
- const fileext = $(this).data('fileext');
- const html = `<div class="input-group input-group-sm">
- <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
- <div class="input-group-append" id="button-${fid}">
- <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
- <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
- </div>
- </div>`;
- $(this).parents('td').html(html);
- });
- // 确认修改文件名
- $('body').on('click', '.shoufang-att-confirm-btn', function () {
- const validText = $.trim($(this).parents('td').find('input').val());
- const orgValue = $.trim($(this).data('filename'));
- const fileext = $(this).data('fileext');
- const fid = $(this).data('fid');
- if (!validText) {
- toastr.error('文件名不能为空');
- return;
- }
- // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
- if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
- toastr.error('文件名中不能包含.字符和空格');
- return;
- }
- if(validText == orgValue) {
- const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
- $(this).parents('td').html(html);
- return;
- }
- const data = {
- id: fid,
- filename: validText,
- };
- const _self = $(this);
- postData('/wap/shoufang/editfile', data, function (result) {
- const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
- _self.parents('td').html(html);
- });
- });
- // 取消修改文件名
- $('body').on('click', '.shoufang-att-cancel-btn', function () {
- const fid = $(this).data('fid');
- const filename = $(this).data('filename');
- const fileext = $(this).data('fileext');
- const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
- $(this).parents('td').html(html);
- });
- // 删除收方单附件
- $('body').on('click', '.del-shoufang-att', function () {
- const id = $(this).data('id');
- const _self = $(this);
- const data = { id };
- const sfid = $(this).data('sfid');
- postData('/wap/shoufang/delfile', data, function (result) {
- _self.parents('tr').remove();
- // 附件个数更新
- $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
- const sfInfo = _.find(sfData, { id: sfid });
- sfInfo.filenum = $('#shoufang-flie-list tr').length;
- });
- });
- // 定位到对应的清单或计量单元
- $('body').on('click', '.show-shoufang-node', function () {
- const id = parseInt($(this).attr('data-id'));
- const sfInfo = _.find(sfData, { id });
- if (sfInfo) {
- const lData = _.find(ledgerData, { id: sfInfo.lid });
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
- stagePosSpreadObj.loadCurPosData();
- if (sfInfo.pid) {
- const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
- SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
- stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
- }
- }
- });
- // 定位到对应的清单或计量单元
- $('body').on('click', '.show-shoufang-report', function () {
- const id = parseInt($(this).attr('data-id'));
- const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
- sessionStorage.qrCodePath = qrCodePath;
- sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
- sessionStorage.req_params = JSON.stringify(req_params);
- sessionStorage.rpt_name = rpt_name;
- window.open('/individualReport/A4');
- });
- $('#importExcel').click(() => {
- importExcel.doImport({
- template: {
- hint: '计量台账',
- url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/导入计量台账Excel格式.xlsx',
- },
- callback: function (sheet) {
- postDataCompress(window.location.pathname + '/importStageSheet', {sheet}, function (result) {
- window.location.reload();
- }, null);
- }
- });
- });
- const stageAssistRela = {
- refreshAssConfirmBtn: function () {
- if (stage.assist) {
- const caption = stage.assist.user_id === stage.user_id
- ? (stage.assist.confirm ? '撤销上报' : '确认上报')
- : (stage.assist.confirm ? '重新审批' : '审批通过');
- if (!stage.readOnly || stage.assist.locked) $('#ass-confirm-btn').show().html(caption);
- } else {
- $('#ass-confirm-btn').hide();
- }
- },
- checkAssistPartUsed(assist) {
- const ass_lid = assist.ass_ledger_id.split(',');
- for (const lid of ass_lid) {
- const node = stageTree.getItems(lid);
- if (!node) continue;
- if (checkUsed(stageTree, stagePos, node)) return true;
- }
- return false;
- },
- refreshAssistTable: function () {
- const html = [];
- for (const ra of stage.relaAssists) {
- const used = this.checkAssistPartUsed(ra);
- const hint = used
- ? (ra.confirm ? `<td class="text-success">${moment(ra.update_time).format('YYYY-MM-DD HH:mm')}</td>` : '<td class="text-warning">待确认</td>')
- : '<td>本期未计量</td>';
- html.push(`<tr><td>${ra.name}</td><td>${ra.company}</td>${hint}</tr>`);
- }
- return $('#assistList').html(html.join(''));
- },
- refreshAssists: function () {
- if (stage.relaAssists.length > 0) {
- $('#assistCount').html(stage.relaAssists.length || '').parent().show();
- } else {
- $('#assistCount').parent().hide();
- }
- },
- refreshReadOnly(){
- stageTreeSpreadObj.assistReadOnly = stage.readOnly || stage.revising || (!!stage.assist && !!stage.assist.confirm);
- SpreadJsObj.refreshSheetReadOnly(slSpread.getActiveSheet());
- stagePosSpreadObj.loadCurPosData();
- },
- init: function() {
- this.refreshAssConfirmBtn();
- this.refreshReadOnly();
- this.refreshAssists();
- },
- };
- stageAssistRela.init();
- $('#ass-confirm-btn').click(() => {
- const data = { user_id: stage.assist.user_id, ass_user_id: stage.assist.ass_user_id, confirm: !stage.assist.confirm, type: 'stage' };
- postData(window.location.pathname + '/ass-confirm', data, function(result) {
- window.location.reload();
- // stage.assist = result;
- // stageAssistRela.refreshAssConfirmBtn();
- // stageAssistRela.refreshReadOnly();
- });
- });
- $('#assists').on('show.bs.modal', function(){
- postData(window.location.pathname + '/ass', { user_id: userID, type: 'stage' }, function (result) {
- stage.relaAssists = result;
- stageAssistRela.refreshAssistTable();
- });
- });
- $('body').on('click', 'a[name=att-delete]', function() {
- const fid = this.getAttribute('file-id');
- if (!fid) return;
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const data = {id: fid};
- postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
- // 删除到attData中
- const att_index = attData.findIndex(function (item) {
- return item.id === parseInt(fid);
- });
- attData.splice(att_index, 1);
- // 重新生成List
- if ($('#alllist-table tr').length === 1) {
- getAllList(parseInt($('#currentPage').text()) - 1);
- } else {
- getAllList(parseInt($('#currentPage').text()));
- }
- getNodeList(node.id);
- $('#showAttachment').hide();
- $('#showAttachment').attr('file-id', '');
- });
- });
- });
- function makeOneShouFang(sf) {
- const lData = _.find(ledgerData, { id: sf.lid });
- sf.name = lData.b_code;
- if (sf.pid) {
- const pData = _.find(posData, { id: sf.pid });
- if (pData && pData.name) {
- sf.name = lData.b_code + ' / ' + pData.name;
- }
- }
- return sf;
- }
- function makeShouFang() {
- for (const sf of sfData) {
- makeOneShouFang(sf);
- }
- getShouFangList();
- }
- // 生成收方单列表
- function getShouFangList(currPageNum = 1) {
- // 每页最多几个附件
- const pageCount = 20;
- // 附件总数
- const total = sfData.length;
- // 总页数
- const pageNum = Math.ceil(total/pageCount);
- $('#shoufang-totalPage').text(pageNum);
- $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
- // 当前页附件内容
- const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
- let html = '';
- for(const att of currPageAttData) {
- html += '<tr><td>' + att.name + '</td>' +
- '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
- '<td width="100">' +
- '<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> ' +
- '<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> ' +
- // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
- makeDelHtml(att.id, att.extra_upload) +
- '</td></tr>';
- }
- function makeDelHtml(id, extra_upload) {
- return cur_uid === stage.user_id &&
- (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
- '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
- '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
- }
- $('#shoufang-table').html(html);
- $('[data-toggle="tooltip"]').tooltip();
- }
- function makeReportData(sfid) {
- const sfInfo = _.find(sfData, { id: sfid });
- const ledger_code = sfInfo.name.split(' / ')[0];
- const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
- const replace_key_params = {
- 'KEY_标段名称': tenderInfo.deal_info.buildName,
- 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
- 'KEY_合同段': tenderInfo.deal_info.dealName,
- 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
- 'KEY_编号': '',
- 'KEY_设计工程数量': 0,
- };
- // if (sfInfo.pid) {
- // const pData = _.find(posData, { id: sfInfo.pid });
- // replace_key_params['KEY_设计工程数量'] = pData.quantity;
- // } else {
- const lData = _.find(ledgerData, { id: sfInfo.lid });
- // }
- replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
- replace_key_params['KEY_桩号及工程部位'] = pos_name;
- const req_params = {
- 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)
- pageSize: 'A4',
- project_id: tender.project_id,
- tender_id: tender.id,
- stage_id: stage.id,
- sp_id: spid,
- };
- const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
- const qrCodePath = sfInfo.qrcode;
- return [qrCodePath, replace_key_params, req_params, rpt_name];
- }
|