glj.js 60 KB

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