revise.js 100 KB

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