revise.js 120 KB

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