ledger.js 121 KB

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