stage.js 247 KB

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