revise.js 91 KB

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