stage.js 270 KB

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