stage.js 196 KB

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