stage.js 243 KB

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