stage.js 269 KB

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