stage.js 201 KB

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