stage.js 247 KB

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