change_revise.js 127 KB

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