revise.js 120 KB

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