revise.js 120 KB

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