glj.js 60 KB

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