revise.js 111 KB

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