revise.js 109 KB

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