change_revise.js 194 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field, converse = false) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return converse ? _.find(exprField, {expr: field}) : _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { enable: 1 },
  39. tp: {
  40. enable: 1,
  41. fields: [
  42. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  43. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  44. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  45. {qty: 'quantity', tp: 'total_price'},
  46. {qty: 'deal_qty', tp: 'deal_tp'},
  47. ],
  48. },
  49. same_code: { enable: 1 },
  50. };
  51. $(document).ready(() => {
  52. let stdXmj, stdGcl, searchLedger;
  53. autoFlashHeight();
  54. billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
  55. if (!billsSpreadSetting.readOnly) {
  56. for (const col of billsSpreadSetting.cols) {
  57. if (!col.readOnly || col.readOnly === false)
  58. col.readOnly = 'readOnly.isChangeAdd';
  59. }
  60. }
  61. posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
  62. if (!posSpreadSetting.readOnly) {
  63. for (const col of posSpreadSetting.cols) {
  64. if (!col.readOnly || col.readOnly === false)
  65. col.readOnly = 'readOnly.isChangeAdd';
  66. }
  67. }
  68. const billsCol = {
  69. readOnly: {
  70. isChangeAdd: function (data) {
  71. return !readOnly && !data.formc;
  72. },
  73. isChangeList: function (data) {
  74. if (!data) return true;
  75. let edit = !readOnly && !(data.is_leaf && data.b_code);
  76. if (!edit && data.id) {
  77. const lPos = pos.getLedgerPos(data.id);
  78. if (lPos && lPos.length > 0) {
  79. edit = true;
  80. }
  81. }
  82. return edit;
  83. }
  84. }
  85. };
  86. const posCol = {
  87. getValue: {
  88. isChange: function (data) {
  89. if (!data) return 0;
  90. if (!data.name) return 0;
  91. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  92. return cInfo ? 1 : 0;
  93. }
  94. },
  95. readOnly: {
  96. isChangeAdd: function (data) {
  97. return !readOnly && !data.formc && (data.settle_status && data.settle_status === settleStatus.finish);
  98. },
  99. isChangeList: function (data) {
  100. if (!data) return true;
  101. // console.log(data.name);
  102. return !readOnly && !data.name;
  103. }
  104. }
  105. };
  106. // 判断是否是已结算清单
  107. function checkIsSettle(data) {
  108. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  109. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  110. return true;
  111. }
  112. return false;
  113. }
  114. // 初始化spread
  115. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  116. const billsSheet = billsSpread.getActiveSheet();
  117. billsSpreadSetting.rowHeader = [
  118. {
  119. rowHeaderType: 'circle',
  120. setting: {
  121. size: 5,
  122. indent: 16,
  123. getColor: function (index, data) {
  124. if (!data) return;
  125. if(!data.formc && !data.cid) return;
  126. return '#dc3545';
  127. }
  128. },
  129. },
  130. ];
  131. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  132. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  133. return spreadColor.stage.settle;
  134. }
  135. if (data && data.is_change) {
  136. return '#c3e6cb';
  137. }
  138. return defaultColor;
  139. };
  140. billsSpreadSetting.localCache = {
  141. key: 'changes-ledger-spread',
  142. colWidth: true,
  143. };
  144. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  145. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  146. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  147. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  148. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  149. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  150. const posSheet = posSpread.getActiveSheet();
  151. posSpreadSetting.rowHeader = [
  152. {
  153. rowHeaderType: 'circle',
  154. setting: {
  155. size: 5,
  156. indent: 16,
  157. getColor: function (index, data) {
  158. if (!data) return;
  159. if(!data.formc) return;
  160. return '#dc3545';
  161. }
  162. },
  163. },
  164. ];
  165. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  166. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  167. return spreadColor.stage.settle;
  168. }
  169. return defaultColor;
  170. };
  171. posSpreadSetting.localCache = {
  172. key: 'changes-pos-spread',
  173. colWidth: true,
  174. };
  175. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  176. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  177. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  178. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  179. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  180. const errorList = $.cs_errorList({
  181. tabSelector: '#error-list-tab',
  182. selector: '#error-list',
  183. relaSpread: billsSpread,
  184. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  185. afterLocated: function () {
  186. posSpreadObj.loadCurPosData();
  187. },
  188. afterShow: function () {
  189. billsSpread.refresh();
  190. if (posSpread) posSpread.refresh();
  191. },
  192. });
  193. const checkList = $.ledger_checkList({
  194. id: 'check-list',
  195. tabSelector: '#check-list-tab',
  196. selector: '#check-list',
  197. relaSpread: billsSpread,
  198. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  199. checkType: getCheckType(checkOption),
  200. afterLocated: function () {
  201. posSpreadObj.loadCurPosData();
  202. },
  203. afterShow: function () {
  204. billsSpread.refresh();
  205. if (posSpread) posSpread.refresh();
  206. },
  207. });
  208. const sumLoadMiss = $.sumLoadMiss({
  209. tabSelector: '#sum-load-miss-tab',
  210. selector: '#sum-load-miss',
  211. relaSpread: billsSpread,
  212. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  213. id: 'revise-slm',
  214. afterLocated: function () {
  215. posSpreadObj.loadCurPosData();
  216. },
  217. afterShow: function () {
  218. billsSpread.refresh();
  219. if (posSpread) posSpread.refresh();
  220. },
  221. });
  222. // 初始化 节点树结构
  223. const treeSetting = {
  224. id: 'ledger_id',
  225. pid: 'ledger_pid',
  226. order: 'order',
  227. level: 'level',
  228. rootId: -1,
  229. keys: ['id', 'tender_id', 'ledger_id'],
  230. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  231. autoExpand: 3,
  232. markExpandKey: 'change-bills-expand',
  233. markExpandSubKey: window.location.pathname.split('/')[2],
  234. };
  235. if (!isTz) {
  236. treeSetting.calcFields.push('deal_tp');
  237. }
  238. treeSetting.calcFun = function (node) {
  239. if (node && node.b_code && isTz) {
  240. const posData = pos.getLedgerPos(node.id) || [];
  241. if (posData.length > 0) {
  242. let sgfh_qty = 0;
  243. let sjcl_qty = 0;
  244. let qtcl_qty = 0;
  245. for (const np of posData) {
  246. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  247. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  248. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  249. }
  250. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  251. node.sgfh_qty = sgfh_qty;
  252. node.sjcl_qty = sjcl_qty;
  253. node.qtcl_qty = qtcl_qty;
  254. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  255. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  256. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  257. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  258. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  259. }
  260. }
  261. }
  262. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  263. };
  264. const billsTree = createNewPathTree('revise', treeSetting);
  265. // 初始化 计量单元
  266. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  267. // 清单 相关方法&绑定spreadjs事件
  268. const billsTreeSpreadObj = {
  269. loadExprToInput(sheet) {
  270. const sel = sheet.getSelections()[0];
  271. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  272. if (col && col.type === 'Number') {
  273. const data = SpreadJsObj.getSelectObject(sheet);
  274. if (data) {
  275. const exprInfo = getExprInfo(col.field);
  276. if (exprInfo) {
  277. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  278. .attr('field', col.field).attr('org', data[col.field]);
  279. } else {
  280. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  281. }
  282. if (col.field.indexOf('dgn') >= 0) {
  283. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  284. } else if (col.field === 'unit_price') {
  285. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  286. } else {
  287. const nodePos = pos.getLedgerPos(data.id);
  288. if (nodePos && nodePos.length > 0) {
  289. $('#bills-expr').val('').attr('readOnly', true);
  290. $('#bills-expr').removeAttr('data-row');
  291. } else {
  292. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  293. }
  294. }
  295. $('#bills-expr').attr('data-row', sel.row);
  296. } else {
  297. $('#bills-expr').val('').attr('readOnly', true);
  298. $('#bills-expr').removeAttr('data-row');
  299. }
  300. } else {
  301. $('#bills-expr').val('').attr('readOnly', true);
  302. $('#bills-expr').removeAttr('data-row');
  303. }
  304. },
  305. getDefaultSelectInfo: function (sheet) {
  306. const tree = sheet.zh_tree;
  307. if (!tree) return;
  308. const sel = sheet.getSelections()[0];
  309. const node = sheet.zh_tree.nodes[sel.row];
  310. if (!node) return;
  311. let count = 1;
  312. if (sel.rowCount > 1) {
  313. for (let r = 1; r < sel.rowCount; r++) {
  314. const rNode = sheet.zh_tree.nodes[sel.row + r];
  315. if (rNode.level > node.level) continue;
  316. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  317. toastr.warning('请选择同一节点下的节点,进行该操作');
  318. return;
  319. }
  320. count += 1;
  321. }
  322. }
  323. return [tree, node, count];
  324. },
  325. /**
  326. * 刷新顶部按钮是否可用
  327. * @param sheet
  328. * @param selections
  329. */
  330. refreshOperationValid: function (sheet, selection) {
  331. const setObjEnable = function (obj, enable) {
  332. if (enable) {
  333. obj.removeClass('disabled');
  334. } else {
  335. obj.addClass('disabled');
  336. }
  337. };
  338. const invalidAll = function () {
  339. setObjEnable($('a[name=base-opr][type=add]'), false);
  340. setObjEnable($('a[name=base-opr][type=delete]'), false);
  341. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  342. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  343. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  344. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  345. };
  346. const sel = selection ? selection[0] : sheet.getSelections()[0];
  347. const row = sel ? sel.row : -1;
  348. const tree = sheet.zh_tree;
  349. if (!tree) {
  350. invalidAll();
  351. return;
  352. }
  353. const first = sheet.zh_tree.nodes[row];
  354. if (!first) {
  355. invalidAll();
  356. return;
  357. }
  358. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  359. if (sel.rowCount > 1 && first) {
  360. for (let r = 1; r < sel.rowCount; r++) {
  361. const rNode = tree.nodes[sel.row + r];
  362. if (!rNode) {
  363. sameParent = false;
  364. break;
  365. }
  366. if (!rNode.formc) {
  367. sameParent = false;
  368. break;
  369. }
  370. nodeUsed = nodeUsed || rNode.used;
  371. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  372. if (rNode.level > first.level) continue;
  373. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  374. sameParent = false;
  375. break;
  376. }
  377. last = rNode;
  378. }
  379. }
  380. const preNode = tree.getPreSiblingNode(first);
  381. const siblings = tree.getChildren(tree.getParent(first));
  382. let upPower = true;
  383. for (let order = last.order; order < siblings.length - 1; order ++) {
  384. if (!siblings[order].formc) {
  385. upPower = false;
  386. break;
  387. }
  388. }
  389. const valid = !sheet.zh_setting.readOnly;
  390. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  391. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  392. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  393. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  394. const posRange = last ? pos.getLedgerPos(last.id) : [];
  395. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  396. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  397. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  398. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  399. && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
  400. setObjEnable($('#cut'), valid);
  401. setObjEnable($('#paste'), valid);
  402. },
  403. /**
  404. *
  405. * @param sheet
  406. * @param data
  407. */
  408. refreshTree: function (sheet, data) {
  409. SpreadJsObj.massOperationSheet(sheet, function () {
  410. const tree = sheet.zh_tree;
  411. // 处理删除
  412. if (data.delete) {
  413. data.delete.sort(function (a, b) {
  414. return b.deleteIndex - a.deleteIndex;
  415. });
  416. for (const d of data.delete) {
  417. sheet.deleteRows(d.deleteIndex, 1);
  418. }
  419. }
  420. // 处理新增
  421. if (data.create) {
  422. const newNodes = data.create;
  423. if (newNodes) {
  424. newNodes.sort(function (a, b) {
  425. return a.index - b.index;
  426. });
  427. for (const node of newNodes) {
  428. sheet.addRows(node.index, 1);
  429. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  430. }
  431. }
  432. }
  433. // 处理更新
  434. if (data.update) {
  435. const rows = [];
  436. for (const u of data.update) {
  437. rows.push(tree.nodes.indexOf(u));
  438. }
  439. SpreadJsObj.reLoadRowsData(sheet, rows);
  440. }
  441. // 处理展开
  442. if (data.expand) {
  443. const expanded = [];
  444. for (const e of data.expand) {
  445. if (expanded.indexOf(e) === -1) {
  446. const posterity = tree.getPosterity(e);
  447. for (const p of posterity) {
  448. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  449. expanded.push(p);
  450. }
  451. }
  452. }
  453. }
  454. });
  455. },
  456. selectionChanged: function (e, info) {
  457. if (info.newSelections) {
  458. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  459. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  460. billsTreeSpreadObj.refreshPosData();
  461. }
  462. }
  463. billsTreeSpreadObj.loadExprToInput(info.sheet);
  464. },
  465. refreshPosData: function() {
  466. SpreadJsObj.resetTopAndSelect(posSheet);
  467. posSpreadObj.loadCurPosData();
  468. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  469. posSearch.search($('#pos-keyword').val());
  470. },
  471. /**
  472. * 新增节点
  473. * @param spread
  474. */
  475. baseOpr: function (sheet, type, addCount = 1) {
  476. const self = this;
  477. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  478. if (!tree || !node || !count) return;
  479. if (type === 'delete') {
  480. const parent = tree.getParent(node);
  481. const children = parent ? parent.children : tree.children;
  482. const index = children.indexOf(node);
  483. for (let i = 0; i < count; i++) {
  484. const child = children[i+index];
  485. if (tree.checkNodeUsed(child, pos)) {
  486. toastr.warning('选中的节点已计量,不可删除');
  487. return;
  488. }
  489. if (child.settle_status === settleStatus.finish) {
  490. toastr.warning('选中的节点已结算,不可删除');
  491. return;
  492. }
  493. }
  494. } else if (type === 'up-level') {
  495. const parent = tree.getParent(node);
  496. const children = parent ? parent.children : tree.children;
  497. const index = children.indexOf(node);
  498. const lastSelect = children[index + count - 1];
  499. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  500. toastr.warning('选中的节点已计量,不可升级');
  501. return;
  502. }
  503. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  504. toastr.warning('选中的节点已结算,不可升级');
  505. return;
  506. }
  507. // for (let i = index; i < children.length; i++) {
  508. // const child = children[index];
  509. // if (tree.checkNodeUsed(child, pos)) {
  510. // if (i >= index + count) {
  511. // toastr.warning('其后节点已计量,选中的节点不可升级');
  512. // } else {
  513. // toastr.warning('选中的节点已计量,不可升级');
  514. // }
  515. // return;
  516. // }
  517. // }
  518. } else if (type === 'down-level') {
  519. const parent = tree.getParent(node);
  520. const children = parent ? parent.children : tree.children;
  521. const index = children.indexOf(node);
  522. if (index > 0 && children[index-1].used) {
  523. toastr.warning('其前节点已计量,选中的节点不可降级');
  524. return;
  525. }
  526. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  527. toastr.warning('其前节点已结算,选中的节点不可降级');
  528. return;
  529. }
  530. for (let i = index; i < count; i++) {
  531. const child = children[i+index];
  532. if (tree.checkNodeUsed(child, pos)) {
  533. toastr.warning('选中的节点已计量,不可降级');
  534. return;
  535. }
  536. if (tree.settle_status === settleStatus.finish) {
  537. toastr.warning('选中的节点已结算,不可降级');
  538. return;
  539. }
  540. }
  541. } else if (type === 'add') {
  542. if (node.settle_status === settleStatus.finish) {
  543. toastr.warning('选中的节点已结算,不可新增子项');
  544. return;
  545. }
  546. }
  547. if (type === 'delete') {
  548. deleteAfterHint(function () {
  549. postData(window.location.pathname + '/update', {
  550. postType: type,
  551. postData: {
  552. id: node.ledger_id,
  553. count: type === 'add' ? addCount : count,
  554. }
  555. }, function (result) {
  556. const refreshData = tree.loadPostData(result);
  557. self.refreshTree(sheet, refreshData);
  558. const sel = sheet.getSelections()[0];
  559. if (sel) {
  560. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  561. billsTreeSpreadObj.refreshPosData();
  562. }
  563. self.refreshOperationValid(sheet);
  564. });
  565. });
  566. } else {
  567. postData(window.location.pathname + '/update', {
  568. postType: type,
  569. postData: {
  570. id: node.ledger_id,
  571. count: type === 'add' ? addCount : count,
  572. }
  573. }, function (result) {
  574. const refreshData = tree.loadPostData(result);
  575. self.refreshTree(sheet, refreshData);
  576. if (['up-move', 'down-move'].indexOf(type) > -1) {
  577. const sel = sheet.getSelections()[0];
  578. if (sel) {
  579. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  580. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  581. }
  582. } else if (type === 'add') {
  583. const sel = sheet.getSelections()[0];
  584. if (sel) {
  585. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  586. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  587. billsTreeSpreadObj.refreshPosData();
  588. }
  589. }
  590. self.refreshOperationValid(sheet);
  591. });
  592. }
  593. },
  594. buttonClicked: function (e, info, v) {
  595. if (info.sheet.zh_setting) {
  596. const select = SpreadJsObj.getSelectObject(info.sheet);
  597. const col = info.sheet.zh_setting.cols[info.col];
  598. if (col.field === 'is_change') {
  599. if (billsCol.readOnly.isChangeList(select)) {
  600. return
  601. }
  602. if (info.sheet.isEditing()) {
  603. info.sheet.endEdit(true);
  604. }
  605. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  606. if (is_change) {
  607. makeGclGatherData();
  608. const gclInfo = _.find(gclGatherData, function (item) {
  609. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  610. });
  611. const xmjInfo = gclInfo.leafXmjs[0];
  612. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  613. const data = {
  614. lid: select.id,
  615. code: gclInfo.b_code,
  616. name: gclInfo.name,
  617. unit: gclInfo.unit,
  618. unit_price: gclInfo.unit_price,
  619. oamount: xmjInfo.quantity,
  620. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  621. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  622. xmj_code: xmjInfo.code || '',
  623. xmj_jldy: xmjInfo.jldy || '',
  624. xmj_dwgc: xmjInfo.dwgc || '',
  625. xmj_fbgc: xmjInfo.fbgc || '',
  626. xmj_fxgc: xmjInfo.fxgc || '',
  627. gcl_id: select.id,
  628. mx_id: '',
  629. };
  630. if (oldCInfo) {
  631. data.detail = oldCInfo.detail;
  632. data.camount = oldCInfo.camount;
  633. data.spamount = oldCInfo.spamount;
  634. data.is_valuation = oldCInfo.is_valuation;
  635. data.delimit = oldCInfo.delimit;
  636. }
  637. // 更新至服务器
  638. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  639. changeList = result.changeList;
  640. select.is_change = 1;
  641. }, function () {
  642. info.sheet.setValue(info.row, info.col, 0);
  643. });
  644. console.log(data);
  645. } else {
  646. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
  647. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  648. info.sheet.setValue(info.row, info.col, 1);
  649. return
  650. }
  651. const cInfo = _.find(changeList, { gcl_id: select.id });
  652. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  653. toastr.warning('该清单计量单元已被使用,无法取消勾选');
  654. info.sheet.setValue(info.row, info.col, 1);
  655. return
  656. } else if (checkIsSettle(cInfo)) {
  657. toastr.warning('该清单计量单元已结算,无法取消勾选');
  658. info.sheet.setValue(info.row, info.col, 1);
  659. return
  660. } else {
  661. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  662. changeList = result.changeList;
  663. select.is_change = 0;
  664. }, function () {
  665. info.sheet.setValue(info.row, info.col, 1);
  666. });
  667. }
  668. }
  669. }
  670. }
  671. },
  672. /**
  673. * 编辑单元格响应事件
  674. * @param {Object} e
  675. * @param {Object} info
  676. */
  677. editEnded: function (e, info) {
  678. if (info.sheet.zh_setting) {
  679. const col = info.sheet.zh_setting.cols[info.col];
  680. if (col.field === 'is_change') {
  681. return;
  682. }
  683. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  684. const node = sortData[info.row];
  685. const data = {
  686. id: node.id,
  687. tender_id: node.tender_id,
  688. ledger_id: node.ledger_id
  689. };
  690. // 未改变值则不提交
  691. const orgValue = node[col.field];
  692. const newValue = trimInvalidChar(info.editingText);
  693. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  694. return;
  695. }
  696. // 台账模式,检查计量单元相关
  697. if (isTz) {
  698. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  699. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  700. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  701. if (!node.children || node.children.length ===0) {
  702. const lPos = pos.getLedgerPos(node.id);
  703. if (lPos && lPos.length > 0) {
  704. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  705. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  706. return;
  707. }
  708. }
  709. }
  710. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  711. const lPos = pos.getLedgerPos(node.id);
  712. if (lPos && lPos.length > 0) {
  713. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  714. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  715. return;
  716. }
  717. }
  718. }
  719. // 获取更新数据
  720. const exprInfo = getExprInfo(col.field);
  721. if (info.editingText) {
  722. const text = newValue;
  723. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  724. toastr.error('节点已计量,请勿删除编号');
  725. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  726. return;
  727. }
  728. if (col.type === 'Number') {
  729. const num = _.toNumber(text);
  730. if (_.isFinite(num)) {
  731. data[col.field] = num;
  732. if (exprInfo) {
  733. data[exprInfo.expr] = '';
  734. }
  735. } else {
  736. try {
  737. data[col.field] = math.evaluate(transExpr(text));
  738. if (exprInfo) {
  739. data[exprInfo.expr] = newValue;
  740. }
  741. } catch(err) {
  742. toastr.error('输入的表达式非法');
  743. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  744. return;
  745. }
  746. }
  747. } else {
  748. data[col.field] = text;
  749. }
  750. } else {
  751. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  752. toastr.error('节点已计量,请勿删除编号');
  753. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  754. return;
  755. }
  756. data[col.field] = null;
  757. if (exprInfo) {
  758. data[exprInfo.expr] = '';
  759. }
  760. }
  761. if (col.field === 'b_code' && newValue) {
  762. const ledgerData = _.filter(billsTree.nodes, function (item) {
  763. return item.b_code !== null && item.b_code !== '' && !item.formc;
  764. });
  765. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  766. if (ledgerOneData) {
  767. data.name = ledgerOneData.name;
  768. data.unit = ledgerOneData.unit;
  769. data.unit_price = ledgerOneData.unit_price;
  770. }
  771. }
  772. // 更新至服务器
  773. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  774. const refreshNode = billsTree.loadPostData(result);
  775. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  776. });
  777. }
  778. },
  779. clipboardPasting: function (e, info) {
  780. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  781. info.cancel = true;
  782. if (!setting || !tree) return;
  783. // const range = info.cellRange;
  784. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  785. // const node = tree.nodes[iRow];
  786. // if (tree.checkNodeUsed(node, pos)) {
  787. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  788. // return;
  789. // }
  790. // }
  791. const pasteData = info.pasteData.html
  792. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  793. : (info.pasteData.text === ''
  794. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  795. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  796. const hint = {
  797. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  798. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  799. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  800. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  801. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  802. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  803. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  804. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  805. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  806. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  807. };
  808. const datas = [], filterNodes = [];
  809. let pid, level, filterRow = 0;
  810. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  811. const curRow = info.cellRange.row + iRow;
  812. const node = tree.nodes[curRow];
  813. if (!node) continue;
  814. if (!pid) pid = node.ledger_pid;
  815. if (!level) level = node.level;
  816. // if (node.ledger_pid !== pid) {
  817. // toastMessageUniq(hint.sameParent);
  818. // filterRow+=1;
  819. // continue;
  820. // }
  821. if (node.level < level) break;
  822. let bPaste = false;
  823. const data = info.sheet.zh_tree.getNodeKeyData(node);
  824. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  825. const curCol = info.cellRange.col + iCol;
  826. const colSetting = info.sheet.zh_setting.cols[curCol];
  827. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  828. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  829. toastMessageUniq(hint.parent);
  830. continue;
  831. }
  832. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  833. toastMessageUniq(hint.gcl);
  834. continue;
  835. }
  836. const lPos = pos.getLedgerPos(node.id);
  837. if (lPos && lPos.length > 0) {
  838. if (value === '' && colSetting.field === 'b_code') {
  839. toastMessageUniq(hint.posCode);
  840. continue;
  841. }
  842. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  843. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  844. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  845. toastMessageUniq(hint.posQty);
  846. continue;
  847. }
  848. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  849. toastMessageUniq(hint.posXmj);
  850. continue;
  851. }
  852. }
  853. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  854. toastMessageUniq (hint.usedUp);
  855. continue;
  856. }
  857. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  858. toastMessageUniq(hint.settle);
  859. continue;
  860. }
  861. if (colSetting.type === 'Number') {
  862. const num = _.toNumber(value);
  863. if (num) {
  864. data[colSetting.field] = num;
  865. } else {
  866. try {
  867. data[colSetting.field] = math.evaluate(transExpr(value));
  868. const exprInfo = getExprInfo(colSetting.field);
  869. if (exprInfo) {
  870. data[exprInfo.expr] = value;
  871. }
  872. bPaste = true;
  873. } catch (err) {
  874. toastMessageUniq(hint.invalidExpr);
  875. continue;
  876. }
  877. }
  878. } else {
  879. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  880. && data[colSetting.field] !== '' && value === '') {
  881. toastMessageUniq(hint.usedCode);
  882. continue;
  883. }
  884. data[colSetting.field] = value;
  885. }
  886. if (colSetting.field === 'b_code' && value) {
  887. const ledgerData = _.filter(billsTree.nodes, function (item) {
  888. return item.b_code !== null && item.b_code !== '' && !item.formc;
  889. });
  890. const ledgerOneData = _.find(ledgerData, { b_code: value });
  891. if (ledgerOneData) {
  892. data.name = ledgerOneData.name;
  893. data.unit = ledgerOneData.unit;
  894. data.unit_price = ledgerOneData.unit_price;
  895. }
  896. }
  897. bPaste = true;
  898. }
  899. if (bPaste) {
  900. datas.push(data);
  901. } else {
  902. filterNodes.push(node);
  903. }
  904. }
  905. if (datas.length > 0) {
  906. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  907. const refreshNode = tree.loadPostData(result);
  908. if (refreshNode.update) {
  909. refreshNode.update = refreshNode.update.concat(filterNodes);
  910. }
  911. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  912. }, function () {
  913. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  914. });
  915. } else {
  916. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  917. }
  918. },
  919. clipboardPasted: function (e, info) {
  920. const hint = {
  921. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  922. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  923. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  924. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  925. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  926. };
  927. const tree = info.sheet.zh_tree;
  928. if (!tree) { return; }
  929. const sortData = info.sheet.zh_tree.nodes;
  930. const datas = [], filterNodes = [];
  931. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  932. let bPaste = false;
  933. const curRow = info.cellRange.row + iRow;
  934. const node = sortData[curRow];
  935. if (node) {
  936. const data = info.sheet.zh_tree.getNodeKeyData(node);
  937. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  938. const curCol = info.cellRange.col + iCol;
  939. const colSetting = info.sheet.zh_setting.cols[curCol];
  940. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  941. const lPos = pos.getLedgerPos(node.id);
  942. if (lPos && lPos.length > 0) {
  943. if (value === '' && colSetting.field === 'b_code') {
  944. toastMessageUniq(hint.posCode);
  945. continue;
  946. }
  947. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  948. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  949. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  950. toastMessageUniq(hint.posQty);
  951. continue;
  952. }
  953. }
  954. if (node.used && colSetting.field === 'unit_price') {
  955. toastMessageUniq (hint.usedUp);
  956. continue;
  957. }
  958. if (colSetting.type === 'Number') {
  959. const num = _.toNumber(value);
  960. if (num) {
  961. data[colSetting.field] = num;
  962. } else {
  963. try {
  964. data[colSetting.field] = math.evaluate(transExpr(value));
  965. } catch (err) {
  966. toastMessageUniq(hint.invalidExpr);
  967. continue;
  968. }
  969. }
  970. } else {
  971. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  972. && data[colSetting.field] !== '' && value === '') {
  973. toastMessageUniq(hint.usedCode);
  974. continue;
  975. }
  976. data[colSetting.field] = value;
  977. }
  978. if (colSetting.field === 'b_code' && value) {
  979. const ledgerData = _.filter(billsTree.nodes, function (item) {
  980. return item.b_code !== null && item.b_code !== '' && !item.formc;
  981. });
  982. const ledgerOneData = _.find(ledgerData, { b_code: value });
  983. if (ledgerOneData) {
  984. data.name = ledgerOneData.name;
  985. data.unit = ledgerOneData.unit;
  986. data.unit_price = ledgerOneData.unit_price;
  987. }
  988. }
  989. bPaste = true;
  990. }
  991. if (bPaste) {
  992. datas.push(data);
  993. } else {
  994. filterNodes.push(node);
  995. }
  996. }
  997. }
  998. if (datas.length > 0) {
  999. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1000. const refreshNode = tree.loadPostData(result);
  1001. if (refreshNode.update) {
  1002. refreshNode.update = refreshNode.update.concat(filterNodes);
  1003. }
  1004. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1005. }, function () {
  1006. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1007. });
  1008. } else {
  1009. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1010. }
  1011. },
  1012. deletePress: function (sheet) {
  1013. if (!sheet.zh_setting) return;
  1014. const sel = sheet.getSelections()[0], datas = [];
  1015. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1016. let bDel = false;
  1017. const node = sheet.zh_tree.nodes[iRow];
  1018. const data = sheet.zh_tree.getNodeKeyData(node);
  1019. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1020. const col = sheet.zh_setting.cols[iCol];
  1021. const style = sheet.getStyle(iRow, iCol);
  1022. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  1023. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  1024. if (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  1025. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  1026. return;
  1027. }
  1028. data[col.field] = null;
  1029. const exprInfo = getExprInfo(col.field);
  1030. if (exprInfo) {
  1031. data[exprInfo.expr] = '';
  1032. }
  1033. bDel = true;
  1034. }
  1035. if (bDel) datas.push(data);
  1036. }
  1037. if (datas.length > 0) {
  1038. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1039. const refreshNode = sheet.zh_tree.loadPostData(result);
  1040. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1041. billsTreeSpreadObj.loadExprToInput(sheet);
  1042. });
  1043. }
  1044. },
  1045. pasteBlock: function (spread, copyInfo) {
  1046. const self = this;
  1047. const sheet = spread.getActiveSheet();
  1048. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  1049. if (node.settle_status === settleStatus.finish) {
  1050. toastr.warning('选中的节点已结算,不可粘贴整块');
  1051. return;
  1052. }
  1053. postData(window.location.pathname + '/update', {
  1054. postType: 'paste-block',
  1055. postData: {
  1056. id: tree.getNodeKey(node),
  1057. tid: copyInfo.tid,
  1058. block: copyInfo.block,
  1059. }
  1060. }, function (data) {
  1061. pos.updateDatas(data.pos);
  1062. const result = tree.loadPostData(data.ledger);
  1063. self.refreshTree(sheet, result);
  1064. const sel = sheet.getSelections()[0];
  1065. if (sel) {
  1066. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  1067. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  1068. }
  1069. self.refreshOperationValid(sheet);
  1070. removeLocalCache(copyBlockTag);
  1071. }, null, true);
  1072. },
  1073. topRowChanged: function (e, info) {
  1074. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1075. },
  1076. editStarting(e, info) {
  1077. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1078. const col = info.sheet.zh_setting.cols[info.col];
  1079. const node = info.sheet.zh_tree.nodes[info.row];
  1080. if (!node) {
  1081. info.cancel = true;
  1082. return;
  1083. }
  1084. const exprInfo = getExprInfo(col.field);
  1085. if (exprInfo) {
  1086. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1087. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1088. }
  1089. }
  1090. switch (col.field) {
  1091. case 'code':
  1092. const posRange = pos.getLedgerPos(node.id);
  1093. info.cancel = posRange && posRange.length > 0;
  1094. break;
  1095. case 'unit_price':
  1096. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  1097. break;
  1098. case 'sgfh_qty':
  1099. case 'sgfh_tp':
  1100. case 'sjcl_qty':
  1101. case 'sjcl_tp':
  1102. case 'qtcl_qty':
  1103. case 'qtcl_tp':
  1104. case 'deal_qty':
  1105. case 'deal_tp':
  1106. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  1107. break;
  1108. case 'dgn_qty1':
  1109. case 'dgn_qty2':
  1110. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  1111. break;
  1112. }
  1113. },
  1114. cut: function (sheet, sel, callback) {
  1115. if (!sheet || !sel) return;
  1116. if (sel.colCount >= sheet.zh_setting.cols.length) {
  1117. toastr.warning('请勿选中整行剪切');
  1118. return;
  1119. }
  1120. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1121. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1122. const node = sortData[iRow];
  1123. if (node) {
  1124. const data = sheet.zh_tree.getNodeKeyData(node);
  1125. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1126. const col = sheet.zh_setting.cols[iCol];
  1127. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1128. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1129. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  1130. const lPos = pos.getLedgerPos(node.id);
  1131. if (lPos && lPos.length > 0) {
  1132. toastr.error('不可剪切');
  1133. return;
  1134. }
  1135. }
  1136. const style = sheet.getStyle(iRow, iCol);
  1137. if (style.locked) {
  1138. toastr.error('不可剪切');
  1139. return;
  1140. }
  1141. const colSetting = sheet.zh_setting.cols[iCol];
  1142. data[colSetting.field] = null;
  1143. const exprInfo = getExprInfo(colSetting.field);
  1144. if (exprInfo) {
  1145. data[exprInfo.expr] = '';
  1146. }
  1147. }
  1148. datas.push(data);
  1149. }
  1150. }
  1151. if (datas.length > 0) {
  1152. callback();
  1153. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1154. const refreshNode = sheet.zh_tree.loadPostData(result);
  1155. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1156. });
  1157. }
  1158. },
  1159. sortCode: function (sheet) {
  1160. const tree = sheet.zh_tree;
  1161. if (!tree) return;
  1162. const select = SpreadJsObj.getSelectObject(sheet);
  1163. if (!select || !select.code || select.code === '') return;
  1164. const recursiveSortCode = function (data, parentCode, children) {
  1165. if (!children || children.length === 0) return;
  1166. for (const [i, child] of children.entries()) {
  1167. if (!child.b_code || child.b_code === '') {
  1168. const code = parentCode + '-' + (i + 1);
  1169. const cData = tree.getNodeKeyData(child);
  1170. cData.code = code;
  1171. data.push(cData);
  1172. if (!tree.isLeafXmj(child)) {
  1173. recursiveSortCode(data, code, child.children);
  1174. }
  1175. }
  1176. }
  1177. };
  1178. const data = [];
  1179. recursiveSortCode(data, select.code, select.children);
  1180. if (data.length > 0) {
  1181. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1182. const refreshNode = tree.loadPostData(result);
  1183. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1184. })
  1185. }
  1186. }
  1187. };
  1188. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1189. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1190. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1191. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1192. if (!readOnly) {
  1193. // 增删上下移升降级
  1194. $('a[name="base-opr"]').click(function () {
  1195. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1196. });
  1197. $('a[name=cpc]').click(function () {
  1198. billsSpread.commandManager().execute({
  1199. cmd: this.getAttribute('type'),
  1200. sheetName: billsSheet.name()
  1201. });
  1202. });
  1203. $('#bills-expr').bind('change onblur', function () {
  1204. if (this.readOnly) return;
  1205. const expr = $(this);
  1206. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1207. const select = billsTree.getItemsByIndex(row);
  1208. if (!select) return;
  1209. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1210. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1211. const data = {
  1212. id: select.id,
  1213. tender_id: select.tender_id,
  1214. ledger_id: select.ledger_id
  1215. };
  1216. const exprInfo = getExprInfo(field);
  1217. if (newValue !== '') {
  1218. const num = _.toNumber(newValue);
  1219. if (num) {
  1220. data[field] = num;
  1221. if (exprInfo) {
  1222. data[exprInfo.expr] = '';
  1223. }
  1224. } else {
  1225. try {
  1226. data[field] = math.evaluate(transExpr(newValue));
  1227. if (exprInfo) {
  1228. data[exprInfo.expr] = newValue;
  1229. }
  1230. } catch (err) {
  1231. toastr.error('输入的表达式非法');
  1232. return;
  1233. }
  1234. }
  1235. } else {
  1236. data[field] = null;
  1237. if (exprInfo) {
  1238. data[exprInfo.expr] = '';
  1239. }
  1240. }
  1241. // 更新至服务器
  1242. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1243. const refreshNode = billsTree.loadPostData(result);
  1244. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1245. });
  1246. });
  1247. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  1248. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  1249. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  1250. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  1251. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1252. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1253. SpreadJsObj.Clipboard.setCopyData(copyText);
  1254. });
  1255. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  1256. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  1257. }
  1258. // 右键菜单
  1259. let batchInsertObj;
  1260. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1261. const self = this;
  1262. if ($.isFunction(item.icon)) {
  1263. item._icon = item.icon.call(this, this, $t, key, item);
  1264. } else {
  1265. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1266. // to enable font awesome
  1267. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1268. } else {
  1269. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1270. }
  1271. }
  1272. this.addClass(item._icon);
  1273. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  1274. .appendTo(this);
  1275. const $input = $obj.find('input');
  1276. const event = () => {
  1277. if (self.hasClass('context-menu-disabled')) return;
  1278. item.batchInsert($input[0], root);
  1279. };
  1280. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1281. $input.click((e) => {e.stopPropagation();})
  1282. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1283. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1284. };
  1285. const billsContextMenuOptions = {
  1286. selector: '#bills-spread',
  1287. build: function ($trigger, e) {
  1288. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  1289. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1290. },
  1291. items: {}
  1292. };
  1293. if (!readOnly) {
  1294. billsContextMenuOptions.items.create = {
  1295. name: '新增',
  1296. icon: 'fa-sign-in',
  1297. callback: function (key, opt) {
  1298. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  1299. },
  1300. disabled: function (key, opt) {
  1301. const sheet = billsSheet;
  1302. const selection = sheet.getSelections();
  1303. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1304. const row = sel ? sel.row : -1;
  1305. const tree = sheet.zh_tree;
  1306. if (!tree) return true;
  1307. const first = sheet.zh_tree.nodes[row];
  1308. const valid = !sheet.zh_setting.readOnly;
  1309. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1310. }
  1311. };
  1312. billsContextMenuOptions.items.delete = {
  1313. name: '删除',
  1314. icon: 'fa-remove',
  1315. callback: function (key, opt) {
  1316. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  1317. },
  1318. disabled: function (key, opt) {
  1319. const sheet = billsSheet;
  1320. const selection = sheet.getSelections();
  1321. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1322. const row = sel ? sel.row : -1;
  1323. const tree = sheet.zh_tree;
  1324. if (!tree) return true;
  1325. const first = sheet.zh_tree.nodes[row];
  1326. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  1327. if (sel.rowCount > 1 && first) {
  1328. for (let r = 1; r < sel.rowCount; r++) {
  1329. const rNode = tree.nodes[sel.row + r];
  1330. if (!rNode) {
  1331. sameParent = false;
  1332. break;
  1333. }
  1334. if (!rNode.formc) {
  1335. return true;
  1336. }
  1337. nodeUsed = nodeUsed || rNode.used;
  1338. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  1339. if (rNode.level > first.level) continue;
  1340. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1341. sameParent = false;
  1342. break;
  1343. }
  1344. last = rNode;
  1345. }
  1346. }
  1347. const valid = !sheet.zh_setting.readOnly;
  1348. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  1349. }
  1350. };
  1351. billsContextMenuOptions.items.sprBase = '----';
  1352. }
  1353. billsContextMenuOptions.items.copyBlock = {
  1354. name: '复制整块',
  1355. icon: 'fa-files-o',
  1356. callback: function (key, opt) {
  1357. const copyBlockList = [];
  1358. const sheet = billsSheet;
  1359. const sel = sheet.getSelections()[0];
  1360. let iRow = sel.row;
  1361. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1362. while (iRow < sel.row + sel.rowCount) {
  1363. const node = sheet.zh_tree.nodes[iRow];
  1364. if (node.ledger_pid !== pid) {
  1365. toastr.error('仅可同时选中同层节点');
  1366. return;
  1367. }
  1368. const posterity = sheet.zh_tree.getPosterity(node);
  1369. iRow += posterity.length + 1;
  1370. posterity.unshift(node);
  1371. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1372. }
  1373. for (const cbl of copyBlockList) {
  1374. for (const b of cbl) {
  1375. const posRange = pos.getLedgerPos(b.id);
  1376. if (posRange && posRange.length > 0) b.pos = posRange;
  1377. }
  1378. }
  1379. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1380. },
  1381. visible: function (key, opt) {
  1382. const sheet = billsSheet;
  1383. const selection = sheet.getSelections();
  1384. const row = selection[0].row;
  1385. const select = billsTree.nodes[row];
  1386. return select;
  1387. },
  1388. disabled: function (key, opt) {
  1389. const sheet = billsSheet;
  1390. const selection = sheet.getSelections();
  1391. const row = selection[0].row;
  1392. const select = billsTree.nodes[row];
  1393. return select && select.level <= 1;
  1394. }
  1395. };
  1396. billsContextMenuOptions.items.copyBlockXmj = {
  1397. name: '复制整块(只复制项目节)',
  1398. icon: 'fa-files-o',
  1399. callback: function (key, opt) {
  1400. const copyBlockList = [];
  1401. const sheet = billsSheet;
  1402. const sel = sheet.getSelections()[0];
  1403. let iRow = sel.row;
  1404. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1405. while (iRow < sel.row + sel.rowCount) {
  1406. const node = sheet.zh_tree.nodes[iRow];
  1407. if (node.ledger_pid !== pid) {
  1408. toastr.error('仅可同时选中同层节点');
  1409. return;
  1410. }
  1411. const posterity = sheet.zh_tree.getPosterity(node);
  1412. iRow += posterity.length + 1;
  1413. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1414. copyPosterity.unshift(node);
  1415. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1416. for (const p of copyData) {
  1417. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1418. p.is_leaf = children.length === 0;
  1419. }
  1420. copyBlockList.push(copyData);
  1421. }
  1422. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1423. },
  1424. visible: function (key, opt) {
  1425. const sheet = billsSheet;
  1426. const selection = sheet.getSelections();
  1427. const row = selection[0].row;
  1428. const select = billsTree.nodes[row];
  1429. return select;
  1430. },
  1431. disabled: function (key, opt) {
  1432. const sheet = billsSheet;
  1433. const selection = sheet.getSelections();
  1434. const row = selection[0].row;
  1435. const select = billsTree.nodes[row];
  1436. return select && select.level <= 1;
  1437. }
  1438. };
  1439. if (!readOnly) {
  1440. billsContextMenuOptions.items.pasteBlock = {
  1441. name: '粘贴整块',
  1442. icon: 'fa-clipboard',
  1443. disabled: function (key, opt) {
  1444. //const block = treeOperationObj.block || [];
  1445. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1446. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1447. },
  1448. callback: function (key, opt) {
  1449. //const block = treeOperationObj.block || [];
  1450. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1451. if (copyInfo.block.length > 0) {
  1452. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1453. } else {
  1454. document.execCommand('paste');
  1455. }
  1456. },
  1457. visible: function (key, opt) {
  1458. return !readOnly;
  1459. }
  1460. };
  1461. billsContextMenuOptions.items.sprBlock = '----';
  1462. }
  1463. if (!readOnly) {
  1464. billsContextMenuOptions.items.batchInsert = {
  1465. name: '批量插入',
  1466. type: 'batchInsert',
  1467. value: '2',
  1468. icon: 'fa-sign-in',
  1469. batchInsert: function (obj, root) {
  1470. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1471. obj.value = obj.max;
  1472. toastr.warning('批量插入不可多于' + obj.max);
  1473. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1474. obj.value = obj.min;
  1475. toastr.warning('批量插入不可少于' + obj.min);
  1476. } else {
  1477. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1478. root.$menu.trigger('contextmenu:hide');
  1479. }
  1480. },
  1481. disabled: function (key, opt) {
  1482. const sheet = billsSheet;
  1483. const selection = sheet.getSelections();
  1484. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1485. const row = sel ? sel.row : -1;
  1486. const tree = sheet.zh_tree;
  1487. if (!tree) return true;
  1488. const first = sheet.zh_tree.nodes[row];
  1489. const valid = !sheet.zh_setting.readOnly;
  1490. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1491. }
  1492. };
  1493. billsContextMenuOptions.items.batchInsertBillsPos = {
  1494. name: '批量插入清单-计量单元',
  1495. icon: 'fa-sign-in',
  1496. visible: function (key, opt) {
  1497. return false;
  1498. },
  1499. disabled: function (key, opt) {
  1500. if (!isTz) return true;
  1501. const select = SpreadJsObj.getSelectObject(billsSheet);
  1502. if (select) {
  1503. if (select.code && select.code !== '') {
  1504. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  1505. } else {
  1506. const parent = billsTree.getParent(select);
  1507. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  1508. }
  1509. } else {
  1510. return false;
  1511. }
  1512. },
  1513. callback: function (key, opt) {
  1514. if (!batchInsertObj) {
  1515. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1516. } else {
  1517. batchInsertObj.initView();
  1518. }
  1519. $('#batch').modal('show');
  1520. }
  1521. };
  1522. }
  1523. billsContextMenuOptions.items.sprTag = '----';
  1524. billsContextMenuOptions.items.showLast = {
  1525. name: '显示至最底层',
  1526. callback: function (key, opt, menu, e) {
  1527. const node = SpreadJsObj.getSelectObject(billsSheet);
  1528. setTimeout(() => {
  1529. showWaitingView();
  1530. billsTree.expandByCustom(x => {
  1531. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1532. });
  1533. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  1534. closeWaitingView();
  1535. }, 100);
  1536. },
  1537. };
  1538. $.contextMenu(billsContextMenuOptions);
  1539. // 计量单元 相关方法&绑定spreadjs事件
  1540. const posSpreadObj = {
  1541. refreshOperationValid: function (sheet, selection) {
  1542. const setObjEnable = function (obj, enable) {
  1543. if (enable) {
  1544. obj.removeClass('disabled');
  1545. } else {
  1546. obj.addClass('disabled');
  1547. }
  1548. };
  1549. const invalidAll = function () {
  1550. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1551. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1552. };
  1553. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1554. const row = sel ? sel.row : -1;
  1555. const first = sheet.zh_data[row];
  1556. if (!first) {
  1557. invalidAll();
  1558. return;
  1559. }
  1560. let last = first;
  1561. if (sel.rowCount > 1 && first) {
  1562. for (let r = 1; r < sel.rowCount; r++) {
  1563. const rNode = sheet.zh_data[sel.row + r];
  1564. if (!rNode) break;
  1565. last = rNode;
  1566. }
  1567. }
  1568. const preNode = sheet.zh_data[row - 1];
  1569. const valid = !sheet.zh_setting.readOnly;
  1570. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  1571. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  1572. },
  1573. loadExprToInput: function () {
  1574. const sel = posSheet.getSelections()[0];
  1575. if (!sel) return;
  1576. const col = posSheet.zh_setting.cols[sel.col];
  1577. const cell = posSheet.getCell(sel.col, sel.col);
  1578. if (col && col.type === 'Number') {
  1579. const data = SpreadJsObj.getSelectObject(posSheet);
  1580. if (data) {
  1581. const exprInfo = getExprInfo(col.field);
  1582. const value = exprInfo
  1583. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1584. : data[col.field];
  1585. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1586. .attr('readOnly', readOnly || (!data.formc && cell.locked()) || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  1587. } else {
  1588. $('#pos-expr').val('').attr('readOnly', true);
  1589. $('#pos-expr').removeAttr('data-row');
  1590. }
  1591. } else {
  1592. $('#pos-expr').val('').attr('readOnly', true);
  1593. $('#pos-expr').removeAttr('data-row');
  1594. }
  1595. },
  1596. /**
  1597. * 加载计量单元 根据当前台账选择节点
  1598. */
  1599. loadCurPosData: function () {
  1600. const node = SpreadJsObj.getSelectObject(billsSheet);
  1601. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  1602. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  1603. if (node) {
  1604. const posData = pos.getLedgerPos(node.id) || [];
  1605. console.log(posData);
  1606. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1607. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  1608. } else {
  1609. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1610. posSheet.zh_setting.readOnly = true;
  1611. }
  1612. SpreadJsObj.massOperationSheet(posSheet, function () {
  1613. if (posSheet.zh_setting) {
  1614. posSheet.zh_setting.cols.forEach(function (col, i) {
  1615. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  1616. if (i !== 0) {
  1617. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  1618. } else {
  1619. let lock = false;
  1620. if (!posSheet.zh_data[iRow]) {
  1621. lock = true;
  1622. }
  1623. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  1624. }
  1625. }
  1626. });
  1627. }
  1628. });
  1629. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  1630. posSpreadObj.loadExprToInput();
  1631. posSpreadObj.refreshOperationValid(posSheet);
  1632. },
  1633. baseOpr: function (sheet, type) {
  1634. const data = {
  1635. postType: 'pos',
  1636. posPostType: type === 'delete' ? type : 'update',
  1637. postData: [],
  1638. };
  1639. const selection = sheet.getSelections();
  1640. const row = selection[0].row, count = selection[0].rowCount;
  1641. const first = sheet.zh_data[row];
  1642. if (type === 'delete') {
  1643. for (let iRow = 0; iRow < count; iRow++) {
  1644. const posData = sheet.zh_data[iRow + row];
  1645. if (posData) {
  1646. if (posData.used) {
  1647. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1648. return;
  1649. }
  1650. if (posData.settle_status) {
  1651. toastr.error('"' + posData.name + '"已结算,请勿删除');
  1652. return;
  1653. }
  1654. data.postData.push(sheet.zh_data[iRow + row].id);
  1655. }
  1656. }
  1657. } else if (type === 'up-move') {
  1658. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1659. for (let iRow = 0; iRow < count; iRow++) {
  1660. const posData = sheet.zh_data[iRow + row];
  1661. if (posData) {
  1662. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1663. preUpdate.porder = posData.porder;
  1664. }
  1665. }
  1666. data.postData.push(preUpdate);
  1667. } else if (type === 'down-move') {
  1668. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1669. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1670. const posData = sheet.zh_data[iRow + row];
  1671. if (posData) {
  1672. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1673. nextUpdate.porder = posData.porder;
  1674. }
  1675. }
  1676. data.postData.push(nextUpdate);
  1677. } else if (type === 'add') {
  1678. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1679. if (billsNode.settle_status === settleStatus.finish) {
  1680. toastr.warning('清单已结算,不可新增计量单元');
  1681. return;
  1682. }
  1683. }
  1684. if (data.postData.length > 0) {
  1685. postData(window.location.pathname + '/update', data, function (result) {
  1686. if (type === 'delete') {
  1687. pos.removeDatas(result.pos);
  1688. sheet.deleteRows(row, count);
  1689. const loadResult = billsTree.loadPostData(result.ledger);
  1690. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1691. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1692. posSpreadObj.refreshOperationValid(posSheet);
  1693. } else {
  1694. pos.updateDatas(result.pos);
  1695. const sel = selection[0];
  1696. if (sel) {
  1697. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1698. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1699. }
  1700. posSpreadObj.loadCurPosData();
  1701. }
  1702. });
  1703. }
  1704. },
  1705. editStarting: function (e, info) {
  1706. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1707. const sel = info.sheet.getSelections();
  1708. if (!sel || !sel[0]) return;
  1709. const col = info.sheet.zh_setting.cols[sel[0].col];
  1710. const node = SpreadJsObj.getSelectObject(info.sheet);
  1711. const exprInfo = getExprInfo(col.field);
  1712. if (node && exprInfo) {
  1713. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1714. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1715. }
  1716. }
  1717. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1718. info.cancel = true;
  1719. }
  1720. },
  1721. buttonClicked: function (e, info) {
  1722. if (info.sheet.zh_setting) {
  1723. const select = SpreadJsObj.getSelectObject(info.sheet);
  1724. const col = info.sheet.zh_setting.cols[info.col];
  1725. if (col.field === 'is_change') {
  1726. if (posCol.readOnly.isChangeList(select)) {
  1727. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  1728. return
  1729. }
  1730. if (info.sheet.isEditing()) {
  1731. info.sheet.endEdit(true);
  1732. }
  1733. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  1734. if (is_change) {
  1735. makeGclGatherData();
  1736. const gclInfo = _.find(gclGatherData, function (item) {
  1737. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  1738. });
  1739. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  1740. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  1741. const data = {
  1742. lid: select.lid,
  1743. code: gclInfo.b_code,
  1744. name: gclInfo.name,
  1745. unit: gclInfo.unit,
  1746. unit_price: gclInfo.unit_price,
  1747. oamount: xmjInfo.quantity,
  1748. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1749. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  1750. xmj_code: xmjInfo.code || '',
  1751. xmj_jldy: xmjInfo.jldy || '',
  1752. xmj_dwgc: xmjInfo.dwgc || '',
  1753. xmj_fbgc: xmjInfo.fbgc || '',
  1754. xmj_fxgc: xmjInfo.fxgc || '',
  1755. gcl_id: select.lid,
  1756. mx_id: select.id,
  1757. }
  1758. if (oldCInfo) {
  1759. data.detail = oldCInfo.detail;
  1760. data.camount = oldCInfo.camount;
  1761. data.spamount = oldCInfo.spamount;
  1762. data.is_valuation = oldCInfo.is_valuation;
  1763. data.delimit = oldCInfo.delimit;
  1764. }
  1765. // 更新至服务器
  1766. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  1767. changeList = result.changeList;
  1768. select.is_change = 1;
  1769. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  1770. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1771. billsNode.is_change = 1;
  1772. const loadResult = { update: [billsNode] };
  1773. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1774. }
  1775. }, function () {
  1776. info.sheet.setValue(info.row, info.col, 0);
  1777. });
  1778. } else {
  1779. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  1780. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  1781. info.sheet.setValue(info.row, info.col, 1);
  1782. return
  1783. }
  1784. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  1785. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  1786. toastr.warning('该计量单元已被使用,无法取消变更');
  1787. info.sheet.setValue(info.row, info.col, 1);
  1788. return
  1789. } else if (checkIsSettle(cInfo)) {
  1790. toastr.warning('该计量单元已结算,无法取消变更');
  1791. info.sheet.setValue(info.row, info.col, 1);
  1792. return
  1793. } else {
  1794. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  1795. changeList = result.changeList;
  1796. select.is_change = 0;
  1797. // 判断是否只剩一个,并同步去勾
  1798. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  1799. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1800. billsNode.is_change = 0;
  1801. const loadResult = { update: [billsNode] };
  1802. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1803. }
  1804. }, function () {
  1805. info.sheet.setValue(info.row, info.col, 1);
  1806. });
  1807. }
  1808. }
  1809. }
  1810. }
  1811. },
  1812. /**
  1813. * 编辑单元格响应事件
  1814. * @param {Object} e
  1815. * @param {Object} info
  1816. */
  1817. editEnded: function (e, info) {
  1818. if (!info.sheet.zh_setting) {
  1819. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1820. return;
  1821. }
  1822. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1823. const col = info.sheet.zh_setting.cols[info.col];
  1824. if (col.field === 'is_change') {
  1825. return;
  1826. }
  1827. const orgText = posData ? posData[col.field] : null;
  1828. const newText = trimInvalidChar(info.editingText);
  1829. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1830. const node = posSpreadObj.billsNode;
  1831. if (!node) {
  1832. toastr.error('数据错误,请选择台账节点后再试');
  1833. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1834. return;
  1835. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1836. toastr.error('父节点不可插入计量单元');
  1837. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1838. return;
  1839. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1840. toastr.error('项目节不可插入计量单元');
  1841. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1842. return;
  1843. }
  1844. const data = {postType: 'pos'};
  1845. if (col.field === 'name') {
  1846. if (newText === '' && posData) {
  1847. toastr.error('部位名称不可为空', 'error');
  1848. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1849. return;
  1850. } else if (!posData) {
  1851. if (newText && newText !== '') {
  1852. data.posPostType = 'add';
  1853. const sortData = info.sheet.zh_data;
  1854. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1855. data.postData = { name: newText, lid: node.id, porder: order};
  1856. if (node.settle_status === settleStatus.finish) {
  1857. toastr.error('已结算清单不可插入计量单元');
  1858. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1859. return;
  1860. }
  1861. } else {
  1862. return;
  1863. }
  1864. } else {
  1865. data.posPostType = 'update';
  1866. data.postData = {id: posData.id, name: newText};
  1867. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  1868. toastr.error('计量单元已结算,不可修改');
  1869. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1870. return;
  1871. }
  1872. }
  1873. } else if (!posData) {
  1874. toastr.warning('新增计量单元请先输入名称');
  1875. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1876. return;
  1877. } else {
  1878. data.posPostType = 'update';
  1879. data.postData = {id: posData.id};
  1880. if (col.type === 'Number') {
  1881. const exprInfo = getExprInfo(col.field);
  1882. const num = _.toNumber(newText);
  1883. if (_.isFinite(num)) {
  1884. data.postData[col.field] = num;
  1885. if (exprInfo) {
  1886. data.postData[exprInfo.expr] = '';
  1887. }
  1888. } else {
  1889. try {
  1890. data.postData[col.field] = math.evaluate(transExpr(newText));
  1891. if (exprInfo) {
  1892. data.postData[exprInfo.expr] = newText;
  1893. }
  1894. } catch(err) {
  1895. toastr.error('输入的表达式非法');
  1896. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1897. return;
  1898. }
  1899. }
  1900. } else if (col.field.indexOf('_expr') > 0) {
  1901. const exprInfo = getExprInfo(col.field, true);
  1902. if (!exprInfo) return;
  1903. if (newText) {
  1904. try {
  1905. data.postData[exprInfo.qty] = math.evaluate(transExpr(newText));
  1906. data.postData[exprInfo.expr] = newText;
  1907. } catch(err) {
  1908. toastr.error('输入的表达式非法');
  1909. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1910. return;
  1911. }
  1912. } else {
  1913. data.postData[exprInfo.qty] = 0;
  1914. data.postData[exprInfo.expr] = '';
  1915. }
  1916. } else {
  1917. data.postData[col.field] = newText;
  1918. }
  1919. }
  1920. postData(window.location.pathname + '/update', data, function (result) {
  1921. const updateRst = pos.updateDatas(result.pos);
  1922. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1923. if (updateRst.create.length > 0) {
  1924. posSpreadObj.loadCurPosData();
  1925. } else {
  1926. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1927. }
  1928. const loadResult = billsTree.loadPostData(result.ledger);
  1929. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1930. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1931. }, function () {
  1932. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1933. });
  1934. },
  1935. /**
  1936. * 删除按钮响应事件
  1937. * @param sheet
  1938. */
  1939. deletePress: function (sheet) {
  1940. if (!sheet.zh_setting) return;
  1941. const sortData = sheet.zh_data;
  1942. const datas = [], posSelects = [];
  1943. const sel = sheet.getSelections()[0];
  1944. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1945. let bDel = false;
  1946. const node = sortData[iRow];
  1947. if (node) {
  1948. const data = {id: node.id};
  1949. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1950. const colSetting = sheet.zh_setting.cols[iCol];
  1951. if (colSetting.field === 'name') {
  1952. toastr.error('部位名称不能为空');
  1953. return;
  1954. }
  1955. const style = sheet.getStyle(iRow, iCol);
  1956. if (!style.locked) {
  1957. const colSetting = sheet.zh_setting.cols[iCol];
  1958. if (colSetting.field.indexOf('_expr') > 0) {
  1959. const exprInfo = getExprInfo(colSetting.field, true);
  1960. if (!exprInfo) continue;
  1961. data[exprInfo.expr] = '';
  1962. data[exprInfo.qty] = 0;
  1963. } else {
  1964. data[colSetting.field] = null;
  1965. const exprInfo = getExprInfo(colSetting.field);
  1966. if (exprInfo) data[exprInfo.expr] = '';
  1967. }
  1968. bDel = true;
  1969. }
  1970. }
  1971. if (bDel) {
  1972. datas.push(data);
  1973. posSelects.push(node);
  1974. }
  1975. }
  1976. }
  1977. if (datas.length > 0) {
  1978. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1979. pos.updateDatas(result.pos);
  1980. posSpreadObj.loadCurPosData();
  1981. const loadResult = billsTree.loadPostData(result.ledger);
  1982. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1983. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1984. }, function () {
  1985. posSpreadObj.loadCurPosData();
  1986. });
  1987. }
  1988. },
  1989. /**
  1990. * 删除 计量单元
  1991. * @param sheet
  1992. */
  1993. deletePos: function (sheet) {
  1994. const selection = sheet.getSelections();
  1995. const data = {
  1996. postType: 'pos',
  1997. posPostType: 'delete',
  1998. postData: [],
  1999. };
  2000. const row = selection[0].row, count = selection[0].rowCount;
  2001. const sortData = sheet.zh_data;
  2002. for (let iRow = 0; iRow < count; iRow++) {
  2003. const posData = sortData[iRow + row];
  2004. if (posData) {
  2005. if (posData.used) {
  2006. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2007. return;
  2008. }
  2009. if (posData.settle_status === settleStatus.finish) {
  2010. toastr.error(`"${posData.name}"已计量,请勿删除`);
  2011. return;
  2012. }
  2013. data.postData.push(sortData[iRow + row].id);
  2014. }
  2015. }
  2016. if (data.postData.length > 0) {
  2017. postData(window.location.pathname + '/update', data, function (result) {
  2018. pos.removeDatas(result.pos);
  2019. sheet.deleteRows(row, count);
  2020. const loadResult = billsTree.loadPostData(result.ledger);
  2021. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2022. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2023. });
  2024. }
  2025. },
  2026. /**
  2027. * 粘贴单元格响应事件
  2028. * @param e
  2029. * @param info
  2030. */
  2031. clipboardPasted: function (e, info) {
  2032. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2033. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2034. }
  2035. const node = SpreadJsObj.getSelectObject(billsSheet);
  2036. if (node.code && (node.code !== '')) {
  2037. toastr.error('项目节不可含有节点明细');
  2038. posSpreadObj.loadCurPosData();
  2039. return;
  2040. }
  2041. if (node.children && (node.children.length > 0)) {
  2042. toastr.error('仅节点子项可以含有计量单元');
  2043. posSpreadObj.loadCurPosData();
  2044. return;
  2045. }
  2046. if (node.settle_status === settleStatus.finish) {
  2047. toastr.error('清单已结算,请勿修改计量单元数据');
  2048. posSpread.loadCurPosData();
  2049. return;
  2050. }
  2051. if (!info.sheet.zh_setting) {
  2052. posSpreadObj.loadCurPosData();
  2053. return;
  2054. }
  2055. const data = [];
  2056. const sortData = info.sheet.zh_data || [];
  2057. const hint = {
  2058. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2059. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  2060. };
  2061. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  2062. if (info.cellRange.col !== 0) {
  2063. toastr.warning('新增计量单元请先输入名称');
  2064. posSpreadObj.loadCurPosData();
  2065. return;
  2066. }
  2067. }
  2068. let bHint = false;
  2069. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2070. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2071. let bPaste = true;
  2072. const curRow = info.cellRange.row + iRow;
  2073. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2074. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2075. const curCol = info.cellRange.col + iCol;
  2076. const colSetting = info.sheet.zh_setting.cols[curCol];
  2077. if (!colSetting) continue;
  2078. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2079. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  2080. bPaste = false;
  2081. toastMessageUniq(hint.settle);
  2082. continue;
  2083. }
  2084. if (colSetting.type === 'Number') {
  2085. const num = _.toNumber(posData[colSetting.field]);
  2086. if (num) {
  2087. posData[colSetting.field] = num;
  2088. } else {
  2089. try {
  2090. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  2091. const exprInfo = getExprInfo(colSetting.field);
  2092. if (exprInfo) {
  2093. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2094. }
  2095. } catch (err) {
  2096. if (!bHint) {
  2097. toastr.warning('粘贴了非法表达式,已过滤');
  2098. bHint = true;
  2099. }
  2100. bPaste = false;
  2101. }
  2102. }
  2103. } else if (colSetting.field.indexOf('_expr') > 0) {
  2104. try {
  2105. const exprInfo = getExprInfo(colSetting.field, true);
  2106. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2107. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  2108. posData[exprInfo.qty] = math.evaluate(transExpr(posData[exprInfo.expr]));
  2109. }
  2110. bPaste = true;
  2111. } catch (err) {
  2112. toastMessageUniq(hint.expr);
  2113. }
  2114. } else {
  2115. bPaste = true;
  2116. }
  2117. }
  2118. if (bPaste) {
  2119. data.push(posData);
  2120. }
  2121. }
  2122. if (data.length === 0) {
  2123. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2124. return;
  2125. }
  2126. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  2127. pos.updateDatas(result.pos);
  2128. posSpreadObj.loadCurPosData();
  2129. const loadResult = billsTree.loadPostData(result.ledger);
  2130. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2131. posSpreadObj.loadCurPosData();
  2132. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2133. }, function () {
  2134. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2135. });
  2136. },
  2137. selectionChanged: function (e, info) {
  2138. posSpreadObj.loadExprToInput();
  2139. posSpreadObj.refreshOperationValid(posSheet);
  2140. },
  2141. addPegs: function (pegs) {
  2142. if (!pegs || pegs.length <= 0) return;
  2143. const node = SpreadJsObj.getSelectObject(billsSheet);
  2144. if (!node) return;
  2145. const sheet = posSpread.getActiveSheet();
  2146. const sortData = sheet.zh_data || [];
  2147. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2148. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2149. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  2150. pos.updateDatas(result.pos);
  2151. posSpreadObj.loadCurPosData();
  2152. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2153. });
  2154. }
  2155. };
  2156. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  2157. if (!readOnly && isTz) {
  2158. $('a[name="pos-opr"]').click(function () {
  2159. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  2160. });
  2161. $('#pos-expr').bind('change onblur', function () {
  2162. if (this.readOnly) return;
  2163. const expr = $(this);
  2164. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2165. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2166. if (!select) return;
  2167. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  2168. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  2169. const data = {id: select.id};
  2170. const exprInfo = getExprInfo(field);
  2171. if (newValue !== '') {
  2172. const num = _.toNumber(newValue);
  2173. if (num) {
  2174. data[field] = num;
  2175. if (exprInfo) data[exprInfo.expr] = '';
  2176. } else {
  2177. try {
  2178. data[field] = math.evaluate(transExpr(newValue));
  2179. if (exprInfo) data[exprInfo.expr] = newValue;
  2180. } catch (err) {
  2181. toastr.error('输入的表达式非法');
  2182. return;
  2183. }
  2184. }
  2185. } else {
  2186. data[field] = null;
  2187. if (exprInfo) data[exprInfo.expr] = '';
  2188. }
  2189. // 更新至服务器
  2190. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  2191. const updateRst = pos.updateDatas(result.pos);
  2192. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2193. SpreadJsObj.reLoadRowData(posSheet, row);
  2194. const loadResult = billsTree.loadPostData(result.ledger);
  2195. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2196. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2197. });
  2198. });
  2199. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  2200. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  2201. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  2202. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  2203. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  2204. $.contextMenu({
  2205. selector: '#pos-spread',
  2206. build: function ($trigger, e) {
  2207. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2208. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2209. },
  2210. items: {
  2211. 'delete': {
  2212. name: '删除',
  2213. icon: 'fa-remove',
  2214. disabled: function (key, opt) {
  2215. if (posSheet.zh_data) {
  2216. const selection = posSheet.getSelections();
  2217. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2218. const row = sel ? sel.row : -1;
  2219. const rowCount = sel.rowCount;
  2220. let settleFinish = false;
  2221. for (let i = row; i < row + rowCount; i++) {
  2222. if (!posSheet.zh_data[i]) continue;
  2223. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  2224. }
  2225. return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
  2226. } else {
  2227. return true;
  2228. }
  2229. },
  2230. callback: function (key, opt) {
  2231. posSpreadObj.deletePos(posSheet);
  2232. }
  2233. },
  2234. }
  2235. });
  2236. }
  2237. // 加载清单&计量单元数据
  2238. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  2239. let gclGatherData;
  2240. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  2241. for (const b of result.bills) {
  2242. if (!(b.is_leaf && b.b_code)) {
  2243. b.is_change = 0;
  2244. } else {
  2245. const cInfo = _.find(changeList, { gcl_id: b.id });
  2246. b.is_change = cInfo ? 1 : 0;
  2247. }
  2248. }
  2249. billsTree.loadDatas(result.bills);
  2250. pos.loadDatas(result.pos);
  2251. treeCalc.calculateAll(billsTree);
  2252. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  2253. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  2254. checkShowLast(result.bills.length);
  2255. posSpreadObj.loadCurPosData();
  2256. SpreadJsObj.resetTopAndSelect(posSheet);
  2257. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2258. billsTreeSpreadObj.loadExprToInput(billsSheet);
  2259. checkList.loadHisCheckData();
  2260. console.log(billsTree);
  2261. }, null);
  2262. $.divResizer({
  2263. select: '#revise-resize',
  2264. callback: function () {
  2265. billsSpread.refresh();
  2266. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2267. $(".sp-wrap").height(bcontent-30);
  2268. posSpread.refresh();
  2269. }
  2270. });
  2271. function makeGclGatherData() {
  2272. gclGatherModel.loadLedgerData(billsTree.datas);
  2273. gclGatherModel.loadPosData(pos.datas);
  2274. gclGatherData = gclGatherModel.gatherGclData();
  2275. gclGatherData = _.filter(gclGatherData, function (item) {
  2276. return item.leafXmjs && item.leafXmjs.length !== 0;
  2277. });
  2278. gclGatherData = gclGatherData.sort(sortByCode);
  2279. console.log(gclGatherData);
  2280. }
  2281. class DealBills {
  2282. constructor (selector, spreadSetting) {
  2283. const self = this;
  2284. this.loaded = false;
  2285. this.obj = $(selector)[0];
  2286. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2287. this.spreadSetting = spreadSetting;
  2288. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2289. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2290. if (!readOnly) {
  2291. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2292. const dealSheet = info.sheet;
  2293. const mainSheet = billsSheet;
  2294. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2295. if (!dealBills) { return; }
  2296. const mainTree = mainSheet.zh_tree;
  2297. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2298. if (!mainNode || !mainTree) { return; }
  2299. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2300. toastr.warning('非最底层项目下,不应添加节点');
  2301. return;
  2302. }
  2303. if (mainNode.settle_status === settleStatus.finish) {
  2304. toastr.warning('已结算节点下,不应添加签约清单');
  2305. return;
  2306. }
  2307. postData(window.location.pathname + '/update', {
  2308. postType: 'add-deal',
  2309. postData: {
  2310. id: mainNode.ledger_id,
  2311. type: mainNode.code ? 'child' : 'next',
  2312. dealBills: {
  2313. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2314. unit_price: dealBills.unit_price,
  2315. }
  2316. },
  2317. }, function (result) {
  2318. const refreshData = mainTree.loadPostData(result);
  2319. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2320. const sel = mainSheet.getSelections()[0];
  2321. if (sel && refreshData.create[0]) {
  2322. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2323. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2324. }
  2325. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2326. billsSpread.focus();
  2327. posSpreadObj.loadCurPosData();
  2328. });
  2329. });
  2330. }
  2331. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2332. }
  2333. loadData (callback) {
  2334. if (this.loaded) {
  2335. if (callback) callback();
  2336. return;
  2337. }
  2338. const self = this;
  2339. postData(this.url+'/get-data', {}, function (data) {
  2340. self.data = data;
  2341. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2342. self.loaded = true;
  2343. if (callback) callback();
  2344. });
  2345. }
  2346. calculateData () {
  2347. if (this.data) {
  2348. for (const d of this.data) {
  2349. d.total_price = _.multiply(d.quantity, d.unit_price);
  2350. }
  2351. }
  2352. }
  2353. }
  2354. class BatchInsertBillsPosObj {
  2355. constructor (obj) {
  2356. const self = this;
  2357. this.obj = obj;
  2358. this.billsCount = 6;
  2359. this.posCount = 1000;
  2360. this.filter = getLocalCache('zh-calc-batch-filter');
  2361. if (!this.filter) {
  2362. this.filter = '1';
  2363. }
  2364. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2365. // 初始化 清单编号窗口 参数
  2366. this.qdSpreadSetting = {
  2367. cols: [
  2368. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2369. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2370. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2371. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2372. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2373. ],
  2374. emptyRows: this.billsCount,
  2375. headRows: 1,
  2376. headRowHeight: [32],
  2377. headerFont: '12px 微软雅黑',
  2378. font: '12px 微软雅黑',
  2379. };
  2380. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2381. // 初始化 部位数量复核表 参数
  2382. this.posSpreadSetting = {
  2383. cols: [
  2384. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2385. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2386. ],
  2387. emptyRows: this.posCount,
  2388. headRows: 1,
  2389. headRowHeight: [32],
  2390. headerFont: '12px 微软雅黑',
  2391. font: '12px 微软雅黑',
  2392. };
  2393. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2394. this.posSpreadSetting.cols.push(
  2395. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2396. )
  2397. }
  2398. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2399. // 初始化 签约节点 参数
  2400. this.dealSpreadSetting = {
  2401. cols: [
  2402. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2403. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2404. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2405. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2406. ],
  2407. emptyRows: 0,
  2408. headRows: 1,
  2409. headRowHeight: [32],
  2410. headerFont: '12px 微软雅黑',
  2411. font: '12px 微软雅黑',
  2412. };
  2413. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2414. // 初始化 清单编号、部位数量复核表 表格
  2415. this.initView();
  2416. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2417. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2418. // 拉取签约节点数据
  2419. dealBills.loadData(() => {
  2420. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2421. });
  2422. // 双击签约节点,自动添加到清单编号窗口
  2423. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  2424. const deal = info.sheet.zh_data[info.row];
  2425. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2426. const sel = qdSheet.getSelections()[0];
  2427. qdSheet.getCell(sel.row, 0).value(deal.code);
  2428. qdSheet.getCell(sel.row, 1).value(deal.name);
  2429. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2430. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2431. if (sel.row + 1 === qdSheet.getRowCount()) {
  2432. const count = sel.row + 2;
  2433. qdSheet.setRowCount(count);
  2434. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2435. const colCount = posSheet.getColumnCount() + 1;
  2436. posSheet.setColumnCount(colCount);
  2437. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2438. }
  2439. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2440. qdSheet.getParent().focus();
  2441. });
  2442. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2443. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  2444. const count = posSheet.getColumnCount() - 2;
  2445. if (billsCount > count) {
  2446. posSheet.setColumnCount(billsCount + 2);
  2447. for (let i = count + 1; i <= billsCount; i++) {
  2448. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2449. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2450. }
  2451. }
  2452. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  2453. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2454. if (dealBills && dealBills.length > 0) {
  2455. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2456. const curRow = iRow + info.cellRange.row;
  2457. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  2458. if (bills) {
  2459. info.sheet.getCell(curRow, 1).value(bills.name);
  2460. info.sheet.getCell(curRow, 2).value(bills.unit);
  2461. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  2462. }
  2463. }
  2464. }
  2465. }
  2466. });
  2467. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2468. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2469. const count = qdSheet.getRowCount();
  2470. if (billsCount > count) {
  2471. qdSheet.setRowCount(billsCount);
  2472. for (let i = count + 1; i <= billsCount; i++) {
  2473. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2474. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2475. }
  2476. }
  2477. });
  2478. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2479. if (info.col === 0) {
  2480. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2481. if (dealBills && dealBills.length > 0) {
  2482. const bills = _.find(dealBills, {code: info.editingText});
  2483. if (bills) {
  2484. info.sheet.getCell(info.row, 1).value(bills.name);
  2485. info.sheet.getCell(info.row, 2).value(bills.unit);
  2486. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2487. }
  2488. }
  2489. }
  2490. });
  2491. this.obj.bind('shown.bs.modal', function () {
  2492. self.qdSpread.refresh();
  2493. self.posSpread.refresh();
  2494. self.dealSpread.refresh();
  2495. });
  2496. $('#batch-ok').click(function () {
  2497. const selection = billsSheet.getSelections();
  2498. const sel = selection[0];
  2499. const row = selection[0].row;
  2500. const select = billsTree.nodes[row];
  2501. if (select) {
  2502. const insertData = {};
  2503. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2504. insertData.id = select[billsTree.setting.id];
  2505. insertData.batchData = self.getBatchData();
  2506. if (insertData.batchData.length > 0) {
  2507. postData(window.location.pathname + '/update', {
  2508. postType: 'batch-insert',
  2509. postData: insertData
  2510. }, function (data) {
  2511. pos.updateDatas(data.pos);
  2512. const result = billsTree.loadPostData(data.ledger);
  2513. billsTreeSpreadObj.refreshTree(billsSheet, result);
  2514. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2515. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  2516. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  2517. posSpreadObj.loadCurPosData();
  2518. self.obj.modal('hide');
  2519. }, null, true);
  2520. } else {
  2521. self.obj.modal('hide');
  2522. }
  2523. }
  2524. });
  2525. $('input[name=batch-filter]').change(function () {
  2526. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  2527. });
  2528. $.contextMenu({
  2529. selector: '.batch-l-t',
  2530. build: function ($trigger, e) {
  2531. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2532. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2533. },
  2534. items: {
  2535. 'create': {
  2536. name: '新增行',
  2537. icon: 'fa-sign-in',
  2538. callback: function (key, opt) {
  2539. const qdSheet = self.qdSpread.getActiveSheet();
  2540. const posSheet = self.posSpread.getActiveSheet();
  2541. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2542. const index = qdSheet.getRowCount();
  2543. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2544. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2545. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2546. },
  2547. },
  2548. 'delete': {
  2549. name: '删除行',
  2550. icon: 'fa-remove',
  2551. callback: function (key, opt) {
  2552. const qdSheet = self.qdSpread.getActiveSheet();
  2553. const posSheet = self.posSpread.getActiveSheet();
  2554. const sel = qdSheet.getSelections()[0];
  2555. qdSheet.deleteRows(sel.row, sel.rowCount);
  2556. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2557. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2558. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2559. }
  2560. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2561. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2562. }
  2563. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2564. },
  2565. },
  2566. }
  2567. });
  2568. }
  2569. // 初始化左侧表格
  2570. initView () {
  2571. // 初始化 清单编号
  2572. const qdSheet = this.qdSpread.getActiveSheet();
  2573. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2574. SpreadJsObj.refreshColumnAlign(qdSheet);
  2575. // 清理原有数据
  2576. SpreadJsObj.beginMassOperation(qdSheet);
  2577. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2578. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2579. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2580. }
  2581. qdSheet.setSelection(0, 0, 1 ,1);
  2582. SpreadJsObj.endMassOperation(qdSheet);
  2583. // 初始化 部位数量复核表
  2584. const posSheet = this.posSpread.getActiveSheet();
  2585. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2586. SpreadJsObj.refreshColumnAlign(posSheet);
  2587. // 清理原有数据
  2588. SpreadJsObj.beginMassOperation(posSheet);
  2589. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2590. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2591. posSheet.setSelection(0, 0, 1 ,1);
  2592. SpreadJsObj.endMassOperation(posSheet);
  2593. // 检查签约节点数据,以工具栏数据为准
  2594. if (dealBills) {
  2595. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2596. }
  2597. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2598. }
  2599. // 获取界面数据
  2600. getBatchData () {
  2601. const result = [];
  2602. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2603. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2604. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2605. const qd = {
  2606. b_code: qdSheet.getText(iRow, 0),
  2607. name: qdSheet.getText(iRow, 1),
  2608. unit: qdSheet.getText(iRow, 2),
  2609. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2610. pos: [],
  2611. };
  2612. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2613. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2614. if (value !== 0 && !isNaN(value)) {
  2615. qd.pos.push({
  2616. name: posSheet.getText(iPosRow, 0),
  2617. drawing_code: posSheet.getText(iPosRow, 1),
  2618. quantity: value, porder: qd.pos.length + 1,
  2619. });
  2620. }
  2621. }
  2622. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2623. }
  2624. return result;
  2625. }
  2626. }
  2627. const dealBills = new DealBills('#deal-bills-spread', {
  2628. cols: [
  2629. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2630. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2631. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2632. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2633. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2634. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2635. ],
  2636. emptyRows: 0,
  2637. headRows: 1,
  2638. headRowHeight: [32],
  2639. headColWidth: [30],
  2640. defaultRowHeight: 21,
  2641. headerFont: '12px 微软雅黑',
  2642. font: '12px 微软雅黑',
  2643. selectedBackColor: '#fffacd',
  2644. });
  2645. class Jlzf {
  2646. constructor (selector, spreadSetting) {
  2647. const self = this;
  2648. this.loaded = false;
  2649. this.obj = $(selector);
  2650. const relaSelect = {
  2651. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2652. searchText: `cb-${spreadSetting.stdType}-st`,
  2653. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2654. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2655. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2656. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2657. };
  2658. this.obj.html(
  2659. '<div class="sjs-bar d-flex">\n' +
  2660. ' <div class="ml-1">\n' +
  2661. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  2662. ' <div class="d-inline-block">\n' +
  2663. ' <div class="input-group input-group-sm mr-1">' +
  2664. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2665. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2666. ' <div class="input-group-append" >\n' +
  2667. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2668. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2669. ' </div>\n' +
  2670. ' </div>\n' +
  2671. ' </div>\n' +
  2672. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2673. ' </div>\n' +
  2674. ' </div>' +
  2675. '</div>\n' +
  2676. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2677. );
  2678. autoFlashHeight();
  2679. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2680. function getObjHeight(select) {
  2681. return select.length > 0 ? select.height() : 0;
  2682. }
  2683. const cHeader = getObjHeight($(".c-header"));
  2684. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2685. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2686. this.spreadSetting = spreadSetting;
  2687. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2688. const searchSheet = this.spread.getActiveSheet();
  2689. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2690. if (!readOnly) {
  2691. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2692. const dealSheet = info.sheet;
  2693. const mainSheet = billsSheet;
  2694. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2695. if (!dealBills) { return; }
  2696. const mainTree = mainSheet.zh_tree;
  2697. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2698. if (!mainNode || !mainTree) { return; }
  2699. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2700. toastr.warning('非最底层项目下,不应添加节点');
  2701. return;
  2702. }
  2703. if (mainNode.settle_status === settleStatus.finish) {
  2704. toastr.warning('已结算节点下,不应添加签约清单');
  2705. return;
  2706. }
  2707. postData(window.location.pathname + '/update', {
  2708. postType: 'add-deal',
  2709. postData: {
  2710. id: mainNode.ledger_id,
  2711. type: mainNode.code ? 'child' : 'next',
  2712. dealBills: {
  2713. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2714. unit_price: dealBills.unit_price,
  2715. }
  2716. },
  2717. }, function (result) {
  2718. const refreshData = mainTree.loadPostData(result);
  2719. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2720. const sel = mainSheet.getSelections()[0];
  2721. if (sel && refreshData.create[0]) {
  2722. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2723. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2724. }
  2725. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2726. billsSpread.focus();
  2727. posSpreadObj.loadCurPosData();
  2728. });
  2729. });
  2730. }
  2731. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2732. const searchObj = {
  2733. result: [],
  2734. cur: 0,
  2735. searchStdNode: function() {
  2736. const keyword = $(`#${relaSelect.searchText}`).val();
  2737. const sortData = SpreadJsObj.getSortData(searchSheet);
  2738. searchObj.result = keyword ? sortData.filter(x => {
  2739. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2740. }) : [];
  2741. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  2742. searchObj.cur = 0;
  2743. if (searchObj.result.length > 0) {
  2744. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2745. }
  2746. },
  2747. searchPre: function () {
  2748. if (searchObj.result.length === 0) return;
  2749. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  2750. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2751. },
  2752. searchNext: function () {
  2753. if (searchObj.result.length === 0) return;
  2754. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  2755. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2756. },
  2757. clear: function () {
  2758. $(`#${relaSelect.searchText}`).val('');
  2759. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  2760. searchObj.result = [];
  2761. searchObj.cur = 0;
  2762. }
  2763. };
  2764. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  2765. $(`#${relaSelect.searchPre}`).click(function (e) {
  2766. searchObj.searchPre();
  2767. e.stopPropagation();
  2768. });
  2769. $(`#${relaSelect.searchNext}`).click(function (e) {
  2770. searchObj.searchNext();
  2771. e.stopPropagation();
  2772. });
  2773. $(`#${relaSelect.searchClose}`).click(function (e) {
  2774. searchObj.clear();
  2775. e.stopPropagation();
  2776. });
  2777. };
  2778. loadData (callback) {
  2779. // if (this.loaded) {
  2780. // if (callback) callback();
  2781. // return;
  2782. // }
  2783. const self = this;
  2784. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  2785. const showDatas = [];
  2786. for (const d of datas) {
  2787. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  2788. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  2789. }
  2790. }
  2791. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  2792. // self.loaded = true;
  2793. if (callback) callback();
  2794. }
  2795. }
  2796. const jlzfBills = new Jlzf('#jlzf-spread', {
  2797. cols: [
  2798. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2799. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  2800. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2801. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2802. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2803. ],
  2804. emptyRows: 0,
  2805. headRows: 1,
  2806. headRowHeight: [32],
  2807. headColWidth: [30],
  2808. defaultRowHeight: 21,
  2809. headerFont: '12px 微软雅黑',
  2810. font: '12px 微软雅黑',
  2811. selectedBackColor: '#fffacd',
  2812. readOnly: true,
  2813. stdType: 'jlzf',
  2814. });
  2815. class Dsk {
  2816. constructor (selector, spreadSetting) {
  2817. const self = this;
  2818. this.loaded = false;
  2819. this.obj = $(selector);
  2820. const dskProjectHtml = spreadSetting.libs.map(l => {
  2821. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  2822. });
  2823. const relaSelect = {
  2824. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2825. searchText: `cb-${spreadSetting.stdType}-st`,
  2826. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2827. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2828. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2829. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2830. };
  2831. this.obj.html(
  2832. '<div class="sjs-bar d-flex">\n' +
  2833. ' <div class="dropdown mr-1">\n' +
  2834. ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2835. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  2836. ' </button>\n' +
  2837. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  2838. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  2839. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  2840. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  2841. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  2842. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  2843. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  2844. ' </div>\n' +
  2845. ' </div>' +
  2846. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
  2847. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
  2848. ' <div class="ml-1">\n' +
  2849. ' <div class="dropdown">\n' +
  2850. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2851. ' <i class="fa fa-search"></i>\n' +
  2852. ' </button>\n' +
  2853. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  2854. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  2855. ' <div class="d-inline-block">\n' +
  2856. ' <div class="input-group input-group-sm mr-1">' +
  2857. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2858. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2859. ' <div class="input-group-append" >\n' +
  2860. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2861. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2862. ' </div>\n' +
  2863. ' </div>\n' +
  2864. ' </div>\n' +
  2865. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2866. ' </div>\n' +
  2867. ' </div>\n' +
  2868. ' </div>\n' +
  2869. ' </div>' +
  2870. '</div>\n' +
  2871. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2872. );
  2873. autoFlashHeight();
  2874. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2875. function getObjHeight(select) {
  2876. return select.length > 0 ? select.height() : 0;
  2877. }
  2878. const cHeader = getObjHeight($(".c-header"));
  2879. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2880. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2881. this.spreadSetting = spreadSetting;
  2882. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2883. const searchSheet = this.spread.getActiveSheet();
  2884. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2885. (function (select, sheet) {
  2886. $(select).click(function () {
  2887. if (!sheet.zh_tree) return;
  2888. const tag = $(this).attr('tag');
  2889. const tree = sheet.zh_tree;
  2890. setTimeout(() => {
  2891. switch (tag) {
  2892. case "1":
  2893. case "2":
  2894. case "3":
  2895. case "4":
  2896. case "5":
  2897. tree.expandByLevel(parseInt(tag));
  2898. SpreadJsObj.refreshTreeRowVisible(sheet);
  2899. break;
  2900. case "last":
  2901. tree.expandByCustom(() => { return true; });
  2902. SpreadJsObj.refreshTreeRowVisible(sheet);
  2903. break;
  2904. }
  2905. }, 100);
  2906. });
  2907. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  2908. if (!readOnly) {
  2909. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2910. const dealSheet = info.sheet;
  2911. const mainSheet = billsSheet;
  2912. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2913. if (!dealBills) { return; }
  2914. const mainTree = mainSheet.zh_tree;
  2915. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2916. if (!mainNode || !mainTree) { return; }
  2917. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2918. toastr.warning('非最底层项目下,不应添加节点');
  2919. return;
  2920. }
  2921. if (mainNode.settle_status === settleStatus.finish) {
  2922. toastr.warning('已结算节点下,不应添加签约清单');
  2923. return;
  2924. }
  2925. const is_bill = dealBills.kind === 4;
  2926. const oneBills = {
  2927. b_code: is_bill ? dealBills.code : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  2928. unit_price: is_bill ? dealBills.unitPrice : null, quantity: is_bill ? dealBills.quantity : null, total_price: is_bill ? dealBills.totalPrice : null,
  2929. sgfh_qty: is_bill ? dealBills.quantity : null, sgfh_tp: is_bill ? dealBills.totalPrice : null,
  2930. };
  2931. postData(window.location.pathname + '/update', {
  2932. postType: 'add-deal',
  2933. postData: {
  2934. id: mainNode.ledger_id,
  2935. type: mainNode.code ? 'child' : 'next',
  2936. dealBills: oneBills,
  2937. },
  2938. }, function (result) {
  2939. const refreshData = mainTree.loadPostData(result);
  2940. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2941. const sel = mainSheet.getSelections()[0];
  2942. if (sel && refreshData.create[0]) {
  2943. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2944. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2945. }
  2946. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2947. billsSpread.focus();
  2948. posSpreadObj.loadCurPosData();
  2949. });
  2950. });
  2951. }
  2952. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2953. const searchObj = {
  2954. result: [],
  2955. cur: 0,
  2956. searchStdNode: function() {
  2957. const keyword = $(`#${relaSelect.searchText}`).val();
  2958. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  2959. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2960. }) : [];
  2961. // searchObj.result = [];
  2962. // for (const x of pathTree.nodes) {
  2963. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  2964. // searchObj.result.push(x);
  2965. // }
  2966. // }
  2967. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  2968. searchObj.cur = 0;
  2969. if (searchObj.result.length > 0) {
  2970. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  2971. }
  2972. },
  2973. searchPre: function () {
  2974. if (searchObj.result.length === 0) return;
  2975. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  2976. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  2977. },
  2978. searchNext: function () {
  2979. if (searchObj.result.length === 0) return;
  2980. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  2981. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  2982. },
  2983. clear: function () {
  2984. $(`#${relaSelect.searchText}`).val('');
  2985. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  2986. searchObj.result = [];
  2987. searchObj.cur = 0;
  2988. }
  2989. };
  2990. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  2991. $(`#${relaSelect.searchPre}`).click(function (e) {
  2992. searchObj.searchPre();
  2993. e.stopPropagation();
  2994. });
  2995. $(`#${relaSelect.searchNext}`).click(function (e) {
  2996. searchObj.searchNext();
  2997. e.stopPropagation();
  2998. });
  2999. $(`#${relaSelect.searchClose}`).click(function (e) {
  3000. searchObj.clear();
  3001. e.stopPropagation();
  3002. });
  3003. };
  3004. loadData (callback) {
  3005. if (this.loaded) {
  3006. if (callback) callback();
  3007. return;
  3008. }
  3009. const self = this;
  3010. if (dskAccountData && dskAccountData.select_project) {
  3011. self.loaded = true;
  3012. changeDskProject(dskAccountData.select_project);
  3013. } else {
  3014. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  3015. self.loaded = true;
  3016. }
  3017. if (callback) callback();
  3018. }
  3019. }
  3020. $('body').on('change', '#change-dsk-project', function () {
  3021. const pid = $(this).val();
  3022. changeDskProject(pid);
  3023. });
  3024. $('body').on('change', '#change-dsk-project-tree', function () {
  3025. const treeId = $(this).val();
  3026. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  3027. changeDskProjectTree(projectInfo, treeId);
  3028. });
  3029. function setDskProjectTreeSelect(trees) {
  3030. let html = '';
  3031. for (const tree of trees) {
  3032. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  3033. }
  3034. $('#change-dsk-project-tree').html(html);
  3035. }
  3036. function changeDskProject(pid) {
  3037. const projectInfo = _.find(dskProjects, { pid });
  3038. if (!projectInfo) {
  3039. dskAccountData.select_project = null;
  3040. dskAccountData.select_tree = null;
  3041. const tree = dskProjectBills2Tree.convert([]);
  3042. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3043. return;
  3044. }
  3045. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  3046. const trees = _.filter(datas, x => x.type === 4);
  3047. dskAccountData.select_project = projectInfo.pid;
  3048. setDskProjectTreeSelect(trees);
  3049. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  3050. });
  3051. }
  3052. function changeDskProjectTree(projectInfo, treeId) {
  3053. dskAccountData.select_tree = treeId;
  3054. if (!treeId) {
  3055. const tree = dskProjectBills2Tree.convert([]);
  3056. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3057. return;
  3058. }
  3059. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  3060. const tree = dskProjectBills2Tree.convert(result);
  3061. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3062. });
  3063. }
  3064. const dskBills = new Dsk('#dsk-spread', {
  3065. cols: [
  3066. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  3067. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  3068. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3069. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  3070. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  3071. ],
  3072. emptyRows: 0,
  3073. headRows: 1,
  3074. headRowHeight: [32],
  3075. headColWidth: [30],
  3076. defaultRowHeight: 21,
  3077. headerFont: '12px 微软雅黑',
  3078. font: '12px 微软雅黑',
  3079. selectedBackColor: '#fffacd',
  3080. readOnly: true,
  3081. stdType: 'dsk',
  3082. libs: dskProjects,
  3083. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  3084. });
  3085. const dskProjectBills2Tree = (function () {
  3086. const treeSetting = {
  3087. id: 'dpb_id',
  3088. pid: 'dpb_pid',
  3089. order: 'seq',
  3090. level: 'level',
  3091. rootId: '-1',
  3092. fullPath: 'full_path',
  3093. };
  3094. const tenderTree = createNewPathTree('gather', treeSetting);
  3095. function setChildrenNode(node, dxs, files, tenders) {
  3096. const dxchildren = _.filter(dxs, { parentID: node.bid });
  3097. const children = _.filter(files, { parentID: node.bid });
  3098. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  3099. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  3100. for (const t of checkChildren) {
  3101. const child = {
  3102. bid: t.ID,
  3103. parentID: t.parentID,
  3104. name: t.name,
  3105. kind: t.kind,
  3106. code: t.code,
  3107. quantity: t.quantity,
  3108. quantity2: t.quantity2,
  3109. unit: t.unit,
  3110. unitPrice: t.unitPrice,
  3111. totalPrice: t.totalPrice,
  3112. formulaCode: t.formulaCode,
  3113. flag: t.flag,
  3114. remark: t.remark,
  3115. };
  3116. tenderTree.addNode(child, node);
  3117. setChildrenNode(child, dxs, files, tenders);
  3118. }
  3119. }
  3120. function convert (projects) {
  3121. tenderTree.clearDatas();
  3122. // 区分文件夹及项目
  3123. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  3124. const dxs = _.filter(projects, { kind: 1 });
  3125. const files = _.filter(projects, { kind: 4 });
  3126. const tenders = _.filter(projects, { kind: 8 });
  3127. for (const t of topLevel) {
  3128. const node = {
  3129. bid: t.ID,
  3130. parentID: t.parentID,
  3131. name: t.name,
  3132. kind: t.kind,
  3133. code: t.code,
  3134. quantity: t.quantity,
  3135. quantity2: t.quantity2,
  3136. unit: t.unit,
  3137. unitPrice: t.unitPrice,
  3138. totalPrice: t.totalPrice,
  3139. formulaCode: t.formulaCode,
  3140. flag: t.flag,
  3141. remark: t.remark,
  3142. };
  3143. tenderTree.addNode(node, null);
  3144. setChildrenNode(node, dxs, files, tenders);
  3145. }
  3146. tenderTree.sortTreeNode(true);
  3147. return tenderTree;
  3148. }
  3149. return { tenderTree, convert }
  3150. })();
  3151. $.divResizer({
  3152. select: '#revise-right-spr',
  3153. callback: function () {
  3154. billsSpread.refresh();
  3155. if (posSpread) posSpread.refresh();
  3156. if (stdXmj) stdXmj.spread.refresh();
  3157. if (stdGcl) stdGcl.spread.refresh();
  3158. if (dealBills) dealBills.spread.refresh();
  3159. if (searchLedger) searchLedger.spread.refresh();
  3160. if (errorList) errorList.spread.refresh();
  3161. if (checkList) checkList.spread.refresh();
  3162. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3163. if (jlzfBills) jlzfBills.spread.refresh();
  3164. if (dskBills) dskBills.spread.refresh();
  3165. }
  3166. });
  3167. $.subMenu({
  3168. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  3169. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  3170. key: 'menu.1.0.0',
  3171. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  3172. callback: function (info) {
  3173. if (info.mini) {
  3174. $('.panel-title').addClass('fluid');
  3175. $('#sub-menu').removeClass('panel-sidebar');
  3176. } else {
  3177. $('.panel-title').removeClass('fluid');
  3178. $('#sub-menu').addClass('panel-sidebar');
  3179. }
  3180. autoFlashHeight();
  3181. billsSpread.refresh();
  3182. if (posSpread) posSpread.refresh();
  3183. if (stdXmj) stdXmj.spread.refresh();
  3184. if (stdGcl) stdGcl.spread.refresh();
  3185. if (dealBills) dealBills.spread.refresh();
  3186. if (searchLedger) searchLedger.spread.refresh();
  3187. if (errorList) errorList.spread.refresh();
  3188. if (checkList) checkList.spread.refresh();
  3189. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3190. if (jlzfBills) jlzfBills.spread.refresh();
  3191. if (dskBills) dskBills.spread.refresh();
  3192. }
  3193. });
  3194. // showSideTools(true);
  3195. billsSpread.refresh();
  3196. if (posSpread) posSpread.refresh();
  3197. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  3198. const mainSheet = billsSheet;
  3199. if (!stdTree || !mainSheet.zh_tree) { return; }
  3200. const mainTree = mainSheet.zh_tree;
  3201. const sel = mainSheet.getSelections()[0];
  3202. const mainNode = mainTree.nodes[sel.row];
  3203. if (!stdNode) return;
  3204. if (updateData.postData.stdType === 'gcl') {
  3205. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3206. toastr.warning('非最底层项目下,不应添加节点');
  3207. return;
  3208. }
  3209. if (mainNode.settle_status === settleStatus.finish) {
  3210. toastr.warning('已结算节点下,不可添加工程量清单');
  3211. return;
  3212. }
  3213. } else {
  3214. const stdNodes = stdTree.getAllParents(stdNode);
  3215. for (const node of stdNodes) {
  3216. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  3217. if (parent && parent.settle_status === settleStatus.finish) {
  3218. toastr.warning('项目节父项已结算,不可添加节点');
  3219. return;
  3220. }
  3221. }
  3222. }
  3223. postData(window.location.pathname + '/update', {
  3224. postType: 'add-std',
  3225. postData: {
  3226. id: mainTree.getNodeKey(mainNode),
  3227. tender_id: mainNode.tender_id,
  3228. stdType: updateData.postData.stdType,
  3229. stdLibId: stdNode.list_id,
  3230. stdNode: stdTree.getNodeKey(stdNode)
  3231. }
  3232. }, function (result) {
  3233. const refreshNode = mainTree.loadPostData(result);
  3234. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  3235. if (sel) {
  3236. if (refreshNode.create && refreshNode.create.length > 0) {
  3237. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  3238. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  3239. } else {
  3240. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  3241. if (node) {
  3242. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  3243. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  3244. }
  3245. }
  3246. }
  3247. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3248. billsSpread.focus();
  3249. posSpreadObj.loadCurPosData();
  3250. });
  3251. };
  3252. const stdXmjSetting = {
  3253. selector: '#std-xmj',
  3254. stdType: 'xmj',
  3255. libs: stdChapters,
  3256. treeSetting: {
  3257. id: 'chapter_id',
  3258. pid: 'pid',
  3259. order: 'order',
  3260. level: 'level',
  3261. rootId: -1,
  3262. keys: ['id', 'list_id', 'chapter_id'],
  3263. },
  3264. spreadSetting: {
  3265. cols: [
  3266. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3267. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3268. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3269. ],
  3270. treeCol: 0,
  3271. emptyRows: 0,
  3272. headRows: 1,
  3273. headRowHeight: [32],
  3274. defaultRowHeight: 21,
  3275. headerFont: '12px 微软雅黑',
  3276. font: '12px 微软雅黑',
  3277. headColWidth: [30],
  3278. selectedBackColor: '#fffacd',
  3279. },
  3280. cellDoubleClick: stdLibCellDoubleClick,
  3281. page: 'revise',
  3282. tid: window.location.pathname.split('/')[2],
  3283. };
  3284. const stdGclSetting = {
  3285. selector: '#std-gcl',
  3286. stdType: 'gcl',
  3287. libs: stdBills,
  3288. treeSetting: {
  3289. id: 'bill_id',
  3290. pid: 'pid',
  3291. order: 'order',
  3292. level: 'level',
  3293. rootId: -1,
  3294. keys: ['id', 'list_id', 'bill_id']
  3295. },
  3296. spreadSetting: {
  3297. cols: [
  3298. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3299. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3300. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3301. ],
  3302. treeCol: 0,
  3303. emptyRows: 0,
  3304. headRows: 1,
  3305. headRowHeight: [32],
  3306. defaultRowHeight: 21,
  3307. headerFont: '12px 微软雅黑',
  3308. font: '12px 微软雅黑',
  3309. headColWidth: [30],
  3310. selectedBackColor: '#fffacd',
  3311. },
  3312. cellDoubleClick: stdLibCellDoubleClick,
  3313. page: 'revise',
  3314. tid: window.location.pathname.split('/')[2],
  3315. };
  3316. // 展开收起标准节点
  3317. $('a', '#side-menu').bind('click', function (e) {
  3318. e.preventDefault();
  3319. const tab = $(this), tabPanel = $(tab.attr('content'));
  3320. // 展开工具栏、切换标签
  3321. if (!tab.hasClass('active')) {
  3322. const close = $('.active', '#side-menu').length === 0;
  3323. $('a', '#side-menu').removeClass('active');
  3324. tab.addClass('active');
  3325. $('.tab-content .tab-pane').removeClass('active');
  3326. tabPanel.addClass('active');
  3327. showSideTools(tab.hasClass('active'));
  3328. if (tab.attr('content') === '#std-xmj') {
  3329. if (!stdXmj) {
  3330. stdXmj = $.stdLib(stdXmjSetting);
  3331. }
  3332. stdXmj.spread.refresh();
  3333. } else if (tab.attr('content') === '#std-gcl') {
  3334. if (!stdGcl) {
  3335. stdGcl = $.stdLib(stdGclSetting);
  3336. }
  3337. stdGcl.spread.refresh();
  3338. } else if (tab.attr('content') === '#deal-bills') {
  3339. dealBills.loadData();
  3340. dealBills.spread.refresh();
  3341. } else if (tab.attr('content') === '#search') {
  3342. if (!searchLedger) {
  3343. searchLedger = $.billsSearch({
  3344. selector: '#search',
  3345. searchSpread: billsSpread,
  3346. searchOver: true,
  3347. searchEmpty: true,
  3348. resultSpreadSetting: {
  3349. cols: [
  3350. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3351. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3352. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3353. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3354. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3355. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3356. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  3357. ],
  3358. emptyRows: 0,
  3359. headRows: 1,
  3360. headRowHeight: [32],
  3361. headColWidth: [30],
  3362. defaultRowHeight: 21,
  3363. headerFont: '12px 微软雅黑',
  3364. font: '12px 微软雅黑',
  3365. selectedBackColor: '#fffacd',
  3366. readOnly: true,
  3367. },
  3368. afterLocated: function () {
  3369. posSpreadObj.loadCurPosData();
  3370. },
  3371. customSearch: [
  3372. {
  3373. key: 'revise', title: '新增部位', valid: true, parent: true,
  3374. check: function (node) {
  3375. if (node.formc || node.cid) {
  3376. return true;
  3377. } else {
  3378. return false;
  3379. }
  3380. }
  3381. }
  3382. ],
  3383. });
  3384. }
  3385. searchLedger.spread.refresh();
  3386. } else if (tab.attr('content') === '#error-list') {
  3387. errorList.spread.refresh();
  3388. } else if (tab.attr('content') === '#check-list') {
  3389. checkList.spread.refresh();
  3390. } else if (tab.attr('content') === '#sum-load-miss') {
  3391. sumLoadMiss.spread.refresh();
  3392. } else if (tab.attr('content') === '#dsk-list') {
  3393. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  3394. $(dskActiveTab).addClass('active');
  3395. if (dskActiveTab === '#jlzf-spread') {
  3396. $('#get-dsk-btn').hide();
  3397. $('#get-dsk-bills-btn').hide();
  3398. jlzfBills.loadData();
  3399. jlzfBills.spread.refresh();
  3400. } else if (dskActiveTab === '#dsk-spread') {
  3401. $('#get-dsk-btn').show();
  3402. $('#get-dsk-bills-btn').show();
  3403. dskBills.loadData();
  3404. dskBills.spread.refresh();
  3405. }
  3406. }
  3407. }
  3408. else {// 收起工具栏
  3409. tab.removeClass('active');
  3410. tabPanel.removeClass('active');
  3411. showSideTools(tab.hasClass('active'));
  3412. }
  3413. billsSpread.refresh();
  3414. if (posSpread) posSpread.refresh();
  3415. });
  3416. // 新增清单切换tab
  3417. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  3418. e.preventDefault();
  3419. const dskActiveTab = $(this).attr('href');
  3420. if (dskActiveTab === '#jlzf-spread') {
  3421. $('#get-dsk-btn').hide();
  3422. $('#get-dsk-bills-btn').hide();
  3423. jlzfBills.loadData();
  3424. jlzfBills.spread.refresh();
  3425. } else if (dskActiveTab === '#dsk-spread') {
  3426. $('#get-dsk-btn').show();
  3427. $('#get-dsk-bills-btn').show();
  3428. dskBills.loadData();
  3429. dskBills.spread.refresh();
  3430. }
  3431. });
  3432. // 显示层次
  3433. (function (select, sheet) {
  3434. $(select).click(function () {
  3435. if (!sheet.zh_tree) return;
  3436. const tag = $(this).attr('tag');
  3437. const tree = sheet.zh_tree;
  3438. setTimeout(() => {
  3439. showWaitingView();
  3440. switch (tag) {
  3441. case "1":
  3442. case "2":
  3443. case "3":
  3444. case "4":
  3445. case "5":
  3446. tree.expandByLevel(parseInt(tag));
  3447. SpreadJsObj.refreshTreeRowVisible(sheet);
  3448. break;
  3449. case "last":
  3450. tree.expandByCustom(() => { return true; });
  3451. SpreadJsObj.refreshTreeRowVisible(sheet);
  3452. break;
  3453. case "leafXmj":
  3454. tree.expandToLeafXmj();
  3455. SpreadJsObj.refreshTreeRowVisible(sheet);
  3456. break;
  3457. }
  3458. closeWaitingView();
  3459. }, 100);
  3460. });
  3461. })('a[name=showLevel]', billsSheet);
  3462. if (openRevise) {
  3463. const dataChecker = DataChecker({
  3464. checkUrl: window.location.pathname + '/check',
  3465. completeData: function (data) {
  3466. pos.updateDatas({update: data.source.pos});
  3467. const loadResult = billsTree.loadPostData({update: data.source.bills});
  3468. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3469. posSpreadObj.loadCurPosData();
  3470. for (const e of data.error) {
  3471. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  3472. }
  3473. },
  3474. errorList: errorList,
  3475. });
  3476. $('#ledger-check2').click(() => {
  3477. ledgerCheck2({
  3478. ledgerTree: billsTree,
  3479. ledgerPos: pos,
  3480. checkList: checkList,
  3481. decimal: decimal,
  3482. checkOption: checkOption,
  3483. }).then(result => {
  3484. check2Viewing({
  3485. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  3486. randomWait: true,
  3487. prefix: 'check2-',
  3488. checks: result,
  3489. checkList: checkList,
  3490. });
  3491. });
  3492. });
  3493. if (isYb) {
  3494. let compilationList = [];
  3495. $('#get-dsk-btn').click(function () {
  3496. // 判断是否已绑定dsk用户
  3497. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  3498. if (result === 1) {
  3499. $('#error-dsk .modal-body').find('h5').eq(0).show();
  3500. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  3501. $('#error-dsk').modal('show');
  3502. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  3503. } else if (result === 2) {
  3504. $('#error-dsk .modal-body').find('h5').eq(1).show();
  3505. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  3506. $('#error-dsk').modal('show');
  3507. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  3508. } else {
  3509. postData('/profile/dsk/api', {
  3510. type: 'compilation',
  3511. getProject: 1,
  3512. compilationId: getLocalCache(dskCompilation)
  3513. }, function (result) {
  3514. let html = '';
  3515. for (const data of result.compilation) {
  3516. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  3517. }
  3518. dskAccountData = result.dskAccountData;
  3519. compilationList = result.compilation;
  3520. console.log(compilationList);
  3521. $('#dsk-compilation-list').html(html);
  3522. $('#add-dsk').modal('show');
  3523. setLocalCache(dskCompilation, result.select_compilation);
  3524. makeDskProjectSjsHtml(result.project);
  3525. });
  3526. }
  3527. })
  3528. });
  3529. $('#get-dsk-bills-btn').click(function () {
  3530. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  3531. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  3532. });
  3533. $('body').on('change', '#dsk-compilation-list', function () {
  3534. const compilationId = $(this).val();
  3535. setLocalCache(dskCompilation, compilationId);
  3536. dskProjectSpreadObj.refreshSourceTree();
  3537. });
  3538. $('.hide-dsk-modal').click(function () {
  3539. $('#error-dsk').modal('hide');
  3540. });
  3541. let dp = false;
  3542. let gsObj = {
  3543. setting: null,
  3544. gsSheet: null,
  3545. grSheet: null,
  3546. tenderSourceTree: null,
  3547. grArray: dskProjects ? dskProjects : [],
  3548. orgSelect: null,
  3549. };
  3550. function makeDskProjectSjsHtml(datas) {
  3551. if (!dp) {
  3552. initDskProjectTree();
  3553. dp = true;
  3554. }
  3555. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  3556. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  3557. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  3558. if (datas.length === 0) {
  3559. $('#show-project-0').show();
  3560. } else {
  3561. $('#show-project-0').hide();
  3562. }
  3563. }
  3564. const dskProjectSpreadObj = {
  3565. _addTender: function (tender) {
  3566. const gr = gsObj.grArray.find(function (x) {
  3567. return x.pid === tender.pid;
  3568. });
  3569. const c_id = getLocalCache(dskCompilation);
  3570. const t = {
  3571. pid: tender.pid,
  3572. name: tender.name,
  3573. compilationId: c_id,
  3574. compilationName: _.find(compilationList, {ID: c_id}).name
  3575. };
  3576. if (!gr) gsObj.grArray.push(t);
  3577. return t;
  3578. },
  3579. _removeTender: function (tender) {
  3580. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  3581. return x.pid === tender.pid;
  3582. });
  3583. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  3584. },
  3585. reloadResultData: function () {
  3586. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  3587. },
  3588. refreshSourceTree: function () {
  3589. const c_id = getLocalCache(dskCompilation);
  3590. if (c_id) {
  3591. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  3592. makeDskProjectSjsHtml(result);
  3593. });
  3594. }
  3595. },
  3596. gsButtonClicked: function (e, info) {
  3597. if (!info.sheet.zh_setting) return;
  3598. const col = info.sheet.zh_setting.cols[info.col];
  3599. if (col.field !== 'selected') return;
  3600. const node = SpreadJsObj.getSelectObject(info.sheet);
  3601. node.selected = !node.selected;
  3602. if (node.children && node.children.length > 0) {
  3603. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  3604. for (const p of posterity) {
  3605. p.selected = node.selected;
  3606. if ((!p.children || p.children.length === 0) && p.type === 2) {
  3607. if (p.selected) {
  3608. dskProjectSpreadObj._addTender(p);
  3609. } else {
  3610. dskProjectSpreadObj._removeTender(p);
  3611. }
  3612. }
  3613. }
  3614. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  3615. } else if (node.type === 2) {
  3616. if (node.selected) {
  3617. dskProjectSpreadObj._addTender(node);
  3618. } else {
  3619. dskProjectSpreadObj._removeTender(node);
  3620. }
  3621. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  3622. }
  3623. dskProjectSpreadObj.reloadResultData();
  3624. },
  3625. deleteGr: function () {
  3626. if (gsObj.grArray.length === 0) return;
  3627. if (gsObj.grSheet.getSelections().length === 0) return;
  3628. const selections = gsObj.grSheet.getSelections();
  3629. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  3630. const row = sel && sel.row !== undefined ? sel.row : -1;
  3631. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3632. return false;
  3633. }
  3634. const delList = [];
  3635. for (let r = 0; r < sel.rowCount; r++) {
  3636. const select = gsObj.grArray[row + r];
  3637. delList.push(select);
  3638. }
  3639. _.pullAll(gsObj.grArray, delList);
  3640. dskProjectSpreadObj.reloadResultData();
  3641. dskProjectSpreadObj.refreshSourceTree();
  3642. },
  3643. };
  3644. const initDskProjectTree = function () {
  3645. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  3646. gsObj.gsSheet = gsSpread.getActiveSheet();
  3647. const gsSpreadSetting = {
  3648. cols: [
  3649. {
  3650. title: '选择',
  3651. field: 'selected',
  3652. hAlign: 1,
  3653. width: 40,
  3654. formatter: '@',
  3655. cellType: 'checkbox',
  3656. readOnly: true,
  3657. },
  3658. {
  3659. title: '名称',
  3660. field: 'name',
  3661. hAlign: 0,
  3662. width: 400,
  3663. formatter: '@',
  3664. readOnly: true,
  3665. folderCell: true,
  3666. cellType: 'tree'
  3667. },
  3668. ],
  3669. emptyRows: 0,
  3670. headRows: 1,
  3671. headRowHeight: [32],
  3672. defaultRowHeight: 21,
  3673. headerFont: '12px 微软雅黑',
  3674. font: '12px 微软雅黑',
  3675. headColWidth: [0],
  3676. selectedBackColor: '#fffacd',
  3677. };
  3678. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  3679. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  3680. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  3681. gsObj.grSheet = grSpread.getActiveSheet();
  3682. const grSpreadSetting = {
  3683. cols: [
  3684. {
  3685. title: '名称',
  3686. colSpan: '1',
  3687. rowSpan: '1',
  3688. field: 'name',
  3689. hAlign: 0,
  3690. width: 250,
  3691. formatter: '@',
  3692. readOnly: true,
  3693. cellType: 'ellipsisAutoTip',
  3694. scrollHeightClass: '.modal-height-500'
  3695. },
  3696. {
  3697. title: '所属编办',
  3698. colSpan: '1',
  3699. rowSpan: '1',
  3700. field: 'compilationName',
  3701. hAlign: 0,
  3702. width: 150,
  3703. formatter: '@',
  3704. readOnly: true
  3705. },
  3706. ],
  3707. emptyRows: 0,
  3708. headRows: 1,
  3709. headRowHeight: [32],
  3710. defaultRowHeight: 21,
  3711. headerFont: '12px 微软雅黑',
  3712. font: '12px 微软雅黑',
  3713. headColWidth: []
  3714. };
  3715. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  3716. // 右键删除已选项目
  3717. const gsContextMenuOptions = {
  3718. selector: '#dsk-project-result-spread',
  3719. build: function ($trigger, e) {
  3720. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  3721. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3722. },
  3723. items: {
  3724. delete: {
  3725. name: '删除',
  3726. icon: 'fa-remove',
  3727. callback: function (key, opt) {
  3728. dskProjectSpreadObj.deleteGr();
  3729. },
  3730. disabled: function (key, opt) {
  3731. const selection = gsObj.grSheet.getSelections();
  3732. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  3733. const row = sel && sel.row !== undefined ? sel.row : -1;
  3734. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3735. return true;
  3736. }
  3737. return false;
  3738. }
  3739. },
  3740. }
  3741. };
  3742. $.contextMenu(gsContextMenuOptions);
  3743. $('#add-dsk').bind('shown.bs.modal', function () {
  3744. if (gsSpread) gsSpread.refresh();
  3745. if (grSpread) grSpread.refresh();
  3746. });
  3747. };
  3748. const dskProject2Tree = (function () {
  3749. const treeSetting = {
  3750. id: 'tmt_id',
  3751. pid: 'tmt_pid',
  3752. order: 'seq',
  3753. level: 'level',
  3754. rootId: '-1',
  3755. fullPath: 'full_path',
  3756. };
  3757. const tenderTree = createNewPathTree('gather', treeSetting);
  3758. function setChildrenNode(node, files, tenders) {
  3759. const children = _.filter(files, {parentID: node.pid});
  3760. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  3761. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  3762. for (const c of checkChildren) {
  3763. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  3764. // // 判断文件夹下有无东西,没有就不插入
  3765. // continue;
  3766. // }
  3767. const child = {
  3768. pid: c.ID,
  3769. parentID: c.parentID,
  3770. name: c.name,
  3771. type: c.type,
  3772. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  3773. };
  3774. tenderTree.addNode(child, node);
  3775. if (c.type === 1) setChildrenNode(child, files, tenders);
  3776. }
  3777. }
  3778. function convert(projects) {
  3779. tenderTree.clearDatas();
  3780. const result = filterFolders(projects);
  3781. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  3782. const files = _.filter(result, {type: 1});
  3783. const tenders = _.filter(result, {type: 2});
  3784. for (const t of topLevel) {
  3785. const node = {
  3786. pid: t.ID,
  3787. parentID: t.parentID,
  3788. name: t.name,
  3789. type: t.type,
  3790. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  3791. };
  3792. tenderTree.addNode(node, null);
  3793. if (t.type === 1) setChildrenNode(node, files, tenders);
  3794. }
  3795. tenderTree.sortTreeNode(true);
  3796. return tenderTree;
  3797. }
  3798. return {tenderTree, convert}
  3799. })();
  3800. function filterFolders(data) {
  3801. // 构建ID到节点的映射
  3802. const idMap = data.reduce((map, node) => {
  3803. map[node.ID] = node;
  3804. return map;
  3805. }, {});
  3806. // 建立父子关系映射
  3807. const parentMap = data.reduce((map, node) => {
  3808. if (node.parentID !== '-1') {
  3809. if (!map[node.parentID]) {
  3810. map[node.parentID] = [];
  3811. }
  3812. map[node.parentID].push(node.ID);
  3813. }
  3814. return map;
  3815. }, {});
  3816. // 检查节点及其子节点是否包含清单(type=1)
  3817. const hasChecklist = (id) => {
  3818. const node = idMap[id];
  3819. if (node.type === 2) {
  3820. return true;
  3821. }
  3822. if (!parentMap[id]) {
  3823. return false;
  3824. }
  3825. return parentMap[id].some(childID => hasChecklist(childID));
  3826. };
  3827. // 过滤节点
  3828. const filteredIDs = new Set();
  3829. data.forEach(node => {
  3830. if (node.type === 2 || hasChecklist(node.ID)) {
  3831. let currentID = node.ID;
  3832. while (currentID !== '-1') {
  3833. filteredIDs.add(currentID);
  3834. currentID = idMap[currentID].parentID;
  3835. }
  3836. }
  3837. });
  3838. // 返回过滤后的数据
  3839. return data.filter(node => filteredIDs.has(node.ID));
  3840. }
  3841. $('#set-dsk-project').click(function () {
  3842. postData('/profile/dsk/api', {
  3843. type: 'save_projects',
  3844. tid: window.location.pathname.split('/')[2],
  3845. project_list: gsObj.grArray
  3846. }, function (result) {
  3847. // dskAccountData.select_project = result;
  3848. dskProjects = gsObj.grArray;
  3849. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  3850. dskAccountData.select_project = result;
  3851. changeDskProject(result);
  3852. dskBills.spread.refresh();
  3853. }
  3854. setDskProjectSelect(gsObj.grArray);
  3855. $('#add-dsk').modal('hide');
  3856. });
  3857. });
  3858. $('#add-dsk').on('hide.bs.modal', function () {
  3859. $('#autoTip').hide();
  3860. });
  3861. function setDskProjectSelect(projects) {
  3862. let html = '';
  3863. for (const project of projects) {
  3864. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  3865. }
  3866. $('#change-dsk-project').html(html);
  3867. }
  3868. // 选中所有新增部位/清单
  3869. $('#add-all-revise').click(function() {
  3870. const this_cid = window.location.pathname.split('/')[4];
  3871. makeGclGatherData();
  3872. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3873. type: 'get-revise-list',
  3874. }, function (result) {
  3875. const addDatas = [];
  3876. for (const ggd in gclGatherData) {
  3877. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  3878. let hadcid = 0;
  3879. for (const xmj of gclGatherData[ggd].leafXmjs) {
  3880. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  3881. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  3882. if (changeLedger || changePos) {
  3883. xmj.cid = 1;
  3884. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  3885. hadcid = 1;
  3886. }
  3887. }
  3888. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  3889. }
  3890. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  3891. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  3892. if (leafXmjs.length > 0) {
  3893. gclInfo.is_change = 1;
  3894. for (const xmj of leafXmjs) {
  3895. if (_.findIndex(changeList, function (item) {
  3896. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  3897. }) === -1) {
  3898. addDatas.push({
  3899. lid: xmj.gcl_id,
  3900. code: gclInfo.code,
  3901. name: gclInfo.name || '',
  3902. unit: gclInfo.unit || '',
  3903. unit_price: gclInfo.unit_price,
  3904. oamount: xmj.quantity,
  3905. oamount2: xmj.quantity,
  3906. bwmx: xmj.bwmx || xmj.jldy || '',
  3907. xmj_code: xmj.code || '',
  3908. xmj_jldy: xmj.jldy || '',
  3909. xmj_dwgc: xmj.dwgc || '',
  3910. xmj_fbgc: xmj.fbgc || '',
  3911. xmj_fxgc: xmj.fxgc || '',
  3912. gcl_id: xmj.gcl_id,
  3913. mx_id: xmj.mx_id || '',
  3914. });
  3915. }
  3916. }
  3917. }
  3918. }
  3919. console.log(addDatas);
  3920. if (addDatas.length > 0) {
  3921. // 更新至服务器
  3922. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3923. type: 'add-change-list',
  3924. postData: addDatas,
  3925. }, function (result) {
  3926. toastr.success('已新增当前变更令新增的所有部位/清单');
  3927. changeList = result.changeList;
  3928. const sortData = SpreadJsObj.getSortData(billsSheet);
  3929. const billsNodes = _.filter(sortData, function (item) {
  3930. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  3931. });
  3932. for (const billsNode of billsNodes) {
  3933. billsNode.is_change = 1;
  3934. }
  3935. const loadResult = { update: billsNodes };
  3936. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3937. posSpreadObj.loadCurPosData();
  3938. });
  3939. } else {
  3940. toastr.warning('未存在当前变更令新增的部位/清单');
  3941. }
  3942. });
  3943. });
  3944. }
  3945. }
  3946. });
  3947. // 编号排序,多重判断
  3948. function sortByCode(a, b, code = 'b_code') {
  3949. let code1 = a[code].split('-');
  3950. let code2 = b[code].split('-');
  3951. let code1length = code1.length;
  3952. let code2length = code2.length;
  3953. for (let i = 0; i < code1length; i ++) {
  3954. if (i+1 <= code2length) {
  3955. if (code1[i] != code2[i]) {
  3956. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  3957. return parseInt(code1[i]) - parseInt(code2[i]);
  3958. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  3959. return 1;
  3960. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  3961. return -1;
  3962. } else {
  3963. const str1length = code1[i].length;
  3964. const str2length = code2[i].length;
  3965. for (let j = 0; j < str1length; j++) {
  3966. if (j+1 <= str2length) {
  3967. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  3968. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  3969. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  3970. if (str1length == str2length) {
  3971. return 0;
  3972. } else {
  3973. return str1length - str2length;
  3974. }
  3975. }
  3976. } else {
  3977. if (j+1 >= str1length) {
  3978. return 1;
  3979. } else {
  3980. return -1;
  3981. }
  3982. }
  3983. }
  3984. }
  3985. } else if (i+1 == code1length && code1[i] == code2[i]) {
  3986. if (code1length == code2length) {
  3987. return 0;
  3988. } else {
  3989. return code1length - code2length;
  3990. }
  3991. }
  3992. } else {
  3993. if (i+1 >= code1length) {
  3994. return 1;
  3995. } else {
  3996. return -1;
  3997. }
  3998. }
  3999. }
  4000. }