ledger.js 131 KB

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