revise.js 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106
  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. if (!child.b_code || child.b_code === '') {
  708. const code = parentCode + '-' + (i + 1);
  709. const cData = tree.getNodeKeyData(child);
  710. cData.code = code;
  711. data.push(cData);
  712. if (!tree.isLeafXmj(child)) {
  713. recursiveSortCode(data, code, child.children);
  714. }
  715. }
  716. }
  717. };
  718. const data = [];
  719. recursiveSortCode(data, select.code, select.children);
  720. if (data.length > 0) {
  721. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  722. const refreshNode = tree.loadPostData(result);
  723. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  724. })
  725. }
  726. }
  727. };
  728. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  729. billsTreeSpreadObj.loadExprToInput(billsSheet);
  730. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  731. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  732. if (!readOnly) {
  733. // 增删上下移升降级
  734. $('a[name="base-opr"]').click(function () {
  735. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  736. });
  737. $('a[name=cpc]').click(function () {
  738. billsSpread.commandManager().execute({
  739. cmd: this.getAttribute('type'),
  740. sheetName: billsSheet.name()
  741. });
  742. });
  743. $('#bills-expr').bind('change mouseleave', function () {
  744. if (this.readOnly) return;
  745. const expr = $(this);
  746. const select = SpreadJsObj.getSelectObject(billsSheet);
  747. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  748. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  749. const data = {
  750. id: select.id,
  751. tender_id: select.tender_id,
  752. ledger_id: select.ledger_id
  753. };
  754. if (newValue !== '') {
  755. const num = _.toNumber(newValue);
  756. if (num) {
  757. data[field] = num;
  758. } else {
  759. try {
  760. data[field] = math.evaluate(transExpr(newValue));
  761. } catch (err) {
  762. toastr.error('输入的表达式非法');
  763. return;
  764. }
  765. }
  766. } else {
  767. data[field] = null;
  768. }
  769. // 更新至服务器
  770. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  771. const refreshNode = billsTree.loadPostData(result);
  772. expr.val(select[field]);
  773. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  774. });
  775. });
  776. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  777. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  778. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  779. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  780. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  781. SpreadJsObj.Clipboard.setCopyData(copyText);
  782. });
  783. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  784. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  785. let batchInsertObj;
  786. $.contextMenu.types.batchInsert = function (item, opt, root) {
  787. const self = this;
  788. if ($.isFunction(item.icon)) {
  789. item._icon = item.icon.call(this, this, $t, key, item);
  790. } else {
  791. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  792. // to enable font awesome
  793. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  794. } else {
  795. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  796. }
  797. }
  798. this.addClass(item._icon);
  799. 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>')
  800. .appendTo(this);
  801. const $input = $obj.find('input');
  802. const event = () => {
  803. if (self.hasClass('context-menu-disabled')) return;
  804. item.batchInsert($input[0], root);
  805. };
  806. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  807. $input.click((e) => {e.stopPropagation();})
  808. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  809. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  810. };
  811. // 右键菜单
  812. $.contextMenu({
  813. selector: '#bills-spread',
  814. build: function ($trigger, e) {
  815. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  816. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  817. },
  818. items: {
  819. 'create': {
  820. name: '新增',
  821. icon: 'fa-sign-in',
  822. callback: function (key, opt) {
  823. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  824. },
  825. disabled: function (key, opt) {
  826. const sheet = billsSheet;
  827. const selection = sheet.getSelections();
  828. const sel = selection ? selection[0] : sheet.getSelections()[0];
  829. const row = sel ? sel.row : -1;
  830. const tree = sheet.zh_tree;
  831. if (!tree) return true;
  832. const first = sheet.zh_tree.nodes[row];
  833. const valid = !sheet.zh_setting.readOnly;
  834. return !(valid && first && first.level > 1);
  835. }
  836. },
  837. 'delete': {
  838. name: '删除',
  839. icon: 'fa-remove',
  840. callback: function (key, opt) {
  841. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  842. },
  843. disabled: function (key, opt) {
  844. const sheet = billsSheet;
  845. const selection = sheet.getSelections();
  846. const sel = selection ? selection[0] : sheet.getSelections()[0];
  847. const row = sel ? sel.row : -1;
  848. const tree = sheet.zh_tree;
  849. if (!tree) return true;
  850. const first = sheet.zh_tree.nodes[row];
  851. let last = first, sameParent = true, nodeUsed = first.used;
  852. if (sel.rowCount > 1 && first) {
  853. for (let r = 1; r < sel.rowCount; r++) {
  854. const rNode = tree.nodes[sel.row + r];
  855. if (!rNode) {
  856. sameParent = false;
  857. break;
  858. }
  859. nodeUsed = nodeUsed || rNode.used;
  860. if (rNode.level > first.level) continue;
  861. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  862. sameParent = false;
  863. break;
  864. }
  865. last = rNode;
  866. }
  867. }
  868. const valid = !sheet.zh_setting.readOnly;
  869. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  870. }
  871. },
  872. 'sprBase': '-----------',
  873. 'batchInsert': {
  874. name: '批量插入',
  875. type: 'batchInsert',
  876. value: '2',
  877. icon: 'fa-sign-in',
  878. batchInsert: function (obj, root) {
  879. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  880. obj.value = obj.max;
  881. toastr.warning('批量插入不可多于' + obj.max);
  882. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  883. obj.value = obj.min;
  884. toastr.warning('批量插入不可少于' + obj.min);
  885. } else {
  886. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  887. root.$menu.trigger('contextmenu:hide');
  888. }
  889. },
  890. disabled: function (key, opt) {
  891. const sheet = billsSheet;
  892. const selection = sheet.getSelections();
  893. const sel = selection ? selection[0] : sheet.getSelections()[0];
  894. const row = sel ? sel.row : -1;
  895. const tree = sheet.zh_tree;
  896. if (!tree) return true;
  897. const first = sheet.zh_tree.nodes[row];
  898. const valid = !sheet.zh_setting.readOnly;
  899. return !(valid && first && first.level > 1);
  900. }
  901. },
  902. 'batchInsertBillsPos': {
  903. name: '批量插入清单-计量单元',
  904. icon: 'fa-sign-in',
  905. disabled: function (key, opt) {
  906. if (!isTz) return true;
  907. const select = SpreadJsObj.getSelectObject(billsSheet);
  908. if (select) {
  909. if (select.code && select.code !== '') {
  910. return !billsTree.isLeafXmj(select);
  911. } else {
  912. const parent = billsTree.getParent(select);
  913. return !(parent && billsTree.isLeafXmj(parent));
  914. }
  915. } else {
  916. return false;
  917. }
  918. },
  919. callback: function (key, opt) {
  920. if (!batchInsertObj) {
  921. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  922. } else {
  923. batchInsertObj.initView();
  924. }
  925. $('#batch').modal('show');
  926. }
  927. },
  928. 'sprBatch': '-----------',
  929. 'importGclBills2Xmj': {
  930. name: '导入工程量清单至项目节',
  931. icon: 'fa-file-excel-o',
  932. disabled: function (key, opt) {
  933. const node = SpreadJsObj.getSelectObject(billsSheet);
  934. return readOnly
  935. || (node.children && node.children.length > 0)
  936. || (!_.isNil(node.b_code) && node.b_code !== '')
  937. || billsTree.checkNodeUsed(node, pos);
  938. },
  939. callback: function (key, opt) {
  940. const node = SpreadJsObj.getSelectObject(billsSheet);
  941. importExcel.doImport({
  942. template: {
  943. hint: '工程量清单',
  944. url: '/template/导入工程量清单EXCEL格式.xls',
  945. },
  946. callback: function (sheet) {
  947. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  948. const sel = billsSheet.getSelections();
  949. const refreshNode = billsTree.loadPostData(result);
  950. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  951. if (refreshNode.create[0]) {
  952. if (sel && sel[0]) {
  953. billsSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  954. } else {
  955. billsSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  956. }
  957. }
  958. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  959. }, null);
  960. }
  961. });
  962. }
  963. },
  964. }
  965. });
  966. }
  967. const posSpreadObj = {
  968. /**
  969. * 加载计量单元 根据当前台账选择节点
  970. */
  971. loadCurPosData: function () {
  972. const node = SpreadJsObj.getSelectObject(billsSheet);
  973. if (node) {
  974. const posData = pos.getLedgerPos(node.id) || [];
  975. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  976. } else {
  977. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  978. }
  979. SpreadJsObj.resetFieldReadOnly(posSheet);
  980. },
  981. editStarting: function (e, info) {
  982. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  983. },
  984. /**
  985. * 编辑单元格响应事件
  986. * @param {Object} e
  987. * @param {Object} info
  988. */
  989. editEnded: function (e, info) {
  990. if (!info.sheet.zh_setting) {
  991. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  992. return;
  993. }
  994. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  995. const col = info.sheet.zh_setting.cols[info.col];
  996. const orgText = posData ? posData[col.field] : null;
  997. const newText = trimInvalidChar(info.sheet.getCell(info.row, info.col).text());
  998. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  999. const node = posSpreadObj.billsNode;
  1000. if (!node) {
  1001. toastr.error('数据错误,请选择台账节点后再试');
  1002. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1003. return;
  1004. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1005. toastr.error('父节点不可插入计量单元');
  1006. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1007. return;
  1008. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1009. toastr.error('项目节不可插入计量单元');
  1010. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1011. return;
  1012. }
  1013. const data = {postType: 'pos'};
  1014. if (col.field === 'name') {
  1015. if (newText === '' && posData) {
  1016. toastr.error('部位名称不可为空', 'error');
  1017. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1018. return;
  1019. } else if (!posData) {
  1020. if (newText && newText !== '') {
  1021. data.posPostType = 'add';
  1022. const sortData = info.sheet.zh_data;
  1023. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1024. data.postData = { name: newText, lid: node.id, porder: order};
  1025. } else {
  1026. return;
  1027. }
  1028. } else {
  1029. data.posPostType = 'update';
  1030. data.postData = {id: posData.id, name: newText};
  1031. }
  1032. } else if (!posData) {
  1033. toastr.warning('新增计量单元请先输入名称');
  1034. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1035. return;
  1036. } else {
  1037. data.posPostType = 'update';
  1038. data.postData = {id: posData.id};
  1039. if (col.type === 'Number') {
  1040. const num = _.toNumber(newText);
  1041. if (_.isFinite(num)) {
  1042. data.postData[col.field] = num;
  1043. } else {
  1044. try {
  1045. data.postData[col.field] = math.evaluate(transExpr(newText));
  1046. } catch(err) {
  1047. toastr.error('输入的表达式非法');
  1048. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1049. return;
  1050. }
  1051. }
  1052. } else {
  1053. data.postData[col.field] = newText;
  1054. }
  1055. }
  1056. postData(window.location.pathname + '/update', data, function (result) {
  1057. const updateRst = pos.updateDatas(result.pos);
  1058. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1059. if (updateRst.create.length > 0) {
  1060. posSpreadObj.loadCurPosData();
  1061. } else {
  1062. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1063. }
  1064. const loadResult = billsTree.loadPostData(result.ledger);
  1065. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1066. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1067. }, function () {
  1068. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1069. });
  1070. },
  1071. /**
  1072. * 删除按钮响应事件
  1073. * @param sheet
  1074. */
  1075. deletePress: function (sheet) {
  1076. if (!sheet.zh_settting) return;
  1077. const sortData = sheet.zh_data;
  1078. const datas = [], posSelects = [];
  1079. const sel = sheet.getSelections()[0];
  1080. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1081. let bDel = false;
  1082. const node = sortData[iRow];
  1083. if (node) {
  1084. const data = {id: node.id};
  1085. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1086. const colSetting = sheet.zh_setting.cols[iCol];
  1087. if (colSetting.field === 'name') {
  1088. toastr.error('部位名称不能为空');
  1089. return;
  1090. }
  1091. const style = sheet.getStyle(iRow, iCol);
  1092. if (!style.locked) {
  1093. const colSetting = sheet.zh_setting.cols[iCol];
  1094. data[colSetting.field] = null;
  1095. bDel = true;
  1096. }
  1097. }
  1098. if (bDel) {
  1099. datas.push(data);
  1100. posSelects.push(node);
  1101. }
  1102. }
  1103. }
  1104. if (datas.length > 0) {
  1105. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1106. pos.updateDatas(result.pos);
  1107. posSpreadObj.loadCurPosData();
  1108. const loadResult = billsTree.loadPostData(result.ledger);
  1109. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1110. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1111. }, function () {
  1112. posSpreadObj.loadCurPosData();
  1113. });
  1114. }
  1115. },
  1116. /**
  1117. * 删除 计量单元
  1118. * @param sheet
  1119. */
  1120. deletePos: function (sheet) {
  1121. const selection = sheet.getSelections();
  1122. const data = {
  1123. postType: 'pos',
  1124. posPostType: 'delete',
  1125. postData: [],
  1126. };
  1127. const row = selection[0].row, count = selection[0].rowCount;
  1128. const sortData = sheet.zh_data;
  1129. for (let iRow = 0; iRow < count; iRow++) {
  1130. const posData = sortData[iRow + row];
  1131. if (posData) {
  1132. if (posData.used) {
  1133. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1134. return;
  1135. }
  1136. data.postData.push(sortData[iRow + row].id);
  1137. }
  1138. }
  1139. if (data.postData.length > 0) {
  1140. postData(window.location.pathname + '/update', data, function (result) {
  1141. pos.removeDatas(result.pos);
  1142. sheet.deleteRows(row, count);
  1143. const loadResult = billsTree.loadPostData(result.ledger);
  1144. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1145. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1146. });
  1147. }
  1148. },
  1149. clipboardPasting: function (e, info) {
  1150. if (!info.sheet.zh_setting) {
  1151. info.cancel = true;
  1152. return;
  1153. }
  1154. const range = info.cellRange;
  1155. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1156. const posData = info.sheet.zh_data[iRow];
  1157. if (posData && posData.used) {
  1158. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  1159. info.cancel = true;
  1160. return;
  1161. }
  1162. }
  1163. },
  1164. /**
  1165. * 粘贴单元格响应事件
  1166. * @param e
  1167. * @param info
  1168. */
  1169. clipboardPasted: function (e, info) {
  1170. const node = SpreadJsObj.getSelectObject(billsSheet);
  1171. if (node.code && (node.code !== '')) {
  1172. toastr.error('项目节不可含有节点明细');
  1173. posSpreadObj.loadCurPosData();
  1174. return;
  1175. }
  1176. if (node.children && (node.children.length > 0)) {
  1177. toastr.error('仅节点子项可以含有计量单元');
  1178. posSpreadObj.loadCurPosData();
  1179. return;
  1180. }
  1181. if (!info.sheet.zh_setting) {
  1182. posSpreadObj.loadCurPosData();
  1183. return;
  1184. }
  1185. const data = [];
  1186. const sortData = info.sheet.zh_data || [];
  1187. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1188. if (info.cellRange.col !== 0) {
  1189. toastr.warning('新增计量单元请先输入名称');
  1190. posSpreadObj.loadCurPosData();
  1191. return;
  1192. }
  1193. }
  1194. let bHint = false;
  1195. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1196. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1197. let bPaste = true;
  1198. const curRow = info.cellRange.row + iRow;
  1199. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1200. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1201. const curCol = info.cellRange.col + iCol;
  1202. const colSetting = info.sheet.zh_setting.cols[curCol];
  1203. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1204. if (colSetting.type === 'Number') {
  1205. const num = _.toNumber(posData[colSetting.field]);
  1206. if (num) {
  1207. posData[colSetting.field] = num;
  1208. } else {
  1209. try {
  1210. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1211. } catch (err) {
  1212. if (!bHint) {
  1213. toastr.warning('粘贴了非法表达式,已过滤');
  1214. bHint = true;
  1215. }
  1216. bPaste = false;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. if (bPaste) {
  1222. data.push(posData);
  1223. }
  1224. }
  1225. if (data.length === 0) {
  1226. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1227. return;
  1228. }
  1229. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1230. pos.updateDatas(result.pos);
  1231. posSpreadObj.loadCurPosData();
  1232. const loadResult = billsTree.loadPostData(result.ledger);
  1233. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1234. posSpreadObj.loadCurPosData();
  1235. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1236. }, function () {
  1237. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1238. });
  1239. },
  1240. selectionChanged: function (e, info) {
  1241. const col = info.sheet.zh_setting.cols[info.newSelections[0].col];
  1242. const cell = info.sheet.getCell(info.newSelections[0].col, info.newSelections[0].col);
  1243. if (col && col.type === 'Number') {
  1244. const data = SpreadJsObj.getSelectObject(info.sheet);
  1245. if (data) {
  1246. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  1247. .attr('row', info.newSelections[0].row).attr('readOnly', readOnly || cell.locked());
  1248. } else {
  1249. $('#pos-expr').val('').attr('readOnly', true);
  1250. }
  1251. } else {
  1252. $('#pos-expr').val('').attr('readOnly', true);
  1253. }
  1254. },
  1255. addPegs: function (pegs) {
  1256. if (!pegs || pegs.length <= 0) return;
  1257. const node = SpreadJsObj.getSelectObject(billsSheet);
  1258. if (!node) return;
  1259. const sheet = posSpread.getActiveSheet();
  1260. const sortData = sheet.zh_data || [];
  1261. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1262. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1263. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1264. pos.updateDatas(result.pos);
  1265. posSpreadObj.loadCurPosData();
  1266. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1267. });
  1268. }
  1269. };
  1270. posSpreadObj.loadCurPosData();
  1271. SpreadJsObj.resetTopAndSelect(posSheet);
  1272. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1273. if (!readOnly && isTz) {
  1274. $('#pos-expr').bind('change mouseleave', function () {
  1275. if (this.readOnly) return;
  1276. const expr = $(this);
  1277. const select = SpreadJsObj.getSelectObject(posSheet);
  1278. const row = posSheet.getSelections()[0].row;
  1279. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1280. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1281. const data = {id: select.id};
  1282. if (newValue !== '') {
  1283. const num = _.toNumber(newValue);
  1284. if (num) {
  1285. data[field] = num;
  1286. } else {
  1287. try {
  1288. data[field] = math.evaluate(transExpr(newValue));
  1289. } catch (err) {
  1290. toastr.error('输入的表达式非法');
  1291. return;
  1292. }
  1293. }
  1294. } else {
  1295. data[field] = null;
  1296. }
  1297. // 更新至服务器
  1298. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1299. const updateRst = pos.updateDatas(result.pos);
  1300. expr.val(select[field]);
  1301. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1302. SpreadJsObj.reLoadRowData(posSheet, row);
  1303. const loadResult = billsTree.loadPostData(result.ledger);
  1304. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1305. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1306. });
  1307. });
  1308. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1309. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1310. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  1311. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1312. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1313. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1314. $.contextMenu({
  1315. selector: '#pos-spread',
  1316. build: function ($trigger, e) {
  1317. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1318. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1319. },
  1320. items: {
  1321. 'delete': {
  1322. name: '删除',
  1323. icon: 'fa-remove',
  1324. disabled: function (key, opt) {
  1325. if (posSheet.zh_data) {
  1326. const selection = posSheet.getSelections();
  1327. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1328. } else {
  1329. return true;
  1330. }
  1331. },
  1332. callback: function (key, opt) {
  1333. posSpreadObj.deletePos(posSheet);
  1334. }
  1335. },
  1336. 'merge-peg': {
  1337. name: '合并起讫桩号',
  1338. disabled: function (key, opt) {
  1339. const node = SpreadJsObj.getSelectObject(billsSheet);
  1340. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1341. },
  1342. callback: function (key, opt) {
  1343. mergePeg.show();
  1344. },
  1345. visible: function (key, opt) {
  1346. return isTz;
  1347. }
  1348. }
  1349. }
  1350. });
  1351. }
  1352. $.divResizer({
  1353. select: '#revise-resize',
  1354. callback: function () {
  1355. billsSpread.refresh();
  1356. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1357. $(".sp-wrap").height(bcontent-30);
  1358. posSpread.refresh();
  1359. }
  1360. });
  1361. class DealBills {
  1362. constructor (selector, spreadSetting) {
  1363. const self = this;
  1364. this.loaded = false;
  1365. this.obj = $(selector)[0];
  1366. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1367. this.spreadSetting = spreadSetting;
  1368. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1369. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1370. if (!readOnly) {
  1371. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1372. const dealSheet = info.sheet;
  1373. const mainSheet = billsSheet;
  1374. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1375. if (!dealBills) { return; }
  1376. const mainTree = mainSheet.zh_tree;
  1377. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1378. if (!mainNode || !mainTree) { return; }
  1379. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1380. toastr.warning('非最底层项目下,不应添加节点');
  1381. return;
  1382. }
  1383. postData(window.location.pathname + '/update', {
  1384. postType: 'add-deal',
  1385. postData: {
  1386. id: mainNode.ledger_id,
  1387. type: mainNode.code ? 'child' : 'next',
  1388. dealBills: {
  1389. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1390. unit_price: dealBills.unit_price,
  1391. }
  1392. },
  1393. }, function (result) {
  1394. const refreshData = mainTree.loadPostData(result);
  1395. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1396. const sel = mainSheet.getSelections()[0];
  1397. if (sel && refreshData.create[0]) {
  1398. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1399. }
  1400. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1401. billsSpread.focus();
  1402. posSpreadObj.loadCurPosData();
  1403. });
  1404. });
  1405. }
  1406. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1407. }
  1408. loadData (callback) {
  1409. if (this.loaded) {
  1410. if (callback) callback();
  1411. return;
  1412. }
  1413. const self = this;
  1414. postData(this.url+'/get-data', {}, function (data) {
  1415. self.data = data;
  1416. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1417. self.loaded = true;
  1418. if (callback) callback();
  1419. });
  1420. }
  1421. calculateData () {
  1422. if (this.data) {
  1423. for (const d of this.data) {
  1424. d.total_price = _.multiply(d.quantity, d.unit_price);
  1425. }
  1426. }
  1427. }
  1428. }
  1429. class BgBills {
  1430. constructor (selector, spreadSetting) {
  1431. this.loaded = false;
  1432. this.obj = $(selector)[0];
  1433. this.spreadSetting = spreadSetting;
  1434. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1435. this.sheet = this.spread.getActiveSheet();
  1436. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1437. if (!readOnly) {
  1438. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1439. const dealSheet = info.sheet;
  1440. const mainSheet = billsSheet;
  1441. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  1442. if (!bgBills) { return; }
  1443. const mainTree = mainSheet.zh_tree;
  1444. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1445. if (!mainNode || !mainTree) { return; }
  1446. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1447. toastr.warning('非最底层项目下,不应添加变更清单');
  1448. return;
  1449. }
  1450. postData(window.location.pathname + '/update', {
  1451. postType: 'add-bg',
  1452. postData: {
  1453. id: mainNode.ledger_id,
  1454. type: mainNode.code ? 'child' : 'next',
  1455. dealBills: {
  1456. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  1457. unit_price: bgBills.unit_price,
  1458. }
  1459. },
  1460. }, function (result) {
  1461. const refreshData = mainTree.loadPostData(result);
  1462. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1463. const sel = mainSheet.getSelections()[0];
  1464. if (sel && refreshData.create[0]) {
  1465. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1466. }
  1467. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1468. billsSpread.focus();
  1469. posSpreadObj.loadCurPosData();
  1470. });
  1471. });
  1472. }
  1473. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1474. }
  1475. loadData () {
  1476. if (this.loaded) return;
  1477. const self = this;
  1478. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  1479. self.data = data;
  1480. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1481. self.loaded = true;
  1482. });
  1483. }
  1484. }
  1485. class BatchInsertBillsPosObj {
  1486. constructor (obj) {
  1487. const self = this;
  1488. this.obj = obj;
  1489. this.billsCount = 6;
  1490. this.posCount = 1000;
  1491. // 初始化 清单编号窗口 参数
  1492. this.qdSpreadSetting = {
  1493. cols: [
  1494. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1495. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1496. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1497. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1498. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1499. ],
  1500. emptyRows: this.billsCount,
  1501. headRows: 1,
  1502. headRowHeight: [32],
  1503. headerFont: '12px 微软雅黑',
  1504. font: '12px 微软雅黑',
  1505. };
  1506. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1507. // 初始化 部位数量复核表 参数
  1508. this.posSpreadSetting = {
  1509. cols: [
  1510. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1511. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1512. ],
  1513. emptyRows: this.posCount,
  1514. headRows: 1,
  1515. headRowHeight: [32],
  1516. headerFont: '12px 微软雅黑',
  1517. font: '12px 微软雅黑',
  1518. };
  1519. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1520. this.posSpreadSetting.cols.push(
  1521. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1522. )
  1523. }
  1524. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1525. // 初始化 签约节点 参数
  1526. this.dealSpreadSetting = {
  1527. cols: [
  1528. {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
  1529. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  1530. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  1531. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  1532. ],
  1533. emptyRows: 0,
  1534. headRows: 1,
  1535. headRowHeight: [32],
  1536. headerFont: '12px 微软雅黑',
  1537. font: '12px 微软雅黑',
  1538. };
  1539. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1540. // 初始化 清单编号、部位数量复核表 表格
  1541. this.initView();
  1542. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1543. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1544. // 拉取签约节点数据
  1545. dealBills.loadData(() => {
  1546. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1547. });
  1548. // 双击签约节点,自动添加到清单编号窗口
  1549. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1550. const deal = info.sheet.zh_data[info.row];
  1551. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1552. const sel = qdSheet.getSelections()[0];
  1553. qdSheet.getCell(sel.row, 0).value(deal.code);
  1554. qdSheet.getCell(sel.row, 1).value(deal.name);
  1555. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1556. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1557. if (sel.row + 1 === qdSheet.getRowCount()) {
  1558. const count = sel.row + 2;
  1559. qdSheet.setRowCount(count);
  1560. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1561. const colCount = posSheet.getColumnCount() + 1;
  1562. posSheet.setColumnCount(colCount);
  1563. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  1564. }
  1565. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1566. qdSheet.getParent().focus();
  1567. });
  1568. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1569. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  1570. const count = posSheet.getColumnCount() - 2;
  1571. if (billsCount > count) {
  1572. posSheet.setColumnCount(billsCount + 2);
  1573. for (let i = count + 1; i <= billsCount; i++) {
  1574. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1575. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1576. }
  1577. }
  1578. });
  1579. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  1580. if (info.col === 0) {
  1581. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1582. if (dealBills && dealBills.length > 0) {
  1583. const bills = _.find(dealBills, {code: info.editingText});
  1584. if (bills) {
  1585. info.sheet.getCell(info.row, 1).value(bills.name);
  1586. info.sheet.getCell(info.row, 2).value(bills.unit);
  1587. }
  1588. }
  1589. }
  1590. });
  1591. this.obj.bind('shown.bs.modal', function () {
  1592. self.qdSpread.refresh();
  1593. self.posSpread.refresh();
  1594. self.dealSpread.refresh();
  1595. });
  1596. $('#batch-ok').click(function () {
  1597. const selection = billsSheet.getSelections();
  1598. const row = selection[0].row;
  1599. const select = billsTree.nodes[row];
  1600. if (select) {
  1601. const insertData = {};
  1602. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1603. insertData.id = select[billsTree.setting.id];
  1604. insertData.batchData = self.getBatchData();
  1605. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  1606. pos.updateDatas(data.pos);
  1607. const result = billsTree.loadPostData(data.ledger);
  1608. billsTreeSpreadObj.refreshTree(billsSheet, result);
  1609. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  1610. self.obj.modal('hide');
  1611. }, null, true);
  1612. }
  1613. });
  1614. $.contextMenu({
  1615. selector: '.batch-l-t',
  1616. build: function ($trigger, e) {
  1617. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  1618. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1619. },
  1620. items: {
  1621. 'create': {
  1622. name: '新增行',
  1623. icon: 'fa-sign-in',
  1624. callback: function (key, opt) {
  1625. const qdSheet = self.qdSpread.getActiveSheet();
  1626. const posSheet = self.posSpread.getActiveSheet();
  1627. qdSheet.addRows(qdSheet.getRowCount(), 1);
  1628. const index = qdSheet.getRowCount();
  1629. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  1630. posSheet.addColumns(posSheet.getColumnCount(), 1);
  1631. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  1632. },
  1633. },
  1634. 'delete': {
  1635. name: '删除行',
  1636. icon: 'fa-remove',
  1637. callback: function (key, opt) {
  1638. const qdSheet = self.qdSpread.getActiveSheet();
  1639. const posSheet = self.posSpread.getActiveSheet();
  1640. const sel = qdSheet.getSelections()[0];
  1641. qdSheet.deleteRows(sel.row, sel.rowCount);
  1642. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  1643. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  1644. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  1645. }
  1646. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  1647. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  1648. }
  1649. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  1650. },
  1651. },
  1652. }
  1653. });
  1654. }
  1655. // 初始化左侧表格
  1656. initView () {
  1657. // 初始化 清单编号
  1658. const qdSheet = this.qdSpread.getActiveSheet();
  1659. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1660. SpreadJsObj.refreshColumnAlign(qdSheet);
  1661. // 清理原有数据
  1662. SpreadJsObj.beginMassOperation(qdSheet);
  1663. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1664. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1665. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  1666. }
  1667. qdSheet.setSelection(0, 0, 1 ,1);
  1668. SpreadJsObj.endMassOperation(qdSheet);
  1669. // 初始化 部位数量复核表
  1670. const posSheet = this.posSpread.getActiveSheet();
  1671. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1672. SpreadJsObj.refreshColumnAlign(posSheet);
  1673. // 清理原有数据
  1674. SpreadJsObj.beginMassOperation(posSheet);
  1675. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1676. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1677. posSheet.setSelection(0, 0, 1 ,1);
  1678. SpreadJsObj.endMassOperation(posSheet);
  1679. // 检查签约节点数据,以工具栏数据为准
  1680. if (dealBills) {
  1681. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1682. }
  1683. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1684. }
  1685. // 获取界面数据
  1686. getBatchData () {
  1687. const result = [];
  1688. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1689. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1690. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1691. const qd = {
  1692. b_code: qdSheet.getText(iRow, 0),
  1693. name: qdSheet.getText(iRow, 1),
  1694. unit: qdSheet.getText(iRow, 2),
  1695. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1696. pos: [],
  1697. };
  1698. result.push(qd);
  1699. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1700. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1701. if (value !== 0 && !isNaN(value)) {
  1702. qd.pos.push({
  1703. name: posSheet.getText(iPosRow, 0),
  1704. drawing_code: posSheet.getText(iPosRow, 1),
  1705. quantity: value,
  1706. });
  1707. }
  1708. }
  1709. }
  1710. return result;
  1711. }
  1712. }
  1713. const dealBills = new DealBills('#deal-bills-spread', {
  1714. cols: [
  1715. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1716. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1717. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1718. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1719. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1720. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1721. ],
  1722. emptyRows: 0,
  1723. headRows: 1,
  1724. headRowHeight: [32],
  1725. defaultRowHeight: 21,
  1726. headerFont: '12px 微软雅黑',
  1727. font: '12px 微软雅黑',
  1728. });
  1729. const bgBills = new BgBills('#bg-bills-spread', {
  1730. cols: [
  1731. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1732. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1733. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1734. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1735. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1736. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1737. ],
  1738. emptyRows: 0,
  1739. headRows: 1,
  1740. headRowHeight: [32],
  1741. defaultRowHeight: 21,
  1742. headerFont: '12px 微软雅黑',
  1743. font: '12px 微软雅黑',
  1744. });
  1745. $.divResizer({
  1746. select: '#revise-right-spr',
  1747. callback: function () {
  1748. billsSpread.refresh();
  1749. if (posSpread) {
  1750. posSpread.refresh();
  1751. }
  1752. if (stdXmj) {
  1753. stdXmj.spread.refresh();
  1754. }
  1755. if (stdGcl) {
  1756. stdGcl.spread.refresh();
  1757. }
  1758. if (dealBills) {
  1759. dealBills.spread.refresh();
  1760. }
  1761. if (bgBills) {
  1762. bgBills.spread.refresh();
  1763. }
  1764. if (searchLedger) {
  1765. searchLedger.spread.refresh();
  1766. }
  1767. }
  1768. });
  1769. $.subMenu({
  1770. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1771. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1772. key: 'menu.1.0.0',
  1773. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1774. callback: function (info) {
  1775. if (info.mini) {
  1776. $('.panel-title').addClass('fluid');
  1777. $('#sub-menu').removeClass('panel-sidebar');
  1778. } else {
  1779. $('.panel-title').removeClass('fluid');
  1780. $('#sub-menu').addClass('panel-sidebar');
  1781. }
  1782. autoFlashHeight();
  1783. billsSpread.refresh();
  1784. if (posSpread) {
  1785. posSpread.refresh();
  1786. }
  1787. if (stdXmj) {
  1788. stdXmj.spread.refresh();
  1789. }
  1790. if (stdGcl) {
  1791. stdGcl.spread.refresh();
  1792. }
  1793. if (dealBills) {
  1794. dealBills.spread.refresh();
  1795. }
  1796. if (bgBills) {
  1797. bgBills.spread.refresh();
  1798. }
  1799. if (searchLedger) {
  1800. searchLedger.spread.refresh();
  1801. }
  1802. }
  1803. });
  1804. const showSideTools = function (show) {
  1805. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1806. if (show) {
  1807. right.show();
  1808. autoFlashHeight();
  1809. /**
  1810. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1811. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1812. * 故需要通过最终的parent.width再计算一次left.width
  1813. *
  1814. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1815. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1816. *
  1817. */
  1818. //left.css('width', parent.width() - right.outerWidth());
  1819. //left.css('width', parent.width() - right.outerWidth());
  1820. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1821. left.css('width', percent + '%');
  1822. } else {
  1823. left.width(parent.width());
  1824. right.hide();
  1825. }
  1826. };
  1827. $('#content-tab').addClass('active');
  1828. $('#xd-content').addClass('active');
  1829. showSideTools(true);
  1830. billsSpread.refresh();
  1831. if (posSpread) {
  1832. posSpread.refresh();
  1833. }
  1834. const stdLibCellDoubleClick = function (e, info) {
  1835. const stdSheet = info.sheet;
  1836. const mainSheet = billsSheet;
  1837. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  1838. const stdTree = stdSheet.zh_tree;
  1839. const stdNode = stdTree.nodes[info.row];
  1840. const mainTree = mainSheet.zh_tree;
  1841. const sel = mainSheet.getSelections()[0];
  1842. const mainNode = mainTree.nodes[sel.row];
  1843. if (!stdNode) return;
  1844. if (info.sheet.zh_setting.stdType === 'gcl') {
  1845. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1846. toastr.warning('非最底层项目下,不应添加节点');
  1847. return;
  1848. }
  1849. }
  1850. postData(window.location.pathname + '/update', {
  1851. postType: 'add-std',
  1852. postData: {
  1853. id: mainTree.getNodeKey(mainNode),
  1854. tender_id: mainNode.tender_id,
  1855. stdType: info.sheet.zh_setting.stdType,
  1856. stdLibId: stdNode.list_id,
  1857. stdNode: stdTree.getNodeKey(stdNode)
  1858. }
  1859. }, function (result) {
  1860. const refreshNode = mainTree.loadPostData(result);
  1861. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  1862. if (sel) {
  1863. if (refreshNode.create && refreshNode.create.length > 0) {
  1864. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  1865. } else {
  1866. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  1867. if (node) {
  1868. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  1869. }
  1870. }
  1871. }
  1872. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1873. billsSpread.focus();
  1874. posSpreadObj.loadCurPosData();
  1875. });
  1876. };
  1877. const stdXmjSetting = {
  1878. selector: '#std-xmj',
  1879. stdType: 'xmj',
  1880. treeSetting: {
  1881. id: 'chapter_id',
  1882. pid: 'pid',
  1883. order: 'order',
  1884. level: 'level',
  1885. rootId: -1,
  1886. keys: ['id', 'list_id', 'chapter_id'],
  1887. },
  1888. spreadSetting: {
  1889. cols: [
  1890. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1891. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1892. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1893. ],
  1894. treeCol: 0,
  1895. emptyRows: 0,
  1896. headRows: 1,
  1897. headRowHeight: [32],
  1898. defaultRowHeight: 21,
  1899. headerFont: '12px 微软雅黑',
  1900. font: '12px 微软雅黑',
  1901. headColWidth: [0],
  1902. },
  1903. cellDoubleClick: stdLibCellDoubleClick,
  1904. page: 'revise',
  1905. tid: window.location.pathname.split('/')[2],
  1906. };
  1907. const stdGclSetting = {
  1908. selector: '#std-gcl',
  1909. stdType: 'gcl',
  1910. treeSetting: {
  1911. id: 'bill_id',
  1912. pid: 'pid',
  1913. order: 'order',
  1914. level: 'level',
  1915. rootId: -1,
  1916. keys: ['id', 'list_id', 'bill_id']
  1917. },
  1918. spreadSetting: {
  1919. cols: [
  1920. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1921. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1922. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1923. ],
  1924. treeCol: 0,
  1925. emptyRows: 0,
  1926. headRows: 1,
  1927. headRowHeight: [32],
  1928. defaultRowHeight: 21,
  1929. headerFont: '12px 微软雅黑',
  1930. font: '12px 微软雅黑',
  1931. headColWidth: [0],
  1932. },
  1933. cellDoubleClick: stdLibCellDoubleClick,
  1934. page: 'revise',
  1935. tid: window.location.pathname.split('/')[2],
  1936. };
  1937. // 展开收起标准节点
  1938. $('a', '#side-menu').bind('click', function (e) {
  1939. e.preventDefault();
  1940. const tab = $(this), tabPanel = $(tab.attr('content'));
  1941. // 展开工具栏、切换标签
  1942. if (!tab.hasClass('active')) {
  1943. const close = $('.active', '#side-menu').length === 0;
  1944. $('a', '#side-menu').removeClass('active');
  1945. tab.addClass('active');
  1946. $('.tab-content .tab-pane').removeClass('active');
  1947. tabPanel.addClass('active');
  1948. showSideTools(tab.hasClass('active'));
  1949. if (tab.attr('content') === '#std-xmj') {
  1950. if (!stdXmj) {
  1951. stdXmj = new stdLib(stdXmjSetting);
  1952. }
  1953. stdXmj.spread.refresh();
  1954. } else if (tab.attr('content') === '#std-gcl') {
  1955. if (!stdGcl) {
  1956. stdGcl = new stdLib(stdGclSetting);
  1957. }
  1958. stdGcl.spread.refresh();
  1959. } else if (tab.attr('content') === '#deal-bills') {
  1960. dealBills.loadData();
  1961. dealBills.spread.refresh();
  1962. } else if (tab.attr('content') === '#bg-bills') {
  1963. bgBills.loadData();
  1964. bgBills.spread.refresh();
  1965. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1966. if (!searchLedger) {
  1967. searchLedger = $.billsSearch({
  1968. selector: '#search',
  1969. searchSpread: billsSpread,
  1970. resultSpreadSetting: {
  1971. cols: [
  1972. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1973. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1974. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  1975. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1976. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1977. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1978. ],
  1979. emptyRows: 0,
  1980. headRows: 1,
  1981. headRowHeight: [32],
  1982. defaultRowHeight: 21,
  1983. headerFont: '12px 微软雅黑',
  1984. font: '12px 微软雅黑',
  1985. },
  1986. afterLocated: function () {
  1987. posSpreadObj.loadCurPosData();
  1988. }
  1989. });
  1990. }
  1991. searchLedger.spread.refresh();
  1992. }
  1993. }
  1994. else {// 收起工具栏
  1995. tab.removeClass('active');
  1996. tabPanel.removeClass('active');
  1997. showSideTools(tab.hasClass('active'));
  1998. }
  1999. billsSpread.refresh();
  2000. if (posSpread) {
  2001. posSpread.refresh();
  2002. }
  2003. });
  2004. if (!readOnly) {
  2005. // 修订详情 保存
  2006. $('#save').click(function () {
  2007. const content = $('#content').val();
  2008. postData('save', { content: content }, function () {
  2009. $('#content').attr('org-value', content);
  2010. });
  2011. });
  2012. }
  2013. // 显示层次
  2014. (function (select, sheet) {
  2015. $(select).click(function () {
  2016. if (!sheet.zh_tree) return;
  2017. const tag = $(this).attr('tag');
  2018. const tree = sheet.zh_tree;
  2019. switch (tag) {
  2020. case "1":
  2021. case "2":
  2022. case "3":
  2023. case "4":
  2024. case "5":
  2025. tree.expandByLevel(parseInt(tag));
  2026. SpreadJsObj.refreshTreeRowVisible(sheet);
  2027. break;
  2028. case "last":
  2029. tree.expandByCustom(() => { return true; });
  2030. SpreadJsObj.refreshTreeRowVisible(sheet);
  2031. break;
  2032. case "leafXmj":
  2033. tree.expandToLeafXmj();
  2034. SpreadJsObj.refreshTreeRowVisible(sheet);
  2035. break;
  2036. }
  2037. });
  2038. })('a[name=showLevel]', billsSheet);
  2039. });