ledger.js 131 KB

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