stage.js 243 KB

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