stage.js 234 KB

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