revise.js 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-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 checkOption = {
  30. sibling: { enable: 1 },
  31. empty_code: { enable: 1 },
  32. calc: {
  33. enable: 1,
  34. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  35. },
  36. zero: { enable: 1 },
  37. zeroPos: { enable: 1 },
  38. pos_drawingCode: { 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. };
  50. $(document).ready(() => {
  51. let stdXmj, stdGcl, searchLedger;
  52. autoFlashHeight();
  53. // 初始化spread
  54. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  55. const billsSheet = billsSpread.getActiveSheet();
  56. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  57. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  58. billsSpreadSetting.headColWidth = [50];
  59. billsSpreadSetting.rowHeader = [
  60. {
  61. rowHeaderType: 'tag',
  62. setting: {
  63. indent: 14,
  64. tagSize: 0.8,
  65. tagFont: '8px 微软雅黑',
  66. getColor: function (index, data) {
  67. if (!data) return;
  68. return billsTag.getBillsTagsColor(data.id);
  69. },
  70. getTagHtml: function (index, data) {
  71. if (!data) return;
  72. const getHtml = function (list) {
  73. if (!list || list.length === 0) return '';
  74. const html = [];
  75. for (const l of list) {
  76. html.push('<div class="row mr-1">');
  77. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  78. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  79. html.push('</div>');
  80. }
  81. return html.join('');
  82. };
  83. return getHtml(billsTag.getBillsTagsInfo(data.id));
  84. }
  85. },
  86. },
  87. ];
  88. billsSpreadSetting.getColor = function(sheet, data, row, col, defaultColor) {
  89. if (!data) return defaultColor;
  90. return data.used ? spreadColor.revise.used : defaultColor;
  91. };
  92. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  93. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  94. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  95. const posSheet = posSpread.getActiveSheet();
  96. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  97. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  98. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  99. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  100. const billsTag = $.billsTag({
  101. selector: '#bills-tag',
  102. relaSpread: billsSpread,
  103. updateUrl: window.location.pathname + '/tag',
  104. afterModify: function (nodes) {
  105. SpreadJsObj.repaintNodesRowHeader(billsSpread.getActiveSheet(), nodes);
  106. },
  107. afterLocated: function () {
  108. posSpreadObj.loadCurPosData();
  109. },
  110. afterShow: function () {
  111. billsSpread.refresh();
  112. if (posSpread) posSpread.refresh();
  113. },
  114. });
  115. const errorList = $.cs_errorList({
  116. tabSelector: '#error-list-tab',
  117. selector: '#error-list',
  118. relaSpread: billsSpread,
  119. storeKey: 'revise-error-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  120. afterLocated: function () {
  121. posSpreadObj.loadCurPosData();
  122. },
  123. afterShow: function () {
  124. billsSpread.refresh();
  125. if (posSpread) posSpread.refresh();
  126. },
  127. });
  128. const checkList = $.ledger_checkList({
  129. id: 'check-list',
  130. tabSelector: '#check-list-tab',
  131. selector: '#check-list',
  132. relaSpread: billsSpread,
  133. storeKey: 'revise-check-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  134. checkType: getCheckType(checkOption),
  135. afterLocated: function () {
  136. posSpreadObj.loadCurPosData();
  137. },
  138. afterShow: function () {
  139. billsSpread.refresh();
  140. if (posSpread) posSpread.refresh();
  141. },
  142. });
  143. const sumLoadMiss = $.sumLoadMiss({
  144. tabSelector: '#sum-load-miss-tab',
  145. selector: '#sum-load-miss',
  146. relaSpread: billsSpread,
  147. storeKey: 'revise-slm-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  148. id: 'revise-slm',
  149. afterLocated: function () {
  150. posSpreadObj.loadCurPosData();
  151. },
  152. afterShow: function () {
  153. billsSpread.refresh();
  154. if (posSpread) posSpread.refresh();
  155. },
  156. });
  157. // 初始化 节点树结构
  158. const treeSetting = {
  159. id: 'ledger_id',
  160. pid: 'ledger_pid',
  161. order: 'order',
  162. level: 'level',
  163. rootId: -1,
  164. keys: ['id', 'tender_id', 'ledger_id'],
  165. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  166. autoExpand: 3,
  167. markExpandKey: 'revise-bills-expand',
  168. markExpandSubKey: window.location.pathname.split('/')[2],
  169. };
  170. if (!isTz) {
  171. treeSetting.calcFields.push('deal_tp');
  172. }
  173. treeSetting.calcFun = function (node) {
  174. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  175. };
  176. const billsTree = createNewPathTree('revise', treeSetting);
  177. // 初始化 计量单元
  178. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  179. // 清单 相关方法&绑定spreadjs事件
  180. const billsTreeSpreadObj = {
  181. loadExprToInput(sheet) {
  182. const sel = sheet.getSelections()[0];
  183. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  184. if (col && col.type === 'Number') {
  185. const data = SpreadJsObj.getSelectObject(sheet);
  186. if (data) {
  187. const exprInfo = getExprInfo(col.field);
  188. if (exprInfo) {
  189. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  190. .attr('field', col.field).attr('org', data[col.field]);
  191. } else {
  192. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  193. }
  194. if (col.field.indexOf('dgn') >= 0) {
  195. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
  196. } else if (col.field === 'unit_price') {
  197. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true));
  198. } else {
  199. const nodePos = pos.getLedgerPos(data.id);
  200. if (nodePos && nodePos.length > 0) {
  201. $('#bills-expr').val('').attr('readOnly', true);
  202. $('#bills-expr').removeAttr('data-row');
  203. } else {
  204. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
  205. }
  206. }
  207. $('#bills-expr').attr('data-row', sel.row);
  208. } else {
  209. $('#bills-expr').val('').attr('readOnly', true);
  210. $('#bills-expr').removeAttr('data-row');
  211. }
  212. } else {
  213. $('#bills-expr').val('').attr('readOnly', true);
  214. $('#bills-expr').removeAttr('data-row');
  215. }
  216. },
  217. getDefaultSelectInfo: function (sheet) {
  218. const tree = sheet.zh_tree;
  219. if (!tree) return;
  220. const sel = sheet.getSelections()[0];
  221. const node = sheet.zh_tree.nodes[sel.row];
  222. if (!node) return;
  223. let count = 1;
  224. if (sel.rowCount > 1) {
  225. for (let r = 1; r < sel.rowCount; r++) {
  226. const rNode = sheet.zh_tree.nodes[sel.row + r];
  227. if (rNode.level > node.level) continue;
  228. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  229. toastr.warning('请选择同一节点下的节点,进行该操作');
  230. return;
  231. }
  232. count += 1;
  233. }
  234. }
  235. return [tree, node, count];
  236. },
  237. /**
  238. * 刷新顶部按钮是否可用
  239. * @param sheet
  240. * @param selections
  241. */
  242. refreshOperationValid: function (sheet, selection) {
  243. const setObjEnable = function (obj, enable) {
  244. if (enable) {
  245. obj.removeClass('disabled');
  246. } else {
  247. obj.addClass('disabled');
  248. }
  249. };
  250. const invalidAll = function () {
  251. setObjEnable($('a[name=base-opr][type=add]'), false);
  252. setObjEnable($('a[name=base-opr][type=delete]'), false);
  253. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  254. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  255. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  256. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  257. };
  258. const sel = selection ? selection[0] : sheet.getSelections()[0];
  259. const row = sel ? sel.row : -1;
  260. const tree = sheet.zh_tree;
  261. if (!tree) {
  262. invalidAll();
  263. return;
  264. }
  265. const first = sheet.zh_tree.nodes[row];
  266. if (!first) {
  267. invalidAll();
  268. return;
  269. }
  270. let last = first, sameParent = true, nodeUsed = first.used;
  271. if (sel.rowCount > 1 && first) {
  272. for (let r = 1; r < sel.rowCount; r++) {
  273. const rNode = tree.nodes[sel.row + r];
  274. if (!rNode) {
  275. sameParent = false;
  276. break;
  277. }
  278. nodeUsed = nodeUsed || rNode.used;
  279. if (rNode.level > first.level) continue;
  280. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  281. sameParent = false;
  282. break;
  283. }
  284. last = rNode;
  285. }
  286. }
  287. const preNode = tree.getPreSiblingNode(first);
  288. const valid = !sheet.zh_setting.readOnly;
  289. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1);
  290. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed);
  291. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
  292. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  293. const posRange = last ? pos.getLedgerPos(last.id) : [];
  294. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  295. && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
  296. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  297. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  298. && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0) && !preNode.used);
  299. setObjEnable($('#cut'), valid);
  300. setObjEnable($('#paste'), valid);
  301. },
  302. /**
  303. *
  304. * @param sheet
  305. * @param data
  306. */
  307. refreshTree: function (sheet, data) {
  308. SpreadJsObj.massOperationSheet(sheet, function () {
  309. const tree = sheet.zh_tree;
  310. // 处理删除
  311. if (data.delete) {
  312. data.delete.sort(function (a, b) {
  313. return b.deleteIndex - a.deleteIndex;
  314. });
  315. for (const d of data.delete) {
  316. sheet.deleteRows(d.deleteIndex, 1);
  317. }
  318. }
  319. // 处理新增
  320. if (data.create) {
  321. const newNodes = data.create;
  322. if (newNodes) {
  323. newNodes.sort(function (a, b) {
  324. return a.index - b.index;
  325. });
  326. for (const node of newNodes) {
  327. sheet.addRows(node.index, 1);
  328. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  329. }
  330. }
  331. }
  332. // 处理更新
  333. if (data.update) {
  334. const rows = [];
  335. for (const u of data.update) {
  336. rows.push(tree.nodes.indexOf(u));
  337. billsTag.refreshBillsTagView(u);
  338. }
  339. SpreadJsObj.reLoadRowsData(sheet, rows);
  340. }
  341. // 处理展开
  342. if (data.expand) {
  343. const expanded = [];
  344. for (const e of data.expand) {
  345. if (expanded.indexOf(e) === -1) {
  346. const posterity = tree.getPosterity(e);
  347. for (const p of posterity) {
  348. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  349. expanded.push(p);
  350. }
  351. }
  352. }
  353. }
  354. });
  355. },
  356. loadRelaData: function() {
  357. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  358. SpreadJsObj.resetTopAndSelect(posSheet);
  359. posSpreadObj.loadCurPosData();
  360. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  361. posSearch.search($('#pos-keyword').val());
  362. },
  363. selectionChanged: function (e, info) {
  364. if (info.newSelections) {
  365. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row) {
  366. billsTreeSpreadObj.loadRelaData();
  367. }
  368. }
  369. billsTreeSpreadObj.loadExprToInput(info.sheet);
  370. },
  371. /**
  372. * 新增节点
  373. * @param spread
  374. */
  375. baseOpr: function (sheet, type, addCount = 1) {
  376. const self = this;
  377. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  378. if (!tree || !node || !count) return;
  379. if (type === 'delete') {
  380. const parent = tree.getParent(node);
  381. const children = parent ? parent.children : tree.children;
  382. const index = children.indexOf(node);
  383. for (let i = 0; i < count; i++) {
  384. const child = children[i+index];
  385. if (tree.checkNodeUsed(child, pos)) {
  386. toastr.warning('选中的节点已计量,不可删除');
  387. return;
  388. }
  389. }
  390. } else if (type === 'up-level') {
  391. const parent = tree.getParent(node);
  392. const children = parent ? parent.children : tree.children;
  393. const index = children.indexOf(node);
  394. for (let i = index; i < children.length; i++) {
  395. const child = children[index];
  396. if (tree.checkNodeUsed(child, pos)) {
  397. if (i >= index + count) {
  398. toastr.warning('其后节点已计量,选中的节点不可升级');
  399. } else {
  400. toastr.warning('选中的节点已计量,不可升级');
  401. }
  402. return;
  403. }
  404. }
  405. } else if (type === 'down-level') {
  406. const parent = tree.getParent(node);
  407. const children = parent ? parent.children : tree.children;
  408. const index = children.indexOf(node);
  409. if (index > 0 && children[index-1].used) {
  410. toastr.warning('其前节点已计量,选中的节点不可降级');
  411. return;
  412. }
  413. for (let i = index; i < count; i++) {
  414. const child = children[i+index];
  415. if (tree.checkNodeUsed(child, pos)) {
  416. toastr.warning('选中的节点已计量,不可降级');
  417. return;
  418. }
  419. }
  420. }
  421. if (type === 'delete') {
  422. deleteAfterHint(function () {
  423. postData(window.location.pathname + '/update', {
  424. postType: type,
  425. postData: {
  426. id: node.ledger_id,
  427. count: type === 'add' ? addCount : count,
  428. }
  429. }, function (result) {
  430. const refreshData = tree.loadPostData(result);
  431. self.refreshTree(sheet, refreshData);
  432. const sel = sheet.getSelections()[0];
  433. if (sel) {
  434. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  435. }
  436. self.refreshOperationValid(sheet);
  437. billsTag.afterDeleteBills(refreshData.delete);
  438. });
  439. });
  440. } else {
  441. postData(window.location.pathname + '/update', {
  442. postType: type,
  443. postData: {
  444. id: node.ledger_id,
  445. count: type === 'add' ? addCount : count,
  446. }
  447. }, function (result) {
  448. const refreshData = tree.loadPostData(result);
  449. self.refreshTree(sheet, refreshData);
  450. if (['up-move', 'down-move'].indexOf(type) > -1) {
  451. const sel = sheet.getSelections()[0];
  452. if (sel) {
  453. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  454. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  455. }
  456. } else if (type === 'add') {
  457. const sel = sheet.getSelections()[0];
  458. if (sel) {
  459. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  460. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  461. }
  462. }
  463. self.refreshOperationValid(sheet);
  464. });
  465. }
  466. },
  467. /**
  468. * 编辑单元格响应事件
  469. * @param {Object} e
  470. * @param {Object} info
  471. */
  472. editEnded: function (e, info) {
  473. if (info.sheet.zh_setting) {
  474. const col = info.sheet.zh_setting.cols[info.col];
  475. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  476. const node = sortData[info.row];
  477. const data = {
  478. id: node.id,
  479. tender_id: node.tender_id,
  480. ledger_id: node.ledger_id
  481. };
  482. // 未改变值则不提交
  483. const orgValue = node[col.field];
  484. const newValue = trimInvalidChar(info.editingText);
  485. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  486. return;
  487. }
  488. // 台账模式,检查计量单元相关
  489. if (isTz) {
  490. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  491. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  492. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  493. if (!node.children || node.children.length ===0) {
  494. const lPos = pos.getLedgerPos(node.id);
  495. if (lPos && lPos.length > 0) {
  496. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  497. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  498. return;
  499. }
  500. }
  501. }
  502. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  503. const lPos = pos.getLedgerPos(node.id);
  504. if (lPos && lPos.length > 0) {
  505. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  506. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  507. return;
  508. }
  509. }
  510. }
  511. if (col.field === 'node_type' && newValue && newValue !== '0') {
  512. const sameNodeType = sortData.find(x => { return x.node_type == newValue; });
  513. if (sameNodeType) {
  514. toastr.error('已存在该费用类别,请勿重复选择');
  515. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  516. return;
  517. }
  518. }
  519. // 获取更新数据
  520. const exprInfo = getExprInfo(col.field);
  521. if (info.editingText) {
  522. const text = newValue;
  523. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  524. toastr.error('节点已计量,请勿删除编号');
  525. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  526. return;
  527. }
  528. if (col.type === 'Number') {
  529. const num = _.toNumber(text);
  530. if (_.isFinite(num)) {
  531. data[col.field] = num;
  532. if (exprInfo) {
  533. data[exprInfo.expr] = '';
  534. }
  535. } else {
  536. try {
  537. data[col.field] = math.evaluate(transExpr(text));
  538. if (exprInfo) {
  539. data[exprInfo.expr] = newValue;
  540. }
  541. } catch(err) {
  542. toastr.error('输入的表达式非法');
  543. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  544. return;
  545. }
  546. }
  547. } else {
  548. data[col.field] = text;
  549. }
  550. } else {
  551. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  552. toastr.error('节点已计量,请勿删除编号');
  553. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  554. return;
  555. }
  556. data[col.field] = null;
  557. if (exprInfo) {
  558. data[exprInfo.expr] = '';
  559. }
  560. }
  561. // 更新至服务器
  562. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  563. const refreshNode = billsTree.loadPostData(result);
  564. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  565. });
  566. }
  567. },
  568. clipboardPasting: function (e, info) {
  569. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  570. info.cancel = true;
  571. if (!setting || !tree) return;
  572. // const range = info.cellRange;
  573. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  574. // const node = tree.nodes[iRow];
  575. // if (tree.checkNodeUsed(node, pos)) {
  576. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  577. // return;
  578. // }
  579. // }
  580. const pasteData = info.pasteData.html
  581. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  582. : (info.pasteData.text === ''
  583. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  584. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  585. const hint = {
  586. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  587. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  588. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  589. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  590. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  591. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  592. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  593. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  594. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  595. };
  596. const datas = [], filterNodes = [];
  597. let pid, level, filterRow = 0;
  598. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  599. const curRow = info.cellRange.row + iRow;
  600. const node = tree.nodes[curRow];
  601. if (!node) continue;
  602. if (!pid) pid = node.ledger_pid;
  603. if (!level) level = node.level;
  604. // if (node.ledger_pid !== pid) {
  605. // toastMessageUniq(hint.sameParent);
  606. // filterRow+=1;
  607. // continue;
  608. // }
  609. if (node.level < level) break;
  610. let bPaste = false;
  611. const data = info.sheet.zh_tree.getNodeKeyData(node);
  612. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  613. const curCol = info.cellRange.col + iCol;
  614. const colSetting = info.sheet.zh_setting.cols[curCol];
  615. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  616. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  617. toastMessageUniq(hint.parent);
  618. continue;
  619. }
  620. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  621. toastMessageUniq(hint.gcl);
  622. continue;
  623. }
  624. const lPos = pos.getLedgerPos(node.id);
  625. if (lPos && lPos.length > 0) {
  626. if (value === '' && colSetting.field === 'b_code') {
  627. toastMessageUniq(hint.posCode);
  628. continue;
  629. }
  630. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  631. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  632. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  633. if (isTz) {
  634. toastMessageUniq(hint.posQty);
  635. continue;
  636. }
  637. }
  638. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  639. toastMessageUniq(hint.posXmj);
  640. continue;
  641. }
  642. }
  643. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  644. toastMessageUniq (hint.usedUp);
  645. continue;
  646. }
  647. if (colSetting.type === 'Number') {
  648. const num = _.toNumber(value);
  649. if (num) {
  650. data[colSetting.field] = num;
  651. } else {
  652. try {
  653. data[colSetting.field] = math.evaluate(transExpr(value));
  654. const exprInfo = getExprInfo(colSetting.field);
  655. if (exprInfo) {
  656. data[exprInfo.expr] = value;
  657. }
  658. bPaste = true;
  659. } catch (err) {
  660. toastMessageUniq(hint.invalidExpr);
  661. continue;
  662. }
  663. }
  664. } else {
  665. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  666. && data[colSetting.field] !== '' && value === '') {
  667. toastMessageUniq(hint.usedCode);
  668. continue;
  669. }
  670. data[colSetting.field] = value;
  671. }
  672. bPaste = true;
  673. }
  674. if (bPaste) {
  675. datas.push(data);
  676. } else {
  677. filterNodes.push(node);
  678. }
  679. }
  680. if (datas.length > 0) {
  681. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  682. const refreshNode = tree.loadPostData(result);
  683. if (refreshNode.update) {
  684. refreshNode.update = refreshNode.update.concat(filterNodes);
  685. }
  686. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  687. }, function () {
  688. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  689. });
  690. } else {
  691. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  692. }
  693. },
  694. clipboardPasted: function (e, info) {
  695. const hint = {
  696. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  697. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  698. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  699. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  700. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  701. };
  702. const tree = info.sheet.zh_tree;
  703. if (!tree) { return; }
  704. const sortData = info.sheet.zh_tree.nodes;
  705. const datas = [], filterNodes = [];
  706. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  707. let bPaste = false;
  708. const curRow = info.cellRange.row + iRow;
  709. const node = sortData[curRow];
  710. if (node) {
  711. const data = info.sheet.zh_tree.getNodeKeyData(node);
  712. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  713. const curCol = info.cellRange.col + iCol;
  714. const colSetting = info.sheet.zh_setting.cols[curCol];
  715. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  716. const lPos = pos.getLedgerPos(node.id);
  717. if (lPos && lPos.length > 0) {
  718. if (value === '' && colSetting.field === 'b_code') {
  719. toastMessageUniq(hint.posCode);
  720. continue;
  721. }
  722. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  723. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  724. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  725. toastMessageUniq(hint.posQty);
  726. continue;
  727. }
  728. }
  729. if (node.used && col.field === 'unit_price') {
  730. toastMessageUniq (hint.usedUp);
  731. continue;
  732. }
  733. if (colSetting.type === 'Number') {
  734. const num = _.toNumber(value);
  735. if (num) {
  736. data[colSetting.field] = num;
  737. } else {
  738. try {
  739. data[colSetting.field] = math.evaluate(transExpr(value));
  740. } catch (err) {
  741. toastMessageUniq(hint.invalidExpr);
  742. continue;
  743. }
  744. }
  745. } else {
  746. if (node.used && (col.field === 'code' || col.field ==='b_code')
  747. && data[colSetting.field] !== '' && value === '') {
  748. toastMessageUniq(hint.usedCode);
  749. continue;
  750. }
  751. data[colSetting.field] = value;
  752. }
  753. bPaste = true;
  754. }
  755. if (bPaste) {
  756. datas.push(data);
  757. } else {
  758. filterNodes.push(node);
  759. }
  760. }
  761. }
  762. if (datas.length > 0) {
  763. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  764. const refreshNode = tree.loadPostData(result);
  765. if (refreshNode.update) {
  766. refreshNode.update = refreshNode.update.concat(filterNodes);
  767. }
  768. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  769. }, function () {
  770. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  771. });
  772. } else {
  773. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  774. }
  775. },
  776. deletePress: function (sheet) {
  777. if (!sheet.zh_setting) return;
  778. const sel = sheet.getSelections()[0], datas = [];
  779. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  780. let bDel = false;
  781. const node = sheet.zh_tree.nodes[iRow];
  782. const data = sheet.zh_tree.getNodeKeyData(node);
  783. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  784. const col = sheet.zh_setting.cols[iCol];
  785. const style = sheet.getStyle(iRow, iCol);
  786. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  787. if (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  788. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  789. return;
  790. }
  791. data[col.field] = null;
  792. const exprInfo = getExprInfo(col.field);
  793. if (exprInfo) {
  794. data[exprInfo.expr] = '';
  795. }
  796. bDel = true;
  797. }
  798. if (bDel) datas.push(data);
  799. }
  800. if (datas.length > 0) {
  801. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  802. const refreshNode = sheet.zh_tree.loadPostData(result);
  803. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  804. billsTreeSpreadObj.loadExprToInput(sheet);
  805. });
  806. }
  807. },
  808. pasteBlock: function (spread, copyInfo) {
  809. const self = this;
  810. const sheet = spread.getActiveSheet();
  811. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  812. postData(window.location.pathname + '/update', {
  813. postType: 'paste-block',
  814. postData: {
  815. id: tree.getNodeKey(node),
  816. tid: copyInfo.tid,
  817. block: copyInfo.block,
  818. }
  819. }, function (data) {
  820. pos.updateDatas(data.pos);
  821. const result = tree.loadPostData(data.ledger);
  822. self.refreshTree(sheet, result);
  823. const sel = sheet.getSelections()[0];
  824. if (sel) {
  825. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  826. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  827. }
  828. self.refreshOperationValid(sheet);
  829. removeLocalCache(copyBlockTag);
  830. }, null, true);
  831. },
  832. topRowChanged: function (e, info) {
  833. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  834. },
  835. editStarting(e, info) {
  836. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  837. const col = info.sheet.zh_setting.cols[info.col];
  838. const node = info.sheet.zh_tree.nodes[info.row];
  839. if (!node) {
  840. info.cancel = true;
  841. return;
  842. }
  843. const exprInfo = getExprInfo(col.field);
  844. if (exprInfo) {
  845. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  846. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  847. }
  848. }
  849. switch (col.field) {
  850. case 'code':
  851. const posRange = pos.getLedgerPos(node.id);
  852. info.cancel = posRange && posRange.length > 0;
  853. break;
  854. case 'unit_price':
  855. info.cancel = (node.children && node.children.length > 0) || node.used;
  856. break;
  857. case 'sgfh_qty':
  858. case 'sgfh_tp':
  859. case 'sjcl_qty':
  860. case 'sjcl_tp':
  861. case 'qtcl_qty':
  862. case 'qtcl_tp':
  863. case 'deal_qty':
  864. case 'deal_tp':
  865. info.cancel = (node.children && node.children.length > 0);
  866. break;
  867. case 'dgn_qty1':
  868. case 'dgn_qty2':
  869. info.cancel = !_.isEmpty(node.b_code);
  870. break;
  871. }
  872. },
  873. cut: function (sheet, sel, callback) {
  874. if (!sheet || !sel) return;
  875. if (sel.colCount >= sheet.zh_setting.cols.length) {
  876. toastr.warning('请勿选中整行剪切');
  877. return;
  878. }
  879. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  880. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  881. const node = sortData[iRow];
  882. if (node) {
  883. const data = sheet.zh_tree.getNodeKeyData(node);
  884. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  885. const col = sheet.zh_setting.cols[iCol];
  886. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  887. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  888. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  889. const lPos = pos.getLedgerPos(node.id);
  890. if (lPos && lPos.length > 0) {
  891. toastr.error('不可剪切');
  892. return;
  893. }
  894. }
  895. const style = sheet.getStyle(iRow, iCol);
  896. if (style.locked) {
  897. toastr.error('不可剪切');
  898. return;
  899. }
  900. const colSetting = sheet.zh_setting.cols[iCol];
  901. data[colSetting.field] = null;
  902. const exprInfo = getExprInfo(colSetting.field);
  903. if (exprInfo) {
  904. data[exprInfo.expr] = '';
  905. }
  906. }
  907. datas.push(data);
  908. }
  909. }
  910. if (datas.length > 0) {
  911. callback();
  912. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  913. const refreshNode = sheet.zh_tree.loadPostData(result);
  914. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  915. });
  916. }
  917. },
  918. sortCode: function (sheet) {
  919. const tree = sheet.zh_tree;
  920. if (!tree) return;
  921. const select = SpreadJsObj.getSelectObject(sheet);
  922. if (!select || !select.code || select.code === '') return;
  923. const recursiveSortCode = function (data, parentCode, children) {
  924. if (!children || children.length === 0) return;
  925. for (const [i, child] of children.entries()) {
  926. if (!child.b_code || child.b_code === '') {
  927. const code = parentCode + '-' + (i + 1);
  928. const cData = tree.getNodeKeyData(child);
  929. cData.code = code;
  930. data.push(cData);
  931. if (!tree.isLeafXmj(child)) {
  932. recursiveSortCode(data, code, child.children);
  933. }
  934. }
  935. }
  936. };
  937. const data = [];
  938. recursiveSortCode(data, select.code, select.children);
  939. if (data.length > 0) {
  940. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  941. const refreshNode = tree.loadPostData(result);
  942. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  943. })
  944. }
  945. }
  946. };
  947. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  948. billsTreeSpreadObj.loadExprToInput(billsSheet);
  949. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  950. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  951. if (!readOnly) {
  952. // 增删上下移升降级
  953. $('a[name="base-opr"]').click(function () {
  954. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  955. });
  956. $('a[name=cpc]').click(function () {
  957. billsSpread.commandManager().execute({
  958. cmd: this.getAttribute('type'),
  959. sheetName: billsSheet.name()
  960. });
  961. });
  962. $('#bills-expr').bind('change onblur', function () {
  963. if (this.readOnly) return;
  964. const expr = $(this);
  965. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  966. const select = billsTree.getItemsByIndex(row);
  967. if (!select) return;
  968. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  969. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  970. const data = {
  971. id: select.id,
  972. tender_id: select.tender_id,
  973. ledger_id: select.ledger_id
  974. };
  975. const exprInfo = getExprInfo(field);
  976. if (newValue !== '') {
  977. const num = _.toNumber(newValue);
  978. if (num) {
  979. data[field] = num;
  980. if (exprInfo) {
  981. data[exprInfo.expr] = '';
  982. }
  983. } else {
  984. try {
  985. data[field] = math.evaluate(transExpr(newValue));
  986. if (exprInfo) {
  987. data[exprInfo.expr] = newValue;
  988. }
  989. } catch (err) {
  990. toastr.error('输入的表达式非法');
  991. return;
  992. }
  993. }
  994. } else {
  995. data[field] = null;
  996. if (exprInfo) {
  997. data[exprInfo.expr] = '';
  998. }
  999. }
  1000. // 更新至服务器
  1001. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1002. const refreshNode = billsTree.loadPostData(result);
  1003. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1004. });
  1005. });
  1006. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  1007. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  1008. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  1009. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  1010. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  1011. }
  1012. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1013. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1014. SpreadJsObj.Clipboard.setCopyData(copyText);
  1015. });
  1016. // 右键菜单
  1017. let batchInsertObj;
  1018. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1019. const self = this;
  1020. if ($.isFunction(item.icon)) {
  1021. item._icon = item.icon.call(this, this, $t, key, item);
  1022. } else {
  1023. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1024. // to enable font awesome
  1025. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1026. } else {
  1027. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1028. }
  1029. }
  1030. this.addClass(item._icon);
  1031. 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>')
  1032. .appendTo(this);
  1033. const $input = $obj.find('input');
  1034. const event = () => {
  1035. if (self.hasClass('context-menu-disabled')) return;
  1036. item.batchInsert($input[0], root);
  1037. };
  1038. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1039. $input.click((e) => {e.stopPropagation();})
  1040. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1041. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1042. };
  1043. const addTag = newTag({ledgerSheet: billsSpread.getActiveSheet(), billsTag});
  1044. const billsContextMenuOptions = {
  1045. selector: '#bills-spread',
  1046. build: function ($trigger, e) {
  1047. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  1048. billsTreeSpreadObj.loadRelaData();
  1049. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1050. },
  1051. items: {}
  1052. };
  1053. if (!readOnly) {
  1054. billsContextMenuOptions.items.create = {
  1055. name: '新增',
  1056. icon: 'fa-sign-in',
  1057. callback: function (key, opt) {
  1058. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  1059. },
  1060. disabled: function (key, opt) {
  1061. const sheet = billsSheet;
  1062. const selection = sheet.getSelections();
  1063. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1064. const row = sel ? sel.row : -1;
  1065. const tree = sheet.zh_tree;
  1066. if (!tree) return true;
  1067. const first = sheet.zh_tree.nodes[row];
  1068. const valid = !sheet.zh_setting.readOnly;
  1069. return !(valid && first && first.level > 1);
  1070. }
  1071. };
  1072. billsContextMenuOptions.items.delete = {
  1073. name: '删除',
  1074. icon: 'fa-remove',
  1075. callback: function (key, opt) {
  1076. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  1077. },
  1078. disabled: function (key, opt) {
  1079. const sheet = billsSheet;
  1080. const selection = sheet.getSelections();
  1081. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1082. const row = sel ? sel.row : -1;
  1083. const tree = sheet.zh_tree;
  1084. if (!tree) return true;
  1085. const first = sheet.zh_tree.nodes[row];
  1086. let last = first, sameParent = true, nodeUsed = first.used;
  1087. if (sel.rowCount > 1 && first) {
  1088. for (let r = 1; r < sel.rowCount; r++) {
  1089. const rNode = tree.nodes[sel.row + r];
  1090. if (!rNode) {
  1091. sameParent = false;
  1092. break;
  1093. }
  1094. nodeUsed = nodeUsed || rNode.used;
  1095. if (rNode.level > first.level) continue;
  1096. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1097. sameParent = false;
  1098. break;
  1099. }
  1100. last = rNode;
  1101. }
  1102. }
  1103. const valid = !sheet.zh_setting.readOnly;
  1104. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  1105. }
  1106. };
  1107. billsContextMenuOptions.items.sprBase = '----';
  1108. billsContextMenuOptions.items.batchInsert = {
  1109. name: '批量插入',
  1110. type: 'batchInsert',
  1111. value: '2',
  1112. icon: 'fa-sign-in',
  1113. batchInsert: function (obj, root) {
  1114. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1115. obj.value = obj.max;
  1116. toastr.warning('批量插入不可多于' + obj.max);
  1117. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1118. obj.value = obj.min;
  1119. toastr.warning('批量插入不可少于' + obj.min);
  1120. } else {
  1121. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1122. root.$menu.trigger('contextmenu:hide');
  1123. }
  1124. },
  1125. disabled: function (key, opt) {
  1126. const sheet = billsSheet;
  1127. const selection = sheet.getSelections();
  1128. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1129. const row = sel ? sel.row : -1;
  1130. const tree = sheet.zh_tree;
  1131. if (!tree) return true;
  1132. const first = sheet.zh_tree.nodes[row];
  1133. const valid = !sheet.zh_setting.readOnly;
  1134. return !(valid && first && first.level > 1);
  1135. }
  1136. };
  1137. billsContextMenuOptions.items.batchInsertBillsPos = {
  1138. name: '批量插入清单-计量单元',
  1139. icon: 'fa-sign-in',
  1140. disabled: function (key, opt) {
  1141. if (!isTz) return true;
  1142. const select = SpreadJsObj.getSelectObject(billsSheet);
  1143. if (select) {
  1144. if (select.code && select.code !== '') {
  1145. return !billsTree.isLeafXmj(select);
  1146. } else {
  1147. const parent = billsTree.getParent(select);
  1148. return !(parent && billsTree.isLeafXmj(parent));
  1149. }
  1150. } else {
  1151. return false;
  1152. }
  1153. },
  1154. callback: function (key, opt) {
  1155. if (!batchInsertObj) {
  1156. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1157. } else {
  1158. batchInsertObj.initView();
  1159. }
  1160. $('#batch').modal('show');
  1161. }
  1162. };
  1163. billsContextMenuOptions.items.sprBatch = '----';
  1164. }
  1165. billsContextMenuOptions.items.copyBlock = {
  1166. name: '复制整块',
  1167. icon: 'fa-files-o',
  1168. callback: function (key, opt) {
  1169. const copyBlockList = [];
  1170. const sheet = billsSheet;
  1171. const sel = sheet.getSelections()[0];
  1172. let iRow = sel.row;
  1173. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1174. while (iRow < sel.row + sel.rowCount) {
  1175. const node = sheet.zh_tree.nodes[iRow];
  1176. if (node.ledger_pid !== pid) {
  1177. toastr.error('仅可同时选中同层节点');
  1178. return;
  1179. }
  1180. const posterity = sheet.zh_tree.getPosterity(node);
  1181. iRow += posterity.length + 1;
  1182. posterity.unshift(node);
  1183. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1184. }
  1185. for (const cbl of copyBlockList) {
  1186. for (const b of cbl) {
  1187. const posRange = pos.getLedgerPos(b.id);
  1188. if (posRange && posRange.length > 0) b.pos = posRange;
  1189. }
  1190. }
  1191. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1192. },
  1193. visible: function (key, opt) {
  1194. const sheet = billsSheet;
  1195. const selection = sheet.getSelections();
  1196. const row = selection[0].row;
  1197. const select = billsTree.nodes[row];
  1198. return select;
  1199. },
  1200. disabled: function (key, opt) {
  1201. const sheet = billsSheet;
  1202. const selection = sheet.getSelections();
  1203. const row = selection[0].row;
  1204. const select = billsTree.nodes[row];
  1205. return select && select.level <= 1;
  1206. }
  1207. };
  1208. billsContextMenuOptions.items.copyBlockXmj = {
  1209. name: '复制整块(只复制项目节)',
  1210. icon: 'fa-files-o',
  1211. callback: function (key, opt) {
  1212. const copyBlockList = [];
  1213. const sheet = billsSheet;
  1214. const sel = sheet.getSelections()[0];
  1215. let iRow = sel.row;
  1216. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1217. while (iRow < sel.row + sel.rowCount) {
  1218. const node = sheet.zh_tree.nodes[iRow];
  1219. if (node.ledger_pid !== pid) {
  1220. toastr.error('仅可同时选中同层节点');
  1221. return;
  1222. }
  1223. const posterity = sheet.zh_tree.getPosterity(node);
  1224. iRow += posterity.length + 1;
  1225. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1226. copyPosterity.unshift(node);
  1227. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1228. for (const p of copyData) {
  1229. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1230. p.is_leaf = children.length === 0;
  1231. }
  1232. copyBlockList.push(copyData);
  1233. }
  1234. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1235. },
  1236. visible: function (key, opt) {
  1237. const sheet = billsSheet;
  1238. const selection = sheet.getSelections();
  1239. const row = selection[0].row;
  1240. const select = billsTree.nodes[row];
  1241. return select;
  1242. },
  1243. disabled: function (key, opt) {
  1244. const sheet = billsSheet;
  1245. const selection = sheet.getSelections();
  1246. const row = selection[0].row;
  1247. const select = billsTree.nodes[row];
  1248. return select && select.level <= 1;
  1249. }
  1250. };
  1251. if (!readOnly) {
  1252. billsContextMenuOptions.items.pasteBlock = {
  1253. name: '粘贴整块',
  1254. icon: 'fa-clipboard',
  1255. disabled: function (key, opt) {
  1256. //const block = treeOperationObj.block || [];
  1257. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1258. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1259. },
  1260. callback: function (key, opt) {
  1261. //const block = treeOperationObj.block || [];
  1262. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1263. if (copyInfo.block.length > 0) {
  1264. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1265. } else {
  1266. document.execCommand('paste');
  1267. }
  1268. },
  1269. visible: function (key, opt) {
  1270. return !readOnly;
  1271. }
  1272. };
  1273. billsContextMenuOptions.items.sprBlock = '----';
  1274. }
  1275. if (!readOnly) {
  1276. if (!isTz) {
  1277. billsContextMenuOptions.items.applyDeal2Sgfh = {
  1278. name: '填设计量',
  1279. icon: 'fa-pencil',
  1280. callback: function (key, opt) {
  1281. postData(window.location.pathname + '/deal2sgfh', null, function (result) {
  1282. billsTree.loadDatas(result.bills);
  1283. treeCalc.calculateAll(billsTree);
  1284. SpreadJsObj.loadSheetData(billsSheet, 'tree', billsTree);
  1285. });
  1286. }
  1287. };
  1288. billsContextMenuOptions.items.sprSort = '----';
  1289. }
  1290. }
  1291. if (!readOnly) {
  1292. billsContextMenuOptions.items.importGclBills2Xmj = {
  1293. name: '导入工程量清单至项目节',
  1294. icon: 'fa-file-excel-o',
  1295. disabled: function (key, opt) {
  1296. const node = SpreadJsObj.getSelectObject(billsSheet);
  1297. return readOnly
  1298. || (node.children && node.children.length > 0)
  1299. || (!_.isNil(node.b_code) && node.b_code !== '')
  1300. || billsTree.checkNodeUsed(node, pos);
  1301. },
  1302. callback: function (key, opt) {
  1303. const node = SpreadJsObj.getSelectObject(billsSheet);
  1304. importExcel.doImport({
  1305. template: {
  1306. hint: '工程量清单',
  1307. url: '/template/导入工程量清单EXCEL格式.xls',
  1308. },
  1309. callback: function (sheet) {
  1310. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1311. const sel = billsSheet.getSelections();
  1312. const refreshNode = billsTree.loadPostData(result);
  1313. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1314. if (refreshNode.create[0]) {
  1315. if (sel && sel[0]) {
  1316. billsSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1317. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel[0].row, refreshNode.create[0].index]);
  1318. } else {
  1319. billsSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1320. SpreadJsObj.reloadRowsBackColor(billsSheet, [refreshNode.create[0].index]);
  1321. }
  1322. }
  1323. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1324. }, null);
  1325. }
  1326. });
  1327. }
  1328. };
  1329. const tenderSelect = TenderSelect({
  1330. type: 'revise',
  1331. afterLoad: function (result) {
  1332. const refreshNode = billsTree.loadPostData(result);
  1333. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1334. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1335. if (result.sumLoadHis.errors.length > 0) {
  1336. sumLoadMiss.loadMissData(result.sumLoadHis.errors);
  1337. sumLoadMiss.show();
  1338. } else {
  1339. sumLoadMiss.clearMissData();
  1340. }
  1341. }
  1342. });
  1343. billsContextMenuOptions.items.importOtherTender = {
  1344. name: '更新(其他标段)工程量清单至项目节',
  1345. icon: 'fa-link',
  1346. disabled: function (key, opt) {
  1347. const node = SpreadJsObj.getSelectObject(billsSheet);
  1348. return readOnly || !node || !billsTree.isLeafXmj(node);
  1349. },
  1350. callback: function (key, opt) {
  1351. tenderSelect.showSelect(SpreadJsObj.getSelectObject(billsSheet));
  1352. }
  1353. };
  1354. billsContextMenuOptions.items.sprImport = '----';
  1355. }
  1356. billsContextMenuOptions.items.tag = {
  1357. name: '书签',
  1358. callback: function (key, opt, menu, e) {
  1359. const node = SpreadJsObj.getSelectObject(billsSpread.getActiveSheet());
  1360. addTag.do(node);
  1361. },
  1362. disabled: function (key, opt) {
  1363. const node = SpreadJsObj.getSelectObject(billsSpread.getActiveSheet());
  1364. return !node;
  1365. }
  1366. };
  1367. billsContextMenuOptions.items.sprTag = '----';
  1368. billsContextMenuOptions.items.showLast = {
  1369. name: '显示至最底层',
  1370. callback: function (key, opt, menu, e) {
  1371. const node = SpreadJsObj.getSelectObject(billsSheet);
  1372. setTimeout(() => {
  1373. showWaitingView();
  1374. billsTree.expandByCustom(x => {
  1375. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1376. });
  1377. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  1378. closeWaitingView();
  1379. }, 100);
  1380. },
  1381. };
  1382. $.contextMenu(billsContextMenuOptions);
  1383. // 计量单元 相关方法&绑定spreadjs事件
  1384. const posSpreadObj = {
  1385. refreshOperationValid: function (sheet, selection) {
  1386. const setObjEnable = function (obj, enable) {
  1387. if (enable) {
  1388. obj.removeClass('disabled');
  1389. } else {
  1390. obj.addClass('disabled');
  1391. }
  1392. };
  1393. const invalidAll = function () {
  1394. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1395. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1396. };
  1397. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1398. const row = sel ? sel.row : -1;
  1399. const first = sheet.zh_data[row];
  1400. if (!first) {
  1401. invalidAll();
  1402. return;
  1403. }
  1404. let last = first;
  1405. if (sel.rowCount > 1 && first) {
  1406. for (let r = 1; r < sel.rowCount; r++) {
  1407. const rNode = sheet.zh_data[sel.row + r];
  1408. if (!rNode) break;
  1409. last = rNode;
  1410. }
  1411. }
  1412. const preNode = sheet.zh_data[row - 1];
  1413. const valid = !sheet.zh_setting.readOnly;
  1414. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
  1415. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
  1416. },
  1417. loadExprToInput: function () {
  1418. const sel = posSheet.getSelections()[0];
  1419. if (!sel) return;
  1420. const col = posSheet.zh_setting.cols[sel.col];
  1421. const cell = posSheet.getCell(sel.col, sel.col);
  1422. if (col && col.type === 'Number') {
  1423. const data = SpreadJsObj.getSelectObject(posSheet);
  1424. if (data) {
  1425. const exprInfo = getExprInfo(col.field);
  1426. const value = exprInfo
  1427. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1428. : data[col.field];
  1429. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1430. .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
  1431. } else {
  1432. $('#pos-expr').val('').attr('readOnly', true);
  1433. $('#pos-expr').removeAttr('data-row');
  1434. }
  1435. } else {
  1436. $('#pos-expr').val('').attr('readOnly', true);
  1437. $('#pos-expr').removeAttr('data-row');
  1438. }
  1439. },
  1440. /**
  1441. * 加载计量单元 根据当前台账选择节点
  1442. */
  1443. loadCurPosData: function () {
  1444. const node = SpreadJsObj.getSelectObject(billsSheet);
  1445. if (node) {
  1446. const posData = pos.getLedgerPos(node.id) || [];
  1447. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1448. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0);
  1449. } else {
  1450. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1451. posSheet.zh_setting.readOnly = true;
  1452. }
  1453. SpreadJsObj.refreshSheetReadOnly(posSheet);
  1454. posSpreadObj.loadExprToInput();
  1455. posSpreadObj.refreshOperationValid(posSheet);
  1456. },
  1457. baseOpr: function (sheet, type) {
  1458. const data = {
  1459. postType: 'pos',
  1460. posPostType: type === 'delete' ? type : 'update',
  1461. postData: [],
  1462. };
  1463. const selection = sheet.getSelections();
  1464. const row = selection[0].row, count = selection[0].rowCount;
  1465. const first = sheet.zh_data[row];
  1466. if (type === 'delete') {
  1467. for (let iRow = 0; iRow < count; iRow++) {
  1468. const posData = sheet.zh_data[iRow + row];
  1469. if (posData) {
  1470. if (posData.used) {
  1471. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1472. return;
  1473. }
  1474. data.postData.push(sheet.zh_data[iRow + row].id);
  1475. }
  1476. }
  1477. } else if (type === 'up-move') {
  1478. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1479. for (let iRow = 0; iRow < count; iRow++) {
  1480. const posData = sheet.zh_data[iRow + row];
  1481. if (posData) {
  1482. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1483. preUpdate.porder = posData.porder;
  1484. }
  1485. }
  1486. data.postData.push(preUpdate);
  1487. } else if (type === 'down-move') {
  1488. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1489. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1490. const posData = sheet.zh_data[iRow + row];
  1491. if (posData) {
  1492. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1493. nextUpdate.porder = posData.porder;
  1494. }
  1495. }
  1496. data.postData.push(nextUpdate);
  1497. }
  1498. if (data.postData.length > 0) {
  1499. postData(window.location.pathname + '/update', data, function (result) {
  1500. if (type === 'delete') {
  1501. pos.removeDatas(result.pos);
  1502. sheet.deleteRows(row, count);
  1503. const loadResult = billsTree.loadPostData(result.ledger);
  1504. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1505. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1506. posSpreadObj.refreshOperationValid(posSheet);
  1507. } else {
  1508. pos.updateDatas(result.pos);
  1509. const sel = selection[0];
  1510. if (sel) {
  1511. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1512. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1513. }
  1514. posSpreadObj.loadCurPosData();
  1515. }
  1516. });
  1517. }
  1518. },
  1519. editStarting: function (e, info) {
  1520. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1521. const sel = info.sheet.getSelections();
  1522. if (!sel || !sel[0]) return;
  1523. const col = info.sheet.zh_setting.cols[sel[0].col];
  1524. const node = SpreadJsObj.getSelectObject(info.sheet);
  1525. const exprInfo = getExprInfo(col.field);
  1526. if (exprInfo) {
  1527. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1528. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1529. }
  1530. }
  1531. },
  1532. /**
  1533. * 编辑单元格响应事件
  1534. * @param {Object} e
  1535. * @param {Object} info
  1536. */
  1537. editEnded: function (e, info) {
  1538. if (!info.sheet.zh_setting) {
  1539. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1540. return;
  1541. }
  1542. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1543. const col = info.sheet.zh_setting.cols[info.col];
  1544. const orgText = posData ? posData[col.field] : null;
  1545. const newText = trimInvalidChar(info.editingText);
  1546. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1547. const node = posSpreadObj.billsNode;
  1548. if (!node) {
  1549. toastr.error('数据错误,请选择台账节点后再试');
  1550. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1551. return;
  1552. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1553. toastr.error('父节点不可插入计量单元');
  1554. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1555. return;
  1556. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1557. toastr.error('项目节不可插入计量单元');
  1558. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1559. return;
  1560. }
  1561. const data = {postType: 'pos'};
  1562. if (!posData) {
  1563. const sortData = info.sheet.zh_data;
  1564. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1565. data.posPostType = 'add';
  1566. data.postData = { lid: node.id, porder: order };
  1567. } else {
  1568. data.posPostType = 'update';
  1569. data.postData = { id: posData.id };
  1570. }
  1571. if (col.type === 'Number') {
  1572. const exprInfo = getExprInfo(col.field);
  1573. const num = _.toNumber(newText);
  1574. if (_.isFinite(num)) {
  1575. data.postData[col.field] = num;
  1576. if (exprInfo) {
  1577. data.postData[exprInfo.expr] = '';
  1578. }
  1579. } else {
  1580. try {
  1581. data.postData[col.field] = math.evaluate(transExpr(newText));
  1582. if (exprInfo) {
  1583. data.postData[exprInfo.expr] = newText;
  1584. }
  1585. } catch(err) {
  1586. toastr.error('输入的表达式非法');
  1587. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1588. return;
  1589. }
  1590. }
  1591. } else {
  1592. data.postData[col.field] = newText;
  1593. }
  1594. postData(window.location.pathname + '/update', data, function (result) {
  1595. const updateRst = pos.updateDatas(result.pos);
  1596. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1597. if (updateRst.create.length > 0) {
  1598. posSpreadObj.loadCurPosData();
  1599. } else {
  1600. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1601. }
  1602. const loadResult = billsTree.loadPostData(result.ledger);
  1603. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1604. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1605. }, function () {
  1606. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1607. });
  1608. },
  1609. /**
  1610. * 删除按钮响应事件
  1611. * @param sheet
  1612. */
  1613. deletePress: function (sheet) {
  1614. if (!sheet.zh_setting) return;
  1615. const sortData = sheet.zh_data;
  1616. const datas = [], posSelects = [];
  1617. const sel = sheet.getSelections()[0];
  1618. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1619. let bDel = false;
  1620. const node = sortData[iRow];
  1621. if (node) {
  1622. const data = {id: node.id};
  1623. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1624. const colSetting = sheet.zh_setting.cols[iCol];
  1625. const style = sheet.getStyle(iRow, iCol);
  1626. if (!style.locked) {
  1627. const colSetting = sheet.zh_setting.cols[iCol];
  1628. data[colSetting.field] = null;
  1629. const exprInfo = getExprInfo(colSetting.field);
  1630. if (exprInfo) {
  1631. data[exprInfo.expr] = '';
  1632. }
  1633. bDel = true;
  1634. }
  1635. }
  1636. if (bDel) {
  1637. datas.push(data);
  1638. posSelects.push(node);
  1639. }
  1640. }
  1641. }
  1642. if (datas.length > 0) {
  1643. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1644. pos.updateDatas(result.pos);
  1645. posSpreadObj.loadCurPosData();
  1646. const loadResult = billsTree.loadPostData(result.ledger);
  1647. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1648. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1649. }, function () {
  1650. posSpreadObj.loadCurPosData();
  1651. });
  1652. }
  1653. },
  1654. insertPos: function (sheet) {
  1655. const selection = sheet.getSelections();
  1656. const sortData = sheet.zh_data;
  1657. const row = selection[0].row;
  1658. const node = SpreadJsObj.getSelectObject(billsSheet);
  1659. const select = SpreadJsObj.getSelectObject(sheet);
  1660. const porder = select ? select.porder : sortData.length + 1;
  1661. const data = {
  1662. postType: 'pos',
  1663. posPostType: 'insert',
  1664. postData: [ { lid: node.id, porder } ],
  1665. };
  1666. postData(window.location.pathname + '/update', data, function (result) {
  1667. const updateRst = pos.updateDatas(result.pos);
  1668. posSpreadObj.loadCurPosData();
  1669. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1670. });
  1671. },
  1672. /**
  1673. * 删除 计量单元
  1674. * @param sheet
  1675. */
  1676. deletePos: function (sheet) {
  1677. const selection = sheet.getSelections();
  1678. const data = {
  1679. postType: 'pos',
  1680. posPostType: 'delete',
  1681. postData: [],
  1682. };
  1683. const row = selection[0].row, count = selection[0].rowCount;
  1684. const sortData = sheet.zh_data;
  1685. for (let iRow = 0; iRow < count; iRow++) {
  1686. const posData = sortData[iRow + row];
  1687. if (posData) {
  1688. if (posData.used) {
  1689. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1690. return;
  1691. }
  1692. data.postData.push(sortData[iRow + row].id);
  1693. }
  1694. }
  1695. if (data.postData.length > 0) {
  1696. postData(window.location.pathname + '/update', data, function (result) {
  1697. pos.removeDatas(result.pos);
  1698. sheet.deleteRows(row, count);
  1699. const loadResult = billsTree.loadPostData(result.ledger);
  1700. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1701. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1702. });
  1703. }
  1704. },
  1705. /**
  1706. * 粘贴单元格响应事件
  1707. * @param e
  1708. * @param info
  1709. */
  1710. clipboardPasted: function (e, info) {
  1711. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1712. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1713. }
  1714. const node = SpreadJsObj.getSelectObject(billsSheet);
  1715. if (node.code && (node.code !== '')) {
  1716. toastr.error('项目节不可含有节点明细');
  1717. posSpreadObj.loadCurPosData();
  1718. return;
  1719. }
  1720. if (node.children && (node.children.length > 0)) {
  1721. toastr.error('仅节点子项可以含有计量单元');
  1722. posSpreadObj.loadCurPosData();
  1723. return;
  1724. }
  1725. if (!info.sheet.zh_setting) {
  1726. posSpreadObj.loadCurPosData();
  1727. return;
  1728. }
  1729. const data = [];
  1730. const sortData = info.sheet.zh_data || [];
  1731. const hint = {
  1732. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  1733. };
  1734. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1735. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1736. let bPaste = true;
  1737. const curRow = info.cellRange.row + iRow;
  1738. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1739. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1740. const curCol = info.cellRange.col + iCol;
  1741. const colSetting = info.sheet.zh_setting.cols[curCol];
  1742. if (!colSetting) continue;
  1743. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1744. if (colSetting.type === 'Number') {
  1745. const num = _.toNumber(posData[colSetting.field]);
  1746. if (num) {
  1747. posData[colSetting.field] = num;
  1748. } else {
  1749. try {
  1750. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1751. const exprInfo = getExprInfo(colSetting.field);
  1752. if (exprInfo) {
  1753. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1754. }
  1755. } catch (err) {
  1756. toastMessageUniq(hint.expr);
  1757. bPaste = false;
  1758. }
  1759. }
  1760. }
  1761. }
  1762. if (bPaste) {
  1763. data.push(posData);
  1764. }
  1765. }
  1766. if (data.length === 0) {
  1767. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1768. return;
  1769. }
  1770. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1771. pos.updateDatas(result.pos);
  1772. posSpreadObj.loadCurPosData();
  1773. const loadResult = billsTree.loadPostData(result.ledger);
  1774. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1775. posSpreadObj.loadCurPosData();
  1776. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1777. }, function () {
  1778. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1779. });
  1780. },
  1781. selectionChanged: function (e, info) {
  1782. posSpreadObj.loadExprToInput();
  1783. posSpreadObj.refreshOperationValid(posSheet);
  1784. },
  1785. addPegs: function (pegs) {
  1786. if (!pegs || pegs.length <= 0) return;
  1787. const node = SpreadJsObj.getSelectObject(billsSheet);
  1788. if (!node) return;
  1789. const sheet = posSpread.getActiveSheet();
  1790. const sortData = sheet.zh_data || [];
  1791. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1792. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1793. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1794. pos.updateDatas(result.pos);
  1795. posSpreadObj.loadCurPosData();
  1796. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1797. });
  1798. }
  1799. };
  1800. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1801. if (!readOnly && isTz) {
  1802. $('a[name="pos-opr"]').click(function () {
  1803. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  1804. });
  1805. $('#pos-expr').bind('change onblur', function () {
  1806. if (this.readOnly) return;
  1807. const expr = $(this);
  1808. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1809. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1810. if (!select) return;
  1811. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1812. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  1813. const data = {id: select.id};
  1814. const exprInfo = getExprInfo(field);
  1815. if (newValue !== '') {
  1816. const num = _.toNumber(newValue);
  1817. if (num) {
  1818. data[field] = num;
  1819. if (exprInfo) data[exprInfo.expr] = '';
  1820. } else {
  1821. try {
  1822. data[field] = math.evaluate(transExpr(newValue));
  1823. if (exprInfo) data[exprInfo.expr] = newValue;
  1824. } catch (err) {
  1825. toastr.error('输入的表达式非法');
  1826. return;
  1827. }
  1828. }
  1829. } else {
  1830. data[field] = null;
  1831. if (exprInfo) data[exprInfo.expr] = '';
  1832. }
  1833. // 更新至服务器
  1834. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1835. const updateRst = pos.updateDatas(result.pos);
  1836. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1837. SpreadJsObj.reLoadRowData(posSheet, row);
  1838. const loadResult = billsTree.loadPostData(result.ledger);
  1839. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1840. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1841. });
  1842. });
  1843. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1844. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1845. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1846. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1847. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1848. $.contextMenu({
  1849. selector: '#pos-spread',
  1850. build: function ($trigger, e) {
  1851. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1852. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1853. },
  1854. items: {
  1855. 'insert': {
  1856. name: '插入',
  1857. icon: 'fa-plus',
  1858. disabled: function (key, opt) {
  1859. const node = SpreadJsObj.getSelectObject(billsSheet);
  1860. return node && node.children && node.children.length > 0;
  1861. },
  1862. callback: function (key, opt) {
  1863. posSpreadObj.insertPos(posSheet);
  1864. }
  1865. },
  1866. 'delete': {
  1867. name: '删除',
  1868. icon: 'fa-remove',
  1869. disabled: function (key, opt) {
  1870. if (posSheet.zh_data) {
  1871. const selection = posSheet.getSelections();
  1872. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1873. } else {
  1874. return true;
  1875. }
  1876. },
  1877. callback: function (key, opt) {
  1878. posSpreadObj.deletePos(posSheet);
  1879. }
  1880. },
  1881. 'merge-peg': {
  1882. name: '合并起讫桩号',
  1883. disabled: function (key, opt) {
  1884. const node = SpreadJsObj.getSelectObject(billsSheet);
  1885. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1886. },
  1887. callback: function (key, opt) {
  1888. mergePeg.show();
  1889. },
  1890. visible: function (key, opt) {
  1891. return isTz;
  1892. }
  1893. }
  1894. }
  1895. });
  1896. }
  1897. // 加载清单&计量单元数据
  1898. postData(window.location.pathname + '/load', {}, function (result) {
  1899. billsTree.loadRevisePrice(result.price, decimal);
  1900. billsTree.loadDatas(result.bills);
  1901. treeCalc.calculateAll(billsTree);
  1902. for (const t of result.tags) {
  1903. t.node = billsTree.datas.find(x => {return x.id === t.lid});
  1904. }
  1905. billsTag.loadDatas(result.tags);
  1906. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  1907. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  1908. checkShowLast(result.bills.length);
  1909. pos.loadDatas(result.pos);
  1910. posSpreadObj.loadCurPosData();
  1911. SpreadJsObj.resetTopAndSelect(posSheet);
  1912. checkList.loadHisCheckData();
  1913. }, null);
  1914. $.divResizer({
  1915. select: '#revise-resize',
  1916. callback: function () {
  1917. billsSpread.refresh();
  1918. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1919. $(".sp-wrap").height(bcontent-30);
  1920. posSpread.refresh();
  1921. }
  1922. });
  1923. class DealBills {
  1924. constructor (selector, spreadSetting) {
  1925. const self = this;
  1926. this.loaded = false;
  1927. this.obj = $(selector)[0];
  1928. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1929. this.spreadSetting = spreadSetting;
  1930. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1931. this.sheet = this.spread.getActiveSheet();
  1932. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1933. if (!readOnly) {
  1934. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1935. const dealSheet = info.sheet;
  1936. const mainSheet = billsSheet;
  1937. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1938. if (!dealBills) { return; }
  1939. const mainTree = mainSheet.zh_tree;
  1940. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1941. if (!mainNode || !mainTree) { return; }
  1942. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1943. toastr.warning('非最底层项目下,不应添加节点');
  1944. return;
  1945. }
  1946. postData(window.location.pathname + '/update', {
  1947. postType: 'add-deal',
  1948. postData: {
  1949. id: mainNode.ledger_id,
  1950. type: mainNode.code ? 'child' : 'next',
  1951. dealBills: {
  1952. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1953. unit_price: dealBills.unit_price,
  1954. }
  1955. },
  1956. }, function (result) {
  1957. const refreshData = mainTree.loadPostData(result);
  1958. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1959. const sel = mainSheet.getSelections()[0];
  1960. if (sel && refreshData.create[0]) {
  1961. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1962. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  1963. }
  1964. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1965. billsSpread.focus();
  1966. posSpreadObj.loadCurPosData();
  1967. });
  1968. });
  1969. }
  1970. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1971. this.initDealBillsSearch();
  1972. }
  1973. search(keyword) {
  1974. this.searchResult = [];
  1975. this.searchCur = 0;
  1976. if (keyword) {
  1977. for (const [i, d] of this.data.entries()) {
  1978. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  1979. }
  1980. }
  1981. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  1982. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.sheet, this.searchResult[0]);
  1983. }
  1984. searchPre() {
  1985. this.searchCur = this.searchCur - 1;
  1986. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  1987. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  1988. }
  1989. searchNext() {
  1990. this.searchCur = this.searchCur + 1;
  1991. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  1992. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  1993. }
  1994. searchClear() {
  1995. $('#dbs-keyword').val('');
  1996. this.searchResult = [];
  1997. this.searchCur = 0;
  1998. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  1999. }
  2000. initDealBillsSearch() {
  2001. const self = this;
  2002. $('#dbs-keyword').change(function () { self.search(this.value); });
  2003. $('#dbs-pre').click(function (e) {
  2004. self.searchPre();
  2005. e.stopPropagation();
  2006. });
  2007. $('#dbs-next').click(function (e) {
  2008. self.searchNext();
  2009. e.stopPropagation();
  2010. });
  2011. $('#dbs-clear').click(function (e) {
  2012. self.searchClear();
  2013. e.stopPropagation();
  2014. });
  2015. }
  2016. loadData (callback) {
  2017. if (this.loaded) {
  2018. if (callback) callback();
  2019. return;
  2020. }
  2021. const self = this;
  2022. postData(this.url+'/get-data', {}, function (data) {
  2023. self.data = data;
  2024. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2025. self.loaded = true;
  2026. if (callback) callback();
  2027. });
  2028. }
  2029. calculateData () {
  2030. if (this.data) {
  2031. for (const d of this.data) {
  2032. d.total_price = _.multiply(d.quantity, d.unit_price);
  2033. }
  2034. }
  2035. }
  2036. }
  2037. class BgBills {
  2038. constructor (selector, spreadSetting) {
  2039. this.loaded = false;
  2040. this.obj = $(selector)[0];
  2041. this.spreadSetting = spreadSetting;
  2042. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2043. this.sheet = this.spread.getActiveSheet();
  2044. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  2045. if (!readOnly) {
  2046. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2047. const dealSheet = info.sheet;
  2048. const mainSheet = billsSheet;
  2049. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  2050. if (!bgBills) { return; }
  2051. const mainTree = mainSheet.zh_tree;
  2052. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2053. if (!mainNode || !mainTree) { return; }
  2054. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2055. toastr.warning('非最底层项目下,不应添加变更清单');
  2056. return;
  2057. }
  2058. postData(window.location.pathname + '/update', {
  2059. postType: 'add-bg',
  2060. postData: {
  2061. id: mainNode.ledger_id,
  2062. type: mainNode.code ? 'child' : 'next',
  2063. dealBills: {
  2064. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  2065. unit_price: bgBills.unit_price,
  2066. }
  2067. },
  2068. }, function (result) {
  2069. const refreshData = mainTree.loadPostData(result);
  2070. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2071. const sel = mainSheet.getSelections()[0];
  2072. if (sel && refreshData.create[0]) {
  2073. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2074. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2075. }
  2076. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2077. billsSpread.focus();
  2078. posSpreadObj.loadCurPosData();
  2079. });
  2080. });
  2081. }
  2082. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2083. }
  2084. loadData () {
  2085. if (this.loaded) return;
  2086. const self = this;
  2087. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  2088. self.data = data;
  2089. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2090. self.loaded = true;
  2091. });
  2092. }
  2093. }
  2094. class BatchInsertBillsPosObj {
  2095. constructor (obj) {
  2096. const self = this;
  2097. this.obj = obj;
  2098. this.billsCount = 6;
  2099. this.posCount = 1000;
  2100. this.filter = getLocalCache('zh-calc-batch-filter');
  2101. if (!this.filter) {
  2102. this.filter = '1';
  2103. }
  2104. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2105. // 初始化 清单编号窗口 参数
  2106. this.qdSpreadSetting = {
  2107. cols: [
  2108. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2109. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2110. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2111. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2112. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2113. ],
  2114. emptyRows: this.billsCount,
  2115. headRows: 1,
  2116. headRowHeight: [32],
  2117. headerFont: '12px 微软雅黑',
  2118. font: '12px 微软雅黑',
  2119. };
  2120. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2121. // 初始化 部位数量复核表 参数
  2122. this.posSpreadSetting = {
  2123. cols: [
  2124. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2125. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2126. ],
  2127. emptyRows: this.posCount,
  2128. headRows: 1,
  2129. headRowHeight: [32],
  2130. headerFont: '12px 微软雅黑',
  2131. font: '12px 微软雅黑',
  2132. };
  2133. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2134. this.posSpreadSetting.cols.push(
  2135. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2136. )
  2137. }
  2138. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2139. // 初始化 签约节点 参数
  2140. this.dealSpreadSetting = {
  2141. cols: [
  2142. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2143. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2144. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2145. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2146. ],
  2147. emptyRows: 0,
  2148. headRows: 1,
  2149. headRowHeight: [32],
  2150. headerFont: '12px 微软雅黑',
  2151. font: '12px 微软雅黑',
  2152. };
  2153. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2154. this.dealSheet = this.dealSpread.getActiveSheet();
  2155. // 初始化 清单编号、部位数量复核表 表格
  2156. this.initView();
  2157. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2158. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2159. // 拉取签约节点数据
  2160. dealBills.loadData(() => {
  2161. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2162. });
  2163. // 双击签约节点,自动添加到清单编号窗口
  2164. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  2165. const deal = info.sheet.zh_data[info.row];
  2166. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2167. const sel = qdSheet.getSelections()[0];
  2168. qdSheet.getCell(sel.row, 0).value(deal.code);
  2169. qdSheet.getCell(sel.row, 1).value(deal.name);
  2170. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2171. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2172. if (sel.row + 1 === qdSheet.getRowCount()) {
  2173. const count = sel.row + 2;
  2174. qdSheet.setRowCount(count);
  2175. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2176. const colCount = posSheet.getColumnCount() + 1;
  2177. posSheet.setColumnCount(colCount);
  2178. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2179. }
  2180. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2181. qdSheet.getParent().focus();
  2182. });
  2183. this.qdSpread.bind(spreadNS.Events.ClipboardPasting, function (e, info) {
  2184. info.cancel = true;
  2185. const transpose = $('[name=batch-transpose]')[0].checked;
  2186. const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text, transpose);
  2187. const billsSheet = info.sheet, posSheet = self.posSpread.getActiveSheet();
  2188. const billsCount = info.sheet.getRowCount(), finalCount = info.cellRange.row + pasteData.length + 1;
  2189. SpreadJsObj.beginMassOperation(billsSheet);
  2190. if (finalCount > billsCount) {
  2191. billsSheet.setRowCount(finalCount);
  2192. posSheet.setColumnCount(finalCount + 2);
  2193. for (let i = billsCount - 1; i <= finalCount; i++) {
  2194. billsSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2195. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2196. }
  2197. }
  2198. for (let iRow = 0; iRow < pasteData.length; iRow++) {
  2199. const curRow = iRow + info.cellRange.row;
  2200. pasteData[iRow].forEach((value, iCol) => {
  2201. billsSheet.getCell(curRow, iCol + info.cellRange.col).value(value);
  2202. });
  2203. if ([0, 1].indexOf(info.cellRange.col) >= 0) {
  2204. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2205. const bills = _.find(dealBills, {code: billsSheet.getText(curRow, 0)});
  2206. if (bills) {
  2207. billsSheet.getCell(curRow, 1).value(bills.name);
  2208. billsSheet.getCell(curRow, 2).value(bills.unit);
  2209. billsSheet.getCell(curRow, 3).value(bills.unit_price);
  2210. }
  2211. }
  2212. }
  2213. SpreadJsObj.endMassOperation(billsSheet);
  2214. });
  2215. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2216. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2217. const count = qdSheet.getRowCount();
  2218. if (billsCount > count) {
  2219. qdSheet.setRowCount(billsCount);
  2220. for (let i = count + 1; i <= billsCount; i++) {
  2221. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2222. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2223. }
  2224. }
  2225. });
  2226. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2227. if (info.col === 0) {
  2228. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2229. if (dealBills && dealBills.length > 0) {
  2230. const bills = _.find(dealBills, {code: info.editingText});
  2231. if (bills) {
  2232. info.sheet.getCell(info.row, 1).value(bills.name);
  2233. info.sheet.getCell(info.row, 2).value(bills.unit);
  2234. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2235. }
  2236. }
  2237. }
  2238. });
  2239. this.obj.bind('shown.bs.modal', function () {
  2240. self.qdSpread.refresh();
  2241. self.posSpread.refresh();
  2242. self.dealSpread.refresh();
  2243. });
  2244. $('#batch-ok').click(function () {
  2245. const selection = billsSheet.getSelections();
  2246. const sel = selection[0];
  2247. const row = selection[0].row;
  2248. const select = billsTree.nodes[row];
  2249. if (select) {
  2250. const insertData = {};
  2251. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2252. insertData.id = select[billsTree.setting.id];
  2253. insertData.batchData = self.getBatchData();
  2254. if (insertData.batchData.length > 0) {
  2255. postData(window.location.pathname + '/update', {
  2256. postType: 'batch-insert',
  2257. postData: insertData
  2258. }, function (data) {
  2259. pos.updateDatas(data.pos);
  2260. const result = billsTree.loadPostData(data.ledger);
  2261. billsTreeSpreadObj.refreshTree(billsSheet, result);
  2262. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2263. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  2264. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  2265. posSpreadObj.loadCurPosData();
  2266. self.obj.modal('hide');
  2267. }, null, true);
  2268. } else {
  2269. self.obj.modal('hide');
  2270. }
  2271. }
  2272. });
  2273. $('input[name=batch-filter]').change(function () {
  2274. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  2275. });
  2276. $.contextMenu({
  2277. selector: '.batch-l-t',
  2278. build: function ($trigger, e) {
  2279. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2280. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2281. },
  2282. items: {
  2283. 'create': {
  2284. name: '新增行',
  2285. icon: 'fa-sign-in',
  2286. callback: function (key, opt) {
  2287. const qdSheet = self.qdSpread.getActiveSheet();
  2288. const posSheet = self.posSpread.getActiveSheet();
  2289. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2290. const index = qdSheet.getRowCount();
  2291. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2292. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2293. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2294. },
  2295. },
  2296. 'delete': {
  2297. name: '删除行',
  2298. icon: 'fa-remove',
  2299. callback: function (key, opt) {
  2300. const qdSheet = self.qdSpread.getActiveSheet();
  2301. const posSheet = self.posSpread.getActiveSheet();
  2302. const sel = qdSheet.getSelections()[0];
  2303. qdSheet.deleteRows(sel.row, sel.rowCount);
  2304. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2305. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2306. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2307. }
  2308. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2309. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2310. }
  2311. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2312. },
  2313. },
  2314. }
  2315. });
  2316. this.initDealBillsSearch();
  2317. }
  2318. search(keyword) {
  2319. this.searchResult = [];
  2320. this.searchCur = 0;
  2321. if (keyword) {
  2322. for (const [i, d] of this.dealSheet.zh_data.entries()) {
  2323. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  2324. }
  2325. }
  2326. $('#batch-dbs-count').html(`结果:${this.searchResult.length}`);
  2327. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.dealSheet, this.searchResult[0]);
  2328. }
  2329. searchPre() {
  2330. this.searchCur = this.searchCur - 1;
  2331. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  2332. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  2333. }
  2334. searchNext() {
  2335. this.searchCur = this.searchCur + 1;
  2336. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  2337. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  2338. }
  2339. initDealBillsSearch() {
  2340. const self = this;
  2341. $('#batch-dbs-keyword').change(function () { self.search(this.value); });
  2342. $('#batch-dbs-pre').click(function (e) {
  2343. self.searchPre();
  2344. e.stopPropagation();
  2345. });
  2346. $('#batch-dbs-next').click(function (e) {
  2347. self.searchNext();
  2348. e.stopPropagation();
  2349. });
  2350. }
  2351. // 初始化左侧表格
  2352. initView () {
  2353. // 初始化 清单编号
  2354. const qdSheet = this.qdSpread.getActiveSheet();
  2355. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2356. SpreadJsObj.refreshColumnAlign(qdSheet);
  2357. // 清理原有数据
  2358. SpreadJsObj.beginMassOperation(qdSheet);
  2359. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2360. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2361. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2362. }
  2363. qdSheet.setSelection(0, 0, 1 ,1);
  2364. SpreadJsObj.endMassOperation(qdSheet);
  2365. // 初始化 部位数量复核表
  2366. const posSheet = this.posSpread.getActiveSheet();
  2367. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2368. SpreadJsObj.refreshColumnAlign(posSheet);
  2369. // 清理原有数据
  2370. SpreadJsObj.beginMassOperation(posSheet);
  2371. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2372. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2373. posSheet.setSelection(0, 0, 1 ,1);
  2374. SpreadJsObj.endMassOperation(posSheet);
  2375. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2376. }
  2377. // 获取界面数据
  2378. getBatchData () {
  2379. const result = [];
  2380. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2381. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2382. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2383. const qd = {
  2384. b_code: qdSheet.getText(iRow, 0),
  2385. name: qdSheet.getText(iRow, 1),
  2386. unit: qdSheet.getText(iRow, 2),
  2387. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2388. pos: [],
  2389. };
  2390. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2391. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2392. if (value !== 0 && !isNaN(value)) {
  2393. qd.pos.push({
  2394. name: posSheet.getText(iPosRow, 0),
  2395. drawing_code: posSheet.getText(iPosRow, 1),
  2396. quantity: value, porder: qd.pos.length + 1,
  2397. });
  2398. }
  2399. }
  2400. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2401. }
  2402. return result;
  2403. }
  2404. }
  2405. const dealBills = new DealBills('#deal-bills-spread', {
  2406. cols: [
  2407. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2408. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2409. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2410. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2411. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2412. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2413. ],
  2414. emptyRows: 0,
  2415. headRows: 1,
  2416. headRowHeight: [32],
  2417. headColWidth: [30],
  2418. defaultRowHeight: 21,
  2419. headerFont: '12px 微软雅黑',
  2420. font: '12px 微软雅黑',
  2421. selectedBackColor: '#fffacd',
  2422. });
  2423. const bgBills = new BgBills('#bg-bills-spread', {
  2424. cols: [
  2425. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2426. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2427. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2428. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2429. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2430. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2431. ],
  2432. emptyRows: 0,
  2433. headRows: 1,
  2434. headRowHeight: [32],
  2435. headColWidth: [30],
  2436. defaultRowHeight: 21,
  2437. headerFont: '12px 微软雅黑',
  2438. font: '12px 微软雅黑',
  2439. selectedBackColor: '#fffacd',
  2440. });
  2441. $.divResizer({
  2442. select: '#revise-right-spr',
  2443. callback: function () {
  2444. billsSpread.refresh();
  2445. if (posSpread) posSpread.refresh();
  2446. if (stdXmj) stdXmj.spread.refresh();
  2447. if (stdGcl) stdGcl.spread.refresh();
  2448. if (dealBills) dealBills.spread.refresh();
  2449. if (bgBills) bgBills.spread.refresh();
  2450. if (searchLedger) searchLedger.spread.refresh();
  2451. if (errorList) errorList.spread.refresh();
  2452. if (checkList) checkList.spread.refresh();
  2453. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2454. }
  2455. });
  2456. $.subMenu({
  2457. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2458. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2459. key: 'menu.1.0.0',
  2460. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2461. callback: function (info) {
  2462. if (info.mini) {
  2463. $('.panel-title').addClass('fluid');
  2464. $('#sub-menu').removeClass('panel-sidebar');
  2465. } else {
  2466. $('.panel-title').removeClass('fluid');
  2467. $('#sub-menu').addClass('panel-sidebar');
  2468. }
  2469. autoFlashHeight();
  2470. billsSpread.refresh();
  2471. if (posSpread) posSpread.refresh();
  2472. if (stdXmj) stdXmj.spread.refresh();
  2473. if (stdGcl) stdGcl.spread.refresh();
  2474. if (dealBills) dealBills.spread.refresh();
  2475. if (bgBills) bgBills.spread.refresh();
  2476. if (searchLedger) searchLedger.spread.refresh();
  2477. if (errorList) errorList.spread.refresh();
  2478. if (checkList) checkList.spread.refresh();
  2479. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2480. }
  2481. });
  2482. $('#content-tab').addClass('active');
  2483. $('#xd-content').addClass('active');
  2484. showSideTools(true);
  2485. billsSpread.refresh();
  2486. if (posSpread) posSpread.refresh();
  2487. const stdLibCellDoubleClick = function (e, info) {
  2488. const stdSheet = info.sheet;
  2489. const mainSheet = billsSheet;
  2490. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2491. const stdTree = stdSheet.zh_tree;
  2492. const stdNode = stdTree.nodes[info.row];
  2493. const mainTree = mainSheet.zh_tree;
  2494. const sel = mainSheet.getSelections()[0];
  2495. const mainNode = mainTree.nodes[sel.row];
  2496. if (!stdNode) return;
  2497. if (info.sheet.zh_setting.stdType === 'gcl') {
  2498. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2499. toastr.warning('非最底层项目下,不应添加节点');
  2500. return;
  2501. }
  2502. }
  2503. postData(window.location.pathname + '/update', {
  2504. postType: 'add-std',
  2505. postData: {
  2506. id: mainTree.getNodeKey(mainNode),
  2507. tender_id: mainNode.tender_id,
  2508. stdType: info.sheet.zh_setting.stdType,
  2509. stdLibId: stdNode.list_id,
  2510. stdNode: stdTree.getNodeKey(stdNode)
  2511. }
  2512. }, function (result) {
  2513. const refreshNode = mainTree.loadPostData(result);
  2514. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  2515. if (sel) {
  2516. if (refreshNode.create && refreshNode.create.length > 0) {
  2517. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2518. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  2519. } else {
  2520. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  2521. if (node) {
  2522. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2523. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  2524. }
  2525. }
  2526. }
  2527. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2528. billsSpread.focus();
  2529. posSpreadObj.loadCurPosData();
  2530. });
  2531. };
  2532. const stdXmjSetting = {
  2533. selector: '#std-xmj',
  2534. stdType: 'xmj',
  2535. libs: stdChapters,
  2536. treeSetting: {
  2537. id: 'chapter_id',
  2538. pid: 'pid',
  2539. order: 'order',
  2540. level: 'level',
  2541. rootId: -1,
  2542. keys: ['id', 'list_id', 'chapter_id'],
  2543. },
  2544. spreadSetting: {
  2545. cols: [
  2546. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2547. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2548. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2549. ],
  2550. treeCol: 0,
  2551. emptyRows: 0,
  2552. headRows: 1,
  2553. headRowHeight: [32],
  2554. defaultRowHeight: 21,
  2555. headerFont: '12px 微软雅黑',
  2556. font: '12px 微软雅黑',
  2557. headColWidth: [30],
  2558. selectedBackColor: '#fffacd',
  2559. },
  2560. cellDoubleClick: stdLibCellDoubleClick,
  2561. page: 'revise',
  2562. tid: window.location.pathname.split('/')[2],
  2563. };
  2564. const stdGclSetting = {
  2565. selector: '#std-gcl',
  2566. stdType: 'gcl',
  2567. libs: stdBills,
  2568. treeSetting: {
  2569. id: 'bill_id',
  2570. pid: 'pid',
  2571. order: 'order',
  2572. level: 'level',
  2573. rootId: -1,
  2574. keys: ['id', 'list_id', 'bill_id']
  2575. },
  2576. spreadSetting: {
  2577. cols: [
  2578. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2579. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2580. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2581. ],
  2582. treeCol: 0,
  2583. emptyRows: 0,
  2584. headRows: 1,
  2585. headRowHeight: [32],
  2586. defaultRowHeight: 21,
  2587. headerFont: '12px 微软雅黑',
  2588. font: '12px 微软雅黑',
  2589. headColWidth: [30],
  2590. selectedBackColor: '#fffacd',
  2591. },
  2592. cellDoubleClick: stdLibCellDoubleClick,
  2593. page: 'revise',
  2594. tid: window.location.pathname.split('/')[2],
  2595. };
  2596. // 展开收起标准节点
  2597. $('a', '#side-menu').bind('click', function (e) {
  2598. e.preventDefault();
  2599. const tab = $(this), tabPanel = $(tab.attr('content'));
  2600. // 展开工具栏、切换标签
  2601. if (!tab.hasClass('active')) {
  2602. const close = $('.active', '#side-menu').length === 0;
  2603. $('a', '#side-menu').removeClass('active');
  2604. tab.addClass('active');
  2605. $('.tab-content .tab-pane').removeClass('active');
  2606. tabPanel.addClass('active');
  2607. showSideTools(tab.hasClass('active'));
  2608. if (tab.attr('content') === '#std-xmj') {
  2609. if (!stdXmj) {
  2610. stdXmj = $.stdLib(stdXmjSetting);
  2611. }
  2612. stdXmj.spread.refresh();
  2613. } else if (tab.attr('content') === '#std-gcl') {
  2614. if (!stdGcl) {
  2615. stdGcl = $.stdLib(stdGclSetting);
  2616. }
  2617. stdGcl.spread.refresh();
  2618. } else if (tab.attr('content') === '#deal-bills') {
  2619. dealBills.loadData();
  2620. dealBills.spread.refresh();
  2621. } else if (tab.attr('content') === '#bg-bills') {
  2622. bgBills.loadData();
  2623. bgBills.spread.refresh();
  2624. } else if (tab.attr('content') === '#search') {
  2625. if (!searchLedger) {
  2626. searchLedger = $.billsSearch({
  2627. selector: '#search',
  2628. searchSpread: billsSpread,
  2629. resultSpreadSetting: {
  2630. cols: [
  2631. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  2632. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2633. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2634. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2635. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2636. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2637. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  2638. ],
  2639. emptyRows: 0,
  2640. headRows: 1,
  2641. headRowHeight: [32],
  2642. headColWidth: [30],
  2643. defaultRowHeight: 21,
  2644. headerFont: '12px 微软雅黑',
  2645. font: '12px 微软雅黑',
  2646. selectedBackColor: '#fffacd',
  2647. readOnly: true,
  2648. },
  2649. afterLocated: function () {
  2650. posSpreadObj.loadCurPosData();
  2651. },
  2652. calcSum: function (result) {
  2653. const sum = { name: '合计' };
  2654. for (const r of result) {
  2655. sum.quantity = ZhCalc.add(r.quantity, sum.quantity);
  2656. }
  2657. return sum;
  2658. }
  2659. });
  2660. }
  2661. searchLedger.spread.refresh();
  2662. } else if (tab.attr('content') === '#error-list') {
  2663. errorList.spread.refresh();
  2664. } else if (tab.attr('content') === '#check-list') {
  2665. checkList.spread.refresh();
  2666. } else if (tab.attr('content') === '#sum-load-miss') {
  2667. sumLoadMiss.spread.refresh();
  2668. }
  2669. }
  2670. else {// 收起工具栏
  2671. tab.removeClass('active');
  2672. tabPanel.removeClass('active');
  2673. showSideTools(tab.hasClass('active'));
  2674. }
  2675. billsSpread.refresh();
  2676. if (posSpread) posSpread.refresh();
  2677. });
  2678. if (!readOnly) {
  2679. // 修订详情 保存
  2680. $('#save').click(function () {
  2681. const content = $('#content').val();
  2682. postData(`/tender/${window.location.pathname.split('/')[2]}/revise/save`, { content: content }, function () {
  2683. $('#content').attr('org-value', content);
  2684. });
  2685. });
  2686. }
  2687. // 显示层次
  2688. (function (select, sheet) {
  2689. $(select).click(function () {
  2690. if (!sheet.zh_tree) return;
  2691. const tag = $(this).attr('tag');
  2692. const tree = sheet.zh_tree;
  2693. setTimeout(() => {
  2694. showWaitingView();
  2695. switch (tag) {
  2696. case "1":
  2697. case "2":
  2698. case "3":
  2699. case "4":
  2700. case "5":
  2701. tree.expandByLevel(parseInt(tag));
  2702. SpreadJsObj.refreshTreeRowVisible(sheet);
  2703. break;
  2704. case "last":
  2705. tree.expandByCustom(() => { return true; });
  2706. SpreadJsObj.refreshTreeRowVisible(sheet);
  2707. break;
  2708. case "leafXmj":
  2709. tree.expandToLeafXmj();
  2710. SpreadJsObj.refreshTreeRowVisible(sheet);
  2711. break;
  2712. }
  2713. closeWaitingView();
  2714. }, 100);
  2715. });
  2716. })('a[name=showLevel]', billsSheet);
  2717. const dataChecker = DataChecker({
  2718. checkUrl: window.location.pathname + '/check',
  2719. completeData: function (data) {
  2720. pos.updateDatas({update: data.source.pos});
  2721. const loadResult = billsTree.loadPostData({update: data.source.bills});
  2722. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2723. posSpreadObj.loadCurPosData();
  2724. for (const e of data.error) {
  2725. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  2726. }
  2727. },
  2728. errorList: errorList,
  2729. });
  2730. $('#ledger-check2').click(() => {
  2731. ledgerCheck2({
  2732. ledgerTree: billsTree,
  2733. ledgerPos: pos,
  2734. checkList: checkList,
  2735. decimal: decimal,
  2736. checkOption: checkOption,
  2737. }).then(result => {
  2738. check2Viewing({
  2739. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  2740. randomWait: true,
  2741. prefix: 'check2-',
  2742. checks: result,
  2743. checkList: checkList,
  2744. });
  2745. });
  2746. });
  2747. $('[name=revise-start]').submit(function (e) {
  2748. if (checkAuditorFrom()) {
  2749. $(this).parent().parent().parent().modal('hide');
  2750. dataChecker.checkAndPost(this.action, {});
  2751. $('#hide-all').hide();
  2752. }
  2753. return false;
  2754. });
  2755. });