stage.js 261 KB

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