stage.js 245 KB

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