stage.js 248 KB

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