revise.js 93 KB

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