stage.js 215 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477
  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 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 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. loadExprToInput(sheet) {
  827. const sel = sheet.getSelections()[0];
  828. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  829. if (col.type === 'Number') {
  830. const data = SpreadJsObj.getSelectObject(sheet);
  831. if (!data) {
  832. $('#bills-expr').val('').attr('readOnly', true);
  833. $('#bills-expr').removeAttr('data-row');
  834. return;
  835. }
  836. const nodePos = stagePos.getLedgerPos(data.id);
  837. if (nodePos && nodePos.length > 0) {
  838. $('#bills-expr').val('').attr('readOnly', true);
  839. } else {
  840. const exprInfo = getExprInfo(col.field);
  841. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  842. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  843. if (col.field.indexOf('tp') >= 0) {
  844. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  845. } else {
  846. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  847. }
  848. }
  849. $('#bills-expr').attr('data-row', sel.row);
  850. } else {
  851. $('#bills-expr').val('').attr('readOnly', true);
  852. $('#bills-expr').removeAttr('data-row');
  853. }
  854. },
  855. refreshTreeNodes: function (sheet, nodes) {
  856. const tree = sheet.zh_tree;
  857. if (!tree) { return }
  858. const rows = [];
  859. for (const node of nodes) {
  860. rows.push(tree.nodes.indexOf(node));
  861. }
  862. SpreadJsObj.reLoadRowsData(sheet, rows);
  863. },
  864. editEnded: function (e, info) {
  865. if (info.sheet.zh_setting) {
  866. const col = info.sheet.zh_setting.cols[info.col];
  867. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  868. const node = sortData[info.row], updateData = {};
  869. const orgValue = node[col.field];
  870. let newValue = trimInvalidChar(info.editingText);
  871. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  872. return;
  873. }
  874. if (col.type === 'Number' && newValue && newValue !== '') {
  875. const num = _.toNumber(newValue);
  876. if (_.isFinite(num)) {
  877. newValue = num;
  878. } else {
  879. try {
  880. newValue = math.evaluate(transExpr(newValue));
  881. } catch(err) {
  882. toastr.error('输入的表达式非法');
  883. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  884. return;
  885. }
  886. }
  887. }
  888. if (col.field.indexOf('_dgn_') > 0) {
  889. if (node.b_code && node.b_code !== '') {
  890. toastr.error('仅项目节可输入项目节数量');
  891. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  892. return;
  893. }
  894. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  895. if (node.children && node.children.length > 0) {
  896. toastr.error('清单父项不可计量');
  897. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  898. return;
  899. } else {
  900. const nodePos = stagePos.getLedgerPos(node.id);
  901. if (nodePos && nodePos.length > 0) {
  902. toastr.error('该清单有计量单元,请在计量单元处计量');
  903. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  904. return;
  905. }
  906. }
  907. }
  908. if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  909. updateData.main = {
  910. id: node.id
  911. };
  912. updateData.main[col.field] = newValue;
  913. } else if (col.field.indexOf('_dgn_') > 0) {
  914. updateData.dgn = {
  915. id: node.id
  916. };
  917. updateData.dgn[col.field] = newValue;
  918. } else if (col.field !== 'is_tp') {
  919. updateData.stage = {
  920. lid: node.id
  921. };
  922. updateData.stage[col.field] = newValue;
  923. const exprInfo = getExprInfo(col.field);
  924. if (exprInfo) {
  925. updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
  926. }
  927. }
  928. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  929. // tag update
  930. const nodes = stageTree.loadPostStageData(data);
  931. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  932. if (detail) {
  933. detail.loadStageLedgerUpdateData(data, nodes);
  934. } else {
  935. stageIm.loadUpdateLedgerData(data, nodes);
  936. }
  937. }, function () {
  938. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  939. });
  940. }
  941. },
  942. selectionChanged: function (e, info) {
  943. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  944. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  945. stagePosSpreadObj.loadCurPosData();
  946. if (posSearch) {
  947. posSearch.search();
  948. }
  949. }
  950. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  951. stageTreeSpreadObj.loadExprToInput(info.sheet);
  952. },
  953. deletePress(sheet) {
  954. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  955. const tree = sheet.zh_tree;
  956. if (!tree) { return; }
  957. const sel = sheet.getSelections()[0];
  958. const validCols = [];
  959. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  960. const colSetting = sheet.zh_setting.cols[iCol];
  961. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  962. validCols.push(iCol);
  963. }
  964. }
  965. if (validCols.length === 0) { return; }
  966. const sortData = sheet.zh_tree.nodes;
  967. const datas = [], dgnDatas = [], mainDatas = [];
  968. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  969. const node = sortData[iRow];
  970. if (node && !node.lock) {
  971. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  972. let filter = true, filterDgn = true, filterMain = true;
  973. for (const iCol of validCols) {
  974. const colSetting = sheet.zh_setting.cols[iCol];
  975. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  976. if (node.b_code && node.b_code !== '') continue;
  977. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) < 0) {
  978. if (colSetting.field === 'contract_qty') {
  979. if (node.is_tp) continue;
  980. } else if (colSetting.field === 'contract_tp') {
  981. if (!node.is_tp) continue;
  982. }
  983. if (node.children && node.children.length > 0) {
  984. continue;
  985. }
  986. const nodePos = stagePos.getLedgerPos(node.id);
  987. if (nodePos && nodePos.length > 0) {
  988. continue;
  989. }
  990. }
  991. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  992. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  993. dgnData[colSetting.field] = 0;
  994. filterDgn = false;
  995. }
  996. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) >= 0) {
  997. mainData[colSetting.field] = null;
  998. filterMain = false;
  999. } else {
  1000. data[colSetting.field] = null;
  1001. const exprInfo = getExprInfo(colSetting.field);
  1002. if (exprInfo) {
  1003. data[exprInfo.expr] = '';
  1004. }
  1005. filter = false;
  1006. }
  1007. }
  1008. if (!filter) datas.push(data);
  1009. if (!filterDgn) dgnDatas.push(dgnData);
  1010. if (!filterMain) mainDatas.push(mainData);
  1011. }
  1012. }
  1013. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1014. const bills = {};
  1015. if (datas.length > 0) bills.stage = datas;
  1016. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  1017. if (mainDatas.length > 0) bills.main = mainDatas;
  1018. postData(window.location.href + '/update', {bills: bills}, function (result) {
  1019. const nodes = stageTree.loadPostStageData(result);
  1020. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1021. if (detail) {
  1022. detail.loadStageLedgerUpdateData(result, nodes);
  1023. } else {
  1024. stageIm.loadUpdateLedgerData(result, nodes);
  1025. }
  1026. stageTreeSpreadObj.loadExprToInput(sheet);
  1027. });
  1028. }
  1029. }
  1030. },
  1031. clipboardPasting(e, info) {
  1032. if (info.sheet.zh_setting) {
  1033. const setting = info.sheet.zh_setting;
  1034. const range = info.cellRange;
  1035. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'].concat(['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'], setting.dgnUpFields);
  1036. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1037. const col = info.sheet.zh_setting.cols[iCol];
  1038. if ((validField.indexOf(col.field) === -1)) {
  1039. toastr.error('不可修改此数据');
  1040. info.cancel = true;
  1041. return;
  1042. }
  1043. }
  1044. }
  1045. },
  1046. clipboardPasted(e, info) {
  1047. const pasteHint = getHintMsg();
  1048. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  1049. const sheet = info.sheet, setting = info.sheet.zh_setting;
  1050. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  1051. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1052. const curRow = iRow + info.cellRange.row;
  1053. const node = sheet.zh_tree.getItemsByIndex(curRow);
  1054. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  1055. let filter = true, filterDgn = true, filterMain = true;
  1056. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1057. const curCol = info.cellRange.col + iCol;
  1058. const col = info.sheet.zh_setting.cols[curCol];
  1059. if (col.field === 'contract_tp') {
  1060. if (!node.is_tp) continue;
  1061. } else if (col.field === 'contract_qty') {
  1062. if (node.is_tp) continue;
  1063. }
  1064. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1065. if (node.b_code && node.b_code !== '') continue;
  1066. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  1067. if (node.children && node.children.length > 0) continue;
  1068. const nodePos = stagePos.getLedgerPos(node.id);
  1069. if (nodePos && nodePos.length > 0) continue;
  1070. }
  1071. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  1072. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1073. const num = _.toNumber(text);
  1074. if (num) {
  1075. dgnData[col.field] = num;
  1076. filterDgn = false;
  1077. } else {
  1078. try {
  1079. dgnData[col.field] = math.evaluate(transExpr(text));
  1080. filterDgn = false;
  1081. } catch(err) {
  1082. toastMessageUniq(pasteHint.invalidExpr);
  1083. }
  1084. }
  1085. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1086. mainData[col.field] = text;
  1087. filterMain = false;
  1088. } else {
  1089. if (col.type === 'Number') {
  1090. const exprInfo = getExprInfo(col.field);
  1091. if (text) {
  1092. const num = _.toNumber(text);
  1093. data[col.field] = num;
  1094. if (exprInfo) data[exprInfo.expr] = '';
  1095. if (_.isFinite(num)) {
  1096. filter = false;
  1097. } else {
  1098. try {
  1099. data[col.field] = math.evaluate(transExpr(text));
  1100. if (exprInfo) data[exprInfo.expr] = text;
  1101. filter = false;
  1102. } catch(err) {
  1103. toastMessageUniq(pasteHint.invalidExpr);
  1104. }
  1105. }
  1106. } else {
  1107. data[col.field] = null;
  1108. if (exprInfo) data[exprInfo.expr] = '';
  1109. filter = false;
  1110. }
  1111. } else {
  1112. data[col.field] = text;
  1113. }
  1114. }
  1115. }
  1116. if (filter && filterDgn && filterMain) {
  1117. filterNodes.push(node);
  1118. } else {
  1119. if (!filter) datas.push(data);
  1120. if (!filterDgn) dgnDatas.push(dgnData);
  1121. if (!filterMain) mainDatas.push(mainData);
  1122. }
  1123. }
  1124. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1125. const updateData = {};
  1126. if (datas.length > 0) updateData.stage = datas;
  1127. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  1128. if (mainDatas.length > 0) updateData.main = mainDatas;
  1129. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  1130. const nodes = stageTree.loadPostStageData(data);
  1131. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  1132. if (detail) {
  1133. detail.loadStageLedgerUpdateData(data, nodes);
  1134. } else {
  1135. stageIm.loadUpdateLedgerData(data, nodes);
  1136. }
  1137. stageTreeSpreadObj.loadExprToInput(sheet);
  1138. }, function () {
  1139. // todo
  1140. //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1141. });
  1142. } else {
  1143. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1144. }
  1145. }
  1146. },
  1147. measureAllPosInNode(node, ratio = 1) {
  1148. const posterity = stageTree.getPosterity(node);
  1149. const data = {updateType: 'update', updateData: []};
  1150. for (const p of posterity) {
  1151. if (p.children && p.children.length > 0) continue;
  1152. const posRange = stagePos.getLedgerPos(p.id);
  1153. if (posRange && posRange.length > 0) {
  1154. for (const pr of posRange) {
  1155. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  1156. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1157. if (validValue <= 0) continue;
  1158. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  1159. const pData = {
  1160. pid: pr.id,
  1161. lid: pr.lid,
  1162. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  1163. };
  1164. data.updateData.push(pData);
  1165. }
  1166. }
  1167. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  1168. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  1169. break;
  1170. }
  1171. }
  1172. if (data.updateData.length === 0) {
  1173. toastr.info('其下全部计量单元均已计量');
  1174. return;
  1175. }
  1176. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1177. if (result.pos) {
  1178. stagePos.updateDatas(result.pos.pos);
  1179. stagePos.loadCurStageData(result.pos.curStageData);
  1180. }
  1181. const nodes = stageTree.loadPostStageData(result.ledger);
  1182. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1183. stagePosSpreadObj.loadCurPosData();
  1184. if (detail) {
  1185. detail.loadStagePosUpdateData(result, nodes);
  1186. } else {
  1187. stageIm.loadUpdatePosData(result, nodes);
  1188. }
  1189. toastr.success('已计量' + data.updateData.length + '条');
  1190. }, function () {
  1191. stagePosSpreadObj.loadCurPosData();
  1192. });
  1193. },
  1194. topRowChanged(e, info) {
  1195. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1196. },
  1197. editStarting(e, info) {
  1198. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1199. const col = info.sheet.zh_setting.cols[info.col];
  1200. const node = info.sheet.zh_tree.nodes[info.row];
  1201. const exprInfo = getExprInfo(col.field);
  1202. if (exprInfo) {
  1203. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1204. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1205. }
  1206. }
  1207. switch (col.field) {
  1208. case 'contract_qty':
  1209. case 'qc_qty':
  1210. info.cancel = node.is_tp;
  1211. break;
  1212. case 'contract_tp':
  1213. info.cancel = !node.is_tp;
  1214. break;
  1215. case 'is_tp':
  1216. info.cancel = true;
  1217. break;
  1218. }
  1219. },
  1220. buttonClicked: function (e, info) {
  1221. if (info.sheet.zh_setting) {
  1222. const node = SpreadJsObj.getSelectObject(info.sheet);
  1223. const col = info.sheet.zh_setting.cols[info.col];
  1224. const posRange = stagePos.getLedgerPos(node.id);
  1225. if (node.pre_used === 1 ||
  1226. (node.children && node.children.length > 0) ||
  1227. (node.unit !== '总额' && node.unit !== '元') ||
  1228. (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  1229. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1230. return;
  1231. }
  1232. const postIsTp = function () {
  1233. const data = { calcType: {id: node.id} };
  1234. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  1235. // 更新至服务器
  1236. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  1237. const nodes = stageTree.loadPostStageData(result);
  1238. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1239. if (detail) {
  1240. detail.loadStageLedgerUpdateData(result, nodes);
  1241. } else {
  1242. stageIm.loadUpdateLedgerData(result, nodes);
  1243. }
  1244. });
  1245. };
  1246. if (col.field === 'is_tp') {
  1247. if (info.sheet.isEditing()) {
  1248. info.sheet.endEdit(true);
  1249. }
  1250. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
  1251. $.msgBox({
  1252. id: 'calc-type',
  1253. title: '提示',
  1254. message: '切换计量模式,已计量数据会被清空。',
  1255. ok: {
  1256. caption: '确定',
  1257. callback: postIsTp,
  1258. },
  1259. cancel: {
  1260. caption: '取消',
  1261. callback: function () {
  1262. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1263. }
  1264. }
  1265. });
  1266. } else {
  1267. postIsTp();
  1268. }
  1269. }
  1270. }
  1271. },
  1272. measureByBatch: function (posNames, ratio, apply2sibling) {
  1273. if (posNames.length <= 0) return;
  1274. if (ratio <= 0) return;
  1275. const fRatio = ZhCalc.div(ratio, 100);
  1276. const sheet = slSpread.getActiveSheet();
  1277. const node = SpreadJsObj.getSelectObject(sheet);
  1278. const parent = stageTree.getParent(node);
  1279. const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
  1280. const data = {updateType: 'batchUpdate', updateData: []};
  1281. for (const node of nodes) {
  1282. const posRange = stagePos.getLedgerPos(node.id);
  1283. if (!posRange || posRange <= 0) continue;
  1284. for (const p of posRange) {
  1285. if (posNames.indexOf(p.name) < 0) continue;
  1286. data.updateData.push({
  1287. pid: p.id, lid: p.lid,
  1288. contract_qty: ZhCalc.mul(p.quantity, fRatio),
  1289. contract_expr: `${p.quantity}*${ratio}%`,
  1290. });
  1291. }
  1292. }
  1293. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1294. if (result.pos) {
  1295. stagePos.updateDatas(result.pos.pos);
  1296. stagePos.loadCurStageData(result.pos.curStageData);
  1297. }
  1298. const nodes = stageTree.loadPostStageData(result.ledger);
  1299. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1300. stagePosSpreadObj.loadCurPosData();
  1301. if (detail) {
  1302. detail.loadStagePosUpdateData(result, nodes);
  1303. } else {
  1304. stageIm.loadUpdatePosData(result, nodes);
  1305. }
  1306. $('#calc-by-ratio').modal('hide');
  1307. }, function () {
  1308. stagePosSpreadObj.loadCurPosData();
  1309. $('#calc-by-ratio').modal('hide');
  1310. });
  1311. },
  1312. exportExcel: function (filename, nodes) {
  1313. const exportNodesData = function (data, nodes) {
  1314. for (const node of nodes) {
  1315. data.push({
  1316. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  1317. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  1318. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  1319. qc_qty: node.qc_qty, qc_tp: node.qc_tp,
  1320. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  1321. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  1322. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp,
  1323. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_gather_percent: node.end_gather_percent,
  1324. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  1325. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  1326. final_dgn_price: node.final_dgn_price,
  1327. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  1328. });
  1329. if (node.children && node.children.length > 0) {
  1330. exportNodesData(data, node.children);
  1331. } else {
  1332. const posRange = stagePos.getLedgerPos(node.id);
  1333. if (posRange && posRange.length > 0) {
  1334. for (const [i, p] of posRange.entries()) {
  1335. data.push({
  1336. pos_code: (i + 1) + '', name: p.name,
  1337. quantity: p.quantity,
  1338. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  1339. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  1340. drawing_code: p.drawing_code, memo: p.memo, postil: p.postil,
  1341. });
  1342. }
  1343. }
  1344. }
  1345. }
  1346. };
  1347. const data = [];
  1348. exportNodesData(data, nodes ? nodes : stageTree.children);
  1349. SpreadExcelObj.exportSimpleXlsxSheet(exportExcelSetting, data, filename);
  1350. }
  1351. };
  1352. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1353. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1354. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1355. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1356. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1357. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1358. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1359. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1360. if (!readOnly) {
  1361. $('#bills-expr').bind('change onblur', function () {
  1362. if (this.readOnly) return;
  1363. const expr = $(this);
  1364. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1365. const select = stageTree.getItemsByIndex(row);
  1366. if (!select) return;
  1367. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1368. let newValue = expr.val();
  1369. const num = _.toNumber(newValue);
  1370. if (_.isFinite(num)) {
  1371. newValue = num;
  1372. } else {
  1373. try {
  1374. newValue = math.evaluate(transExpr(newValue));
  1375. } catch(err) {
  1376. toastr.error('输入的表达式非法');
  1377. return;
  1378. }
  1379. }
  1380. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1381. if (field.indexOf('_dgn_') > 0) {
  1382. updateData.dgn = {
  1383. id: select.id
  1384. };
  1385. updateData.dgn[field] = newValue;
  1386. } else {
  1387. updateData.stage = {
  1388. lid: select.id
  1389. };
  1390. updateData.stage[field] = newValue;
  1391. const exprInfo = getExprInfo(field);
  1392. if (exprInfo) {
  1393. updateData.stage[exprInfo.expr] = expr.val();
  1394. }
  1395. }
  1396. // 更新至服务器
  1397. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1398. const nodes = stageTree.loadPostStageData(result);
  1399. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1400. if (detail) {
  1401. detail.loadStageLedgerUpdateData(result, nodes);
  1402. } else {
  1403. stageIm.loadUpdateLedgerData(result, nodes);
  1404. }
  1405. });
  1406. });
  1407. }
  1408. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1409. const addTag = newTag({ledgerSheet: slSpread.getActiveSheet(), billsTag});
  1410. const tenderSelect = TenderSelect({
  1411. type: 'stage',
  1412. afterLoad: function (result) {
  1413. const nodes = stageTree.loadPostStageData(result);
  1414. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1415. if (detail) {
  1416. detail.loadStageLedgerUpdateData(result, nodes);
  1417. } else {
  1418. stageIm.loadUpdateLedgerData(result, nodes);
  1419. }
  1420. if (result.sumLoadHis.errors.length > 0) {
  1421. sumLoadMiss.loadMissData(result.sumLoadHis.errors);
  1422. sumLoadMiss.show();
  1423. } else {
  1424. sumLoadMiss.clearMissData();
  1425. }
  1426. }
  1427. });
  1428. $.contextMenu({
  1429. selector: '#stage-ledger',
  1430. build: function ($trigger, e) {
  1431. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1432. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1433. },
  1434. items: {
  1435. 'locateZjjl': {
  1436. name: '定位至中间计量',
  1437. icon: 'fa-sign-in',
  1438. callback: function (key, opt) {
  1439. if (!detail) {
  1440. detail = new Detail($('#detail-spread'));
  1441. }
  1442. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1443. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1444. if (leafUsedBills) {
  1445. if (!$('#zhongjian').hasClass('active')) {
  1446. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  1447. $('a', '.side-menu').removeClass('active');
  1448. $('.tab-content .tab-select-show').removeClass('active');
  1449. tab.addClass('active');
  1450. tabPanel.addClass('active');
  1451. showSideTools(tab.hasClass('active'));
  1452. slSpread.refresh();
  1453. spSpread.refresh();
  1454. }
  1455. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1456. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1457. SpreadJsObj.locateData(detail.sheet, im);
  1458. detail.spread.refresh();
  1459. $('#zhongjian .sjs-bottom').height('400px');
  1460. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1461. detail.reLoadDetailData();
  1462. } else {
  1463. toastr.error('无可定位中间计量');
  1464. }
  1465. },
  1466. disabled: function (key, opt) {
  1467. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1468. return !node;
  1469. }
  1470. },
  1471. tagSpr: '----',
  1472. tag: {
  1473. name: '书签',
  1474. callback: function (key, opt, menu, e) {
  1475. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1476. addTag.do(node);
  1477. },
  1478. disabled: function (key, opt) {
  1479. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1480. return !node;
  1481. }
  1482. },
  1483. showSpr: '----',
  1484. showLast: {
  1485. name: '显示至最底层',
  1486. callback: function (key, opt, menu, e) {
  1487. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1488. setTimeout(() => {
  1489. showWaitingView();
  1490. stageTree.expandByCustom(x => {
  1491. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1492. });
  1493. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  1494. closeWaitingView();
  1495. }, 100);
  1496. },
  1497. disabled: function (key, opt) {
  1498. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1499. return !node;
  1500. }
  1501. },
  1502. exportSpr: '----',
  1503. exportSelectNodeXlsx: {
  1504. name: '导出选中节点至Excel',
  1505. callback: function (key, opt, menu, e) {
  1506. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1507. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  1508. },
  1509. disabled: function (key, opt) {
  1510. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1511. return !node;
  1512. }
  1513. },
  1514. importSpr: '---',
  1515. importStageGcl: {
  1516. name: '导入(其他标段)工程量清单计量数据',
  1517. icon: 'fa-link',
  1518. disabled: function (key, opt) {
  1519. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1520. return readOnly || !node || !stageTree.isLeafXmj(node);
  1521. },
  1522. callback: function (key, opt) {
  1523. tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
  1524. }
  1525. },
  1526. shoufangdanSpr: '---',
  1527. shoufangdan: {
  1528. name: '生成收方单',
  1529. disabled: function (key, opt) {
  1530. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1531. if (!node || !node.b_code || !node.is_leaf) return true;
  1532. },
  1533. callback: function (key, opt) {
  1534. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1535. $('#shoufang-lid').val(node.id);
  1536. $('#shoufang-pid').val('');
  1537. $('#shoufang-ledger').text('清单:' + node.b_code);
  1538. $('#shoufang-pos').text('').hide();
  1539. $('#addshoufang').modal('show');
  1540. }
  1541. }
  1542. }
  1543. });
  1544. const stagePosSpreadObj = {
  1545. loadExprToInput(sheet) {
  1546. const sel = sheet.getSelections()[0];
  1547. if (!sel) return;
  1548. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1549. if (col && col.type === 'Number') {
  1550. const data = SpreadJsObj.getSelectObject(sheet);
  1551. if (data) {
  1552. const exprInfo = getExprInfo(col.field);
  1553. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1554. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1555. .attr('readOnly', readOnly || cell.locked());
  1556. $('#pos-expr').attr('data-row', sel.row);
  1557. } else {
  1558. $('#pos-expr').val('').attr('readOnly', true);
  1559. $('#pos-expr').removeAttr('data-row');
  1560. }
  1561. } else {
  1562. $('#pos-expr').val('').attr('readOnly', true);
  1563. $('#pos-expr').removeAttr('data-row');
  1564. }
  1565. },
  1566. /**
  1567. * 加载计量单元 根据当前台账选择节点
  1568. */
  1569. loadCurPosData: function () {
  1570. const sheet = slSpread.getActiveSheet();
  1571. const node = SpreadJsObj.getSelectObject(sheet);
  1572. if (node) {
  1573. spSpread.getActiveSheet().zh_setting.readOnly = node.lock;
  1574. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1575. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  1576. getNodeList(node.id);
  1577. // 如果是附件是当前节点,隐藏
  1578. // if ($('#dqjiedian').hasClass('active')) {
  1579. // $('#showAttachment').hide();
  1580. // }
  1581. } else {
  1582. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1583. }
  1584. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1585. },
  1586. editEnded: function (e, info) {
  1587. if (info.sheet.zh_setting) {
  1588. // 未改变过,则直接跳过
  1589. const sortData = info.sheet.zh_data;
  1590. const posData = sortData ? sortData[info.row] : null;
  1591. const col = info.sheet.zh_setting.cols[info.col];
  1592. const orgText = posData ? posData[col.field] : null;
  1593. const newText = trimInvalidChar(info.editingText);
  1594. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1595. return;
  1596. }
  1597. // 台账模式下,不可新增
  1598. if (checkTzMeasureType() && !posData) {
  1599. toastr.error('台账模式不可新增计量单元数据');
  1600. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1601. return ;
  1602. }
  1603. // 不同节点下,计量单元检查输入
  1604. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1605. const node = stagePosSpreadObj.stageTreeNode;
  1606. if (!node) {
  1607. toastr.warning('数据错误, 请刷新页面后再试');
  1608. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1609. return;
  1610. } else if (newText !== '' && node.children && node.children > 0) {
  1611. toastr.error('父节点不可插入计量单元');
  1612. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1613. return;
  1614. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1615. toastr.error('项目节不可插入计量单元');
  1616. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1617. return;
  1618. }
  1619. // 生成提交数据
  1620. const data = {};
  1621. if (col.field === 'name') {
  1622. if ((!newText || newText === '') && posData) {
  1623. toastr.error('部位名称不可为空');
  1624. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1625. return;
  1626. } else if (!posData) {
  1627. if (newText !== '') {
  1628. data.updateType = 'add';
  1629. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1630. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1631. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1632. return;
  1633. }
  1634. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1635. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1636. } else {
  1637. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1638. return;
  1639. }
  1640. } else {
  1641. data.updateType = 'update';
  1642. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1643. }
  1644. } else if (!posData) {
  1645. toastr.warning('新增计量单元请先输入名称');
  1646. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1647. data.updateType = 'update';
  1648. data.updateData = {pid: posData.id, lid: posData.lid};
  1649. data.updateData[col.field] = newText;
  1650. } else {
  1651. data.updateType = 'update';
  1652. data.updateData = {pid: posData.id, lid: posData.lid};
  1653. if (col.type === 'Number') {
  1654. const exprInfo = getExprInfo(col.field);
  1655. const num = _.toNumber(newText);
  1656. if (_.isFinite(num)) {
  1657. data.updateData[col.field] = num;
  1658. if (exprInfo) {
  1659. data.updateData[exprInfo.expr] = '';
  1660. }
  1661. } else {
  1662. try {
  1663. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1664. if (exprInfo) {
  1665. data.updateData[exprInfo.expr] = newText;
  1666. }
  1667. } catch(err) {
  1668. toastr.error('输入的表达式非法');
  1669. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1670. return;
  1671. }
  1672. }
  1673. } else {
  1674. data.updateData[col.field] = newText;
  1675. }
  1676. }
  1677. // 提交数据到服务器
  1678. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1679. if (result.pos) {
  1680. stagePos.updateDatas(result.pos.pos);
  1681. stagePos.loadCurStageData(result.pos.curStageData);
  1682. }
  1683. const refreshData = stageTree.loadPostStageData(result.ledger);
  1684. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1685. stagePosSpreadObj.loadCurPosData();
  1686. if (detail) {
  1687. detail.loadStagePosUpdateData(result, refreshData);
  1688. } else {
  1689. stageIm.loadUpdatePosData(result, refreshData);
  1690. }
  1691. }, function () {
  1692. stagePosSpreadObj.loadCurPosData();
  1693. });
  1694. }
  1695. },
  1696. editStarting: function (e, info) {
  1697. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1698. const sel = info.sheet.getSelections();
  1699. if (!sel || !sel[0]) return;
  1700. const col = info.sheet.zh_setting.cols[sel[0].col];
  1701. const node = SpreadJsObj.getSelectObject(info.sheet);
  1702. const exprInfo = getExprInfo(col.field);
  1703. if (exprInfo) {
  1704. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1705. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1706. }
  1707. }
  1708. },
  1709. clipboardPasting: function (e, info) {
  1710. if (info.sheet.zh_setting) {
  1711. const sortData = info.sheet.zh_data;
  1712. const range = info.cellRange;
  1713. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3'];
  1714. if (!checkTzMeasureType()) {
  1715. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1716. }
  1717. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1718. const col = info.sheet.zh_setting.cols[iCol];
  1719. if (validField.indexOf(col.field) === -1) {
  1720. if (checkTzMeasureType()) {
  1721. toastr.error('不可修改此数据');
  1722. info.cancel = true;
  1723. return;
  1724. } else {
  1725. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1726. const pos = sortData(iRow);
  1727. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1728. toastr.error('不可修改此数据');
  1729. info.cancel = true;
  1730. return;
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. },
  1738. clipboardPasted: function (e, info) {
  1739. if (info.sheet.zh_setting) {
  1740. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1741. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1742. }
  1743. const data = { updateType: '', updateData: [], };
  1744. const sortData = info.sheet.zh_data;
  1745. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1746. if (sortData && (info.cellRange.row >= sortData.length)) {
  1747. data.updateType = 'add';
  1748. if (info.cellRange.col !== 0) {
  1749. toastr.warning('新增计量单元请先输入名称');
  1750. stagePosSpreadObj.loadCurPosData();
  1751. return;
  1752. }
  1753. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1754. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1755. stagePosSpreadObj.loadCurPosData();
  1756. return;
  1757. }
  1758. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1759. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1760. const curRow = info.cellRange.row + iRow;
  1761. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1762. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1763. const curCol = info.cellRange.col + iCol;
  1764. const colSetting = info.sheet.zh_setting.cols[curCol];
  1765. if (!colSetting) continue;
  1766. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1767. if (colSetting.type === 'Number') {
  1768. const exprInfo = getExprInfo(colSetting.field);
  1769. if (newValue) {
  1770. const num = _.toNumber(newValue);
  1771. if (num) {
  1772. newData[colSetting.field] = num;
  1773. if (exprInfo) {
  1774. newData[exprInfo.expr] = '';
  1775. }
  1776. } else {
  1777. try {
  1778. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1779. if (exprInfo) {
  1780. newData[exprInfo.expr] = newValue;
  1781. }
  1782. } catch(err) {
  1783. toastr.error('输入的表达式非法');
  1784. stagePosSpreadObj.loadCurPosData();
  1785. return;
  1786. }
  1787. }
  1788. } else {
  1789. newData[colSetting.field] = null;
  1790. if (exprInfo) newData[exprInfo.expr] = '';
  1791. }
  1792. } else {
  1793. newData[colSetting.field] = newValue;
  1794. }
  1795. }
  1796. data.updateData.push(newData);
  1797. }
  1798. } else {
  1799. data.updateType = 'update';
  1800. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1801. const curRow = info.cellRange.row + iRow;
  1802. const curPos = sortData[curRow];
  1803. if (curPos) {
  1804. const newData = {pid: curPos.id, lid: curPos.lid};
  1805. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1806. const curCol = info.cellRange.col + iCol;
  1807. const colSetting = info.sheet.zh_setting.cols[curCol];
  1808. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1809. if (colSetting.type === 'Number') {
  1810. const exprInfo = getExprInfo(colSetting.field);
  1811. if (!newValue) {
  1812. newData[colSetting.field] = newValue;
  1813. if (exprInfo) newData[exprInfo.expr] = '';
  1814. continue;
  1815. }
  1816. const num = _.toNumber(newValue);
  1817. if (num) {
  1818. newData[colSetting.field] = num;
  1819. if (exprInfo) newData[exprInfo.expr] = '';
  1820. } else {
  1821. try {
  1822. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1823. const exprInfo = getExprInfo(colSetting.field);
  1824. if (exprInfo) newData[exprInfo.expr] = newValue;
  1825. } catch(err) {
  1826. toastr.error('输入的表达式非法');
  1827. stagePosSpreadObj.loadCurPosData();
  1828. return;
  1829. }
  1830. }
  1831. } else {
  1832. newData[colSetting.field] = newValue;
  1833. }
  1834. }
  1835. data.updateData.push(newData);
  1836. }
  1837. }
  1838. }
  1839. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1840. if (result.pos) {
  1841. stagePos.updateDatas(result.pos.pos);
  1842. stagePos.loadCurStageData(result.pos.curStageData);
  1843. }
  1844. const nodes = stageTree.loadPostStageData(result.ledger);
  1845. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1846. stagePosSpreadObj.loadCurPosData();
  1847. if (detail) {
  1848. detail.loadStagePosUpdateData(result, nodes);
  1849. } else {
  1850. stageIm.loadUpdatePosData(result, nodes);
  1851. }
  1852. }, function () {
  1853. stagePosSpreadObj.loadCurPosData();
  1854. });
  1855. }
  1856. },
  1857. deletePress: function (sheet) {
  1858. if (sheet.zh_setting.readOnly) return;
  1859. if (sheet.zh_setting && sheet.zh_data) {
  1860. const sortData = sheet.zh_data;
  1861. if (!sortData || sortData.length === 0) { return; }
  1862. const sel = sheet.getSelections()[0];
  1863. const validCols = [];
  1864. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1865. const colSetting = sheet.zh_setting.cols[iCol];
  1866. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1867. validCols.push(iCol);
  1868. }
  1869. }
  1870. if (validCols.length === 0) { return; }
  1871. const datas = [], posSelects = [];
  1872. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1873. const node = sortData[iRow];
  1874. if (node) {
  1875. const data = {pid: node.id, lid: node.lid};
  1876. for (const iCol of validCols) {
  1877. const colSetting = sheet.zh_setting.cols[iCol];
  1878. if (colSetting.field === 'name') {
  1879. toastr.error('部位名称不能为空');
  1880. return;
  1881. }
  1882. data[colSetting.field] = null;
  1883. const exprInfo = getExprInfo(colSetting.field);
  1884. if (exprInfo) {
  1885. data[exprInfo.expr] = '';
  1886. }
  1887. }
  1888. datas.push(data);
  1889. posSelects.push(node);
  1890. }
  1891. }
  1892. if (datas.length > 0) {
  1893. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1894. if (result.pos) {
  1895. stagePos.updateDatas(result.pos.pos);
  1896. stagePos.loadCurStageData(result.pos.curStageData);
  1897. }
  1898. const nodes = stageTree.loadPostStageData(result.ledger);
  1899. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1900. if (detail) {
  1901. detail.loadStagePosUpdateData(result, nodes);
  1902. } else {
  1903. stageIm.loadUpdatePosData(result, nodes);
  1904. }
  1905. // todo 只加载改变项
  1906. stagePosSpreadObj.loadCurPosData();
  1907. });
  1908. }
  1909. }
  1910. },
  1911. deletePos: function (sheet) {
  1912. const sels = sheet.getSelections();
  1913. const sel = sels ? sels[0] : null;
  1914. if (sheet.zh_data && sel) {
  1915. const data = {updateType: 'delete', updateData: []};
  1916. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1917. const posData = sheet.zh_data[sel.row + iRow];
  1918. if (posData) {
  1919. data.updateData.push(posData.id);
  1920. }
  1921. }
  1922. if (data.updateData.length > 0) {
  1923. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1924. stagePos.removeDatas(result.pos.pos);
  1925. const refreshData = stageTree.loadPostStageData(result.ledger);
  1926. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1927. stagePosSpreadObj.loadCurPosData();
  1928. if (detail) {
  1929. detail.loadStagePosUpdateData(result, refreshData);
  1930. } else {
  1931. stageIm.loadUpdatePosData(result, refreshData);
  1932. }
  1933. });
  1934. }
  1935. }
  1936. },
  1937. selectionChanged: function (e, info) {
  1938. stagePosSpreadObj.loadExprToInput(info.sheet);
  1939. },
  1940. addPegs: function (pegs) {
  1941. if (!pegs || pegs.length <= 0) return;
  1942. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1943. if (!node) return;
  1944. const sheet = spSpread.getActiveSheet();
  1945. const sortData = sheet.zh_data || [];
  1946. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1947. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1948. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1949. if (result.pos) {
  1950. stagePos.updateDatas(result.pos.pos);
  1951. }
  1952. stagePosSpreadObj.loadCurPosData();
  1953. });
  1954. }
  1955. };
  1956. // 加载上下窗口resizer
  1957. $.divResizer({
  1958. select: '#main-resize',
  1959. callback: function () {
  1960. slSpread.refresh();
  1961. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1962. $(".sp-wrap").height(bcontent-30);
  1963. spSpread.refresh();
  1964. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1965. }
  1966. });
  1967. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1968. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;cooperation' }, function (result) {
  1969. // 加载树结构
  1970. stageTree.loadDatas(result.ledgerData);
  1971. // stageTree.loadCurStageData(curStageData);
  1972. // stageTree.loadPreStageData(preStageData);
  1973. checkShowLast(result.ledgerData.length);
  1974. treeCalc.calculateAll(stageTree);
  1975. // 加载解锁相关
  1976. if (result.cooperation) {
  1977. stageTree.loadPwd(result.cooperation, 'bills-p-' + userID + '-' + window.location.pathname.split('/')[2], result.cooperationConfirm);
  1978. $('#cooperationCount').html(stageTree.pwd.length || '');
  1979. if (stageTree.pwd.length > 0) $('#cooperationCount').parent().show();
  1980. setCooperationSelectHtml();
  1981. reloadCooperationHtml();
  1982. }
  1983. for (const t of result.tags) {
  1984. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  1985. }
  1986. billsTag.loadDatas(result.tags);
  1987. // 加载部位明细
  1988. stagePos.loadDatas(result.posData);
  1989. stagePos.calculateAll();
  1990. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1991. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1992. stagePosSpreadObj.loadCurPosData();
  1993. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1994. // 加载中间计量
  1995. stageIm.init(stage, imType, tenderInfo.decimal);
  1996. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1997. errorList.loadHisErrorData();
  1998. checkList.loadHisCheckData();
  1999. sumLoadMiss.loadHisMissData();
  2000. // 收方单赋值
  2001. ledgerData = result.ledgerData;
  2002. posData = result.posData;
  2003. makeShouFang();
  2004. }, null, true);
  2005. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2006. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2007. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2008. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2009. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2010. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2011. if (!readOnly) {
  2012. $('#pos-expr').bind('change onblur', function () {
  2013. if (this.readOnly) return;
  2014. const expr = $(this);
  2015. const posSheet = spSpread.getActiveSheet();
  2016. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2017. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2018. if (!select) return;
  2019. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2020. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2021. const data = {pid: select.id, lid: select.lid};
  2022. const exprInfo = getExprInfo(field);
  2023. if (newValue !== '') {
  2024. const num = _.toNumber(newValue);
  2025. if (num) {
  2026. data[field] = num;
  2027. if (exprInfo) data[exprInfo.expr] = '';
  2028. } else {
  2029. try {
  2030. data[field] = math.evaluate(transExpr(newValue));
  2031. if (exprInfo) data[exprInfo.expr] = newValue;
  2032. } catch (err) {
  2033. toastr.error('输入的表达式非法');
  2034. return;
  2035. }
  2036. }
  2037. } else {
  2038. data[field] = null;
  2039. if (exprInfo) data[exprInfo.expr] = '';
  2040. }
  2041. // 提交数据到服务器
  2042. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2043. if (result.pos) {
  2044. stagePos.updateDatas(result.pos.pos);
  2045. stagePos.loadCurStageData(result.pos.curStageData);
  2046. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2047. }
  2048. const refreshData = stageTree.loadPostStageData(result.ledger);
  2049. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2050. if (detail) {
  2051. detail.loadStagePosUpdateData(result, refreshData);
  2052. } else {
  2053. stageIm.loadUpdatePosData(result, refreshData);
  2054. }
  2055. });
  2056. });
  2057. }
  2058. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2059. $.contextMenu({
  2060. selector: '#stage-pos',
  2061. build: function ($trigger, e) {
  2062. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2063. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2064. },
  2065. items: {
  2066. 'del': {
  2067. name: '删除',
  2068. icon: 'fa-remove',
  2069. visible: function (key, opt) {
  2070. return !checkTzMeasureType();
  2071. },
  2072. disabled: function (key, opt) {
  2073. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2074. if (!node || node.lock) return true;
  2075. const sheet = spSpread.getActiveSheet();
  2076. if (sheet.zh_data && !readOnly) {
  2077. const selection = sheet.getSelections();
  2078. if (selection && selection[0]) {
  2079. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2080. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2081. const posData = sheet.zh_data[selection[0].row + iRow];
  2082. if (posData) {
  2083. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2084. valid = true;
  2085. break;
  2086. }
  2087. } else {
  2088. valid = true;
  2089. break;
  2090. }
  2091. }
  2092. return valid;
  2093. } else {
  2094. return true;
  2095. }
  2096. } else {
  2097. return true;
  2098. }
  2099. },
  2100. callback: function (key, opt) {
  2101. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2102. }
  2103. },
  2104. 'merge-peg': {
  2105. name: '合并起讫桩号',
  2106. visible: function (key, opt) {
  2107. return !checkTzMeasureType();
  2108. },
  2109. disabled: function (key, opt) {
  2110. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2111. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2112. },
  2113. callback: function (key, opt) {
  2114. mergePeg.show();
  2115. }
  2116. },
  2117. 'calcByRatio': {
  2118. name: '按比例计量',
  2119. visible: function (key, opt) {
  2120. const data = spSpread.getActiveSheet().zh_data;
  2121. return data && data.length > 0;
  2122. },
  2123. disabled: function (key, opt) {
  2124. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2125. return node.lock;
  2126. },
  2127. callback: function (key, opt) {
  2128. $('#cbr-ratio').val('');
  2129. $('#apply2sibling')[0].checked = false;
  2130. $('#cbr-check-all')[0].checked = false;
  2131. const html = [];
  2132. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2133. html.push('<tr>');
  2134. html.push('<td>', i+1, '</td>');
  2135. html.push('<td>', p.name, '</td>');
  2136. html.push('<td>', p.quantity, '</td>');
  2137. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2138. html.push('</tr>');
  2139. }
  2140. $('#cbr-pos-list').html(html.join(''));
  2141. $('#calc-by-ratio').modal('show');
  2142. }
  2143. },
  2144. 'shoufangdan': {
  2145. name: '生成收方单',
  2146. disabled: function (key, opt) {
  2147. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2148. if (!node) return true;
  2149. },
  2150. callback: function (key, opt) {
  2151. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2152. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2153. $('#shoufang-lid').val(node.lid);
  2154. $('#shoufang-pid').val(node.id);
  2155. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2156. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2157. $('#addshoufang').modal('show');
  2158. }
  2159. }
  2160. }
  2161. });
  2162. $.subMenu({
  2163. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2164. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2165. key: 'menu.1.0.0',
  2166. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2167. callback: function (info) {
  2168. if (info.mini) {
  2169. $('.panel-title').addClass('fluid');
  2170. $('#sub-menu').removeClass('panel-sidebar');
  2171. } else {
  2172. $('.panel-title').removeClass('fluid');
  2173. $('#sub-menu').addClass('panel-sidebar');
  2174. }
  2175. autoFlashHeight();
  2176. slSpread.refresh();
  2177. spSpread.refresh();
  2178. if (searchLedger) searchLedger.spread.refresh();
  2179. if (detail) detail.spread.refresh();
  2180. if (checkedChanges) checkedChanges.refresh();
  2181. if (errorList && errorList.spread) errorList.spread.refresh();
  2182. if (checkList) checkList.spread.refresh();
  2183. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2184. }
  2185. });
  2186. $('#row-view').on('show.bs.modal', function () {
  2187. const html = [], customDisplay = customColDisplay();
  2188. for (const cd of customDisplay) {
  2189. html.push('<tr>');
  2190. html.push('<td>', cd.title, '</td>');
  2191. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2192. html.push('</tr>');
  2193. }
  2194. $('#row-view-list').html(html.join(''));
  2195. });
  2196. $('#row-view-ok').click(function () {
  2197. const customDisplay = customColDisplay();
  2198. const cvl = $('#row-view-list').children();
  2199. for (const cv of cvl) {
  2200. const title = $(cv).children()[0].innerHTML;
  2201. const check = $('input', cv)[0].checked;
  2202. const cd = customDisplay.find(function (c) {
  2203. return c.title === title;
  2204. });
  2205. cd.visible = check;
  2206. }
  2207. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2208. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2209. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2210. $('#row-view').modal('hide');
  2211. });
  2212. const posSearch = (function () {
  2213. let resultArr = [];
  2214. const search = function () {
  2215. resultArr = [];
  2216. const keyword = $('#pos-search-keyword').val();
  2217. const checkOver = $('#pos-over-search')[0].checked;
  2218. const checkEmpty = $('#pos-empty-search')[0].checked;
  2219. const sortData = spSpread.getActiveSheet().zh_data;
  2220. if (checkOver || checkEmpty) {
  2221. if (sortData) {
  2222. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2223. const sd = sortData[i];
  2224. let match = false;
  2225. if (checkOver) {
  2226. if (sd.end_gather_qty) {
  2227. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2228. }
  2229. }
  2230. if (checkEmpty) {
  2231. if (sd.quantity) {
  2232. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2233. }
  2234. }
  2235. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2236. if (match) {
  2237. resultArr.push({index: i, data: sd});
  2238. }
  2239. }
  2240. }
  2241. } else if (keyword && keyword !== '') {
  2242. if (sortData) {
  2243. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2244. const sd = sortData[i];
  2245. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2246. resultArr.push({index: i, data: sd});
  2247. }
  2248. }
  2249. }
  2250. }
  2251. $('#pos-search-result').html('结果:' + resultArr.length);
  2252. };
  2253. const searchAndLocate = function () {
  2254. search();
  2255. if (resultArr.length > 0) {
  2256. const sheet = spSpread.getActiveSheet();
  2257. const sel = sheet.getSelections()[0];
  2258. const curRow = sel ? sel.row : 0;
  2259. const pos = resultArr[0];
  2260. if (pos.index !== curRow) {
  2261. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2262. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2263. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2264. }
  2265. }
  2266. };
  2267. const locateNext = function () {
  2268. if (resultArr.length > 0) {
  2269. const sheet = spSpread.getActiveSheet();
  2270. const sel = sheet.getSelections()[0];
  2271. const curRow = sel ? sel.row : 0;
  2272. let next = _.find(resultArr, function (d) {
  2273. return d.index > curRow;
  2274. });
  2275. if (!next) next = resultArr[0];
  2276. if (next.index !== curRow) {
  2277. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2278. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2279. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2280. }
  2281. }
  2282. };
  2283. const locatePre = function () {
  2284. if (resultArr.length > 0) {
  2285. const sheet = spSpread.getActiveSheet();
  2286. const sel = sheet.getSelections()[0];
  2287. const curRow = sel ? sel.row : 0;
  2288. let next = _.findLast(resultArr, function (d) {
  2289. return d.index < curRow;
  2290. });
  2291. if (!next) next = resultArr[resultArr.length - 1];
  2292. if (next.index !== curRow) {
  2293. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2294. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2295. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2296. }
  2297. }
  2298. };
  2299. return {search, searchAndLocate, locateNext, locatePre};
  2300. })();
  2301. $('#pos-search-keyword').bind('keydown', function(e){
  2302. if (e.keyCode == 13) posSearch.searchAndLocate();
  2303. });
  2304. $('#pos-empty-search').click(function () {
  2305. if (this.checked) {
  2306. $('[for=' + this.id +']').addClass('text-warning');
  2307. } else {
  2308. $('[for=' + this.id +']').removeClass('text-warning');
  2309. }
  2310. if (this.checked) {
  2311. if ($('#pos-over-search')[0].checked) {
  2312. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2313. } else {
  2314. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2315. }
  2316. } else {
  2317. if ($('#pos-over-search')[0].checked) {
  2318. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2319. } else {
  2320. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2321. }
  2322. }
  2323. posSearch.searchAndLocate();
  2324. });
  2325. $('#pos-over-search').click(function () {
  2326. if (this.checked) {
  2327. $('[for=' + this.id +']').addClass('text-danger');
  2328. } else {
  2329. $('[for=' + this.id +']').removeClass('text-danger');
  2330. }
  2331. if (this.checked) {
  2332. if ($('#pos-empty-search')[0].checked) {
  2333. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2334. } else {
  2335. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2336. }
  2337. } else {
  2338. if ($('#pos-empty-search')[0].checked) {
  2339. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2340. } else {
  2341. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2342. }
  2343. }
  2344. posSearch.searchAndLocate();
  2345. });
  2346. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2347. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2348. $.divResizer({
  2349. select: '#right-spr',
  2350. callback: function () {
  2351. slSpread.refresh();
  2352. spSpread.refresh();
  2353. if (searchLedger) {
  2354. searchLedger.spread.refresh();
  2355. }
  2356. if (detail) {
  2357. detail.spread.refresh();
  2358. }
  2359. if (checkedChanges) checkedChanges.refresh();
  2360. if (errorList && errorList.spread) errorList.spread.refresh();
  2361. if (checkList) checkList.spread.refresh();
  2362. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2363. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2364. }
  2365. });
  2366. // 中间计量加载上下窗口resizer
  2367. $.divResizer({
  2368. select: '#zhongjian-spr',
  2369. callback: function () {
  2370. if (detail) {
  2371. detail.spread.refresh();
  2372. }
  2373. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2374. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2375. }
  2376. });
  2377. // 附件加载上下窗口resizer
  2378. $.divResizer({
  2379. select: '#file-spr',
  2380. callback: function () {
  2381. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2382. }
  2383. });
  2384. // 变更令加载上下窗口resizer
  2385. $.divResizer({
  2386. select: '#change-spr',
  2387. callback: function () {
  2388. if (checkedChanges) checkedChanges.refresh();
  2389. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2390. }
  2391. });
  2392. class Detail {
  2393. constructor (obj) {
  2394. const self = this;
  2395. this.spreadSetting = {
  2396. cols: [
  2397. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2398. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2399. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2400. {
  2401. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2402. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2403. },
  2404. ],
  2405. headRows: 1,
  2406. emptyRows: 0,
  2407. headRowHeight: [32],
  2408. headColWidth: [30],
  2409. defaultRowHeight: 21,
  2410. headerFont: '12px 微软雅黑',
  2411. font: '12px 微软雅黑',
  2412. readOnly: readOnly,
  2413. selectedBackColor: '#fffacd',
  2414. };
  2415. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2416. this.sheet = this.spread.getActiveSheet();
  2417. this.spread.options.allowUserDragFill = true;
  2418. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2419. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2420. this.detailObj = {
  2421. selectionChanged: function (e, info) {
  2422. self.reLoadDetailData();
  2423. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2424. self.loadLocateInfo();
  2425. }
  2426. },
  2427. editEnded: function(e, info) {
  2428. if (info.sheet.zh_setting) {
  2429. const col = info.sheet.zh_setting.cols[info.col];
  2430. if (col.field !== 'doc_code') {
  2431. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2432. return;
  2433. }
  2434. const data = SpreadJsObj.getSelectObject(info.sheet);
  2435. if (data) {
  2436. const updateData = {lid: data.lid, pid: data.pid};
  2437. if (data.uuid) {
  2438. updateData.uuid = data.uuid;
  2439. } else {
  2440. updateData.code = data.code;
  2441. updateData.name = data.name;
  2442. updateData.unit = data.unit;
  2443. updateData.unit_price = data.unit_price;
  2444. updateData.pid = data.pid;
  2445. updateData.pos_name = data.pos_name;
  2446. }
  2447. if (data.custom_define.indexOf('doc_code') === -1) {
  2448. updateData.custom_define = data.custom_define;
  2449. updateData.custom_define.push('doc_code');
  2450. updateData.custom_define = updateData.custom_define.join(',');
  2451. }
  2452. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2453. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2454. stageIm.loadUpdateDetailData(result);
  2455. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2456. }, function () {
  2457. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2458. });
  2459. } else {
  2460. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2461. }
  2462. }
  2463. },
  2464. clipboardPasted: function (e, info) {
  2465. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2466. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2467. if (info.cellRange.colCount > 1) {
  2468. toastr.warning('请勿同时复制粘贴多列数据');
  2469. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2470. return;
  2471. }
  2472. if (col.field !== 'doc_code') {
  2473. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2474. return;
  2475. }
  2476. const datas = [];
  2477. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2478. const curRow = info.cellRange.row + iRow;
  2479. const data = info.sheet.zh_data[curRow];
  2480. if (data) {
  2481. const updateData = {lid: data.lid, pid: data.pid};
  2482. if (data.uuid) {
  2483. updateData.uuid = data.uuid;
  2484. } else {
  2485. updateData.code = data.code;
  2486. updateData.name = data.name;
  2487. updateData.unit = data.unit;
  2488. updateData.unit_price = data.unit_price;
  2489. updateData.pid = data.pid;
  2490. updateData.pos_name = data.pos_name;
  2491. }
  2492. if (data.custom_define.indexOf('doc_code') === -1) {
  2493. updateData.custom_define = data.custom_define;
  2494. updateData.custom_define.push('doc_code');
  2495. updateData.custom_define = updateData.custom_define.join(',');
  2496. }
  2497. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2498. datas.push(updateData);
  2499. }
  2500. }
  2501. if (datas.length > 0) {
  2502. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2503. stageIm.loadUpdateDetailData(result);
  2504. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2505. }, function () {
  2506. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2507. })
  2508. }
  2509. }
  2510. },
  2511. deletePress: function (sheet) {
  2512. if (sheet.zh_setting) {
  2513. const datas = [];
  2514. const sel = sheet.getSelections()[0];
  2515. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2516. const col = sheet.zh_setting.cols[iCol];
  2517. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2518. const data = sheet.zh_data[iRow];
  2519. if (col.field === 'doc_code') {
  2520. const updateData = {lid: data.lid};
  2521. if (data.uuid) {
  2522. updateData.uuid = data.uuid;
  2523. updateData.doc_code = '';
  2524. datas.push(updateData);
  2525. }
  2526. }
  2527. }
  2528. }
  2529. if (datas.length > 0) {
  2530. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2531. stageIm.loadUpdateDetailData(result);
  2532. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2533. }, function () {
  2534. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2535. });
  2536. }
  2537. }
  2538. },
  2539. dragFillBlock: function (e, info) {
  2540. info.cancel = true;
  2541. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2542. const sel = info.sheet.getSelections()[0];
  2543. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2544. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2545. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2546. if (text === '') return;
  2547. const regRst = /(\d+)$/g.exec(text), datas = [];
  2548. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2549. const curRow = info.fillRange.row + iRow;
  2550. const data = info.sheet.zh_data[curRow];
  2551. if (data) {
  2552. const updateData = {lid: data.lid};
  2553. if (data.uuid) {
  2554. updateData.uuid = data.uuid;
  2555. } else {
  2556. updateData.code = data.code;
  2557. updateData.name = data.name;
  2558. updateData.unit = data.unit;
  2559. updateData.unit_price = data.unit_price;
  2560. updateData.pid = data.pid;
  2561. updateData.pos_name = data.pos_name;
  2562. }
  2563. if (regRst) {
  2564. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2565. } else {
  2566. updateData.doc_code = text.replace('\n', '');
  2567. }
  2568. if (data.custom_define.indexOf('doc_code') === -1) {
  2569. updateData.custom_define = data.custom_define;
  2570. updateData.custom_define.push('doc_code');
  2571. updateData.custom_define = updateData.custom_define.join(',');
  2572. }
  2573. datas.push(updateData);
  2574. }
  2575. }
  2576. if (datas.length > 0) {
  2577. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2578. stageIm.loadUpdateDetailData(result);
  2579. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2580. }, function () {
  2581. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2582. })
  2583. }
  2584. },
  2585. };
  2586. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2587. if (!readOnly) {
  2588. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2589. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2590. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2591. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2592. }
  2593. this._initImTypeSetRela();
  2594. this._initModifyDetail();
  2595. this._initLocateRela();
  2596. // 草图相关
  2597. this._initImageRela();
  2598. this.reBuildImData();
  2599. }
  2600. _initImTypeSetRela() {
  2601. const self = this;
  2602. const gatherConfirmPopover = {
  2603. reBind: function (obj, eventName, fun) {
  2604. obj.unbind(eventName);
  2605. obj.bind(eventName, fun);
  2606. },
  2607. check: function (pos, hint, okCallback) {
  2608. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2609. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2610. this.reBind(cancelObj, 'click', function () {
  2611. confirmObj.hide();
  2612. });
  2613. this.reBind(okObj, 'click', function () {
  2614. okCallback();
  2615. confirmObj.hide();
  2616. });
  2617. hintObj.text(hint);
  2618. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2619. }
  2620. };
  2621. this.gsTree = stageIm.getGsTree();
  2622. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2623. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2624. jlCol.title = '本期计量金额';
  2625. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2626. $('#type-title-contract').text('本期合同计量金额');
  2627. $('#type-title-qc').text('本期变更计量金额');
  2628. } else {
  2629. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2630. jlCol.title = '本期计量数量';
  2631. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2632. $('#type-title-contract').text('本期合同计量数量');
  2633. $('#type-title-qc').text('本期变更计量数量');
  2634. }
  2635. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2636. $('#show-jldy').parent().show();
  2637. $('#jldy').parent().show();
  2638. $('#show-xm-name').parent().hide();
  2639. $('#xm-name').parent().hide();
  2640. } else {
  2641. $('#show-jldy').parent().hide();
  2642. $('#jldy').parent().hide();
  2643. $('#show-xm-name').parent().show();
  2644. $('#xm-name').parent().show();
  2645. }
  2646. // 选择中间计量模式
  2647. $('div[name="im-type"]').click(function () {
  2648. function chooseType(obj) {
  2649. obj.style.cursor = 'default';
  2650. $(obj).children().addClass('text-primary');
  2651. $(obj).addClass('border-primary');
  2652. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2653. }
  2654. function validType(obj) {
  2655. obj.style.cursor = 'pointer';
  2656. $(obj).children().removeClass('text-primary');
  2657. $(obj).removeClass('border-primary');
  2658. $('i', obj).remove();
  2659. }
  2660. if (this.style.cursor === 'pointer') {
  2661. const typeArr = $('div[name="im-type"]');
  2662. for (const t of typeArr) {
  2663. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2664. chooseType(t);
  2665. } else {
  2666. validType(t)
  2667. }
  2668. }
  2669. }
  2670. });
  2671. $('#choose').on('show.bs.modal', function () {
  2672. function chooseType(obj) {
  2673. obj.style.cursor = 'default';
  2674. $(obj).children().addClass('text-primary');
  2675. $('i', obj).remove();
  2676. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2677. }
  2678. function validType(obj) {
  2679. obj.style.cursor = 'pointer';
  2680. $(obj).children().removeClass('text-primary');
  2681. $('i', obj).remove();
  2682. }
  2683. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2684. const typeArr = $('div[name="im-type"]');
  2685. for (const t of typeArr) {
  2686. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2687. chooseType(t);
  2688. } else {
  2689. validType(t)
  2690. }
  2691. }
  2692. });
  2693. // 提交 中间计量模式
  2694. $('#choose-ok').click(() => {
  2695. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2696. return it.style.cursor !== 'pointer';
  2697. });
  2698. const data = {
  2699. im_type: parseInt($(chooseType).attr('im-type')),
  2700. im_pre: $('#im-pre').val(),
  2701. };
  2702. postData(window.location.pathname + '/detail/build', data, function (result) {
  2703. stage.im_type = data.im_type;
  2704. stage.im_pre = data.im_pre;
  2705. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2706. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2707. jlCol.title = '本期计量金额';
  2708. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2709. $('#type-title-contract').text('本期合同计量金额');
  2710. $('#type-title-qc').text('本期变更计量金额');
  2711. } else {
  2712. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2713. jlCol.title = '本期计量数量';
  2714. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2715. $('#type-title-contract').text('本期合同计量数量');
  2716. $('#type-title-qc').text('本期变更计量数量');
  2717. }
  2718. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2719. $('#show-jldy').parent().show();
  2720. $('#jldy').parent().show();
  2721. $('#show-xm-name').parent().hide();
  2722. $('#xm-name').parent().hide();
  2723. } else {
  2724. $('#show-jldy').parent().hide();
  2725. $('#jldy').parent().hide();
  2726. $('#show-xm-name').parent().show();
  2727. $('#xm-name').parent().show();
  2728. }
  2729. // 加载生成数据
  2730. self.reBuildImData();
  2731. $('#choose').modal('hide');
  2732. });
  2733. });
  2734. // 显示树结构信息
  2735. $('#choose2').on('shown.bs.modal', function () {
  2736. if (!self.gsSpread) {
  2737. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2738. const setting = {
  2739. cols: [
  2740. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2741. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2742. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2743. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2744. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2745. ],
  2746. headRows: 1,
  2747. emptyRows: 0,
  2748. headRowHeight: [32],
  2749. defaultRowHeight: 21,
  2750. headerFont: '12px 微软雅黑',
  2751. font: '12px 微软雅黑',
  2752. };
  2753. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2754. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2755. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2756. function checkParent(node) {
  2757. const parent = self.gsTree.getParent(node);
  2758. if (parent) {
  2759. return parent.check ? parent.check : checkParent(parent);
  2760. } else {
  2761. return false;
  2762. }
  2763. }
  2764. function checkChildren(node) {
  2765. for (const child of node.children) {
  2766. if (child.check) {
  2767. return true;
  2768. } else if (checkChildren(child)) {
  2769. return true;
  2770. }
  2771. }
  2772. return false;
  2773. }
  2774. if (!$('#im-gather-check')[0].checked) { return; }
  2775. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2776. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2777. if (sheet.isEditing()) {
  2778. sheet.endEdit(true);
  2779. }
  2780. }
  2781. if (info.sheet.zh_setting) {
  2782. const col = info.sheet.zh_setting.cols[info.col];
  2783. if (col.field !== 'check') {
  2784. return;
  2785. }
  2786. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2787. const node = sortData[info.row];
  2788. if (!node.check) {
  2789. if (checkParent(node)) {
  2790. const rect = info.sheet.getCellRect(info.row, info.col);
  2791. gatherConfirmPopover.check({
  2792. x: rect.x + rect.width / 2 + 25,
  2793. y: rect.y + rect.height / 2 + 3,
  2794. }, '父项已勾选,继续将取消父项勾选。', function () {
  2795. node.check = true;
  2796. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2797. const rows = [self.gsTree.nodes.indexOf(node)];
  2798. for (const p of parents) {
  2799. if (p.check) {
  2800. p.check = false;
  2801. rows.push(self.gsTree.nodes.indexOf(p));
  2802. }
  2803. }
  2804. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2805. });
  2806. } else if (checkChildren(node)) {
  2807. const rect = info.sheet.getCellRect(info.row, info.col);
  2808. gatherConfirmPopover.check({
  2809. x: rect.x + rect.width / 2 + 25,
  2810. y: rect.y + rect.height / 2 + 3,
  2811. }, '子项已勾选,继续将取消子项勾选。', function () {
  2812. node.check = true;
  2813. const posterity = self.gsTree.getPosterity(node);
  2814. const rows = [self.gsTree.nodes.indexOf(node)];
  2815. for (const p of posterity) {
  2816. if (p.check) {
  2817. rows.push(self.gsTree.nodes.indexOf(p));
  2818. p.check = false;
  2819. }
  2820. }
  2821. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2822. });
  2823. } else {
  2824. node.check = true;
  2825. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2826. }
  2827. } else {
  2828. node.check = false;
  2829. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2830. }
  2831. }
  2832. });
  2833. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2834. for (const node of self.gsTree.datas) {
  2835. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2836. }
  2837. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2838. self.gsTree.expandByLevel(4);
  2839. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2840. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2841. } else {
  2842. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2843. for (const node of self.gsTree.datas) {
  2844. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2845. }
  2846. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2847. }
  2848. });
  2849. // 提交 高级设置
  2850. $('#choose2-ok').click(() => {
  2851. if (!self.gsTree) { return; }
  2852. const nodes = [];
  2853. for (const node of self.gsTree.datas) {
  2854. if (node.check) {
  2855. nodes.push(node.id);
  2856. }
  2857. }
  2858. const data = {
  2859. im_gather: $('#im-gather-check')[0].checked,
  2860. im_gather_node: nodes.join(','),
  2861. };
  2862. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2863. stage.im_gather = data.im_gather;
  2864. stage.im_gather_node = data.im_gather_node;
  2865. $('#choose2').modal('hide');
  2866. });
  2867. });
  2868. }
  2869. _initLocateRela() {
  2870. const self = this;
  2871. $('#im-locate2bills').click(function () {
  2872. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2873. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2874. if (select && select.source) {
  2875. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  2876. stagePosSpreadObj.loadCurPosData();
  2877. }
  2878. });
  2879. $('#im-locate-pre').click(function () {
  2880. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2881. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2882. if (select && select.source) {
  2883. const targetIndex = Math.max(curIndex-1, 1);
  2884. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2885. stagePosSpreadObj.loadCurPosData();
  2886. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2887. }
  2888. });
  2889. $('#im-locate-next').click(function () {
  2890. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2891. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2892. if (select && select.source) {
  2893. const targetIndex = Math.min(curIndex+1, select.source.length);
  2894. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2895. stagePosSpreadObj.loadCurPosData();
  2896. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2897. }
  2898. });
  2899. }
  2900. _initModifyDetail() {
  2901. const self = this;
  2902. // 重置
  2903. $('#reset-detail-ok').click(function () {
  2904. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2905. if (!data.uuid) return;
  2906. const updateData = {
  2907. lid: data.lid, pid: data.pid,
  2908. uuid: data.uuid,
  2909. custom_define: [],
  2910. };
  2911. for (const f of data.custom_define) {
  2912. if (stageIm.resetFields.indexOf(f) >= 0) {
  2913. updateData[f] = null;
  2914. } else {
  2915. updateData.custom_define.push(f);
  2916. }
  2917. }
  2918. updateData.custom_define = updateData.custom_define.join(',');
  2919. $('#reset-detail-modal').modal('hide');
  2920. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2921. stageIm.loadUpdateDetailData(result);
  2922. self.reLoadDetailData();
  2923. });
  2924. });
  2925. // 编辑
  2926. $('#edit-detail').click(function () {
  2927. $(this).hide();
  2928. $('#save-detail').show();
  2929. $('#cancel-detail').show();
  2930. $('#detail-show').hide();
  2931. $('#detail-edit').show();
  2932. self.updateImageData = null;
  2933. });
  2934. // 保存
  2935. $('#save-detail').click(() => {
  2936. function check(field, obj, org, update) {
  2937. const newValue = obj.val();
  2938. if (!org[field]) {
  2939. if (newValue !== '') {
  2940. update[field] = newValue;
  2941. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2942. return true;
  2943. }
  2944. } else if (newValue !== org[field]){
  2945. update[field] = newValue;
  2946. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2947. return true;
  2948. }
  2949. return false;
  2950. }
  2951. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2952. const updateData = {lid: data.lid, pid: data.pid};
  2953. if (data.uuid) {
  2954. updateData.uuid = data.uuid;
  2955. updateData.custom_define = data.custom_define;
  2956. } else {
  2957. updateData.code = data.code;
  2958. updateData.name = data.name;
  2959. updateData.unit = data.unit;
  2960. updateData.unit_price = data.unit_price;
  2961. updateData.pid = data.pid;
  2962. updateData.pos_name = data.pos_name;
  2963. updateData.custom_define = [];
  2964. }
  2965. let infoUpdate = false;
  2966. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  2967. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  2968. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  2969. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  2970. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  2971. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  2972. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  2973. updateData.custom_define = updateData.custom_define.join(',');
  2974. if (infoUpdate) {
  2975. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2976. stageIm.loadUpdateDetailData(result);
  2977. self.reLoadDetailData();
  2978. if (!self.updateImageData) return;
  2979. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  2980. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2981. stageIm.loadUpdateDetailData(result);
  2982. self.reLoadDetailData();
  2983. });
  2984. });
  2985. } else if (self.updateImageData) {
  2986. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2987. stageIm.loadUpdateDetailData(result);
  2988. self.reLoadDetailData();
  2989. });
  2990. } else {
  2991. self.reLoadDetailData();
  2992. }
  2993. });
  2994. // 取消
  2995. $('#cancel-detail').click(() => {
  2996. self.reLoadDetailData();
  2997. });
  2998. }
  2999. _initImageRela() {
  3000. const self = this;
  3001. $('#edit-detail').click(function () {
  3002. loadImageItem();
  3003. });
  3004. function setdraggrable(){
  3005. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3006. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3007. stop: function( event, ui ) {
  3008. }
  3009. });
  3010. }
  3011. function upload(formData) {
  3012. if (formData.length < 1) {
  3013. return;
  3014. }
  3015. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3016. const html = [];
  3017. html.push('<div class="img-item">');
  3018. html.push('<div class="img-bar">');
  3019. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3020. html.push('</div>');
  3021. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3022. html.push('</div>');
  3023. $('.img-view').append(html.join(''));
  3024. $('.img-bar').click(removeImageItem);
  3025. setdraggrable();
  3026. $('#upload-img-file').val('');
  3027. });
  3028. }
  3029. function dragFile(e) {
  3030. var file = null,
  3031. data = e.dataTransfer.types;
  3032. for (var i = 0; i < data.length; i += 1) {
  3033. if (data[i] === 'Files') {
  3034. file = e.dataTransfer.files; //获取文件
  3035. break;
  3036. }
  3037. }
  3038. if (file && file[0].type.indexOf('image') !== -1) {
  3039. var formData = new FormData();
  3040. formData.append('file', file[0]); //上传单个文件的添加方式
  3041. upload(formData); //upload 异步上传
  3042. }
  3043. }
  3044. // 移动图片
  3045. const moveImageItem = function (ev) {
  3046. const item = this;
  3047. const view = $('.img-view')[0];
  3048. let oEvent = ev;
  3049. // 浏览器有一些图片的默认事件,这里要阻止
  3050. oEvent.preventDefault();
  3051. let disX = oEvent.clientX - item.offsetLeft;
  3052. let disY = oEvent.clientY - item.offsetTop;
  3053. view.onmousemove = function (ev) {
  3054. oEvent = ev;
  3055. oEvent.preventDefault();
  3056. let x = oEvent.clientX -disX;
  3057. let y = oEvent.clientY -disY;
  3058. // 图形移动的边界判断
  3059. x = x <= 0 ? 0 : x;
  3060. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3061. y = y <= 0 ? 0 : y;
  3062. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3063. item.style.left = x + 'px';
  3064. item.style.top = y + 'px';
  3065. };
  3066. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3067. view.onmouseleave = function () {
  3068. view.onmousemove = null;
  3069. view.onmouseup = null;
  3070. };
  3071. // 鼠标弹起后停止移动
  3072. view.onmouseup=function() {
  3073. view.onmousemove = null;
  3074. view.onmouseup = null;
  3075. };
  3076. };
  3077. const removeImageItem = function () {
  3078. $(this).parent().remove();
  3079. };
  3080. // 加载草图组成
  3081. const loadImageItem = function () {
  3082. self.updateImageData = null;
  3083. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3084. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3085. const html = [];
  3086. for (const item of items) {
  3087. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3088. html.push('<div class="img-item" style="' + itemStyle + '">');
  3089. html.push('<div class="img-bar">');
  3090. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3091. html.push('</div>');
  3092. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3093. html.push('</div>');
  3094. }
  3095. $('.img-view').html(html.join(''));
  3096. $('.img-bar').click(removeImageItem);
  3097. setdraggrable();
  3098. };
  3099. // 上传图片
  3100. $('#upload-img').click(function () {
  3101. $('#upload-img-file').trigger('click');
  3102. });
  3103. // 拖拽上传
  3104. //拖拽上传文件
  3105. const dragbox = document.querySelector('#upload-img');
  3106. dragbox.addEventListener('dragover', function(e) {
  3107. e.preventDefault(); // 必须阻止默认事件
  3108. }, false);
  3109. dragbox.addEventListener('drop', function(e) {
  3110. e.preventDefault(); // 阻止默认事件
  3111. dragFile(e);
  3112. }, false);
  3113. //拖拽上传文件
  3114. const dragbox2 = document.querySelector('.img-view');
  3115. dragbox2.addEventListener('dragover', function(e) {
  3116. e.preventDefault(); // 必须阻止默认事件
  3117. }, false);
  3118. dragbox2.addEventListener('drop', function(e) {
  3119. e.preventDefault(); // 阻止默认事件
  3120. dragFile(e);
  3121. }, false);
  3122. // 粘贴上传
  3123. $(".img-view").on('paste', function(ev) {
  3124. let file = null;
  3125. const data = (event.clipboardData || window.clipboardData).items;
  3126. for (let i = 0; i < data.length; i += 1) {
  3127. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3128. file = data[i].getAsFile(); //读取图片文件
  3129. break;
  3130. }
  3131. }
  3132. if (file) {
  3133. const formData = new FormData();
  3134. formData.append('file', file); //上传单个文件的添加方式
  3135. upload(formData); //异步上传文件
  3136. }
  3137. });
  3138. $('#upload-img-file').change(function () {
  3139. const file = this.files[0];
  3140. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3141. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3142. if (!imgStr.test(ext)) {
  3143. toastr.error('请上传正确的图片格式文件');
  3144. return
  3145. }
  3146. if ($(this).val()) {
  3147. const formData = new FormData();
  3148. formData.append('file', this.files[0]);
  3149. upload(formData);
  3150. }
  3151. });
  3152. // 保存草图修改结果
  3153. $('#edit-img-ok').click(function () {
  3154. // 记录上传的图片的信息
  3155. const items = $('.img-item');
  3156. const img_remark = $('#text-edit').val();
  3157. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3158. // 生成上传数据
  3159. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  3160. if (data.uuid) {
  3161. updateData.uuid = data.uuid;
  3162. } else {
  3163. updateData.code = data.code;
  3164. updateData.name = data.name;
  3165. updateData.unit = data.unit;
  3166. updateData.unit_price = data.unit_price;
  3167. updateData.pid = data.pid;
  3168. updateData.pos_name = data.pos_name;
  3169. }
  3170. if (items.length > 0) {
  3171. const itemInfo = [];
  3172. for (const item of items) {
  3173. const itemData = {
  3174. src: $('img', item).attr('src'),
  3175. left: item.style.left,
  3176. top: item.style.top,
  3177. width: item.style.width,
  3178. height: item.style.height,
  3179. };
  3180. itemInfo.push(itemData);
  3181. }
  3182. // 获取合并好的图片数据
  3183. const canvas = document.createElement('canvas');
  3184. const view = $('.img-view')[0];
  3185. canvas.height = view.clientHeight;
  3186. canvas.width = view.clientWidth;
  3187. const ctx = canvas.getContext('2d');
  3188. ctx.fillStyle = '#ffffff';
  3189. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3190. for (const b of $('.img-item')) {
  3191. const pos = $(b).position();
  3192. const img = $('img', b)[0];
  3193. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3194. }
  3195. updateData.img = canvas.toDataURL('image/png');
  3196. updateData.imgInfo = itemInfo;
  3197. self.updateImageData = updateData;
  3198. $('#calc-img').attr('src', updateData.img);
  3199. $('#calc-remark').html(img_remark);
  3200. $('#view-calc-img').attr('src', updateData.img);
  3201. $('#show-calc-img').attr('src', updateData.img);
  3202. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  3203. $('#view-calc-remark').text(img_remark);
  3204. $('#edit-img').modal('hide');
  3205. // updateImageData = updateData;
  3206. // $('#edit-img').modal('hide');
  3207. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  3208. // stageIm.loadUpdateDetailData(result);
  3209. // data.calc_img = result.calc_img;
  3210. // data.calc_img_org = result.calc_img_org;
  3211. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3212. // $('#show-calc-img').attr('src', calcImgSrc);
  3213. // $('#calc-img').attr('src', calcImgSrc);
  3214. // $('#view-calc-img').attr('src', calcImgSrc);
  3215. // $('#edit-img').modal('hide');
  3216. // });
  3217. } else if (data.calc_img) {
  3218. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  3219. $('#show-calc-img').attr('src', '');
  3220. $('#show-calc-remark').html('');
  3221. $('#calc-img').attr('src', '');
  3222. $('#calc-remark').html('');
  3223. $('#view-calc-img').attr('src', '');
  3224. $('#view-calc-remark').val('');
  3225. $('#text-edit').val('');
  3226. $('#edit-img').modal('hide');
  3227. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  3228. // stageIm.loadUpdateDetailData(result);
  3229. // data.calc_img = result.calc_img;
  3230. // data.calc_img_org = result.calc_img_org;
  3231. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3232. // $('#show-calc-img').attr('src', calcImgSrc);
  3233. // $('#calc-img').attr('src', calcImgSrc);
  3234. // $('#view-calc-img').attr('src', calcImgSrc);
  3235. // $('#edit-img').modal('hide');
  3236. // });
  3237. } else {
  3238. self.updateImageData = updateData;
  3239. $('#show-calc-img').attr('src', '');
  3240. $('#show-calc-remark').html('');
  3241. $('#calc-img').attr('src', '');
  3242. $('#calc-remark').html('');
  3243. $('#view-calc-img').attr('src', '');
  3244. $('#view-calc-remark').val('');
  3245. $('#text-edit').val('');
  3246. $('#edit-img').modal('hide');
  3247. }
  3248. });
  3249. }
  3250. reBuildImData() {
  3251. const imData = stageIm.buildImData();
  3252. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3253. this.reLoadDetailData();
  3254. this.loadLocateInfo();
  3255. }
  3256. loadStageLedgerUpdateData(data, nodes) {
  3257. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3258. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3259. this.reLoadDetailData();
  3260. }
  3261. loadStagePosUpdateData(data, nodes) {
  3262. const imData = stageIm.loadUpdatePosData(data, nodes);
  3263. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3264. this.reLoadDetailData();
  3265. }
  3266. loadStageChangeUpdateData(data, nodes) {
  3267. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3268. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3269. this.reLoadDetailData();
  3270. }
  3271. loadLocateInfo() {
  3272. const select = SpreadJsObj.getSelectObject(this.sheet);
  3273. if (select && select.source.length > 1) {
  3274. $('#im-locate2bills').next().show();
  3275. } else {
  3276. $('#im-locate2bills').next().hide();
  3277. }
  3278. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  3279. }
  3280. reLoadDetailData() {
  3281. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  3282. $('#reset-detail').hide();
  3283. if (data) {
  3284. for (const f of data.custom_define) {
  3285. if (stageIm.resetFields.indexOf(f) >= 0) {
  3286. $('#reset-detail').show();
  3287. break;
  3288. }
  3289. }
  3290. $('#edit-detail').show();
  3291. $('#modify-img').show();
  3292. } else {
  3293. $('#edit-detail').hide();
  3294. $('#modify-img').hide();
  3295. }
  3296. $('#save-detail').hide();
  3297. $('#cancel-detail').hide();
  3298. $('#detail-show').show();
  3299. $('#detail-edit').hide();
  3300. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  3301. $('#show-contract-jl').text(contractJl);
  3302. $('#contract-jl').val(contractJl);
  3303. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  3304. $('#show-qc-jl').text(qcJl);
  3305. $('#qc-jl').val(qcJl);
  3306. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  3307. $('#show-bgl-code').text(bglCode);
  3308. $('#bgl-code').val(bglCode);
  3309. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  3310. $('#show-bgl-drawing-code').text(bglDrawingCode);
  3311. $('#bgl-drawing-code').val(bglDrawingCode);
  3312. const bwName = data && data.bw ? data.bw : '';
  3313. $('#show-bw-name').text(bwName);
  3314. $('#bw-name').val(bwName);
  3315. const position = data && data.position ? data.position : '';
  3316. $('#show-position').text(position);
  3317. $('#position').val(position);
  3318. const peg = data && data.peg ? data.peg : '';
  3319. $('#show-peg').text(peg);
  3320. $('#peg').val(peg);
  3321. const xmName = data && data.xm ? data.xm: '';
  3322. $('#show-xm-name').text(xmName);
  3323. $('#xm-name').val(xmName);
  3324. const jldy = data && data.jldy ? data.jldy: '';
  3325. $('#show-jldy').text(jldy);
  3326. $('#jldy').val(jldy);
  3327. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  3328. $('#show-drawing-code').text(drawingCode);
  3329. $('#drawing-code').val(drawingCode);
  3330. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  3331. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  3332. $('#calc-memo').val(calcMemo);
  3333. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3334. $('#show-calc-img').attr('src', calcImgSrc);
  3335. $('#calc-img').attr('src', calcImgSrc);
  3336. $('#view-calc-img').attr('src', calcImgSrc);
  3337. const calcImgRemark = data && data.calc_img_remark || '';
  3338. $('#view-calc-remark').val(calcImgRemark);
  3339. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  3340. $('#calc-remark').html(calcImgRemark);
  3341. $("#view-calc-remark").attr('readonly', true);
  3342. // 处理 编辑 -> 添加草图中textarea多余的空格
  3343. $('#text-edit').val(calcImgRemark)
  3344. }
  3345. }
  3346. class CheckedChange {
  3347. constructor (setting) {
  3348. const self = this;
  3349. this.changeSpreadSetting = {
  3350. cols: [
  3351. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  3352. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  3353. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3354. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  3355. ],
  3356. emptyRows: 0,
  3357. headRows: 1,
  3358. headRowHeight: [32],
  3359. headColWidth: [30],
  3360. defaultRowHeight: 21,
  3361. headerFont: '12px 微软雅黑',
  3362. font: '12px 微软雅黑',
  3363. readOnly: true,
  3364. };
  3365. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  3366. this.changeSheet = this.changeSpread.getActiveSheet();
  3367. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  3368. const getTipText = function (data) {
  3369. if (!data) return '';
  3370. const tips = [];
  3371. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  3372. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  3373. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  3374. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  3375. return tips.join('-');
  3376. };
  3377. this.changeBillsSpreadSetting = {
  3378. cols: [
  3379. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', cellType: 'tip', getTip: getTipText},
  3380. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number', cellType: 'tip', getTip: getTipText},
  3381. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'tip', getTip: getTipText},
  3382. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', cellType: 'tip', getTip: getTipText},
  3383. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3384. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3385. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: getTipText},
  3386. ],
  3387. emptyRows: 0,
  3388. headRows: 1,
  3389. headRowHeight: [32],
  3390. defaultRowHeight: 21,
  3391. headerFont: '12px 微软雅黑',
  3392. font: '12px 微软雅黑',
  3393. readOnly: true
  3394. };
  3395. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  3396. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  3397. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  3398. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  3399. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3400. if (change.cid === self.curChangeId) { return; }
  3401. self.curChangeId = change.cid;
  3402. if (change.detail) {
  3403. self.loadChangeDetailData();
  3404. } else {
  3405. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  3406. change.detail = result;
  3407. self.analyzeChange(change);
  3408. self.loadChangeDetailData();
  3409. });
  3410. }
  3411. });
  3412. this.changes = null;
  3413. this.reloadChangeData();
  3414. setting.reloadObj.click(function() {
  3415. self.reloadChangeData();
  3416. });
  3417. $.contextMenu({
  3418. selector: '#' + setting.changeBillsObj.attr('id'),
  3419. build: function ($trigger, e) {
  3420. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  3421. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3422. },
  3423. items: {
  3424. 'locateZjjl': {
  3425. name: '定位至台账',
  3426. icon: 'fa-sign-in',
  3427. callback: function (key, opt) {
  3428. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3429. if (changeBills.gcl_id) {
  3430. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3431. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3432. stagePosSpreadObj.loadCurPosData();
  3433. } else {
  3434. const cb = {
  3435. b_code: changeBills.code || '',
  3436. name: changeBills.name || '',
  3437. unit: changeBills.unit || '',
  3438. unit_price: changeBills.unit_price || 0,
  3439. };
  3440. for (const node of stageTree.nodes) {
  3441. if (node.children && node.children.length > 0) continue;
  3442. const b = {
  3443. b_code: node.b_code || '',
  3444. name: node.name || '',
  3445. unit: node.unit || '',
  3446. unit_price: node.unit_price || 0,
  3447. };
  3448. if (_.isMatch(cb, b)) {
  3449. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3450. stagePosSpreadObj.loadCurPosData();
  3451. return;
  3452. }
  3453. }
  3454. }
  3455. },
  3456. disabled: function (key, opt) {
  3457. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3458. return !changeBills;
  3459. }
  3460. },
  3461. }
  3462. });
  3463. }
  3464. loadChangeDetailData() {
  3465. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  3466. if (change) {
  3467. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  3468. } else {
  3469. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  3470. }
  3471. }
  3472. refresh() {
  3473. this.changeSpread.refresh();
  3474. this.changeBillsSpread.refresh();
  3475. }
  3476. reloadChangeData() {
  3477. const self = this;
  3478. postData(window.location.pathname + '/change/data', null, function (result) {
  3479. self.changes = result.changes;
  3480. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  3481. self.changeSheet.setSelection(0, 0, 1, 1);
  3482. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  3483. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  3484. self.loadChangeDetailData();
  3485. });
  3486. }
  3487. analyzeChange(change) {
  3488. change.bills = change.detail.bills;
  3489. for (const b of change.bills) {
  3490. const aub = change.detail.addUsedBills.find(function (x) {
  3491. return x.id === b.id;
  3492. });
  3493. if (aub) {
  3494. b.used_qty = aub.used_qty;
  3495. }
  3496. b.qty = _.toNumber(b.samount);
  3497. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  3498. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3499. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  3500. b.cur_qty = 0;
  3501. for (const p of b.pos) {
  3502. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  3503. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  3504. }
  3505. }
  3506. }
  3507. }
  3508. // 展开收起附件
  3509. $('a', '.right-nav').bind('click', function () {
  3510. //const main = $('#main-view'), tool = $('#tools-view');
  3511. const tab = $(this), tabPanel = $(tab.attr('content'));
  3512. if (!tab.hasClass('active')) {
  3513. $('a', '.side-menu').removeClass('active');
  3514. $('.tab-content .tab-select-show').removeClass('active');
  3515. tab.addClass('active');
  3516. tabPanel.addClass('active');
  3517. showSideTools(tab.hasClass('active'));
  3518. if (tab.attr('content') === '#search' && !searchLedger) {
  3519. searchLedger = $.billsSearch({
  3520. selector: '#search',
  3521. searchSpread: slSpread,
  3522. searchRangeStr: '项目节编号/名称',
  3523. searchOver: true,
  3524. searchEmpty: true,
  3525. resultSpreadSetting: {
  3526. cols: [
  3527. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3528. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3529. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3530. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3531. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3532. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3533. {title: '完成率(%)', field: 'end_gather_percent', hAlign: 2, width: 70},
  3534. ],
  3535. emptyRows: 0,
  3536. headRows: 1,
  3537. headRowHeight: [32],
  3538. headColWidth: [30],
  3539. defaultRowHeight: 21,
  3540. headerFont: '12px 微软雅黑',
  3541. font: '12px 微软雅黑',
  3542. selectedBackColor: '#fffacd',
  3543. },
  3544. afterLocated: function () {
  3545. stagePosSpreadObj.loadCurPosData();
  3546. },
  3547. customSearch: [
  3548. {
  3549. key: 'less', title: '漏计', valid: true,
  3550. check: function (node) {
  3551. if (node.quantity) {
  3552. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  3553. } else if (node.total_price) {
  3554. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  3555. }
  3556. }
  3557. }, {
  3558. key: 'over', title: '超计', valid: true,
  3559. check: function (node) {
  3560. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  3561. }
  3562. }, {
  3563. key: 'empty', title: '漏计', valid: false,
  3564. check: function (node) {
  3565. if (node.quantity) {
  3566. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  3567. } else if (node.total_price) {
  3568. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  3569. }
  3570. }
  3571. }, {
  3572. key: 'estimate', title: '预计变更', valid: true,
  3573. check: function (node) {
  3574. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  3575. if (posRange.length > 0) {
  3576. for (const p of posRange) {
  3577. if (!checkZero(p.estimate_qty)) return true;
  3578. }
  3579. return false;
  3580. } else {
  3581. return false;
  3582. }
  3583. }
  3584. }
  3585. ],
  3586. });
  3587. searchLedger.spread.refresh();
  3588. }
  3589. if (tab.attr('content') === '#fujian') {
  3590. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3591. node && getNodeList(node.id);
  3592. }
  3593. if (tab.attr('content') === '#zhongjian') {
  3594. if (!detail) {
  3595. detail = new Detail($('#detail-spread'));
  3596. detail.spread.refresh();
  3597. $('#zhongjian .sjs-bottom').height('400px');
  3598. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3599. } else {
  3600. detail.spread.refresh();
  3601. }
  3602. }
  3603. if (tab.attr('content') === '#checked-change') {
  3604. if (!checkedChanges) {
  3605. checkedChanges = new CheckedChange({
  3606. changeObj: $('#cc-spread'),
  3607. changeBillsObj: $('#ccb-spread'),
  3608. reloadObj: $('#refresh-cc'),
  3609. });
  3610. checkedChanges.refresh();
  3611. } else {
  3612. $('#ccb-spread').height('400px');
  3613. checkedChanges.refresh();
  3614. }
  3615. }
  3616. if (tab.attr('content') === '#error-list') {
  3617. errorList.spread.refresh();
  3618. }
  3619. if (tab.attr('content') === '#check-list') {
  3620. checkList.spread.refresh();
  3621. }
  3622. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  3623. } else {
  3624. tab.removeClass('active');
  3625. tabPanel.removeClass('active');
  3626. showSideTools(tab.hasClass('active'));
  3627. }
  3628. slSpread.refresh();
  3629. spSpread.refresh();
  3630. });
  3631. // 切换附件里节点和所有附件
  3632. $('#fujian .nav-link').on('click', function () {
  3633. const tabPanel = $(this).attr('fujian-content');
  3634. if (tabPanel !== 'syfujian') {
  3635. $('#showPage').hide();
  3636. $('#bach-download').prop('type', 'curr');
  3637. } else {
  3638. $('#showPage').show();
  3639. $('#bach-download').prop('type', 'all')
  3640. }
  3641. $('#showAttachment').hide();
  3642. });
  3643. // 上传附件
  3644. $('#upload-file-btn').click(function () {
  3645. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3646. // return toastr.error('当前操作没有权限!');
  3647. // }
  3648. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3649. if (!node) return
  3650. const files = $('#upload-file')[0].files;
  3651. const formData = new FormData();
  3652. formData.append('lid', node.id);
  3653. for (const file of files) {
  3654. if (file === undefined) {
  3655. toastr.error('未选择上传文件!');
  3656. return false;
  3657. }
  3658. const filesize = file.size;
  3659. if (filesize > 30 * 1024 * 1024) {
  3660. toastr.error('存在上传文件大小过大!');
  3661. return false;
  3662. }
  3663. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3664. if (whiteList.indexOf(fileext) === -1) {
  3665. toastr.error('只能上传指定格式的附件!');
  3666. return false;
  3667. }
  3668. formData.append('size', filesize);
  3669. formData.append('file[]', file);
  3670. }
  3671. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  3672. $('#upload').modal('hide');
  3673. // 插入到attData中
  3674. attData = data.concat(attData);
  3675. // 重新生成List
  3676. getAllList();
  3677. getNodeList(node.id);
  3678. }, function () {
  3679. toastr.error('附件上传失败');
  3680. });
  3681. $('#upload-file').val('');
  3682. });
  3683. // 获取附件信息
  3684. $('.list-table').on('click', '.att-file-name', function () {
  3685. const fid = $(this).attr('file-id');
  3686. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3687. return;
  3688. }
  3689. const att = attData.find(function (item) {
  3690. return item.id === parseInt(fid);
  3691. });
  3692. $('#edit-att').hide();
  3693. $('#show-att').show();
  3694. if (att !== undefined) {
  3695. // 进来先把编辑功能隐藏
  3696. $('#btn-att a').eq(3).hide()
  3697. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3698. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3699. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3700. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3701. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3702. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3703. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3704. $('#show-att tr').eq(3).children('td').text(att.remark);
  3705. // 附件uid等于当前用户id, 附件上传本人
  3706. if (parseInt(cur_uid) === att.uid) {
  3707. $('#btn-att').show();
  3708. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3709. // if (!curAuditor) {
  3710. // stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3711. // stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3712. // stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3713. // } else {
  3714. // curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3715. // }
  3716. if (showDel) $('#btn-att a').eq(3).show();
  3717. // $('#btn-att a').eq(3).show();
  3718. $('#btn-att a').eq(2).hide();
  3719. $('#btn-att a').eq(4).hide();
  3720. $('#btn-att a').eq(5).hide();
  3721. } else {
  3722. $('#btn-att').hide();
  3723. $('#btn-att a').eq(3).hide();
  3724. $('#btn-att a').eq(2).hide();
  3725. $('#btn-att a').eq(4).hide();
  3726. $('#btn-att a').eq(5).hide();
  3727. }
  3728. $('#showAttachment').attr('file-id', fid);
  3729. $('#showAttachment').show();
  3730. } else {
  3731. $('#showAttachment').hide();
  3732. $('#showAttachment').attr('file-id', '');
  3733. toastr.error('附件信息获取失败');
  3734. }
  3735. });
  3736. // $('body').on('click', '.alllist-table a', handleFileList);
  3737. $('body').on('click', '#btn-att a', function () {
  3738. const content = $(this).attr('content');
  3739. const fid = $('#showAttachment').attr('file-id');
  3740. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3741. if (content === 'edit') {
  3742. $('#btn-att a').eq(3).hide();
  3743. $('#btn-att a').eq(2).show();
  3744. $('#btn-att a').eq(4).show();
  3745. $('#btn-att a').eq(5).show();
  3746. $('#show-att').hide();
  3747. $('#edit-att').show();
  3748. const att = attData.find(function (item) {
  3749. return item.id === parseInt(fid);
  3750. });
  3751. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3752. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3753. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3754. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3755. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3756. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3757. } else if (content === 'cancel') {
  3758. $('#show-att').show();
  3759. $('#edit-att').hide();
  3760. $('#btn-att a').eq(3).show();
  3761. $('#btn-att a').eq(2).hide();
  3762. $('#btn-att a').eq(4).hide();
  3763. $('#btn-att a').eq(5).hide();
  3764. } else if (content === 'save') {
  3765. const formData = new FormData();
  3766. formData.append('id', fid);
  3767. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3768. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3769. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3770. const file = $('#change-att-btn')[0];
  3771. if (file.files[0] !== undefined) {
  3772. const filesize = file.files[0].size;
  3773. formData.append('size', filesize);
  3774. formData.append('file', file.files[0]);
  3775. }
  3776. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3777. // 替换到attData中
  3778. const att_index = attData.findIndex(function (item) {
  3779. return item.id === parseInt(fid);
  3780. });
  3781. attData.splice(att_index, 1, data);
  3782. // 重新生成List
  3783. getAllList(parseInt($('#currentPage').text()));
  3784. getNodeList(node.id);
  3785. $('#show-att').show();
  3786. $('#edit-att').hide();
  3787. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3788. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3789. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3790. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  3791. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  3792. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  3793. $('#show-att tr').eq(4).children('td').text(data.remark);
  3794. $('#btn-att a').eq(3).show();
  3795. $('#btn-att a').eq(2).hide();
  3796. $('#btn-att a').eq(4).hide();
  3797. $('#btn-att a').eq(5).hide();
  3798. }, function () {
  3799. toastr.error('附件上传失败');
  3800. });
  3801. $('#change-att-btn').val('');
  3802. } else if (content === 'del') {
  3803. const data = {id: fid};
  3804. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  3805. // 删除到attData中
  3806. const att_index = attData.findIndex(function (item) {
  3807. return item.id === parseInt(fid);
  3808. });
  3809. attData.splice(att_index, 1);
  3810. // 重新生成List
  3811. if ($('#alllist-table tr').length === 1) {
  3812. getAllList(parseInt($('#currentPage').text()) - 1);
  3813. } else {
  3814. getAllList(parseInt($('#currentPage').text()));
  3815. }
  3816. getNodeList(node.id);
  3817. $('#showAttachment').hide();
  3818. $('#showAttachment').attr('file-id', '');
  3819. });
  3820. } else if (content === 'view') {
  3821. const data = {id: fid};
  3822. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  3823. const { filepath } = result
  3824. $('#load-file').attr('href', filepath);
  3825. $('#load-file')[0].click();
  3826. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  3827. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  3828. });
  3829. } else if (content === 'location') {
  3830. const att = attData.find(item => item.id === parseInt(fid));
  3831. if (Object.keys(att).length) {
  3832. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  3833. stagePosSpreadObj.loadCurPosData();
  3834. }
  3835. }
  3836. });
  3837. // 替换附件
  3838. $('#change-att-btn').on('change', function () {
  3839. const file = $('#change-att-btn')[0].files[0];
  3840. const name = file.name;
  3841. const filename = name.substring(0, name.lastIndexOf("."));
  3842. const fileext = name.substr(name.indexOf("."));
  3843. const filesize = file.size;
  3844. if (filesize > 10 * 1024 * 1024) {
  3845. toastr.error('文件大小过大!');
  3846. $('#change-att-btn').val('');
  3847. return false;
  3848. }
  3849. if (whiteList.indexOf(fileext) === -1) {
  3850. toastr.error('只能上传指定格式的附件!');
  3851. $('#change-att-btn').val('');
  3852. return false;
  3853. }
  3854. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3855. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3856. });
  3857. // 切换页数
  3858. $('.page-select').on('click', function () {
  3859. const totalPageNum = parseInt($('#totalPage').text());
  3860. const lastPageNum = parseInt($('#currentPage').text());
  3861. const status = $(this).attr('content');
  3862. if (status === 'pre' && lastPageNum > 1) {
  3863. getAllList(lastPageNum-1);
  3864. $('#showAttachment').hide();
  3865. $('#syfujian .check-all-file').prop('checked', false)
  3866. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3867. getAllList(lastPageNum+1);
  3868. $('#showAttachment').hide();
  3869. $('#syfujian .check-all-file').prop('checked', false)
  3870. }
  3871. });
  3872. // 批量下载
  3873. $('#bach-download').click(function() {
  3874. const fileIds = [];
  3875. const type = $(this).attr('type');
  3876. let node = ''
  3877. if (type === 'curr') {
  3878. node = '#nodelist-table .check-file:checked'
  3879. } else {
  3880. node = '#alllist-table .check-file:checked'
  3881. }
  3882. $(node).each(function() {
  3883. const fileId = $(this).attr('file-id');
  3884. fileId && fileIds.push(fileId);
  3885. });
  3886. if (fileIds.length) {
  3887. if (fileIds.length > 10) {
  3888. return toastr.warning(`最大允许10个文件(当前${fileIds.length}个)`)
  3889. }
  3890. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  3891. $(this).attr('disabled', "true")
  3892. const btn = $(this)
  3893. postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  3894. toastr.clear()
  3895. toastr.success('压缩文件成功')
  3896. btn.removeAttr('disabled')
  3897. const href = window.URL.createObjectURL(result)
  3898. $('#zipDown').attr('href', href);
  3899. $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  3900. $("#zipDown")[0].click();
  3901. }, () => {
  3902. btn.removeAttr('disabled')
  3903. toastr.clear()
  3904. toastr.error('批量下载失败')
  3905. });
  3906. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  3907. // $('#zipDown').attr('href', url);
  3908. // $("#zipDown")[0].click();
  3909. }
  3910. });
  3911. // 监听附件check是否选中
  3912. $('.list-table').on('click', '.check-file', function() {
  3913. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  3914. const childs = $(this).parents('.list-table').children().length;
  3915. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  3916. if (checkedList.length === childs) {
  3917. checkBox.prop("checked", true);
  3918. } else {
  3919. checkBox.prop("checked", false);
  3920. }
  3921. });
  3922. $('.check-all-file').click(function() {
  3923. const isCheck = $(this).is(':checked');
  3924. $(this).parents('table').find('.list-table').each(function() {
  3925. $(this).find('input:checkbox').prop("checked", isCheck);
  3926. })
  3927. });
  3928. // 显示层次
  3929. (function (select, sheet) {
  3930. $(select).click(function () {
  3931. if (!sheet.zh_tree) return;
  3932. const tag = $(this).attr('tag');
  3933. const tree = sheet.zh_tree;
  3934. setTimeout(() => {
  3935. showWaitingView();
  3936. switch (tag) {
  3937. case "1":
  3938. case "2":
  3939. case "3":
  3940. case "4":
  3941. case "5":
  3942. tree.expandByLevel(parseInt(tag));
  3943. SpreadJsObj.refreshTreeRowVisible(sheet);
  3944. break;
  3945. case "last":
  3946. tree.expandByCustom(() => { return true; });
  3947. SpreadJsObj.refreshTreeRowVisible(sheet);
  3948. break;
  3949. case "leafXmj":
  3950. tree.expandToLeafXmj();
  3951. SpreadJsObj.refreshTreeRowVisible(sheet);
  3952. break;
  3953. case "curMeasure":
  3954. tree.expandByCustom(function (node) {
  3955. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  3956. if (node[field]) {
  3957. return true;
  3958. }
  3959. }
  3960. return false;
  3961. });
  3962. SpreadJsObj.refreshTreeRowVisible(sheet);
  3963. break;
  3964. }
  3965. closeWaitingView();
  3966. }, 100);
  3967. });
  3968. })('a[name=showLevel]', slSpread.getActiveSheet());
  3969. const stageCheckerSetting = {
  3970. ledgerTree: stageTree,
  3971. ledgerPos: stagePos,
  3972. checkList: checkList,
  3973. decimal: tenderInfo.decimal,
  3974. checkOption: checkOption,
  3975. };
  3976. if (!checkTzMeasureType()) {
  3977. stageCheckerSetting.checkOption.calc.fields.push('sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'quantity');
  3978. stageCheckerSetting.checkOption.tp.fields.push(
  3979. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  3980. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  3981. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  3982. {qty: 'quantity', tp: 'total_price'},
  3983. );
  3984. }
  3985. $('#ledger-check2').click(() => {
  3986. const result = ledgerCheck2(stageCheckerSetting);
  3987. check2Viewing({
  3988. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  3989. randomWait: true,
  3990. prefix: 'check2-',
  3991. checks: result,
  3992. checkList: checkList,
  3993. })
  3994. });
  3995. const dataChecker = DataChecker({
  3996. checkUrl: window.location.pathname + '/check',
  3997. completeData: function (data) {
  3998. stagePos.updateDatas({pos: data.source.pos});
  3999. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  4000. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  4001. stagePosSpreadObj.loadCurPosData();
  4002. for (const e of data.error) {
  4003. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  4004. }
  4005. },
  4006. errorList: errorList,
  4007. });
  4008. $('[name=stage-start]').submit(function (e) {
  4009. if (checkAuditorFrom()) {
  4010. // 再检查多人协同确认情况
  4011. const list = stageTree.pwd.find(x => {return !x.confirm });
  4012. if(list) {
  4013. toastr.error('请检查多人协同确认情况再上报');
  4014. $('#hide-all').hide();
  4015. return false;
  4016. }
  4017. $(this).parent().parent().parent().modal('hide');
  4018. dataChecker.checkAndPost(this.action, {});
  4019. $('#hide-all').hide();
  4020. }
  4021. return false;
  4022. });
  4023. $('#audit-check0').submit(function (e) {
  4024. // 再检查多人协同确认情况
  4025. const list = stageTree.pwd.find(x => {return !x.confirm });
  4026. if(list) {
  4027. toastr.error('请检查多人协同确认情况再审批通过');
  4028. $('#hide-all').hide();
  4029. return false;
  4030. }
  4031. const checkType = parseInt($('[name=checkType]').val());
  4032. const data = {
  4033. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4034. checkType,
  4035. };
  4036. $('#sp-done').modal('hide');
  4037. checkType && dataChecker.checkAndPost(this.action, data);
  4038. $('#hide-all').hide();
  4039. return false;
  4040. });
  4041. $('#audit-check1').submit(function (e) {
  4042. const checkType = parseInt($('[name=checkType]:checked').val());
  4043. const data = {
  4044. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4045. checkType,
  4046. };
  4047. if ($('#warning-text').length) $('#warning-text').remove()
  4048. if (!checkType && !$('#warning-text').length) {
  4049. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  4050. return false
  4051. }
  4052. $('#sp-back').modal('hide');
  4053. checkType && dataChecker.checkAndPost(this.action, data);
  4054. $('#hide-all').hide();
  4055. return false;
  4056. });
  4057. $('#exportExcel').click(function () {
  4058. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  4059. });
  4060. $('#cbr-check-all').click(function () {
  4061. if (this.checked) {
  4062. $('input', '#cbr-pos-list').attr('checked', 'checked');
  4063. } else {
  4064. $('input', '#cbr-pos-list').removeAttr('checked');
  4065. }
  4066. });
  4067. $('#cbr-ok').click(() => {
  4068. const ratio = parseInt($('#cbr-ratio').val());
  4069. if (!ratio) {
  4070. toastr.warning('请输入计量比例');
  4071. return;
  4072. } else if (ratio < 1) {
  4073. toastr.warning('计量比例不可小于1');
  4074. return;
  4075. } else if (ratio > 100) {
  4076. toastr.warning('计量比例不可大于100');
  4077. return;
  4078. }
  4079. const apply2sibling = $('#apply2sibling')[0].checked;
  4080. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  4081. if (posName.length === 0) {
  4082. toastr.warning('请勾选需要按计量比例的计量单元');
  4083. return;
  4084. }
  4085. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  4086. });
  4087. $('body').on('click', '[name=ledger-unlock]', function() {
  4088. $('#cooperation').modal('hide');
  4089. const lid = this.getAttribute('lid');
  4090. if (!lid) return;
  4091. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4092. if (!p) return;
  4093. $('#unlock-info').html(`${p.node.code} ${p.node.name} 解锁密码<b class="text-danger">*</b>`);
  4094. $('#unlock-pwd').val('').removeClass('is-invalid');
  4095. $('.invalid-feedback', '#unlock').hide();
  4096. $('.alert-warning', '#unlock').hide();
  4097. $('#unlock-ok').attr('lid', lid);
  4098. $('#unlock').modal('show');
  4099. });
  4100. $('#unlock-ok').click(function () {
  4101. const lid = this.getAttribute('lid');
  4102. if (!lid) return;
  4103. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4104. if (!p) return;
  4105. if (p.pwd === $('#unlock-pwd').val()) {
  4106. const refresh = stageTree.lockNode(p, false);
  4107. // 修改线上
  4108. SpreadJsObj.reloadRowsReadonly(slSpread.getActiveSheet(), refresh);
  4109. stagePosSpreadObj.loadCurPosData();
  4110. $('#unlock').modal('hide');
  4111. reloadCooperationHtml();
  4112. } else {
  4113. $('#unlock-pwd').addClass('is-invalid');
  4114. $('.invalid-feedback', '#unlock').show();
  4115. $('.alert-warning', '#unlock').show();
  4116. }
  4117. });
  4118. $('#cooperationSelect').change(function () {
  4119. reloadCooperationHtml();
  4120. });
  4121. // 确认
  4122. $('body').on('click', '[name=ledger-confirm]', function() {
  4123. const lid = this.getAttribute('lid');
  4124. if (!lid) return;
  4125. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4126. if (!p) return;
  4127. // 修改线上
  4128. postData(window.location.pathname + '/save/cooperation', { type: 'save-confirm', postData: { ledger_id: lid } }, function (result) {
  4129. p.confirm = true;
  4130. p.confirm_time = new Date();
  4131. stageTree.confirmList = result.cooperationConfirm;
  4132. reloadCooperationHtml();
  4133. });
  4134. });
  4135. // 确认
  4136. $('body').on('click', '[name=ledger-unconfirm]', function() {
  4137. const lid = this.getAttribute('lid');
  4138. if (!lid) return;
  4139. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4140. if (!p) return;
  4141. // 修改线上
  4142. postData(window.location.pathname + '/save/cooperation', { type: 'del-confirm', postData: { ledger_id: lid } }, function (result) {
  4143. p.confirm = false;
  4144. p.confirm_time = null;
  4145. stageTree.confirmList = result.cooperationConfirm;
  4146. reloadCooperationHtml();
  4147. });
  4148. });
  4149. // 收方单生成
  4150. $('#setshoufang').click(function () {
  4151. const lid = $('#shoufang-lid').val();
  4152. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  4153. // 修改线上
  4154. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  4155. // 收方单tab打开并显示在最新
  4156. if (!$('#shoufang-tab').hasClass('active')) {
  4157. $('#shoufang-tab').click();
  4158. }
  4159. const data = makeOneShouFang(result);
  4160. data.filenum = 0;
  4161. sfData = _.concat(data, sfData);
  4162. getShouFangList();
  4163. });
  4164. });
  4165. $('body').on('click', '.del-shoufang', function () {
  4166. const id = $(this).attr('data-id');
  4167. $('#del-shoufang-id').val(id);
  4168. const name = $(this).parents('tr').children('td').eq(0).text();
  4169. const ledger_code = name.split(' / ')[0];
  4170. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  4171. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  4172. if (pos_name) {
  4173. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  4174. } else {
  4175. $('#del-shoufang-pos').text('').hide();
  4176. }
  4177. });
  4178. // 收方单删除
  4179. $('#delshoufang').click(function () {
  4180. const sfid = $('#del-shoufang-id').val();
  4181. // 修改线上
  4182. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  4183. // 删除到sfData中
  4184. const att_index = sfData.findIndex(function (item) {
  4185. return item.id === parseInt(sfid);
  4186. });
  4187. sfData.splice(att_index, 1);
  4188. // 重新生成List
  4189. if ($('#shoufang-table tr').length === 1) {
  4190. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  4191. } else {
  4192. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  4193. }
  4194. $('#shoufangdelete').modal('hide');
  4195. });
  4196. });
  4197. // 切换页数
  4198. $('.shoufang-page-select').on('click', function () {
  4199. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  4200. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  4201. const status = $(this).attr('content');
  4202. if (status === 'pre' && lastPageNum > 1) {
  4203. getShouFangList(lastPageNum-1);
  4204. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4205. getShouFangList(lastPageNum+1);
  4206. }
  4207. });
  4208. // 获取单个收方单附件列表
  4209. $('body').on('click', '.show-shoufang-att', function () {
  4210. const id = parseInt($(this).attr('data-id'));
  4211. let html = '';
  4212. $('#shoufang-flie-list').html(html);
  4213. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  4214. for (const att of result) {
  4215. html += `<tr><td>${att.filename}${att.fileext}</td><td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  4216. `<a href="${att.filepath}" target="_blank"><i class="fa fa-download"></i></a>` + makeDelHtml(att.id) +`</td></tr>`;
  4217. }
  4218. $('#shoufang-flie-list').html(html);
  4219. $('[data-toggle="tooltip"]').tooltip();
  4220. });
  4221. function makeDelHtml(fid) {
  4222. return sfAttDelPower ? '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att text-danger ml-3"><i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4223. }
  4224. });
  4225. // 删除收方单附件
  4226. $('body').on('click', '.del-shoufang-att', function () {
  4227. const id = $(this).data('id');
  4228. const _self = $(this);
  4229. const data = { id };
  4230. const sfid = $(this).data('sfid');
  4231. postData('/wap/shoufang/delfile', data, function (result) {
  4232. _self.parents('tr').remove();
  4233. // 附件个数更新
  4234. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  4235. const sfInfo = _.find(sfData, { id: sfid });
  4236. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  4237. });
  4238. });
  4239. // 定位到对应的清单或计量单元
  4240. $('body').on('click', '.show-shoufang-node', function () {
  4241. const id = parseInt($(this).attr('data-id'));
  4242. const sfInfo = _.find(sfData, { id });
  4243. if (sfInfo) {
  4244. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4245. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  4246. stagePosSpreadObj.loadCurPosData();
  4247. if (sfInfo.pid) {
  4248. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  4249. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  4250. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  4251. }
  4252. }
  4253. });
  4254. // 定位到对应的清单或计量单元
  4255. $('body').on('click', '.show-shoufang-report', function () {
  4256. const id = parseInt($(this).attr('data-id'));
  4257. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  4258. sessionStorage.qrCodePath = qrCodePath;
  4259. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  4260. sessionStorage.req_params = JSON.stringify(req_params);
  4261. sessionStorage.rpt_name = rpt_name;
  4262. window.open('/individualReport/A4');
  4263. });
  4264. });
  4265. function makeOneShouFang(sf) {
  4266. const lData = _.find(ledgerData, { id: sf.lid });
  4267. sf.name = lData.b_code;
  4268. if (sf.pid) {
  4269. const pData = _.find(posData, { id: sf.pid });
  4270. sf.name = lData.b_code + ' / ' + pData.name;
  4271. }
  4272. return sf;
  4273. }
  4274. function makeShouFang() {
  4275. for (const sf of sfData) {
  4276. makeOneShouFang(sf);
  4277. }
  4278. getShouFangList();
  4279. }
  4280. // 生成收方单列表
  4281. function getShouFangList(currPageNum = 1) {
  4282. // 每页最多几个附件
  4283. const pageCount = 15;
  4284. // 附件总数
  4285. const total = sfData.length;
  4286. // 总页数
  4287. const pageNum = Math.ceil(total/pageCount);
  4288. $('#shoufang-totalPage').text(pageNum);
  4289. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  4290. // 当前页附件内容
  4291. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  4292. let html = '';
  4293. for(const att of currPageAttData) {
  4294. html += '<tr><td>' + att.name + '</td>' +
  4295. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  4296. '<td width="100">' +
  4297. '<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> ' +
  4298. '<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> ' +
  4299. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  4300. makeDelHtml(att.id) +
  4301. '</td></tr>';
  4302. }
  4303. function makeDelHtml(id) {
  4304. return cur_uid === stage.user_id ? '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  4305. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4306. }
  4307. $('#shoufang-table').html(html);
  4308. $('[data-toggle="tooltip"]').tooltip();
  4309. }
  4310. function makeReportData(sfid) {
  4311. const sfInfo = _.find(sfData, { id: sfid });
  4312. const ledger_code = sfInfo.name.split(' / ')[0];
  4313. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  4314. const replace_key_params = {
  4315. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  4316. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  4317. 'KEY_合同段': tenderInfo.deal_info.dealName,
  4318. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  4319. 'KEY_编号': '',
  4320. 'KEY_设计工程数量': 0,
  4321. };
  4322. // if (sfInfo.pid) {
  4323. // const pData = _.find(posData, { id: sfInfo.pid });
  4324. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  4325. // } else {
  4326. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4327. // }
  4328. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  4329. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  4330. const req_params = {
  4331. rpt_tpl_id: window.location.host === '127.0.0.1:7002' || window.location.host === 'jlqa.smartcost.com.cn:7002' ? 1784 : 2138, // 1784(qa的,外网是2138)
  4332. pageSize: 'A4',
  4333. project_id: tender.project_id,
  4334. tender_id: tender.id,
  4335. stage_id: stage.id,
  4336. };
  4337. const rpt_name = tender.name + '-第' + stage.order + '期-' + (pos_name ? pos_name : ledger_code + '-' + lData.name);
  4338. const qrCodePath = sfInfo.qrcode;
  4339. return [qrCodePath, replace_key_params, req_params, rpt_name];
  4340. }