revise.js 112 KB

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