ledger.js 152 KB

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