stage.js 258 KB

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