revise.js 136 KB

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