change_revise.js 167 KB

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