revise.js 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  15. };
  16. function transExpr(expr) {
  17. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  18. }
  19. $(document).ready(() => {
  20. let stdXmj, stdGcl, searchLedger;
  21. autoFlashHeight();
  22. // 初始化spread
  23. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  24. const billsSheet = billsSpread.getActiveSheet();
  25. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  26. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  27. const posSheet = posSpread.getActiveSheet();
  28. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  29. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  30. // 初始化 节点树结构
  31. const treeSetting = {
  32. id: 'ledger_id',
  33. pid: 'ledger_pid',
  34. order: 'order',
  35. level: 'level',
  36. rootId: -1,
  37. keys: ['id', 'tender_id', 'ledger_id'],
  38. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  39. };
  40. if (!isTz) {
  41. treeSetting.calcFields.push('deal_tp');
  42. }
  43. treeSetting.calcFun = function (node) {
  44. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  45. };
  46. const billsTree = createNewPathTree('revise', treeSetting);
  47. billsTree.loadDatas(billsData);
  48. treeCalc.calculateAll(billsTree);
  49. // 加载至spread
  50. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  51. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  52. // 初始化 计量单元
  53. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  54. pos.loadDatas(posData);
  55. const billsTreeSpreadObj = {
  56. loadExprToInput(sheet) {
  57. const sel = sheet.getSelections()[0];
  58. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  59. if (col && col.type === 'Number') {
  60. const data = SpreadJsObj.getSelectObject(sheet);
  61. if (data) {
  62. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  63. if (col.field.indexOf('dgn') >= 0) {
  64. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
  65. } else if (col.field === 'unit_price') {
  66. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true));
  67. } else {
  68. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
  69. }
  70. } else {
  71. $('#bills-expr').val('').attr('readOnly', true);
  72. }
  73. } else {
  74. $('#bills-expr').val('').attr('readOnly', true);
  75. }
  76. },
  77. getDefaultSelectInfo: function (sheet) {
  78. const tree = sheet.zh_tree;
  79. if (!tree) return;
  80. const sel = sheet.getSelections()[0];
  81. const node = sheet.zh_tree.nodes[sel.row];
  82. if (!node) return;
  83. let count = 1;
  84. if (sel.rowCount > 1) {
  85. for (let r = 1; r < sel.rowCount; r++) {
  86. const rNode = sheet.zh_tree.nodes[sel.row + r];
  87. if (rNode.level > node.level) continue;
  88. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  89. toastr.warning('请选择同一节点下的节点,进行该操作');
  90. return;
  91. }
  92. count += 1;
  93. }
  94. }
  95. return [tree, node, count];
  96. },
  97. /**
  98. * 刷新顶部按钮是否可用
  99. * @param sheet
  100. * @param selections
  101. */
  102. refreshOperationValid: function (sheet, selection) {
  103. const setObjEnable = function (obj, enable) {
  104. if (enable) {
  105. obj.removeClass('disabled');
  106. } else {
  107. obj.addClass('disabled');
  108. }
  109. };
  110. const invalidAll = function () {
  111. setObjEnable($('a[type=add]'), false);
  112. setObjEnable($('a[type=delete]'), false);
  113. setObjEnable($('a[type=up-move]'), false);
  114. setObjEnable($('a[type=down-move]'), false);
  115. setObjEnable($('a[type=up-level]'), false);
  116. setObjEnable($('a[type=down-level]'), false);
  117. };
  118. const sel = selection ? selection[0] : sheet.getSelections()[0];
  119. const row = sel ? sel.row : -1;
  120. const tree = sheet.zh_tree;
  121. if (!tree) {
  122. invalidAll();
  123. return;
  124. }
  125. const first = sheet.zh_tree.nodes[row];
  126. if (!first) {
  127. invalidAll();
  128. return;
  129. }
  130. let last = first, sameParent = true, nodeUsed = first.used;
  131. if (sel.rowCount > 1 && first) {
  132. for (let r = 1; r < sel.rowCount; r++) {
  133. const rNode = tree.nodes[sel.row + r];
  134. if (!rNode) {
  135. sameParent = false;
  136. break;
  137. }
  138. nodeUsed = nodeUsed || rNode.used;
  139. if (rNode.level > first.level) continue;
  140. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  141. sameParent = false;
  142. break;
  143. }
  144. last = rNode;
  145. }
  146. }
  147. const preNode = tree.getPreSiblingNode(first);
  148. const valid = !sheet.zh_setting.readOnly;
  149. setObjEnable($('a[type=add]'), valid && first && first.level > 1);
  150. setObjEnable($('a[type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed);
  151. setObjEnable($('a[type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
  152. setObjEnable($('a[type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  153. if (isTz) {
  154. const posRange = last ? pos.getLedgerPos(last.id) : [];
  155. setObjEnable($('a[type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  156. && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
  157. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  158. setObjEnable($('a[type=down-level]'), valid && first && sameParent && !nodeUsed
  159. && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  160. } else {
  161. setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
  162. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
  163. }
  164. setObjEnable($('#cut'), valid);
  165. setObjEnable($('#paste'), valid);
  166. },
  167. /**
  168. *
  169. * @param sheet
  170. * @param data
  171. */
  172. refreshTree: function (sheet, data) {
  173. SpreadJsObj.massOperationSheet(sheet, function () {
  174. const tree = sheet.zh_tree;
  175. // 处理删除
  176. if (data.delete) {
  177. data.delete.sort(function (a, b) {
  178. return b.deleteIndex - a.deleteIndex;
  179. });
  180. for (const d of data.delete) {
  181. sheet.deleteRows(d.deleteIndex, 1);
  182. }
  183. }
  184. // 处理新增
  185. if (data.create) {
  186. const newNodes = data.create;
  187. if (newNodes) {
  188. newNodes.sort(function (a, b) {
  189. return a.index - b.index;
  190. });
  191. for (const node of newNodes) {
  192. sheet.addRows(node.index, 1);
  193. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  194. }
  195. }
  196. }
  197. // 处理更新
  198. if (data.update) {
  199. const rows = [];
  200. for (const u of data.update) {
  201. rows.push(tree.nodes.indexOf(u));
  202. }
  203. SpreadJsObj.reLoadRowsData(sheet, rows);
  204. }
  205. // 处理展开
  206. if (data.expand) {
  207. const expanded = [];
  208. for (const e of data.expand) {
  209. if (expanded.indexOf(e) === -1) {
  210. const posterity = tree.getPosterity(e);
  211. for (const p of posterity) {
  212. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  213. expanded.push(p);
  214. }
  215. }
  216. }
  217. }
  218. });
  219. },
  220. selectionChanged: function (e, info) {
  221. if (info.newSelections[0].row !== info.oldSelections[0].row) {
  222. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  223. posSpreadObj.loadCurPosData();
  224. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  225. posSearch.search($('#pos-keyword').val());
  226. }
  227. billsTreeSpreadObj.loadExprToInput(info.sheet);
  228. },
  229. /**
  230. * 新增节点
  231. * @param spread
  232. */
  233. baseOpr: function (sheet, type, addCount = 1) {
  234. const self = this;
  235. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  236. if (!tree || !node || !count) return;
  237. if (type === 'delete') {
  238. const parent = tree.getParent(node);
  239. const children = parent ? parent.children : tree.children;
  240. const index = children.indexOf(node);
  241. for (let i = 0; i < count; i++) {
  242. const child = children[i+index];
  243. if (tree.checkNodeUsed(child, pos)) {
  244. toastr.warning('选中的节点已计量,不可删除');
  245. return;
  246. }
  247. }
  248. } else if (type === 'up-level') {
  249. const parent = tree.getParent(node);
  250. const children = parent ? parent.children : tree.children;
  251. const index = children.indexOf(node);
  252. for (let i = index; i < children.length; i++) {
  253. const child = children[index];
  254. if (tree.checkNodeUsed(child, pos)) {
  255. if (i >= index + count) {
  256. toastr.warning('其后节点已计量,选中的节点不可升级');
  257. } else {
  258. toastr.warning('选中的节点已计量,不可升级');
  259. }
  260. return;
  261. }
  262. }
  263. } else if (type === 'down-level') {
  264. const parent = tree.getParent(node);
  265. const children = parent ? parent.children : tree.children;
  266. const index = children.indexOf(node);
  267. for (let i = 0; i < count; i++) {
  268. const child = children[i+index];
  269. if (tree.checkNodeUsed(child, pos)) {
  270. toastr.warning('选中的节点已计量,不可降级');
  271. return;
  272. }
  273. }
  274. }
  275. postData(window.location.pathname + '/update', {
  276. postType: type,
  277. postData: {
  278. id: node.ledger_id,
  279. count: type === 'add' ? addCount : count,
  280. }
  281. }, function (result) {
  282. const refreshData = tree.loadPostData(result);
  283. self.refreshTree(sheet, refreshData);
  284. if (type === 'delete') {
  285. const sel = sheet.getSelections()[0];
  286. if (sel) {
  287. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  288. }
  289. } else if (['up-move', 'down-move'].indexOf(type) > -1) {
  290. const sel = sheet.getSelections()[0];
  291. if (sel) {
  292. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  293. }
  294. } else if (type === 'add') {
  295. const sel = sheet.getSelections()[0];
  296. if (sel) {
  297. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  298. }
  299. }
  300. self.refreshOperationValid(sheet);
  301. });
  302. },
  303. /**
  304. * 编辑单元格响应事件
  305. * @param {Object} e
  306. * @param {Object} info
  307. */
  308. editEnded: function (e, info) {
  309. if (info.sheet.zh_setting) {
  310. const col = info.sheet.zh_setting.cols[info.col];
  311. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  312. const node = sortData[info.row];
  313. const data = {
  314. id: node.id,
  315. tender_id: node.tender_id,
  316. ledger_id: node.ledger_id
  317. };
  318. // 未改变值则不提交
  319. const orgValue = node[col.field];
  320. const newValue = trimInvalidChar(info.editingText);
  321. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  322. return;
  323. }
  324. // 台账模式,检查计量单元相关
  325. if (isTz) {
  326. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  327. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  328. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  329. if (!node.children || node.children.length ===0) {
  330. const lPos = pos.getLedgerPos(node.id);
  331. if (lPos && lPos.length > 0) {
  332. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  333. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  334. return;
  335. }
  336. }
  337. }
  338. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  339. const lPos = pos.getLedgerPos(node.id);
  340. if (lPos && lPos.length > 0) {
  341. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  342. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  343. return;
  344. }
  345. }
  346. }
  347. // 获取更新数据
  348. if (info.editingText) {
  349. const text = newValue;
  350. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  351. toastr.error('节点已计量,请勿删除编号');
  352. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  353. return;
  354. }
  355. if (col.type === 'Number') {
  356. const num = _.toNumber(text);
  357. if (_.isFinite(num)) {
  358. data[col.field] = num;
  359. } else {
  360. try {
  361. data[col.field] = math.evaluate(transExpr(text));
  362. } catch(err) {
  363. toastr.error('输入的表达式非法');
  364. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  365. return;
  366. }
  367. }
  368. } else {
  369. data[col.field] = text;
  370. }
  371. } else {
  372. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  373. toastr.error('节点已计量,请勿删除编号');
  374. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  375. return;
  376. }
  377. data[col.field] = null;
  378. }
  379. // 更新至服务器
  380. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  381. const refreshNode = billsTree.loadPostData(result);
  382. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  383. });
  384. }
  385. },
  386. clipboardPasting: function (e, info) {
  387. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  388. info.cancel = true;
  389. if (!setting || !tree) return;
  390. // const range = info.cellRange;
  391. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  392. // const node = tree.nodes[iRow];
  393. // if (tree.checkNodeUsed(node, pos)) {
  394. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  395. // return;
  396. // }
  397. // }
  398. const pasteData = info.pasteData.html
  399. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  400. : (info.pasteData.text === ''
  401. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  402. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  403. const hint = {
  404. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  405. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  406. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  407. posCode: {type: 'warning', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  408. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  409. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  410. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  411. };
  412. const datas = [], filterNodes = [];
  413. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  414. const curRow = info.cellRange.row + iRow;
  415. const node = tree.nodes[curRow];
  416. if (!node) continue;
  417. let bPaste = false;
  418. const data = info.sheet.zh_tree.getNodeKeyData(node);
  419. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  420. const curCol = info.cellRange.col + iCol;
  421. const colSetting = info.sheet.zh_setting.cols[curCol];
  422. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  423. toastMessageUniq(hint.parent);
  424. continue;
  425. }
  426. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  427. toastMessageUniq(hint.gcl);
  428. continue;
  429. }
  430. const lPos = pos.getLedgerPos(node.id);
  431. if (lPos && lPos.length > 0) {
  432. if (value === '' && colSetting.field === 'b_code') {
  433. toastMessageUniq(hint.posCode);
  434. continue;
  435. }
  436. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  437. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  438. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  439. toastMessageUniq(hint.posQty);
  440. continue;
  441. }
  442. }
  443. const value = trimInvalidChar(pasteData[iRow][iCol]);
  444. if (tree.checkNodeUsed(node, pos) && col.field === 'unit_price') {
  445. toastMessageUniq (hint.usedUp);
  446. continue;
  447. }
  448. if (colSetting.type === 'Number') {
  449. const num = _.toNumber(value);
  450. if (num) {
  451. data[colSetting.field] = num;
  452. } else {
  453. try {
  454. data[colSetting.field] = math.evaluate(transExpr(value));
  455. } catch (err) {
  456. toastMessageUniq(hint.invalidExpr);
  457. continue;
  458. }
  459. }
  460. } else {
  461. if (node.used && (col.field === 'code' || col.field ==='b_code')
  462. && data[colSetting.field] !== '' && value === '') {
  463. toastMessageUniq(hint.usedCode);
  464. continue;
  465. }
  466. data[colSetting.field] = value;
  467. }
  468. bPaste = true;
  469. }
  470. if (bPaste) {
  471. datas.push(data);
  472. } else {
  473. filterNodes.push(node);
  474. }
  475. }
  476. if (datas.length > 0) {
  477. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  478. const refreshNode = tree.loadPostData(result);
  479. if (refreshNode.update) {
  480. refreshNode.update = refreshNode.update.concat(filterNodes);
  481. }
  482. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  483. }, function () {
  484. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  485. });
  486. } else {
  487. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  488. }
  489. },
  490. clipboardPasted: function (e, info) {
  491. const hint = {
  492. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  493. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  494. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  495. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  496. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  497. };
  498. const tree = info.sheet.zh_tree;
  499. if (!tree) { return; }
  500. const sortData = info.sheet.zh_tree.nodes;
  501. const datas = [], filterNodes = [];
  502. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  503. let bPaste = false;
  504. const curRow = info.cellRange.row + iRow;
  505. const node = sortData[curRow];
  506. if (node) {
  507. const data = info.sheet.zh_tree.getNodeKeyData(node);
  508. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  509. const curCol = info.cellRange.col + iCol;
  510. const colSetting = info.sheet.zh_setting.cols[curCol];
  511. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  512. const lPos = pos.getLedgerPos(node.id);
  513. if (lPos && lPos.length > 0) {
  514. if (value === '' && colSetting.field === 'b_code') {
  515. toastMessageUniq(hint.posCode);
  516. continue;
  517. }
  518. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  519. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  520. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  521. toastMessageUniq(hint.posQty);
  522. continue;
  523. }
  524. }
  525. if (node.used && col.field === 'unit_price') {
  526. toastMessageUniq (hint.usedUp);
  527. continue;
  528. }
  529. if (colSetting.type === 'Number') {
  530. const num = _.toNumber(value);
  531. if (num) {
  532. data[colSetting.field] = num;
  533. } else {
  534. try {
  535. data[colSetting.field] = math.evaluate(transExpr(value));
  536. } catch (err) {
  537. toastMessageUniq(hint.invalidExpr);
  538. continue;
  539. }
  540. }
  541. } else {
  542. if (node.used && (col.field === 'code' || col.field ==='b_code')
  543. && data[colSetting.field] !== '' && value === '') {
  544. toastMessageUniq(hint.usedCode);
  545. continue;
  546. }
  547. data[colSetting.field] = value;
  548. }
  549. bPaste = true;
  550. }
  551. if (bPaste) {
  552. datas.push(data);
  553. } else {
  554. filterNodes.push(node);
  555. }
  556. }
  557. }
  558. if (datas.length > 0) {
  559. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  560. const refreshNode = tree.loadPostData(result);
  561. if (refreshNode.update) {
  562. refreshNode.update = refreshNode.update.concat(filterNodes);
  563. }
  564. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  565. }, function () {
  566. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  567. });
  568. } else {
  569. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  570. }
  571. },
  572. deletePress: function (sheet) {
  573. if (!sheet.zh_setting) return;
  574. const sel = sheet.getSelections()[0], datas = [];
  575. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  576. const node = sheet.zh_tree.nodes[iRow];
  577. if (sheet.zh_tree.checkNodeUsed(node, pos)) {
  578. toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  579. return;
  580. }
  581. const data = sheet.zh_tree.getNodeKeyData(node);
  582. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  583. const col = sheet.zh_setting.cols[iCol];
  584. data[col.field] = null;
  585. }
  586. datas.push(data);
  587. }
  588. if (datas.length > 0) {
  589. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  590. const refreshNode = sheet.zh_tree.loadPostData(result);
  591. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  592. });
  593. }
  594. },
  595. pasteBlock: function (spread, copyInfo) {
  596. const self = this;
  597. const sheet = spread.getActiveSheet();
  598. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  599. postData(window.location.pathname + '/update', {
  600. postType: 'paste-block',
  601. postData: {
  602. id: tree.getNodeKey(node),
  603. tid: copyInfo.tid,
  604. block: copyInfo.block,
  605. }
  606. }, function (data) {
  607. pos.updateDatas(data.pos);
  608. const result = tree.loadPostData(data.ledger);
  609. self.refreshTree(sheet, result);
  610. const sel = sheet.getSelections()[0];
  611. if (sel) {
  612. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  613. }
  614. self.refreshOperationValid(sheet);
  615. removeLocalCache(copyBlockTag);
  616. }, null, true);
  617. },
  618. topRowChanged: function (e, info) {
  619. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  620. },
  621. editStarting(e, info) {
  622. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  623. const col = info.sheet.zh_setting.cols[info.col];
  624. const node = info.sheet.zh_tree.nodes[info.row];
  625. switch (col.field) {
  626. case 'unit_price':
  627. info.cancel = (node.children && node.children.length > 0) || node.used;
  628. break;
  629. case 'sgfh_qty':
  630. case 'sgfh_tp':
  631. case 'sjcl_qty':
  632. case 'sjcl_tp':
  633. case 'qtcl_qty':
  634. case 'qtcl_tp':
  635. case 'deal_qty':
  636. case 'deal_tp':
  637. info.cancel = (node.children && node.children.length > 0);
  638. break;
  639. case 'dgn_qty1':
  640. case 'dgn_qty2':
  641. info.cancel = !_.isEmpty(node.b_code);
  642. break;
  643. }
  644. },
  645. cut: function (sheet, sel, callback) {
  646. if (!sheet || !sel) return;
  647. if (sel.colCount >= sheet.zh_setting.cols.length) {
  648. toastr.warning('请勿选中整行剪切');
  649. return;
  650. }
  651. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  652. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  653. const node = sortData[iRow];
  654. if (node) {
  655. const data = sheet.zh_tree.getNodeKeyData(node);
  656. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  657. const col = sheet.zh_setting.cols[iCol];
  658. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  659. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  660. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  661. const lPos = pos.getLedgerPos(node.id);
  662. if (lPos && lPos.length > 0) {
  663. toastr.error('不可剪切');
  664. return;
  665. }
  666. }
  667. const style = sheet.getStyle(iRow, iCol);
  668. if (style.locked) {
  669. toastr.error('不可剪切');
  670. return;
  671. }
  672. const colSetting = sheet.zh_setting.cols[iCol];
  673. data[colSetting.field] = null;
  674. }
  675. datas.push(data);
  676. }
  677. }
  678. if (datas.length > 0) {
  679. callback();
  680. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  681. const refreshNode = sheet.zh_tree.loadPostData(result);
  682. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  683. });
  684. }
  685. },
  686. sortCode: function (sheet) {
  687. const tree = sheet.zh_tree;
  688. if (!tree) return;
  689. const select = SpreadJsObj.getSelectObject(sheet);
  690. if (!select || !select.code || select.code === '') return;
  691. const recursiveSortCode = function (data, parentCode, children) {
  692. if (!children || children.length === 0) return;
  693. for (const [i, child] of children.entries()) {
  694. const code = parentCode + '-' + (i + 1);
  695. const cData = tree.getNodeKeyData(child);
  696. cData.code = code;
  697. data.push(cData);
  698. if (!tree.isLeafXmj(child)) {
  699. recursiveSortCode(data, code, child.children);
  700. }
  701. }
  702. };
  703. const data = [];
  704. recursiveSortCode(data, select.code, select.children);
  705. if (data.length > 0) {
  706. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  707. const refreshNode = tree.loadPostData(result);
  708. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  709. })
  710. }
  711. }
  712. };
  713. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  714. billsTreeSpreadObj.loadExprToInput(billsSheet);
  715. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  716. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  717. if (!readOnly) {
  718. // 增删上下移升降级
  719. $('a[name="base-opr"]').click(function () {
  720. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  721. });
  722. $('a[name=cpc]').click(function () {
  723. billsSpread.commandManager().execute({
  724. cmd: this.getAttribute('type'),
  725. sheetName: billsSheet.name()
  726. });
  727. });
  728. $('#bills-expr').bind('change mouseleave', function () {
  729. if (this.readOnly) return;
  730. const expr = $(this);
  731. const select = SpreadJsObj.getSelectObject(billsSheet);
  732. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  733. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  734. const data = {
  735. id: select.id,
  736. tender_id: select.tender_id,
  737. ledger_id: select.ledger_id
  738. };
  739. if (newValue !== '') {
  740. const num = _.toNumber(newValue);
  741. if (num) {
  742. data[field] = num;
  743. } else {
  744. try {
  745. data[field] = math.evaluate(transExpr(newValue));
  746. } catch (err) {
  747. toastr.error('输入的表达式非法');
  748. return;
  749. }
  750. }
  751. } else {
  752. data[field] = null;
  753. }
  754. // 更新至服务器
  755. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  756. const refreshNode = billsTree.loadPostData(result);
  757. expr.val(select[field]);
  758. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  759. });
  760. });
  761. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  762. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  763. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  764. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  765. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  766. SpreadJsObj.Clipboard.setCopyData(copyText);
  767. });
  768. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  769. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  770. let batchInsertObj;
  771. $.contextMenu.types.batchInsert = function (item, opt, root) {
  772. const self = this;
  773. if ($.isFunction(item.icon)) {
  774. item._icon = item.icon.call(this, this, $t, key, item);
  775. } else {
  776. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  777. // to enable font awesome
  778. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  779. } else {
  780. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  781. }
  782. }
  783. this.addClass(item._icon);
  784. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  785. .appendTo(this);
  786. const $input = $obj.find('input');
  787. const event = () => {
  788. if (self.hasClass('context-menu-disabled')) return;
  789. item.batchInsert($input[0], root);
  790. };
  791. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  792. $input.click((e) => {e.stopPropagation();})
  793. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  794. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  795. };
  796. // 右键菜单
  797. $.contextMenu({
  798. selector: '#bills-spread',
  799. build: function ($trigger, e) {
  800. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  801. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  802. },
  803. items: {
  804. 'create': {
  805. name: '新增',
  806. icon: 'fa-sign-in',
  807. callback: function (key, opt) {
  808. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  809. },
  810. disabled: function (key, opt) {
  811. const sheet = billsSheet;
  812. const selection = sheet.getSelections();
  813. const sel = selection ? selection[0] : sheet.getSelections()[0];
  814. const row = sel ? sel.row : -1;
  815. const tree = sheet.zh_tree;
  816. if (!tree) return true;
  817. const first = sheet.zh_tree.nodes[row];
  818. const valid = !sheet.zh_setting.readOnly;
  819. return !(valid && first && first.level > 1);
  820. }
  821. },
  822. 'delete': {
  823. name: '删除',
  824. icon: 'fa-remove',
  825. callback: function (key, opt) {
  826. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  827. },
  828. disabled: function (key, opt) {
  829. const sheet = billsSheet;
  830. const selection = sheet.getSelections();
  831. const sel = selection ? selection[0] : sheet.getSelections()[0];
  832. const row = sel ? sel.row : -1;
  833. const tree = sheet.zh_tree;
  834. if (!tree) return true;
  835. const first = sheet.zh_tree.nodes[row];
  836. let last = first, sameParent = true, nodeUsed = first.used;
  837. if (sel.rowCount > 1 && first) {
  838. for (let r = 1; r < sel.rowCount; r++) {
  839. const rNode = tree.nodes[sel.row + r];
  840. if (!rNode) {
  841. sameParent = false;
  842. break;
  843. }
  844. nodeUsed = nodeUsed || rNode.used;
  845. if (rNode.level > first.level) continue;
  846. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  847. sameParent = false;
  848. break;
  849. }
  850. last = rNode;
  851. }
  852. }
  853. const valid = !sheet.zh_setting.readOnly;
  854. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  855. }
  856. },
  857. 'sprBase': '-----------',
  858. 'batchInsert': {
  859. name: '批量插入',
  860. type: 'batchInsert',
  861. value: '2',
  862. icon: 'fa-sign-in',
  863. batchInsert: function (obj, root) {
  864. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  865. obj.value = obj.max;
  866. toastr.warning('批量插入不可多于' + obj.max);
  867. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  868. obj.value = obj.min;
  869. toastr.warning('批量插入不可少于' + obj.min);
  870. } else {
  871. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  872. root.$menu.trigger('contextmenu:hide');
  873. }
  874. },
  875. disabled: function (key, opt) {
  876. const sheet = billsSheet;
  877. const selection = sheet.getSelections();
  878. const sel = selection ? selection[0] : sheet.getSelections()[0];
  879. const row = sel ? sel.row : -1;
  880. const tree = sheet.zh_tree;
  881. if (!tree) return true;
  882. const first = sheet.zh_tree.nodes[row];
  883. const valid = !sheet.zh_setting.readOnly;
  884. return !(valid && first && first.level > 1);
  885. }
  886. },
  887. 'batchInsertBillsPos': {
  888. name: '批量插入清单-计量单元',
  889. icon: 'fa-sign-in',
  890. disabled: function (key, opt) {
  891. if (!isTz) return true;
  892. const select = SpreadJsObj.getSelectObject(billsSheet);
  893. if (select) {
  894. if (select.code && select.code !== '') {
  895. return !billsTree.isLeafXmj(select);
  896. } else {
  897. const parent = billsTree.getParent(select);
  898. return !(parent && billsTree.isLeafXmj(parent));
  899. }
  900. } else {
  901. return false;
  902. }
  903. },
  904. callback: function (key, opt) {
  905. if (!batchInsertObj) {
  906. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  907. } else {
  908. batchInsertObj.initView();
  909. }
  910. $('#batch').modal('show');
  911. }
  912. },
  913. 'sprBatch': '-----------',
  914. 'sortChildren': {
  915. name: '顺序重排子项编号',
  916. icon: 'fa-sort-numeric-asc',
  917. disabled: function (key, opt) {
  918. const node = SpreadJsObj.getSelectObject(billsSheet);
  919. return !node || !node.code || !node.children || node.children === 0;
  920. },
  921. callback: function (key, opt) {
  922. billsTreeSpreadObj.sortCode(billsSheet);
  923. }
  924. },
  925. 'sprSort': '-----------',
  926. 'importGclBills2Xmj': {
  927. name: '导入工程量清单至项目节',
  928. icon: 'fa-file-excel-o',
  929. disabled: function (key, opt) {
  930. const node = SpreadJsObj.getSelectObject(billsSheet);
  931. return readOnly
  932. || (node.children && node.children.length > 0)
  933. || (!_.isNil(node.b_code) && node.b_code !== '')
  934. || billsTree.checkNodeUsed(node, pos);
  935. },
  936. callback: function (key, opt) {
  937. const node = SpreadJsObj.getSelectObject(billsSheet);
  938. importExcel.doImport({
  939. template: {
  940. hint: '工程量清单',
  941. url: '/template/导入工程量清单EXCEL格式.xls',
  942. },
  943. callback: function (sheet) {
  944. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  945. const sel = billsSheet.getSelections();
  946. const refreshNode = billsTree.loadPostData(result);
  947. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  948. if (refreshNode.create[0]) {
  949. if (sel && sel[0]) {
  950. billsSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  951. } else {
  952. billsSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  953. }
  954. }
  955. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  956. }, null);
  957. }
  958. });
  959. }
  960. },
  961. }
  962. });
  963. }
  964. const posSpreadObj = {
  965. /**
  966. * 加载计量单元 根据当前台账选择节点
  967. */
  968. loadCurPosData: function () {
  969. const node = SpreadJsObj.getSelectObject(billsSheet);
  970. if (node) {
  971. const posData = pos.getLedgerPos(node.id) || [];
  972. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  973. } else {
  974. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  975. }
  976. SpreadJsObj.resetFieldReadOnly(posSheet);
  977. },
  978. editStarting: function (e, info) {
  979. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  980. },
  981. /**
  982. * 编辑单元格响应事件
  983. * @param {Object} e
  984. * @param {Object} info
  985. */
  986. editEnded: function (e, info) {
  987. if (!info.sheet.zh_setting) {
  988. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  989. return;
  990. }
  991. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  992. const col = info.sheet.zh_setting.cols[info.col];
  993. const orgText = posData ? posData[col.field] : null;
  994. const newText = trimInvalidChar(info.sheet.getCell(info.row, info.col).text());
  995. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  996. const node = posSpreadObj.billsNode;
  997. if (!node) {
  998. toastr.error('数据错误,请选择台账节点后再试');
  999. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1000. return;
  1001. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1002. toastr.error('父节点不可插入计量单元');
  1003. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1004. return;
  1005. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1006. toastr.error('项目节不可插入计量单元');
  1007. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1008. return;
  1009. }
  1010. const data = {postType: 'pos'};
  1011. if (col.field === 'name') {
  1012. if (newText === '' && posData) {
  1013. toastr.error('部位名称不可为空', 'error');
  1014. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1015. return;
  1016. } else if (!posData) {
  1017. if (newText && newText !== '') {
  1018. data.posPostType = 'add';
  1019. const sortData = info.sheet.zh_data;
  1020. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1021. data.postData = { name: newText, lid: node.id, porder: order};
  1022. } else {
  1023. return;
  1024. }
  1025. } else {
  1026. data.posPostType = 'update';
  1027. data.postData = {id: posData.id, name: newText};
  1028. }
  1029. } else if (!posData) {
  1030. toastr.warning('新增部位请先输入名称');
  1031. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1032. return;
  1033. } else {
  1034. data.posPostType = 'update';
  1035. data.postData = {id: posData.id};
  1036. if (col.type === 'Number') {
  1037. const num = _.toNumber(newText);
  1038. if (_.isFinite(num)) {
  1039. data.postData[col.field] = num;
  1040. } else {
  1041. try {
  1042. data.postData[col.field] = math.evaluate(transExpr(newText));
  1043. } catch(err) {
  1044. toastr.error('输入的表达式非法');
  1045. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1046. return;
  1047. }
  1048. }
  1049. } else {
  1050. data.postData[col.field] = newText;
  1051. }
  1052. }
  1053. postData(window.location.pathname + '/update', data, function (result) {
  1054. const updateRst = pos.updateDatas(result.pos);
  1055. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1056. if (updateRst.create.length > 0) {
  1057. posSpreadObj.loadCurPosData();
  1058. } else {
  1059. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1060. }
  1061. const loadResult = billsTree.loadPostData(result.ledger);
  1062. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1063. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1064. }, function () {
  1065. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1066. });
  1067. },
  1068. /**
  1069. * 删除按钮响应事件
  1070. * @param sheet
  1071. */
  1072. deletePress: function (sheet) {
  1073. if (!sheet.zh_settting) return;
  1074. const sortData = sheet.zh_data;
  1075. const datas = [], posSelects = [];
  1076. const sel = sheet.getSelections()[0];
  1077. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1078. let bDel = false;
  1079. const node = sortData[iRow];
  1080. if (node) {
  1081. const data = {id: node.id};
  1082. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1083. const colSetting = sheet.zh_setting.cols[iCol];
  1084. if (colSetting.field === 'name') {
  1085. toastr.error('部位名称不能为空');
  1086. return;
  1087. }
  1088. const style = sheet.getStyle(iRow, iCol);
  1089. if (!style.locked) {
  1090. const colSetting = sheet.zh_setting.cols[iCol];
  1091. data[colSetting.field] = null;
  1092. bDel = true;
  1093. }
  1094. }
  1095. if (bDel) {
  1096. datas.push(data);
  1097. posSelects.push(node);
  1098. }
  1099. }
  1100. }
  1101. if (datas.length > 0) {
  1102. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1103. pos.updateDatas(result.pos);
  1104. posSpreadObj.loadCurPosData();
  1105. const loadResult = billsTree.loadPostData(result.ledger);
  1106. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1107. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1108. }, function () {
  1109. posSpreadObj.loadCurPosData();
  1110. });
  1111. }
  1112. },
  1113. /**
  1114. * 删除 计量单元
  1115. * @param sheet
  1116. */
  1117. deletePos: function (sheet) {
  1118. const selection = sheet.getSelections();
  1119. const data = {
  1120. postType: 'pos',
  1121. posPostType: 'delete',
  1122. postData: [],
  1123. };
  1124. const row = selection[0].row, count = selection[0].rowCount;
  1125. const sortData = sheet.zh_data;
  1126. for (let iRow = 0; iRow < count; iRow++) {
  1127. const posData = sortData[iRow + row];
  1128. if (posData) {
  1129. if (posData.used) {
  1130. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1131. return;
  1132. }
  1133. data.postData.push(sortData[iRow + row].id);
  1134. }
  1135. }
  1136. if (data.postData.length > 0) {
  1137. postData(window.location.pathname + '/update', data, function (result) {
  1138. pos.removeDatas(result.pos);
  1139. sheet.deleteRows(row, count);
  1140. const loadResult = billsTree.loadPostData(result.ledger);
  1141. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1142. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1143. });
  1144. }
  1145. },
  1146. clipboardPasting: function (e, info) {
  1147. if (!info.sheet.zh_setting) {
  1148. info.cancel = true;
  1149. return;
  1150. }
  1151. const range = info.cellRange;
  1152. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1153. const posData = info.sheet.zh_data[iRow];
  1154. if (posData && posData.used) {
  1155. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  1156. info.cancel = true;
  1157. return;
  1158. }
  1159. }
  1160. },
  1161. /**
  1162. * 粘贴单元格响应事件
  1163. * @param e
  1164. * @param info
  1165. */
  1166. clipboardPasted: function (e, info) {
  1167. const node = SpreadJsObj.getSelectObject(billsSheet);
  1168. if (node.code && (node.code !== '')) {
  1169. toastr.error('项目节不可含有节点明细');
  1170. posSpreadObj.loadCurPosData();
  1171. return;
  1172. }
  1173. if (node.children && (node.children.length > 0)) {
  1174. toastr.error('仅节点子项可以含有计量单元');
  1175. posSpreadObj.loadCurPosData();
  1176. return;
  1177. }
  1178. if (!info.sheet.zh_setting) {
  1179. posSpreadObj.loadCurPosData();
  1180. return;
  1181. }
  1182. const data = [];
  1183. const sortData = info.sheet.zh_data || [];
  1184. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1185. if (info.cellRange.col !== 0) {
  1186. toastr.warning('新增部位请先输入名称');
  1187. posSpreadObj.loadCurPosData();
  1188. return;
  1189. }
  1190. }
  1191. let bHint = false;
  1192. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1193. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1194. let bPaste = true;
  1195. const curRow = info.cellRange.row + iRow;
  1196. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1197. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1198. const curCol = info.cellRange.col + iCol;
  1199. const colSetting = info.sheet.zh_setting.cols[curCol];
  1200. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1201. if (colSetting.type === 'Number') {
  1202. const num = _.toNumber(posData[colSetting.field]);
  1203. if (num) {
  1204. posData[colSetting.field] = num;
  1205. } else {
  1206. try {
  1207. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1208. } catch (err) {
  1209. if (!bHint) {
  1210. toastr.warning('粘贴了非法表达式,已过滤');
  1211. bHint = true;
  1212. }
  1213. bPaste = false;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. if (bPaste) {
  1219. data.push(posData);
  1220. }
  1221. }
  1222. if (data.length === 0) {
  1223. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1224. return;
  1225. }
  1226. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1227. pos.updateDatas(result.pos);
  1228. posSpreadObj.loadCurPosData();
  1229. const loadResult = billsTree.loadPostData(result.ledger);
  1230. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1231. posSpreadObj.loadCurPosData();
  1232. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1233. }, function () {
  1234. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1235. });
  1236. },
  1237. selectionChanged: function (e, info) {
  1238. const col = info.sheet.zh_setting.cols[info.newSelections[0].col];
  1239. const cell = info.sheet.getCell(info.newSelections[0].col, info.newSelections[0].col);
  1240. if (col && col.type === 'Number') {
  1241. const data = SpreadJsObj.getSelectObject(info.sheet);
  1242. if (data) {
  1243. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  1244. .attr('row', info.newSelections[0].row).attr('readOnly', readOnly || cell.locked());
  1245. } else {
  1246. $('#pos-expr').val('').attr('readOnly', true);
  1247. }
  1248. } else {
  1249. $('#pos-expr').val('').attr('readOnly', true);
  1250. }
  1251. },
  1252. addPegs: function (pegs) {
  1253. if (!pegs || pegs.length <= 0) return;
  1254. const node = SpreadJsObj.getSelectObject(billsSheet);
  1255. if (!node) return;
  1256. const sheet = posSpread.getActiveSheet();
  1257. const sortData = sheet.zh_data || [];
  1258. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1259. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1260. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1261. pos.updateDatas(result.pos);
  1262. posSpreadObj.loadCurPosData();
  1263. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1264. });
  1265. }
  1266. };
  1267. posSpreadObj.loadCurPosData();
  1268. SpreadJsObj.resetTopAndSelect(posSheet);
  1269. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1270. if (!readOnly) {
  1271. $('#pos-expr').bind('change mouseleave', function () {
  1272. if (this.readOnly) return;
  1273. const expr = $(this);
  1274. const select = SpreadJsObj.getSelectObject(posSheet);
  1275. const row = posSheet.getSelections()[0].row;
  1276. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1277. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1278. const data = {id: select.id};
  1279. if (newValue !== '') {
  1280. const num = _.toNumber(newValue);
  1281. if (num) {
  1282. data[field] = num;
  1283. } else {
  1284. try {
  1285. data[field] = math.evaluate(transExpr(newValue));
  1286. } catch (err) {
  1287. toastr.error('输入的表达式非法');
  1288. return;
  1289. }
  1290. }
  1291. } else {
  1292. data[field] = null;
  1293. }
  1294. // 更新至服务器
  1295. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1296. const updateRst = pos.updateDatas(result.pos);
  1297. expr.val(select[field]);
  1298. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1299. SpreadJsObj.reLoadRowData(posSheet, row);
  1300. const loadResult = billsTree.loadPostData(result.ledger);
  1301. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1302. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1303. });
  1304. });
  1305. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1306. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1307. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  1308. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1309. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1310. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1311. $.contextMenu({
  1312. selector: '#pos-spread',
  1313. build: function ($trigger, e) {
  1314. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1315. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1316. },
  1317. items: {
  1318. 'delete': {
  1319. name: '删除',
  1320. icon: 'fa-remove',
  1321. disabled: function (key, opt) {
  1322. if (posSheet.zh_data) {
  1323. const selection = posSheet.getSelections();
  1324. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1325. } else {
  1326. return true;
  1327. }
  1328. },
  1329. callback: function (key, opt) {
  1330. posSpreadObj.deletePos(posSheet);
  1331. }
  1332. },
  1333. 'merge-peg': {
  1334. name: '合并起讫桩号',
  1335. disabled: function (key, opt) {
  1336. const node = SpreadJsObj.getSelectObject(billsSheet);
  1337. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1338. },
  1339. callback: function (key, opt) {
  1340. mergePeg.show();
  1341. }
  1342. }
  1343. }
  1344. });
  1345. }
  1346. $.divResizer({
  1347. select: '#revise-resize',
  1348. callback: function () {
  1349. billsSpread.refresh();
  1350. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1351. $(".sp-wrap").height(bcontent-40);
  1352. posSpread.refresh();
  1353. }
  1354. });
  1355. class DealBills {
  1356. constructor (selector, spreadSetting) {
  1357. const self = this;
  1358. this.loaded = false;
  1359. this.obj = $(selector)[0];
  1360. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1361. this.spreadSetting = spreadSetting;
  1362. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1363. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1364. if (!readOnly) {
  1365. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1366. const dealSheet = info.sheet;
  1367. const mainSheet = billsSheet;
  1368. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1369. if (!dealBills) { return; }
  1370. const mainTree = mainSheet.zh_tree;
  1371. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1372. if (!mainNode || !mainTree) { return; }
  1373. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1374. toastr.warning('非最底层项目下,不应添加节点');
  1375. return;
  1376. }
  1377. postData(window.location.pathname + '/update', {
  1378. postType: 'add-deal',
  1379. postData: {
  1380. id: mainNode.ledger_id,
  1381. type: mainNode.code ? 'child' : 'next',
  1382. dealBills: {
  1383. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1384. unit_price: dealBills.unit_price,
  1385. }
  1386. },
  1387. }, function (result) {
  1388. const refreshData = mainTree.loadPostData(result);
  1389. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1390. const sel = mainSheet.getSelections()[0];
  1391. if (sel && refreshData.create[0]) {
  1392. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1393. }
  1394. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1395. billsSpread.focus();
  1396. posSpreadObj.loadCurPosData();
  1397. });
  1398. });
  1399. }
  1400. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1401. }
  1402. loadData (callback) {
  1403. if (this.loaded) {
  1404. if (callback) callback();
  1405. return;
  1406. }
  1407. const self = this;
  1408. postData(this.url+'/get-data', {}, function (data) {
  1409. self.data = data;
  1410. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1411. self.loaded = true;
  1412. if (callback) callback();
  1413. });
  1414. }
  1415. calculateData () {
  1416. if (this.data) {
  1417. for (const d of this.data) {
  1418. d.total_price = _.multiply(d.quantity, d.unit_price);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. class BgBills {
  1424. constructor (selector, spreadSetting) {
  1425. this.loaded = false;
  1426. this.obj = $(selector)[0];
  1427. this.spreadSetting = spreadSetting;
  1428. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1429. this.sheet = this.spread.getActiveSheet();
  1430. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1431. if (!readOnly) {
  1432. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1433. const dealSheet = info.sheet;
  1434. const mainSheet = billsSheet;
  1435. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  1436. if (!bgBills) { return; }
  1437. const mainTree = mainSheet.zh_tree;
  1438. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1439. if (!mainNode || !mainTree) { return; }
  1440. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1441. toastr.warning('非最底层项目下,不应添加变更清单');
  1442. return;
  1443. }
  1444. postData(window.location.pathname + '/update', {
  1445. postType: 'add-bg',
  1446. postData: {
  1447. id: mainNode.ledger_id,
  1448. type: mainNode.code ? 'child' : 'next',
  1449. dealBills: {
  1450. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  1451. unit_price: bgBills.unit_price,
  1452. }
  1453. },
  1454. }, function (result) {
  1455. const refreshData = mainTree.loadPostData(result);
  1456. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1457. const sel = mainSheet.getSelections()[0];
  1458. if (sel && refreshData.create[0]) {
  1459. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1460. }
  1461. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1462. billsSpread.focus();
  1463. posSpreadObj.loadCurPosData();
  1464. });
  1465. });
  1466. }
  1467. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1468. }
  1469. loadData () {
  1470. if (this.loaded) return;
  1471. const self = this;
  1472. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  1473. self.data = data;
  1474. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1475. self.loaded = true;
  1476. });
  1477. }
  1478. }
  1479. class BatchInsertBillsPosObj {
  1480. constructor (obj) {
  1481. const self = this;
  1482. this.obj = obj;
  1483. this.billsCount = 6;
  1484. this.posCount = 1000;
  1485. // 初始化 清单编号窗口 参数
  1486. this.qdSpreadSetting = {
  1487. cols: [
  1488. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1489. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1490. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1491. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1492. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1493. ],
  1494. emptyRows: this.billsCount,
  1495. headRows: 1,
  1496. headRowHeight: [32],
  1497. headerFont: '12px 微软雅黑',
  1498. font: '12px 微软雅黑',
  1499. };
  1500. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1501. // 初始化 部位数量复核表 参数
  1502. this.posSpreadSetting = {
  1503. cols: [
  1504. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1505. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1506. ],
  1507. emptyRows: this.posCount,
  1508. headRows: 1,
  1509. headRowHeight: [32],
  1510. headerFont: '12px 微软雅黑',
  1511. font: '12px 微软雅黑',
  1512. };
  1513. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1514. this.posSpreadSetting.cols.push(
  1515. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1516. )
  1517. }
  1518. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1519. // 初始化 签约节点 参数
  1520. this.dealSpreadSetting = {
  1521. cols: [
  1522. {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
  1523. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  1524. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  1525. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  1526. ],
  1527. emptyRows: 0,
  1528. headRows: 1,
  1529. headRowHeight: [32],
  1530. headerFont: '12px 微软雅黑',
  1531. font: '12px 微软雅黑',
  1532. };
  1533. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1534. // 初始化 清单编号、部位数量复核表 表格
  1535. this.initView();
  1536. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1537. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1538. // 拉取签约节点数据
  1539. dealBills.loadData(() => {
  1540. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1541. });
  1542. // 双击签约节点,自动添加到清单编号窗口
  1543. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1544. const deal = info.sheet.zh_data[info.row];
  1545. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1546. const sel = qdSheet.getSelections()[0];
  1547. qdSheet.getCell(sel.row, 0).value(deal.code);
  1548. qdSheet.getCell(sel.row, 1).value(deal.name);
  1549. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1550. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1551. if (sel.row + 1 === qdSheet.getRowCount()) {
  1552. const count = sel.row + 2;
  1553. qdSheet.setRowCount(count);
  1554. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1555. const colCount = posSheet.getColumnCount() + 1;
  1556. posSheet.setColumnCount(colCount);
  1557. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
  1558. }
  1559. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1560. qdSheet.getParent().focus();
  1561. });
  1562. this.obj.bind('shown.bs.modal', function () {
  1563. self.qdSpread.refresh();
  1564. self.posSpread.refresh();
  1565. self.dealSpread.refresh();
  1566. });
  1567. $('#batch-ok').click(function () {
  1568. const selection = billsSheet.getSelections();
  1569. const row = selection[0].row;
  1570. const select = billsTree.nodes[row];
  1571. if (select) {
  1572. const insertData = {};
  1573. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1574. insertData.id = select[billsTree.setting.id];
  1575. insertData.batchData = self.getBatchData();
  1576. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  1577. pos.updateDatas(data.pos);
  1578. const result = billsTree.loadPostData(data.ledger);
  1579. billsTreeSpreadObj.refreshTree(billsSheet, result);
  1580. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  1581. self.obj.modal('hide');
  1582. }, null, true);
  1583. }
  1584. });
  1585. }
  1586. // 初始化左侧表格
  1587. initView () {
  1588. // 初始化 清单编号
  1589. const qdSheet = this.qdSpread.getActiveSheet();
  1590. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1591. SpreadJsObj.refreshColumnAlign(qdSheet);
  1592. // 清理原有数据
  1593. SpreadJsObj.beginMassOperation(qdSheet);
  1594. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1595. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1596. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  1597. }
  1598. qdSheet.setSelection(0, 0, 1 ,1);
  1599. SpreadJsObj.endMassOperation(qdSheet);
  1600. // 初始化 部位数量复核表
  1601. const posSheet = this.posSpread.getActiveSheet();
  1602. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1603. SpreadJsObj.refreshColumnAlign(posSheet);
  1604. // 清理原有数据
  1605. SpreadJsObj.beginMassOperation(posSheet);
  1606. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1607. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1608. posSheet.setSelection(0, 0, 1 ,1);
  1609. SpreadJsObj.endMassOperation(posSheet);
  1610. // 检查签约节点数据,以工具栏数据为准
  1611. if (dealBills) {
  1612. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1613. }
  1614. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1615. }
  1616. // 获取界面数据
  1617. getBatchData () {
  1618. const result = [];
  1619. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1620. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1621. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1622. const qd = {
  1623. b_code: qdSheet.getText(iRow, 0),
  1624. name: qdSheet.getText(iRow, 1),
  1625. unit: qdSheet.getText(iRow, 2),
  1626. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1627. pos: [],
  1628. };
  1629. result.push(qd);
  1630. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1631. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1632. if (value !== 0 && !isNaN(value)) {
  1633. qd.pos.push({
  1634. name: posSheet.getText(iPosRow, 0),
  1635. drawing_code: posSheet.getText(iPosRow, 1),
  1636. quantity: value,
  1637. });
  1638. }
  1639. }
  1640. }
  1641. return result;
  1642. }
  1643. }
  1644. const dealBills = new DealBills('#deal-bills-spread', {
  1645. cols: [
  1646. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1647. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1648. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1649. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1650. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1651. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1652. ],
  1653. emptyRows: 0,
  1654. headRows: 1,
  1655. headRowHeight: [32],
  1656. defaultRowHeight: 21,
  1657. headerFont: '12px 微软雅黑',
  1658. font: '12px 微软雅黑',
  1659. });
  1660. const bgBills = new BgBills('#bg-bills-spread', {
  1661. cols: [
  1662. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1663. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1664. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1665. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1666. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1667. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1668. ],
  1669. emptyRows: 0,
  1670. headRows: 1,
  1671. headRowHeight: [32],
  1672. defaultRowHeight: 21,
  1673. headerFont: '12px 微软雅黑',
  1674. font: '12px 微软雅黑',
  1675. });
  1676. $.divResizer({
  1677. select: '#revise-right-spr',
  1678. callback: function () {
  1679. billsSpread.refresh();
  1680. if (posSpread) {
  1681. posSpread.refresh();
  1682. }
  1683. if (stdXmj) {
  1684. stdXmj.spread.refresh();
  1685. }
  1686. if (stdGcl) {
  1687. stdGcl.spread.refresh();
  1688. }
  1689. if (dealBills) {
  1690. dealBills.spread.refresh();
  1691. }
  1692. if (bgBills) {
  1693. bgBills.spread.refresh();
  1694. }
  1695. if (searchLedger) {
  1696. searchLedger.spread.refresh();
  1697. }
  1698. }
  1699. });
  1700. $.subMenu({
  1701. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1702. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1703. key: 'menu.1.0.0',
  1704. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1705. callback: function (info) {
  1706. if (info.mini) {
  1707. $('.panel-title').addClass('fluid');
  1708. $('#sub-menu').removeClass('panel-sidebar');
  1709. } else {
  1710. $('.panel-title').removeClass('fluid');
  1711. $('#sub-menu').addClass('panel-sidebar');
  1712. }
  1713. autoFlashHeight();
  1714. billsSpread.refresh();
  1715. if (posSpread) {
  1716. posSpread.refresh();
  1717. }
  1718. if (stdXmj) {
  1719. stdXmj.spread.refresh();
  1720. }
  1721. if (stdGcl) {
  1722. stdGcl.spread.refresh();
  1723. }
  1724. if (dealBills) {
  1725. dealBills.spread.refresh();
  1726. }
  1727. if (bgBills) {
  1728. bgBills.spread.refresh();
  1729. }
  1730. if (searchLedger) {
  1731. searchLedger.spread.refresh();
  1732. }
  1733. }
  1734. });
  1735. const showSideTools = function (show) {
  1736. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1737. if (show) {
  1738. right.show();
  1739. autoFlashHeight();
  1740. /**
  1741. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1742. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1743. * 故需要通过最终的parent.width再计算一次left.width
  1744. *
  1745. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1746. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1747. *
  1748. */
  1749. //left.css('width', parent.width() - right.outerWidth());
  1750. //left.css('width', parent.width() - right.outerWidth());
  1751. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1752. left.css('width', percent + '%');
  1753. } else {
  1754. left.width(parent.width());
  1755. right.hide();
  1756. }
  1757. };
  1758. $('#content-tab').addClass('active');
  1759. $('#xd-content').addClass('active');
  1760. showSideTools(true);
  1761. billsSpread.refresh();
  1762. if (posSpread) {
  1763. posSpread.refresh();
  1764. }
  1765. const stdLibCellDoubleClick = function (e, info) {
  1766. const stdSheet = info.sheet;
  1767. const mainSheet = billsSheet;
  1768. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  1769. const stdTree = stdSheet.zh_tree;
  1770. const stdNode = stdTree.nodes[info.row];
  1771. const mainTree = mainSheet.zh_tree;
  1772. const sel = mainSheet.getSelections()[0];
  1773. const mainNode = mainTree.nodes[sel.row];
  1774. if (!stdNode) return;
  1775. if (info.sheet.zh_setting.stdType === 'gcl') {
  1776. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1777. toastr.warning('非最底层项目下,不应添加节点');
  1778. return;
  1779. }
  1780. }
  1781. postData(window.location.pathname + '/update', {
  1782. postType: 'add-std',
  1783. postData: {
  1784. id: mainTree.getNodeKey(mainNode),
  1785. tender_id: mainNode.tender_id,
  1786. stdType: info.sheet.zh_setting.stdType,
  1787. stdLibId: stdNode.list_id,
  1788. stdNode: stdTree.getNodeKey(stdNode)
  1789. }
  1790. }, function (result) {
  1791. const refreshNode = mainTree.loadPostData(result);
  1792. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  1793. if (sel) {
  1794. if (refreshNode.create && refreshNode.create.length > 0) {
  1795. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  1796. } else {
  1797. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  1798. if (node) {
  1799. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  1800. }
  1801. }
  1802. }
  1803. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1804. billsSpread.focus();
  1805. posSpreadObj.loadCurPosData();
  1806. });
  1807. };
  1808. const stdXmjSetting = {
  1809. selector: '#std-xmj',
  1810. stdType: 'xmj',
  1811. treeSetting: {
  1812. id: 'chapter_id',
  1813. pid: 'pid',
  1814. order: 'order',
  1815. level: 'level',
  1816. rootId: -1,
  1817. keys: ['id', 'list_id', 'chapter_id'],
  1818. },
  1819. spreadSetting: {
  1820. cols: [
  1821. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1822. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1823. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1824. ],
  1825. treeCol: 0,
  1826. emptyRows: 0,
  1827. headRows: 1,
  1828. headRowHeight: [32],
  1829. defaultRowHeight: 21,
  1830. headerFont: '12px 微软雅黑',
  1831. font: '12px 微软雅黑',
  1832. headColWidth: [0],
  1833. },
  1834. cellDoubleClick: stdLibCellDoubleClick,
  1835. page: 'revise',
  1836. tid: window.location.pathname.split('/')[2],
  1837. };
  1838. const stdGclSetting = {
  1839. selector: '#std-gcl',
  1840. stdType: 'gcl',
  1841. treeSetting: {
  1842. id: 'bill_id',
  1843. pid: 'pid',
  1844. order: 'order',
  1845. level: 'level',
  1846. rootId: -1,
  1847. keys: ['id', 'list_id', 'bill_id']
  1848. },
  1849. spreadSetting: {
  1850. cols: [
  1851. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1852. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1853. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1854. ],
  1855. treeCol: 0,
  1856. emptyRows: 0,
  1857. headRows: 1,
  1858. headRowHeight: [32],
  1859. defaultRowHeight: 21,
  1860. headerFont: '12px 微软雅黑',
  1861. font: '12px 微软雅黑',
  1862. headColWidth: [0],
  1863. },
  1864. cellDoubleClick: stdLibCellDoubleClick,
  1865. page: 'revise',
  1866. tid: window.location.pathname.split('/')[2],
  1867. };
  1868. // 展开收起标准节点
  1869. $('a', '#side-menu').bind('click', function (e) {
  1870. e.preventDefault();
  1871. const tab = $(this), tabPanel = $(tab.attr('content'));
  1872. // 展开工具栏、切换标签
  1873. if (!tab.hasClass('active')) {
  1874. const close = $('.active', '#side-menu').length === 0;
  1875. $('a', '#side-menu').removeClass('active');
  1876. tab.addClass('active');
  1877. $('.tab-content .tab-pane').removeClass('active');
  1878. tabPanel.addClass('active');
  1879. showSideTools(tab.hasClass('active'));
  1880. if (tab.attr('content') === '#std-xmj') {
  1881. if (!stdXmj) {
  1882. stdXmj = new stdLib(stdXmjSetting);
  1883. }
  1884. stdXmj.spread.refresh();
  1885. } else if (tab.attr('content') === '#std-gcl') {
  1886. if (!stdGcl) {
  1887. stdGcl = new stdLib(stdGclSetting);
  1888. }
  1889. stdGcl.spread.refresh();
  1890. } else if (tab.attr('content') === '#deal-bills') {
  1891. dealBills.loadData();
  1892. dealBills.spread.refresh();
  1893. } else if (tab.attr('content') === '#bg-bills') {
  1894. bgBills.loadData();
  1895. bgBills.spread.refresh();
  1896. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1897. if (!searchLedger) {
  1898. searchLedger = $.billsSearch({
  1899. selector: '#search',
  1900. searchSpread: billsSpread,
  1901. resultSpreadSetting: {
  1902. cols: [
  1903. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1904. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1905. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  1906. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1907. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1908. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1909. ],
  1910. emptyRows: 0,
  1911. headRows: 1,
  1912. headRowHeight: [32],
  1913. defaultRowHeight: 21,
  1914. headerFont: '12px 微软雅黑',
  1915. font: '12px 微软雅黑',
  1916. },
  1917. afterLocated: function () {
  1918. posSpreadObj.loadCurPosData();
  1919. }
  1920. });
  1921. }
  1922. searchLedger.spread.refresh();
  1923. }
  1924. }
  1925. else {// 收起工具栏
  1926. tab.removeClass('active');
  1927. tabPanel.removeClass('active');
  1928. showSideTools(tab.hasClass('active'));
  1929. }
  1930. billsSpread.refresh();
  1931. if (posSpread) {
  1932. posSpread.refresh();
  1933. }
  1934. });
  1935. if (!readOnly) {
  1936. // 修订详情 保存
  1937. $('#save').click(function () {
  1938. const content = $('#content').val();
  1939. postData('save', { content: content }, function () {
  1940. $('#content').attr('org-value', content);
  1941. });
  1942. });
  1943. }
  1944. // 显示层次
  1945. (function (select, sheet) {
  1946. $(select).click(function () {
  1947. if (!sheet.zh_tree) return;
  1948. const tag = $(this).attr('tag');
  1949. const tree = sheet.zh_tree;
  1950. switch (tag) {
  1951. case "1":
  1952. case "2":
  1953. case "3":
  1954. case "4":
  1955. case "5":
  1956. tree.expandByLevel(parseInt(tag));
  1957. SpreadJsObj.refreshTreeRowVisible(sheet);
  1958. break;
  1959. case "last":
  1960. tree.expandByCustom(() => { return true; });
  1961. SpreadJsObj.refreshTreeRowVisible(sheet);
  1962. break;
  1963. case "leafXmj":
  1964. tree.expandToLeafXmj();
  1965. SpreadJsObj.refreshTreeRowVisible(sheet);
  1966. break;
  1967. }
  1968. });
  1969. })('a[name=showLevel]', billsSheet);
  1970. });