revise.js 100 KB

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