revise.js 101 KB

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