stage.js 230 KB

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