stage.js 261 KB

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