stage.js 271 KB

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