stage.js 246 KB

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