ledger.js 131 KB

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