revise.js 114 KB

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