revise.js 111 KB

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