revise.js 93 KB

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