revise.js 111 KB

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