revise.js 109 KB

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