change_revise.js 188 KB

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