ledger.js 129 KB

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