ledger.js 137 KB

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