change_revise.js 120 KB

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