revise.js 112 KB

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