stage.js 216 KB

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