stage.js 200 KB

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