revise.js 120 KB

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