change_revise.js 118 KB

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