stage.js 243 KB

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