revise.js 99 KB

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