revise.js 101 KB

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