glj.js 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /**
  2. * Created by Zhong on 2017/8/14.
  3. */
  4. $(document).ready(function () {
  5. let moduleName = 'compleGLj';
  6. SlideResize.loadHorizonWidth(moduleName, [$('#rightResize'), $('#leftResize')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  7. refreshALlWorkBook();
  8. });
  9. //章节树与人材机表
  10. let leftElesObj = {};
  11. leftElesObj.module = moduleName;
  12. leftElesObj.resize = $('#leftResize');
  13. leftElesObj.parent = $('#dataRow');
  14. leftElesObj.left = $('#leftContent');
  15. leftElesObj.right = $('#midContent');
  16. SlideResize.horizontalSlide(leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
  17. refreshALlWorkBook();
  18. });
  19. //人材机表与人材机组成物表
  20. let rightElesObj = {};
  21. rightElesObj.module = moduleName;
  22. rightElesObj.resize = $('#rightResize');
  23. rightElesObj.parent = $('#dataRow');
  24. rightElesObj.left = $('#midContent');
  25. rightElesObj.right = $('#rightContent');
  26. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
  27. refreshALlWorkBook();
  28. });
  29. });
  30. function refreshALlWorkBook() {
  31. if (gljClassTreeObj.workBook) {
  32. gljClassTreeObj.workBook.refresh();
  33. }
  34. if (repositoryGljObj.workBook) {
  35. repositoryGljObj.workBook.refresh();
  36. }
  37. if (gljComponentOprObj.workBook) {
  38. gljComponentOprObj.workBook.refresh();
  39. }
  40. }
  41. let pageOprObj = {
  42. gljLibName : null,
  43. stdGljLibId: null,
  44. userId: null,
  45. compilationId: null,
  46. initPage : function(container, containerComponent, containerC) {
  47. let me = pageOprObj;
  48. me.stdGljLibId = stdGljLibId;
  49. me.userId = userId;
  50. me.compilationId = compilationId;
  51. repositoryGljObj.buildSheet(container);
  52. gljComponentOprObj.buildSheet(containerComponent);
  53. componentOprObj.buildSheet(containerC);
  54. //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
  55. //repositoryGljObj.getRationGljIds(gljLibId);
  56. repositoryGljObj.getGljDistType(function () {
  57. repositoryGljObj.currentRepositoryId = me.stdGljLibId;
  58. repositoryGljObj.getGljItems(me.stdGljLibId, function () {
  59. gljClassTreeObj.getGljClassTree(stdGljLibId);
  60. });
  61. });
  62. }
  63. };
  64. let repositoryGljObj = {
  65. treeObj : null,
  66. workBook: null,
  67. gljCurTypeId: -1,
  68. currentRepositoryId: -1,
  69. currentCache: null,
  70. parentNodeIds: {},
  71. gljList: [],
  72. stdGljList:[],
  73. complementaryGljList: [],
  74. feeDataCode: ['grossWeightCoe', 'purchaseStorageRate', 'offSiteTransportLossRate', 'handlingLossRate'],
  75. distTypeTree: null,//add
  76. setting: {
  77. header:[
  78. {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  79. {headerName:"名称",headerWidth:160,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
  80. {headerName:"规格型号",headerWidth:120,dataCode:"specs", dataType: "String", hAlign: "left", vAlign: "center"},
  81. {headerName:"单位",headerWidth:45,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
  82. {headerName:"定额价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  83. {headerName:"类型",headerWidth:90,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"},
  84. {headerName:"毛重系数",headerWidth:90,dataCode:"grossWeightCoe", dataType: "Number", hAlign: "center", vAlign: "center"},
  85. {headerName:"采购保管费率",headerWidth:90,dataCode:"purchaseStorageRate", dataType: "Number", hAlign: "center", vAlign: "center"},
  86. {headerName:"场外运输损耗率",headerWidth:100,dataCode:"offSiteTransportLossRate", dataType: "Number", hAlign: "center", vAlign: "center"},
  87. {headerName:"每增一次装卸损耗率",headerWidth:100,dataCode:"handlingLossRate", dataType: "Number", hAlign: "center", vAlign: "center"},
  88. {headerName:"是否新增",headerWidth:60,dataCode:"isComplementary", hAlign: "center", vAlign: "center"}
  89. ],
  90. view:{
  91. comboBox:[
  92. {row:-1,col:3,rowCount:-1,colCount:1}
  93. ],
  94. lockedCells:[
  95. ]
  96. }
  97. },
  98. setUnitCombo: function (sheet, headers) {
  99. let me = this;
  100. sheet.suspendPaint();
  101. sheet.suspendEvent();
  102. let combo = sheetCommonObj.getDynamicCombo();
  103. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  104. for(let i = 0; i < headers.length; i++){
  105. if(headers[i].dataCode === 'unit'){
  106. sheet.getRange(-1, i, -1, 1).cellType(combo);
  107. break;
  108. }
  109. }
  110. sheet.resumePaint();
  111. sheet.resumeEvent();
  112. },
  113. getComboData: function (gljDistType) {
  114. let distType;
  115. let distTypeTree = {
  116. prefix : 'gljType',
  117. distTypes: {},
  118. comboDatas: [],
  119. distTypesArr: []
  120. };
  121. gljDistType.forEach(function (typeData) {
  122. let typeObj = {
  123. data: typeData,
  124. children: [],
  125. parent: null
  126. };
  127. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  128. distTypeTree.distTypesArr.push(typeObj);
  129. });
  130. gljDistType.forEach(function (typeData) {
  131. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  132. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  133. if(parent){
  134. distType.parent = parent;
  135. parent.children.push(distType);
  136. }
  137. });
  138. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  139. if(allowGljType.includes(distTypeObj.data.ID)){
  140. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  141. }
  142. });
  143. return distTypeTree;
  144. },
  145. getGljDistType: function (callback) {
  146. let me = this;
  147. CommonAjax.post('complementartGlj/api/getGljDistType', {}, function (rstData) {
  148. if(callback){
  149. me.distTypeTree = me.getComboData(rstData);
  150. console.log(me.distTypeTree);
  151. callback();
  152. }
  153. });
  154. },
  155. getGljTree: function(gljLibId, callback) {
  156. let me = this;
  157. CommonAjax.post('complementartGlj/api/getGljTree', {gljLibId: gljLibId}, function (rstData) {
  158. zTreeHelper.createTree(rstData, gljSetting, "repositoryTree", me);
  159. zTreeHelper.createTree(rstData, componentSetting, "componentTree", componentOprObj);
  160. if (rstData && rstData.length > 0) {
  161. me.gljCurTypeId = rstData[0].ID;
  162. } else {
  163. //重新创建库?
  164. // gljTypeTreeOprObj.addRootNode();
  165. }
  166. if(callback){
  167. callback();
  168. }
  169. });
  170. },
  171. getGljItems: function(stdGljLibId, callback) {
  172. let me = this;
  173. CommonAjax.post('complementartGlj/api/getGljItems', {stdGljLibId: stdGljLibId}, function (rstData) {
  174. me.stdGljList = rstData.stdGljs;
  175. //兼容多单价情况
  176. for(let sGlj of me.stdGljList){
  177. if(sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined') {
  178. sGlj.basePrice = sGlj.priceProperty.price1;
  179. }
  180. }
  181. me.complementaryGljList = rstData.complementaryGljs;
  182. me.workBook.getSheet(0).setRowCount(me.stdGljList.length);
  183. me.sortGlj(me.stdGljList);
  184. me.setProp('isStd', true, me.stdGljList);
  185. me.sortGlj(me.complementaryGljList);
  186. if(callback){
  187. callback();
  188. }
  189. });
  190. },
  191. showGljItems: function(data, type) {
  192. let me = repositoryGljObj;
  193. let sheet = me.workBook.getActiveSheet();
  194. if (me.workBook) {
  195. let cacheSection = [];
  196. let pArr = me.parentNodeIds["_pNodeId_" + type];
  197. for (let i = 0; i < data.length; i++) {
  198. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  199. cacheSection.push(data[i]);
  200. } else if (type == data[i].gljClass) {
  201. cacheSection.push(data[i]);
  202. }
  203. }
  204. sheetOpr.cleanData(sheet, me.setting, -1);
  205. //清除是否新增复选框
  206. gljClassTreeObj.renderFunc(sheet, function () {
  207. let isComplementaryCol = 0;
  208. for(let colData of me.setting.header){
  209. if(colData.dataCode === 'isComplementary'){
  210. isComplementaryCol = me.setting.header.indexOf(colData);
  211. }
  212. }
  213. let baseCell = new GC.Spread.Sheets.CellTypes.Base();
  214. for(let row = 0; row < sheet.getRowCount(); row++){
  215. sheet.setCellType(row, isComplementaryCol, baseCell);
  216. }
  217. });
  218. sheetOpr.showData(sheet, me.setting, cacheSection, me.distTypeTree);
  219. sheetCommonObj.setDynamicCombo(sheet, 0, 5, sheet.getRowCount(), me.distTypeTree.comboDatas, false, 'text');
  220. cacheSection = null;
  221. }
  222. },
  223. bindEnterKey: function () {
  224. let me = this;
  225. let sheet = me.workBook.getActiveSheet();
  226. me.workBook.commandManager().register("myEnter", function(){
  227. let orgRow = sheet.getActiveRowIndex();
  228. let orgCol = sheet.getActiveColumnIndex();
  229. if(sheet.isEditing()){
  230. sheet.endEdit();
  231. }
  232. let code = sheet.getValue(orgRow, 0);
  233. let newRow, newCol;
  234. if(!me.currentCache[orgRow] && code !== undefined && code !== null && orgCol !== me.setting.header.length - 1){
  235. newRow = orgRow;
  236. newCol = orgCol + 1;
  237. sheet.setActiveCell(newRow, newCol);
  238. }
  239. else{
  240. newRow = orgRow + 1;
  241. newCol = me.currentCache[orgRow + 1] ? orgCol : 0;
  242. sheet.setActiveCell(newRow, newCol);
  243. }
  244. //触发事件
  245. //me.onLeaveCell({type: 'LeaveCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: orgRow, col: orgCol});
  246. me.onEnterCell({type: 'EnterCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: newRow, col: newCol});
  247. let newSels = [{row: newRow, rowCount: 1, col: newCol, colCount: 1}];
  248. let oldSels = [{row: orgRow, rowCount: 1, col: orgRow, colCount: 1}];
  249. me.onSelectionChanged({type: 'SelectionChanged'}, {sheet: sheet, sheetName: sheet.name(), newSelections: newSels, oldSelections: oldSels});
  250. });
  251. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
  252. me.workBook.commandManager().setShortcutKey("myEnter", GC.Spread.Commands.Key.enter, false, false, false, false);
  253. },
  254. buildSheet: function(container) {
  255. let me = repositoryGljObj;
  256. me.workBook = sheetOpr.buildSheet(container, me.setting, 30);
  257. sheetCommonObj.spreadDefaultStyle(me.workBook);
  258. me.repositoryGljDelOpr();
  259. me.onContextmenuOpr();
  260. me.bindEnterKey();
  261. me.setUnitCombo(me.workBook.getActiveSheet(), me.setting.header);
  262. me.workBook.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  263. me.workBook.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  264. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  265. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  266. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  267. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  268. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  269. },
  270. isDef: function (v) {
  271. return v !== undefined && v !== null;
  272. },
  273. getCurrentComponent: function (gljComponent) {
  274. let me = repositoryGljObj, rst = [];
  275. for(let i = 0; i < gljComponent.length; i++){
  276. let obj = {};
  277. for(let j = 0; j < me.complementaryGljList.length; j++){
  278. if(gljComponent[i].ID == me.complementaryGljList[j].ID){
  279. obj.isStd = false;
  280. obj.ID = me.complementaryGljList[j].ID;
  281. obj.code = me.complementaryGljList[j].code;
  282. obj.name = me.complementaryGljList[j].name;
  283. obj.unit = me.complementaryGljList[j].unit;
  284. obj.basePrice = me.complementaryGljList[j].basePrice;
  285. obj.consumeAmt = gljComponent[i].consumeAmt;
  286. rst.push(obj);
  287. }
  288. }
  289. for(let j = 0; j < me.stdGljList.length; j++){
  290. if(gljComponent[i].ID == me.stdGljList[j].ID){
  291. obj.isStd = true;
  292. obj.ID = me.stdGljList[j].ID;
  293. obj.code = me.stdGljList[j].code;
  294. obj.name = me.stdGljList[j].name;
  295. obj.unit = me.stdGljList[j].unit;
  296. obj.basePrice = me.stdGljList[j].basePrice;
  297. obj.consumeAmt = gljComponent[i].consumeAmt;
  298. rst.push(obj);
  299. }
  300. }
  301. }
  302. rst.sort(function (a, b) {
  303. let r = 0;
  304. if(a.code > b.code) r = 1;
  305. else if(a.code < b.code) r = -1;
  306. return r;
  307. });
  308. return rst;
  309. },
  310. //获得引用了组成物id为componentId的工料机,和重新变化组成物数组、重新计算单价
  311. getUpdateGljs: function (rObj, isDelete) {
  312. let me = repositoryGljObj, that = gljComponentOprObj,
  313. rst = {updateArr: [], updateBasePrcArr: []};
  314. //改变单价,以便reCalGljBasePrc方法可行
  315. if(!isDelete){
  316. for(let i = 0; i < me.complementaryGljList.length; i++){
  317. if(me.complementaryGljList[i].ID === rObj.ID){
  318. me.complementaryGljList[i].basePrice = rObj.basePrice;
  319. break;
  320. }
  321. }
  322. }
  323. for(let i = 0; i < me.complementaryGljList.length; i++){
  324. let thisComponent = me.complementaryGljList[i].component, isChange = false;
  325. for(let j = 0; j < thisComponent.length; j++){
  326. if(thisComponent[j].ID === rObj.ID){
  327. //删除
  328. isChange = true;
  329. if(isDelete){
  330. thisComponent.splice(j--, 1);
  331. }
  332. else {
  333. break;
  334. }
  335. }
  336. }
  337. if(isChange){//引用了此组成物
  338. let gljBasePrc = that.reCalGljBasePrc(me.getCurrentComponent(thisComponent));
  339. if(me.complementaryGljList[i].basePrice !== gljBasePrc){
  340. me.complementaryGljList[i].basePrice = gljBasePrc;
  341. rst.updateBasePrcArr.push({gljId: me.complementaryGljList[i].ID, gljType: me.complementaryGljList[i].gljType, basePrice: me.complementaryGljList[i].basePrice});
  342. }
  343. rst.updateArr.push(me.complementaryGljList[i]);
  344. }
  345. }
  346. return rst;
  347. },
  348. reshowGljBasePrc: function (glj) {
  349. let me = repositoryGljObj;
  350. let cacheSection = me.currentCache;
  351. for(let i = 0; i < cacheSection.length; i++){
  352. if(glj.ID === cacheSection[i].ID){
  353. cacheSection[i].basePrice = glj.basePrice;
  354. me.workBook.getSheet(0).setValue(i, 4, glj.basePrice);
  355. break;
  356. }
  357. }
  358. },
  359. onSelectionChanged: function (sender, info) {
  360. let me = repositoryGljObj, that = gljComponentOprObj;
  361. //混凝土202、砂浆203、配合比204、机械3
  362. if(typeof info.oldSelections || info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  363. let row = info.newSelections[0].row;
  364. me.initSel(row);
  365. }
  366. },
  367. initSel: function (row) {
  368. let me = repositoryGljObj, that = gljComponentOprObj, componentCanEdit = false;
  369. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, -1);
  370. me.workBook.focus(true);
  371. me.currentComponent = [];
  372. that.workBook.getSheet(0).setRowCount(5);
  373. if(row < me.currentCache.length){
  374. //标记当前工料机
  375. me.currentGlj = me.currentCache[row];
  376. if(allowComponent.includes(me.currentCache[row].gljType)){
  377. componentCanEdit = true;
  378. //展示数据
  379. if(me.currentGlj.component.length > 0){
  380. me.currentComponent = me.getCurrentComponent(me.currentGlj.component);
  381. if(me.currentComponent.length > 0){
  382. sheetOpr.showData(that.workBook.getSheet(0), that.setting, me.currentComponent);
  383. }
  384. }
  385. }
  386. } else{
  387. me.currentGlj = null;
  388. }
  389. //组成物表能编辑则显示,否则隐藏该工作表
  390. let rightWidth = getLocalCache('compleGLjrightContentWidth') || '25%';
  391. rightWidth = rightWidth.replace('%', '');
  392. let curMidWidth = $('#midContent')[0].style.width.replace('%', ''),
  393. curRightWidth = $('#rightContent')[0].style.width.replace('%', '');
  394. if (componentCanEdit && curRightWidth === '0') {
  395. curMidWidth = parseFloat(curMidWidth) - parseFloat(rightWidth);
  396. $('#midContent').css('width', `${curMidWidth}%`);
  397. $('#rightContent').css('width', `${rightWidth}%`);
  398. } else if(!componentCanEdit && curRightWidth !== '0') {
  399. curMidWidth = parseFloat(curMidWidth) + parseFloat(rightWidth);
  400. $('#midContent').css('width', `${curMidWidth}%`);
  401. $('#rightContent').css('width', `0%`);
  402. }
  403. //减少触发
  404. if (me.preComponentCanEdit !== componentCanEdit) {
  405. refreshALlWorkBook();
  406. }
  407. me.preComponentCanEdit = componentCanEdit;
  408. },
  409. onEnterCell: function (sender, args) {
  410. let me = repositoryGljObj;
  411. args.sheet.repaint();
  412. me.cellRowIdx = args.row;
  413. let isHasData = false;
  414. if(me.addGljObj){
  415. for(let i=0; i<me.setting.header.length; i++){
  416. if(me.addGljObj[me.setting.header[i].dataCode]){
  417. isHasData = true;
  418. break;
  419. }
  420. }
  421. }
  422. if(isHasData){
  423. if(me.editingRowIdx !== me.cellRowIdx) {
  424. let isComple = true;
  425. let focusToCol;
  426. function getFocusToCol (me){
  427. if(!me.addGljObj[me.setting.header[0].dataCode]){
  428. $('#alertGljTxt').text('编号不能为空,继续增加人材机?');
  429. return 0;
  430. }
  431. else if(!me.addGljObj[me.setting.header[1].dataCode]){
  432. $('#alertGljTxt').text('名称不能为空,继续增加人材机?');
  433. return 1;
  434. }
  435. else if(!me.addGljObj[me.setting.header[3].dataCode]){
  436. $('#alertGljTxt').text('计量单位不能为空,继续增加人材机?');
  437. return 3;
  438. }
  439. else if(!me.addGljObj[me.setting.header[5].dataCode]){
  440. $('#alertGljTxt').text('类型不能为空,继续增加人材机?');
  441. return 5;
  442. }
  443. else {
  444. return -1;
  445. }
  446. }
  447. focusToCol = getFocusToCol(me);
  448. if(focusToCol === -1){
  449. }
  450. else {
  451. $('#gljAlertBtn').click();
  452. $('#aleConfBtn').unbind('click');
  453. $('#aleConfBtn').bind('click', function () {
  454. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  455. });
  456. $('#gljAleClose').unbind('click');
  457. $('#gljAleClose').bind('click', function () {
  458. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  459. });
  460. $('#aleCanceBtn').unbind('click');
  461. $('#aleCanceBtn').bind('click', function () {
  462. me.addGljObj = null;
  463. me.workBook.getSheet(0).suspendPaint();
  464. me.workBook.getSheet(0).suspendEvent();
  465. for(let col=0; col<me.setting.header.length; col++){
  466. if(col === 0){
  467. me.workBook.getSheet(0).getCell(me.editingRowIdx, 0).formatter("@");
  468. }
  469. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  470. }
  471. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
  472. me.workBook.getSheet(0).resumePaint();
  473. me.workBook.getSheet(0).resumeEvent();
  474. });
  475. }
  476. }
  477. }
  478. },
  479. onButtonClicked: function (sender, args) {
  480. let me = repositoryGljObj;
  481. if(me.setting.header[args.col].dataCode === 'isComplementary' && args.row < me.currentCache.length){
  482. args.sheet.setValue(args.row, args.col, true);
  483. }
  484. },
  485. onCellEditStart: function(sender, args) {
  486. let me = repositoryGljObj;
  487. let rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
  488. me.currentEditingGlj = rObj;
  489. me.orgCode = me.workBook.getSheet(0).getValue(args.row, 0);
  490. let dataCode = me.setting.header[args.col].dataCode;
  491. if(args.row < me.currentCache.length){
  492. me.currentGlj = me.currentCache[args.row];
  493. //费率数据列只有普通材料能用,可添加组成物的人材机,基价只读
  494. if (dataCode === 'code'|| (me.feeDataCode.includes(dataCode) && me.currentGlj.gljType !== 201) ||
  495. (dataCode === 'basePrice' && allowComponent.includes(me.currentGlj.gljType)) ||
  496. dataCode === 'isComplementary'){
  497. args.cancel = true;
  498. } else {
  499. rObj.ID = me.currentGlj.ID;
  500. rObj.gljClass = me.currentGlj.gljClass;
  501. }
  502. } else {
  503. me.currentGlj = null;
  504. }
  505. },
  506. onCellEditEnd: function(sender, args) {
  507. let me = repositoryGljObj, that = gljComponentOprObj,
  508. rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
  509. updateArr = [], addArr = [], updateBasePrcArr = [];
  510. let dataCode = me.setting.header[args.col].dataCode;
  511. me.editingRowIdx = args.row;
  512. rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
  513. //更新
  514. if (me.currentEditingGlj["ID"]) {
  515. rObj["ID"] = me.currentEditingGlj["ID"];
  516. rObj.gljClass = me.currentEditingGlj.gljClass;
  517. if(me.currentEditingGlj[dataCode] !== rObj[dataCode]){
  518. //编码、名称、单位、类型不可为空
  519. if(rObj.code && rObj.name && rObj.unit && rObj.gljType
  520. &&rObj.code.toString().trim().length !== 0 && rObj.name.toString().trim().length !== 0 && rObj.unit.toString().trim().length !== 0&&
  521. rObj.gljType.toString().trim().length !== 0){
  522. if(rObj.gljType !== me.currentEditingGlj.gljType){//修改了工料机类型
  523. if(me.currentGlj){
  524. me.currentGlj.component = [];
  525. }
  526. //工料机类型不为普通材料时,情况费率数据
  527. if (me.currentEditingGlj.gljType === 201 && rObj.gljType !== 201) {
  528. for (let feeCode of me.feeDataCode) {
  529. if (me.currentEditingGlj[feeCode]) {
  530. rObj[feeCode] = null;
  531. }
  532. }
  533. }
  534. if(componentType.includes(me.currentEditingGlj.gljType) &&
  535. !(machineComponent.includes(me.currentEditingGlj.gljType) && machineComponent.includes(rObj.gljType))
  536. && !(materialComponent.includes(me.currentEditingGlj.gljType) && materialComponent.includes(rObj.gljType))){//修改了原本是组成物的工料机
  537. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  538. let updateGljs = me.getUpdateGljs(rObj, true);
  539. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  540. for(let i = 0; i < updateGljs.updateArr.length; i++){
  541. updateArr.push(updateGljs.updateArr[i]);
  542. }
  543. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  544. updateArr.push(updateGljs.updateBasePrcArr[i]);
  545. }
  546. }
  547. }
  548. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, 5);
  549. } else if (me.feeDataCode.includes(dataCode) && rObj[dataCode] !== me.currentEditingGlj[dataCode]) {
  550. if(isNaN(rObj[dataCode])){
  551. args.sheet.setValue(args.row, args.col, me.currentEditingGlj[dataCode] ? me.currentEditingGlj[dataCode] : '');
  552. alert(`${me.setting.header[args.col].headerName}只能输入数值!`);
  553. return;
  554. }
  555. } else if(rObj.basePrice !== me.currentEditingGlj.basePrice){//修改了单价,可修改单价的必为可成为组成物的
  556. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  557. if(isNaN(parseFloat(rObj.basePrice))){
  558. alert('单价只能为数值!');
  559. args.sheet.setValue(args.row, args.col, me.currentEditingGlj.basePrice ? me.currentEditingGlj.basePrice : 0);
  560. return;
  561. }
  562. rObj.basePrice = !isNaN(parseFloat(rObj.basePrice))? scMathUtil.roundTo(parseFloat(rObj.basePrice), -2) : me.currentEditingGlj.basePrice;
  563. let updateGljs = me.getUpdateGljs(rObj);
  564. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  565. for(let i = 0; i < updateGljs.updateArr.length; i++){
  566. updateArr.push(updateGljs.updateArr[i]);
  567. }
  568. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  569. updateArr.push(updateGljs.updateBasePrcArr[i]);
  570. }
  571. }
  572. }
  573. rObj.component = me.currentGlj.component;
  574. updateArr.push(rObj);
  575. }
  576. else{
  577. if(dataCode === 'gljType'){
  578. let distTypeVal = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj[dataCode]].data.fullName;
  579. args.sheet.setValue(args.row, args.col, distTypeVal);
  580. }
  581. else{
  582. args.sheet.setValue(args.row, args.col, me.currentEditingGlj[dataCode]);
  583. }
  584. }
  585. }
  586. //--------------------------------------
  587. if(me.currentEditingGlj.basePrice !== rObj.basePrice){
  588. //update basePrice of ration when editting basePrice of glj
  589. let gljType = -1;
  590. let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
  591. if(gljTypeParent && gljTypeParent.data.ID <=3){
  592. gljType = gljTypeParent.data.ID;
  593. }
  594. if(!gljTypeParent && me.currentEditingGlj.gljType <= 3){
  595. gljType = me.currentEditingGlj.gljType;
  596. }
  597. let gljBasePrcObj = {gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: rObj.basePrice};
  598. if(gljBasePrcObj.gljType !== -1){
  599. updateBasePrcArr.push(gljBasePrcObj);
  600. me.updateRationBasePrcRq(updateBasePrcArr);
  601. }
  602. }
  603. //update basePrice of ration when editting gljType of glj
  604. if(me.currentEditingGlj.gljType !== rObj.gljType){
  605. let gljTypeObj = {gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: rObj.basePrice};
  606. updateBasePrcArr.push(gljTypeObj);
  607. me.updateRationBasePrcRq(updateBasePrcArr);
  608. }
  609. //-----------------------------------------------------------
  610. }
  611. //新增
  612. else {
  613. if(typeof rObj.code !== 'undefined'){
  614. me.addGljObj = rObj;
  615. let isCanSav = true;
  616. if(!rObj.code || !rObj.name || !rObj.unit || !rObj.gljType){
  617. isCanSav = false;
  618. }
  619. if(isCanSav){
  620. me.addGljObj = null;
  621. rObj.component = [];
  622. rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? parseFloat(rObj.basePrice) : 0;
  623. addArr.push(rObj);
  624. }
  625. }
  626. }
  627. if(!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  628. rObj.gljClass = me.gljCurTypeId;
  629. }
  630. if(updateArr.length >0 || addArr.length >0){
  631. me.currentEditingGlj = null;
  632. me.mixUpdateRequest(updateArr, addArr, []);
  633. }
  634. },
  635. delGljs: function (sels) {
  636. let me = repositoryGljObj;
  637. let updateArr = [], removeArr = [],
  638. updateBasePrcArr = [],//删除基价单位后重新计算
  639. canUpdate = false,
  640. cacheSection = me.currentCache;
  641. if(sels.length > 0 && cacheSection.length > 0){
  642. for(let i = 0; i < sels.length; i++){
  643. if(sels[i].colCount === me.setting.header.length){
  644. for(let j = 0; j < sels[i].rowCount; j++){
  645. if(sels[i].row + j < cacheSection.length){
  646. //删除了已被引用成组成物的工料机,重新计算所有引用此组成物的工料机的单价、组成物数组
  647. let updateGljs = me.getUpdateGljs(cacheSection[sels[i].row + j], true);
  648. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  649. for(let i = 0; i < updateGljs.updateArr.length; i++){
  650. updateArr.push(updateGljs.updateArr[i]);
  651. }
  652. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  653. updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  654. }
  655. }
  656. removeArr.push(cacheSection[sels[i].row + j].ID);
  657. //删除后重新计算引用了此工料机的定额单价
  658. updateBasePrcArr.push({gljId: cacheSection[sels[i].row + j].ID, gljType: cacheSection[sels[i].row + j].gljType, basePrice: 0, delete: 1});
  659. }
  660. }
  661. }
  662. else{
  663. let maxCol = sels[i].col + sels[i].colCount - 1;
  664. if(sels[i].col >= 2 && maxCol <= 4){
  665. for(let j = 0; j < sels[i].rowCount; j++){
  666. if(sels[i].row + j < cacheSection.length){
  667. let updateObj = cacheSection[sels[i].row + j];
  668. for(let col = sels[i].col; col <= maxCol; col++){
  669. if(me.setting.header[col].dataCode === 'basePrice'){
  670. //如果类型不为混凝土、砂浆、配合比、机械,才可删除单价 basePrice = 0
  671. if(!allowComponent.includes(updateObj.gljType)){
  672. canUpdate = true;
  673. updateObj[me.setting.header[col].dataCode] = 0;
  674. updateBasePrcArr.push({gljId: updateObj.ID, gljType: updateObj.gljType, basePrice: 0});
  675. }
  676. }
  677. else{
  678. canUpdate = true;
  679. updateObj[me.setting.header[col].dataCode] = '';
  680. }
  681. }
  682. if(canUpdate){
  683. updateArr.push(updateObj);
  684. }
  685. }
  686. }
  687. }
  688. //编号、名称、类型不可为空
  689. else{
  690. if(sels[i].row < cacheSection.length){
  691. let text = '', cantNullStr =['编码', '名称', '类型'];
  692. for(let col = sels[i].col; col <= sels[i].col + sels[i].colCount -1; col++){
  693. if(cantNullStr.indexOf(me.setting.header[col].headerName) !== -1){
  694. text += me.setting.header[col].headerName + " ";
  695. }
  696. }
  697. $('#alertText').text(text + "不可为空!");
  698. $('#codeAlertBtn').click();
  699. $('#codAleConfBtn').click(function () {
  700. });
  701. $('#codAleClose').click(function () {
  702. });
  703. }
  704. }
  705. }
  706. }
  707. if(removeArr.length > 0 || updateArr.length > 0){
  708. //删除警告
  709. $('#alertGljTxt').text('可能已有定额引用了当前工料机,导致定额查找不到此工料机。确定要删除吗?');
  710. $('#gljAlertBtn').click();
  711. //确认
  712. $('#aleConfBtn').unbind('click');
  713. $('#aleConfBtn').bind('click', function () {
  714. me.mixUpdateRequest(updateArr, [], removeArr);
  715. /*if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  716. me.updateRationBasePrcRq(updateBasePrcArr);
  717. }*/
  718. });
  719. }
  720. }
  721. },
  722. repositoryGljDelOpr: function () {
  723. let me = repositoryGljObj;
  724. me.workBook.commandManager().register('repositoryGljDel', function () {
  725. let sels = me.workBook.getActiveSheet().getSelections();
  726. me.delGljs(sels);
  727. });
  728. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  729. me.workBook.commandManager().setShortcutKey('repositoryGljDel', GC.Spread.Commands.Key.del, false, false, false, false);
  730. },
  731. onContextmenuOpr: function () {
  732. let me = repositoryGljObj;
  733. $.contextMenu({
  734. selector: '#GLJListSheet',
  735. build: function($triggerElement, e){
  736. //控制允许右键菜单在哪个位置出现
  737. let sheet = me.workBook.getSheet(0);
  738. let offset = $("#GLJListSheet").offset(),
  739. x = e.pageX - offset.left,
  740. y = e.pageY - offset.top;
  741. let target = sheet.hitTest(x, y);
  742. let sel = sheet.getSelections()[0];
  743. if(sel.row === -1){
  744. sel.row = 0;
  745. }
  746. if(sel.col === -1){
  747. sel.col = 0;
  748. }
  749. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  750. me.initSel(target.row);
  751. if(sel.row > target.row || sel.row + sel.rowCount - 1 < target.row ||
  752. sel.col > target.col || sel.col + sel.colCount - 1 < target.col ){
  753. sheet.setActiveCell(target.row, target.col);
  754. }
  755. return {
  756. callback: function(){},
  757. items: {
  758. "delete": {
  759. name: "删除",
  760. disabled: function () {
  761. return !(me.currentCache && me.currentCache[target.row]);
  762. },
  763. icon: "fa-remove",
  764. callback: function (key, opt) {
  765. let curSel = _.cloneDeep(sheet.getSelections()[0]);
  766. curSel.colCount = me.setting.header.length;
  767. me.delGljs([curSel]);
  768. }}
  769. }
  770. };
  771. }
  772. else{
  773. return false;
  774. }
  775. }
  776. });
  777. },
  778. validUpdateObj: function (pasteObj, rowIdx) {
  779. let rst = {updateGlj: [], updateBasePrcArr: []}, backUpObj = {},
  780. me = repositoryGljObj,
  781. tempObj = me.currentCache[rowIdx],
  782. reCalBasePrc = false,
  783. isValid = true;
  784. //备份原始数据
  785. for(let atr in tempObj){
  786. backUpObj[atr] = tempObj[atr];
  787. }
  788. if(typeof pasteObj.code !== 'undefined'){
  789. if(pasteObj.code.trim().length !== 0){
  790. let isExist = false;
  791. for(let i = 0; i < me.stdGljList.length; i++){
  792. if(me.stdGljList[i].code === pasteObj.code){
  793. isExist = true;
  794. break;
  795. }
  796. }
  797. if(!isExist){
  798. for(let i = 0; i < me.complementaryGljList.length; i++){
  799. if(me.complementaryGljList[i].code === pasteObj.code){
  800. isExist = true;
  801. break;
  802. }
  803. }
  804. }
  805. if(!isExist){
  806. tempObj.code = pasteObj.code;
  807. }
  808. else isValid = false;
  809. }
  810. else isValid = false;
  811. }
  812. if(typeof pasteObj.name !== 'undefined'){
  813. if(pasteObj.name.trim().length === 0) isValid = false;
  814. else tempObj.name = pasteObj.name;
  815. }
  816. if(typeof pasteObj.specs !== 'undefined'){
  817. tempObj.specs = pasteObj.specs;
  818. }
  819. if(typeof pasteObj.unit !== 'undefined'){
  820. tempObj.unit = pasteObj.unit;
  821. }
  822. if(typeof pasteObj.gljType !== 'undefined'){
  823. let isExsit = false;
  824. for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
  825. if(pasteObj.gljType === me.distTypeTree.comboDatas[i].text){
  826. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  827. isExsit = true;
  828. reCalBasePrc = true;
  829. if (pasteObj.gljType !== 201 && tempObj.gljType === 201) {
  830. for (let feeCode of me.feeDataCode) {
  831. tempObj[feeCode] = null;
  832. }
  833. }
  834. if(componentType.includes(tempObj.gljType)&&
  835. !(machineComponent.includes(tempObj.gljType) && machineComponent.includes(pasteObj.gljType)) &&
  836. !(materialComponent.includes(tempObj.gljType) && materialComponent.includes(pasteObj.gljType))){//修改了原本是组成物的工料机
  837. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  838. let updateGljs = me.getUpdateGljs(tempObj, true);
  839. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  840. for(let i = 0; i < updateGljs.updateArr.length; i++){
  841. rst.updateGlj.push(updateGljs.updateArr[i]);
  842. }
  843. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  844. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  845. }
  846. }
  847. }
  848. tempObj.component = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.component : [];
  849. tempObj.gljType = me.distTypeTree.comboDatas[i].value;
  850. tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
  851. break;
  852. }
  853. }
  854. if(!isExsit) isValid = false;
  855. }
  856. for (let feeCode of me.feeDataCode) {
  857. if (typeof pasteObj[feeCode] !== 'undefined' && !isNaN(pasteObj[feeCode])) {
  858. if ((typeof pasteObj.gljType !== 'undefined' && pasteObj.gljType === 201) ||
  859. (tempObj.gljType && tempObj.gljType === 201)) {
  860. tempObj[feeCode] = pasteObj[feeCode];
  861. } else {
  862. isValid = false;
  863. }
  864. }
  865. }
  866. //
  867. pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? scMathUtil.roundTo(parseFloat(pasteObj.basePrice), 2) :
  868. me.currentCache[rowIdx].basePrice;
  869. if(pasteObj.basePrice !== me.currentCache[rowIdx].basePrice){
  870. reCalBasePrc = true;
  871. tempObj.basePrice = pasteObj.basePrice;
  872. let updateGljs = me.getUpdateGljs(tempObj, false);
  873. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  874. for(let i = 0; i < updateGljs.updateArr.length; i++){
  875. rst.updateGlj.push(updateGljs.updateArr[i]);
  876. }
  877. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  878. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  879. }
  880. }
  881. }
  882. if(isValid){
  883. rst.updateGlj.push(tempObj);
  884. if(reCalBasePrc){
  885. //重新计算定额基价对象
  886. let newReObj = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
  887. rst.updateBasePrcArr.push(newReObj);
  888. }
  889. }
  890. else {
  891. for(let attr in backUpObj){
  892. tempObj[attr] = backUpObj[attr];
  893. }
  894. }
  895. return rst;
  896. },
  897. //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
  898. isValidObj: function(pasteObj) {
  899. let me = repositoryGljObj;
  900. if(!(pasteObj.code && typeof pasteObj.code !== 'undefined') || !(pasteObj.name && typeof pasteObj.name !== 'undefined') ||
  901. !(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined')){
  902. return false;
  903. }
  904. if(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined'){
  905. let isExist = false;
  906. for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
  907. if(me.distTypeTree.comboDatas[i].text === pasteObj.gljType){
  908. isExist = true;
  909. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  910. pasteObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + pasteObj.gljType].data.shortName;
  911. break;
  912. }
  913. }
  914. if(!isExist){
  915. return false;
  916. }
  917. }
  918. if(pasteObj.code && typeof pasteObj.code !== 'undefined'){
  919. for(let i = 0; i < me.stdGljList.length; i++){
  920. if(me.stdGljList[i].code === pasteObj.code){
  921. return false;
  922. }
  923. }
  924. for(let i = 0; i < me.complementaryGljList.length; i++){
  925. if(me.complementaryGljList[i].code === pasteObj.code){
  926. return false;
  927. }
  928. }
  929. }
  930. for (let feeCode of me.feeDataCode) {
  931. if (typeof pasteObj[feeCode] !== 'undefined' && (isNaN(pasteObj[feeCode]) || pasteObj.gljType !== 201)) {
  932. return false;
  933. }
  934. }
  935. pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  936. if(!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  937. pasteObj.gljClass = me.gljCurTypeId;
  938. }
  939. return true;
  940. },
  941. canPasted: function (info) {
  942. let rst = true;
  943. let me = repositoryGljObj;
  944. if(me.gljCurTypeId < 0){
  945. return false;
  946. }
  947. if(info.cellRange.col + info.cellRange.colCount - 1 > me.setting.header.length - 2){
  948. return false;
  949. }
  950. if(info.cellRange.row < me.currentCache.length){
  951. if(info.cellRange.col === 0){
  952. return false;
  953. }
  954. //可添加组成物的人材机基价由组成物基价计算得来,基价列只读
  955. else if(info.cellRange.col <= 4 && info.cellRange.col + info.cellRange.colCount - 1 >= 4){
  956. for(let i = 0, len = info.cellRange.rowCount; i < len; i++){
  957. let row = i + info.cellRange.row;
  958. if(row < me.currentCache.length){
  959. if(allowComponent.includes(me.currentCache[row].gljType)){
  960. rst = false;
  961. }
  962. }
  963. else {
  964. break;
  965. }
  966. }
  967. }
  968. }
  969. return rst;
  970. },
  971. onClipboardPasting: function(sender, args) {
  972. let me = repositoryGljObj;
  973. if (!me.canPasted(args)) {
  974. args.cancel = true;
  975. }
  976. },
  977. onClipboardPasted: function(e, info) {
  978. let me = repositoryGljObj;
  979. let updateArr = [], addArr = [];
  980. let items = sheetOpr.analyzePasteData(me.setting, info);
  981. let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,//复制的起始行数和结束行数
  982. maxRow = me.currentCache.length - 1,//当前数据最大行数
  983. updateBasePrcArr = [] ,
  984. updateCount, resumeArr = [];
  985. if(endRow <= maxRow){//只有更新
  986. for(let i = 0; i < items.length; i++){
  987. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  988. if(updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0){
  989. updateArr = updateArr.concat(updateObj.updateGlj);
  990. if(typeof updateObj.updateBasePrcArr !== 'undefined'){
  991. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  992. }
  993. }
  994. }
  995. } else if(beginRow <= maxRow && endRow > maxRow){//更新+新增
  996. updateCount = maxRow - beginRow + 1;
  997. for(let i = 0; i < updateCount; i++){
  998. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  999. if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
  1000. //updateArr = updateObj.updateGlj;
  1001. updateArr = updateArr.concat(updateObj.updateGlj);
  1002. if(typeof updateObj.updateBasePrcArr !== 'undefined'){
  1003. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1004. }
  1005. }
  1006. }
  1007. for(let i = updateCount ; i < items.length; i++){
  1008. if(me.isValidObj(items[i])){
  1009. items[i].component = [];
  1010. addArr.push(items[i]);
  1011. }
  1012. }
  1013. } else{//新增
  1014. for(let i = 0; i < items.length; i++){
  1015. if(me.isValidObj(items[i])){
  1016. items[i].component = [];
  1017. addArr.push(items[i]);
  1018. }
  1019. }
  1020. }
  1021. //repaint
  1022. for(let i = 0; i < info.cellRange.rowCount; i++){
  1023. resumeArr.push(info.cellRange.row + i);
  1024. }
  1025. if(resumeArr.length > 0){
  1026. let sheet = me.workBook.getActiveSheet();
  1027. sheet.suspendPaint();
  1028. for(let i = 0; i < resumeArr.length ; i++){
  1029. if(resumeArr[i] < me.currentCache.length){
  1030. for(let col = 0; col < me.setting.header.length -1; col++){
  1031. let dCode = me.setting.header[col].dataCode;
  1032. if(dCode === 'gljType'){
  1033. let gljType = me.currentCache[resumeArr[i]][dCode];
  1034. sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
  1035. }
  1036. else{
  1037. sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][dCode]);
  1038. }
  1039. }
  1040. }
  1041. else{
  1042. for(let col = 0; col < me.setting.header.length - 1; col++){
  1043. sheet.setValue(resumeArr[i], col, '', GC.Spread.Sheets.SheetArea.viewport);
  1044. }
  1045. }
  1046. }
  1047. sheet.resumePaint();
  1048. }
  1049. if (updateArr.length > 0 || addArr.length > 0) {
  1050. me.mixUpdateRequest(updateArr, addArr, []);
  1051. }
  1052. if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  1053. me.updateRationBasePrcRq(updateBasePrcArr);
  1054. }
  1055. },
  1056. updateRationBasePrcRq: function (basePrcArr) {
  1057. CommonAjax.post('/complementartGlj/api/updateRationBasePrc', {basePrcArr: basePrcArr}, function (rstData) {
  1058. });
  1059. },
  1060. /* getRationGljIds: function (repId) {
  1061. let me = repositoryGljObj;
  1062. $.ajax({
  1063. type: 'post',
  1064. url: 'api/getRationGljIds',
  1065. data: {data: JSON.stringify({repId: repId})},
  1066. dataType: 'json',
  1067. success: function(result){
  1068. if(!result.error){
  1069. me.rationGljIds = result.data;
  1070. }
  1071. }
  1072. });
  1073. },*/
  1074. mixUpdateRequest: function(updateArr, addArr, removeIds) {
  1075. let me = repositoryGljObj;
  1076. if(updateArr.length > 0){
  1077. me.saveInString(updateArr);
  1078. }
  1079. if(addArr.length > 0){
  1080. me.saveInString(addArr);
  1081. }
  1082. let url = 'complementartGlj/api/mixUpdateGljItems';
  1083. let post = {updateItems: updateArr, addItems: addArr, removeIds: removeIds};
  1084. let scCaller = function (rstData) {
  1085. me.updateCache(addArr, updateArr, removeIds, rstData);
  1086. me.sortGlj(me.complementaryGljList);
  1087. if(me.currentOprParent === 1){
  1088. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  1089. }
  1090. else{
  1091. me.currentCache = me.getCache();
  1092. }
  1093. me.showGljItems(me.complementaryGljList, me.gljCurTypeId);
  1094. //getCurrentGlj
  1095. let row = me.workBook.getSheet(0).getSelections()[0].row;
  1096. /* me.currentGlj = row < me.currentCache.length ? me.currentCache[row] : null;
  1097. me.currentComponent = me.currentGlj ? me.getCurrentComponent(me.currentGlj.component) : [];
  1098. sheetOpr.cleanData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, -1);
  1099. sheetOpr.showData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, me.currentComponent);*/
  1100. me.initSel(row);
  1101. }
  1102. let errCaller = function (err) {
  1103. alert('保存失败');
  1104. };
  1105. CommonAjax.post(url, post, scCaller, errCaller);
  1106. },
  1107. saveInString: function (datas) {
  1108. for(let i = 0, len = datas.length; i < len; i++){
  1109. let data = datas[i];
  1110. if(_exist(data, 'basePrice')){
  1111. data['basePrice'] = data['basePrice'].toString();
  1112. }
  1113. if(_exist(data, 'component')){
  1114. for(let j = 0, jLen = data['component'].length; j < jLen; j++){
  1115. let comGljObj = data['component'][j];
  1116. if(_exist(comGljObj, 'consumeAmt')){
  1117. comGljObj['consumeAmt'] = comGljObj['consumeAmt'].toString();
  1118. }
  1119. }
  1120. }
  1121. }
  1122. function _exist(data, attr){
  1123. return data && data[attr] !== undefined && data[attr];
  1124. }
  1125. },
  1126. getParentCache: function (nodes) {
  1127. let me = repositoryGljObj, rst = [];
  1128. for(let i = 0; i < me.complementaryGljList.length; i++){
  1129. if(nodes.indexOf(me.complementaryGljList[i].gljClass) !== -1){
  1130. rst.push(me.complementaryGljList[i]);
  1131. }
  1132. }
  1133. rst.sort(function (a, b) {
  1134. let rst = 0;
  1135. if(a.code > b.code) rst = 1;
  1136. else if(a.code < b.code)rst = -1;
  1137. return rst;
  1138. });
  1139. return rst;
  1140. },
  1141. getCache: function() {
  1142. let me = this, rst = [];
  1143. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1144. if (me.complementaryGljList[i].gljClass == me.gljCurTypeId) {
  1145. rst.push(me.complementaryGljList[i]);
  1146. }
  1147. }
  1148. return rst;
  1149. },
  1150. updateCache: function(addArr, updateArr, removeIds, rstData) {
  1151. let me = this, cacheSection = me.complementaryGljList;
  1152. if (addArr.length > 0) {
  1153. me.complementaryGljList = me.complementaryGljList.concat(addArr);
  1154. cacheSection = me.complementaryGljList;
  1155. }
  1156. for (let i = removeIds.length - 1; i >= 0; i--) {
  1157. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  1158. if (cacheSection[j]["ID"] == removeIds[i]) {
  1159. cacheSection.splice(j,1);
  1160. }
  1161. }
  1162. }
  1163. if (rstData && rstData.ops && rstData.ops.length > 0) {
  1164. for (let i = 0; i < rstData.ops.length; i++) {
  1165. for (let j = 0; j < cacheSection.length; j++) {
  1166. if (cacheSection[j][me.setting.header[0].dataCode] == rstData.ops[i][me.setting.header[0].dataCode]) {
  1167. cacheSection[j]["ID"] = rstData.ops[i]["ID"];
  1168. }
  1169. }
  1170. }
  1171. }
  1172. for (let i = 0; i < updateArr.length; i++) {
  1173. for (let j = 0; j < cacheSection.length; j++) {
  1174. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  1175. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  1176. cacheSection[j] = updateArr[i];
  1177. }
  1178. } else {
  1179. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  1180. cacheSection[j] = updateArr[i];
  1181. }
  1182. }
  1183. }
  1184. }
  1185. //allgljs
  1186. },
  1187. updateParentNodeIds: function (nodes, caller) {
  1188. let private_build_parentNodeIds = function(pNodeId, nodesArr){
  1189. let rst = [];
  1190. for (let i = 0; i < nodesArr.length; i++) {
  1191. if (nodesArr[i].children.length > 0) {
  1192. rst = rst.concat(private_build_parentNodeIds(nodesArr[i].data.ID, nodesArr[i].children));
  1193. } else {
  1194. rst.push(nodesArr[i].data.ID);
  1195. }
  1196. }
  1197. if (pNodeId && rst.length > 0) {
  1198. caller.parentNodeIds["_pNodeId_" + pNodeId] = rst;
  1199. }
  1200. return rst;
  1201. };
  1202. if (caller.parentNodeIds) {
  1203. private_build_parentNodeIds(null, nodes);
  1204. }
  1205. },
  1206. setProp: function (prop, value, gljList) {
  1207. let me = this;
  1208. for(let i = 0, len = gljList.length; i < len; i++){
  1209. gljList[i][prop] = value;
  1210. }
  1211. },
  1212. sortGlj: function(gljList) {
  1213. let me = this;
  1214. gljList.sort(function(a, b){
  1215. let rst = 0;
  1216. if (a.code > b.code) rst = 1
  1217. else if (a.code < b.code) rst = -1;
  1218. return rst;
  1219. });
  1220. }
  1221. }
  1222. let gljTypeTreeOprObj = {
  1223. onClick: function(event,treeId,treeNode) {
  1224. let me = repositoryGljObj,
  1225. that = gljComponentOprObj,
  1226. gljTypeId = treeNode.ID;
  1227. me.gljCurTypeId = treeNode.ID;
  1228. //消除新增到一半的数据
  1229. me.addGljObj = null;
  1230. //me.currentCache = me.getCache();
  1231. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, 5);
  1232. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  1233. me.currentOprParent = 1;
  1234. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  1235. me.workBook.getSheet(0).setRowCount(me.currentCache.length);
  1236. } else {
  1237. me.currentOprParent = 0;
  1238. me.currentCache = me.getCache();
  1239. }
  1240. me.showGljItems(me.complementaryGljList, gljTypeId);
  1241. }
  1242. }