stage.js 269 KB

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