revise.js 107 KB

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