revise.js 125 KB

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