glj.js 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. /**
  2. * Created by Zhong on 2017/8/14.
  3. */
  4. $(document).ready(function () {
  5. let moduleName = 'compleGLj';
  6. SlideResize.loadHorizonWidth(moduleName, [$('#rightResize'), $('#leftResize')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  7. refreshALlWorkBook();
  8. });
  9. //章节树与人材机表
  10. let leftElesObj = {};
  11. leftElesObj.module = moduleName;
  12. leftElesObj.resize = $('#leftResize');
  13. leftElesObj.parent = $('#dataRow');
  14. leftElesObj.left = $('#leftContent');
  15. leftElesObj.right = $('#midContent');
  16. SlideResize.horizontalSlide(leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
  17. refreshALlWorkBook();
  18. });
  19. //人材机表与人材机组成物表
  20. let rightElesObj = {};
  21. rightElesObj.module = moduleName;
  22. rightElesObj.resize = $('#rightResize');
  23. rightElesObj.parent = $('#dataRow');
  24. rightElesObj.left = $('#midContent');
  25. rightElesObj.right = $('#rightContent');
  26. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
  27. refreshALlWorkBook();
  28. });
  29. });
  30. function refreshALlWorkBook() {
  31. if (gljClassTreeObj.workBook) {
  32. gljClassTreeObj.workBook.refresh();
  33. }
  34. if (repositoryGljObj.workBook) {
  35. repositoryGljObj.workBook.refresh();
  36. }
  37. if (gljComponentOprObj.workBook) {
  38. gljComponentOprObj.workBook.refresh();
  39. }
  40. }
  41. let pageOprObj = {
  42. gljLibName : null,
  43. stdGljLibId: null,
  44. userId: null,
  45. compilationId: null,
  46. initPage : function(container, containerComponent, containerC) {
  47. let me = pageOprObj;
  48. me.stdGljLibId = stdGljLibId;
  49. me.userId = userId;
  50. me.compilationId = compilationId;
  51. repositoryGljObj.buildSheet(container);
  52. gljComponentOprObj.buildSheet(containerComponent);
  53. componentOprObj.buildSheet(containerC);
  54. //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
  55. //repositoryGljObj.getRationGljIds(gljLibId);
  56. repositoryGljObj.getGljDistType(function () {
  57. repositoryGljObj.currentRepositoryId = me.stdGljLibId;
  58. repositoryGljObj.getGljItems(me.stdGljLibId, function () {
  59. gljClassTreeObj.getGljClassTree(stdGljLibId);
  60. });
  61. });
  62. }
  63. };
  64. let repositoryGljObj = {
  65. treeObj : null,
  66. workBook: null,
  67. gljCurTypeId: -1,
  68. currentRepositoryId: -1,
  69. currentCache: null,
  70. parentNodeIds: {},
  71. gljList: [],
  72. stdGljList:[],
  73. complementaryGljList: [],
  74. 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. 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. let rightWidth = getLocalCache('compleGLjrightContentWidth') || '25%';
  411. rightWidth = rightWidth.replace('%', '');
  412. let curMidWidth = $('#midContent')[0].style.width.replace('%', ''),
  413. curRightWidth = $('#rightContent')[0].style.width.replace('%', '');
  414. if (componentCanEdit && curRightWidth === '0') {
  415. curMidWidth = parseFloat(curMidWidth) - parseFloat(rightWidth);
  416. $('#midContent').css('width', `${curMidWidth}%`);
  417. $('#rightContent').css('width', `${rightWidth}%`);
  418. } else if(!componentCanEdit && curRightWidth !== '0') {
  419. curMidWidth = parseFloat(curMidWidth) + parseFloat(rightWidth);
  420. $('#midContent').css('width', `${curMidWidth}%`);
  421. $('#rightContent').css('width', `0%`);
  422. }
  423. //减少触发
  424. if (me.preComponentCanEdit !== componentCanEdit) {
  425. refreshALlWorkBook();
  426. }
  427. me.preComponentCanEdit = componentCanEdit;
  428. },
  429. onEnterCell: function (sender, args) {
  430. let me = repositoryGljObj;
  431. args.sheet.repaint();
  432. me.cellRowIdx = args.row;
  433. let isHasData = false;
  434. if(me.addGljObj){
  435. for(let i=0; i<me.setting.header.length; i++){
  436. if(me.addGljObj[me.setting.header[i].dataCode]){
  437. isHasData = true;
  438. break;
  439. }
  440. }
  441. }
  442. if(isHasData){
  443. if(me.editingRowIdx !== me.cellRowIdx) {
  444. let isComple = true;
  445. let focusToCol;
  446. function getFocusToCol (me){
  447. if(!me.addGljObj[me.setting.header[0].dataCode]){
  448. $('#alertGljTxt').text('编号不能为空,继续增加人材机?');
  449. return 0;
  450. }
  451. else if(!me.addGljObj[me.setting.header[1].dataCode]){
  452. $('#alertGljTxt').text('名称不能为空,继续增加人材机?');
  453. return 1;
  454. }
  455. else if(!me.addGljObj[me.setting.header[3].dataCode]){
  456. $('#alertGljTxt').text('计量单位不能为空,继续增加人材机?');
  457. return 3;
  458. }
  459. else if(!me.addGljObj[me.setting.header[5].dataCode]){
  460. $('#alertGljTxt').text('类型不能为空,继续增加人材机?');
  461. return 5;
  462. }
  463. else {
  464. return -1;
  465. }
  466. }
  467. focusToCol = getFocusToCol(me);
  468. if(focusToCol === -1){
  469. }
  470. else {
  471. $('#gljAlertBtn').click();
  472. $('#aleConfBtn').unbind('click');
  473. $('#aleConfBtn').bind('click', function () {
  474. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  475. });
  476. $('#gljAleClose').unbind('click');
  477. $('#gljAleClose').bind('click', function () {
  478. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  479. });
  480. $('#aleCanceBtn').unbind('click');
  481. $('#aleCanceBtn').bind('click', function () {
  482. me.addGljObj = null;
  483. me.workBook.getSheet(0).suspendPaint();
  484. me.workBook.getSheet(0).suspendEvent();
  485. for(let col=0; col<me.setting.header.length; col++){
  486. if(col === 0){
  487. me.workBook.getSheet(0).getCell(me.editingRowIdx, 0).formatter("@");
  488. }
  489. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  490. }
  491. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
  492. me.workBook.getSheet(0).resumePaint();
  493. me.workBook.getSheet(0).resumeEvent();
  494. });
  495. }
  496. }
  497. }
  498. },
  499. onButtonClicked: function (sender, args) {
  500. let me = repositoryGljObj;
  501. if(args.col === 6 && args.row < me.currentCache.length){
  502. args.sheet.setValue(args.row, args.col, true);
  503. }
  504. },
  505. onCellEditStart: function(sender, args) {
  506. let me = repositoryGljObj;
  507. let rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
  508. me.currentEditingGlj = rObj;
  509. me.orgCode = me.workBook.getSheet(0).getValue(args.row, 0);
  510. if(args.row < me.currentCache.length){
  511. me.currentGlj = me.currentCache[args.row];
  512. if(args.col === 0 || (args.col === 4 && allowComponent.includes(me.currentGlj.gljType) && me.currentGlj.component.length > 0)
  513. || (args.col === 6 && me.currentGlj.gljType !== 301) || args.col === 7){
  514. args.cancel = true;
  515. }
  516. else {
  517. rObj.ID = me.currentGlj.ID;
  518. rObj.gljClass = me.currentGlj.gljClass;
  519. }
  520. }
  521. else {
  522. me.currentGlj = null;
  523. }
  524. },
  525. onCellEditEnd: function(sender, args) {
  526. let me = repositoryGljObj, that = gljComponentOprObj,
  527. rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
  528. updateArr = [], addArr = [], updateBasePrcArr = [];
  529. me.editingRowIdx = args.row;
  530. rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
  531. //更新
  532. if (me.currentEditingGlj["ID"]) {
  533. rObj["ID"] = me.currentEditingGlj["ID"];
  534. rObj.gljClass = me.currentEditingGlj.gljClass;
  535. //for(let col =0; col< me.setting.header.length; col++){
  536. if(me.currentEditingGlj[me.setting.header[args.col].dataCode] !== rObj[me.setting.header[args.col].dataCode]){
  537. //me.addGljObj = rObj;
  538. //编码、名称、单位、类型不可为空
  539. 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]
  540. &&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&&
  541. rObj[me.setting.header[5].dataCode].toString().trim().length !== 0){
  542. if(rObj.gljType !== me.currentEditingGlj.gljType){//修改了工料机类型
  543. if(me.currentGlj){
  544. me.currentGlj.component = [];
  545. }
  546. /* if(me.allowComponent.indexOf(rObj.gljType) !== -1){
  547. rObj.basePrice = 0;
  548. }*/
  549. //工料机类型不为机械台班时,清空机型
  550. if(me.currentEditingGlj.gljType === 301 && rObj.gljType !== 301 && me.currentEditingGlj.model){
  551. rObj.model = null;
  552. }
  553. if(componentType.includes(me.currentEditingGlj.gljType) &&
  554. !(machineComponent.includes(me.currentEditingGlj.gljType) && machineComponent.includes(rObj.gljType))
  555. && !(materialComponent.includes(me.currentEditingGlj.gljType) && materialComponent.includes(rObj.gljType))){//修改了原本是组成物的工料机
  556. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  557. let updateGljs = me.getUpdateGljs(rObj, true);
  558. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  559. for(let i = 0; i < updateGljs.updateArr.length; i++){
  560. updateArr.push(updateGljs.updateArr[i]);
  561. }
  562. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  563. updateArr.push(updateGljs.updateBasePrcArr[i]);
  564. }
  565. }
  566. }
  567. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, 5);
  568. }
  569. else if(rObj.basePrice !== me.currentEditingGlj.basePrice){//修改了单价,可修改单价的必为可成为组成物的
  570. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  571. if(isNaN(parseFloat(rObj.basePrice))){
  572. alert('单价只能为数值!');
  573. args.sheet.setValue(args.row, args.col, me.currentEditingGlj.basePrice ? me.currentEditingGlj.basePrice : 0);
  574. return;
  575. }
  576. rObj.basePrice = !isNaN(parseFloat(rObj.basePrice))? scMathUtil.roundTo(parseFloat(rObj.basePrice), -2) : me.currentEditingGlj.basePrice;
  577. let updateGljs = me.getUpdateGljs(rObj);
  578. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  579. for(let i = 0; i < updateGljs.updateArr.length; i++){
  580. updateArr.push(updateGljs.updateArr[i]);
  581. }
  582. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  583. updateArr.push(updateGljs.updateBasePrcArr[i]);
  584. }
  585. }
  586. //rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? that.round(parseFloat(rObj.basePrice), 2) : 0;
  587. }
  588. rObj.component = me.currentGlj.component;
  589. updateArr.push(rObj);
  590. }
  591. else{
  592. if(me.setting.header[args.col].dataCode === 'gljType'){
  593. let distTypeVal = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj[me.setting.header[args.col].dataCode]].data.fullName;
  594. args.sheet.setValue(args.row, args.col, distTypeVal);
  595. }
  596. else{
  597. args.sheet.setValue(args.row, args.col, me.currentEditingGlj[me.setting.header[args.col].dataCode]);
  598. }
  599. }
  600. }
  601. // }
  602. //--------------------------------------
  603. if(me.currentEditingGlj.basePrice !== rObj.basePrice){
  604. //update basePrice of ration when editting basePrice of glj
  605. let gljType = -1;
  606. let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
  607. if(gljTypeParent && gljTypeParent.data.ID <=3){
  608. gljType = gljTypeParent.data.ID;
  609. }
  610. if(!gljTypeParent && me.currentEditingGlj.gljType <= 3){
  611. gljType = me.currentEditingGlj.gljType;
  612. }
  613. let gljBasePrcObj = {gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: rObj.basePrice};
  614. if(gljBasePrcObj.gljType !== -1){
  615. updateBasePrcArr.push(gljBasePrcObj);
  616. me.updateRationBasePrcRq(updateBasePrcArr);
  617. }
  618. }
  619. //update basePrice of ration when editting gljType of glj
  620. if(me.currentEditingGlj.gljType !== rObj.gljType){
  621. let gljTypeObj = {gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: rObj.basePrice};
  622. updateBasePrcArr.push(gljTypeObj);
  623. me.updateRationBasePrcRq(updateBasePrcArr);
  624. }
  625. //-----------------------------------------------------------
  626. }
  627. //新增
  628. else {
  629. if(typeof rObj.code !== 'undefined'){
  630. me.addGljObj = rObj;
  631. let isCanSav = true;
  632. 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]){
  633. isCanSav = false;
  634. }
  635. if(isCanSav){
  636. me.addGljObj = null;
  637. rObj.component = [];
  638. //如果类型为混凝土、砂浆、配合比、机械台班时,添加时填写的单价清空
  639. /* if(me.allowComponent.indexOf(rObj.gljType) !== -1){
  640. rObj.basePrice = 0;
  641. }*/
  642. rObj.basePrice = !isNaN(parseFloat(rObj.basePrice)) && (rObj.basePrice && typeof rObj.basePrice !== 'undefined') ? parseFloat(rObj.basePrice) : 0;
  643. addArr.push(rObj);
  644. }
  645. }
  646. }
  647. if(!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  648. rObj.gljClass = me.gljCurTypeId;
  649. }
  650. if(updateArr.length >0 || addArr.length >0){
  651. me.currentEditingGlj = null;
  652. me.mixUpdateRequest(updateArr, addArr, []);
  653. }
  654. },
  655. delGljs: function (sels) {
  656. let me = repositoryGljObj;
  657. let sheet = me.workBook.getSheet(0),
  658. updateArr = [], removeArr = [],
  659. tempRemoveArr= [],
  660. refGljCodes = [], //已被引用的工料机
  661. updateBasePrcArr = [],//删除基价单位后重新计算
  662. canUpdate = false,
  663. cacheSection = me.currentCache;
  664. if(sels.length > 0 && cacheSection.length > 0){
  665. for(let i = 0; i < sels.length; i++){
  666. if(sels[i].colCount === me.setting.header.length){
  667. for(let j = 0; j < sels[i].rowCount; j++){
  668. if(sels[i].row + j < cacheSection.length){
  669. //删除了已被引用成组成物的工料机,重新计算所有引用此组成物的工料机的单价、组成物数组
  670. let updateGljs = me.getUpdateGljs(cacheSection[sels[i].row + j], true);
  671. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  672. for(let i = 0; i < updateGljs.updateArr.length; i++){
  673. updateArr.push(updateGljs.updateArr[i]);
  674. }
  675. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  676. updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  677. }
  678. }
  679. removeArr.push(cacheSection[sels[i].row + j].ID);
  680. //tempRemoveArr.push({ID: cacheSection[sels[i].row + j].ID, code: cacheSection[sels[i].row + j].code});
  681. //删除后重新计算引用了此工料机的定额单价
  682. updateBasePrcArr.push({gljId: cacheSection[sels[i].row + j].ID, gljType: cacheSection[sels[i].row + j].gljType, basePrice: 0, delete: 1});
  683. }
  684. }
  685. }
  686. else{
  687. let maxCol = sels[i].col + sels[i].colCount - 1;
  688. if(sels[i].col >= 2 && maxCol <= 4){
  689. for(let j = 0; j < sels[i].rowCount; j++){
  690. if(sels[i].row + j < cacheSection.length){
  691. let updateObj = cacheSection[sels[i].row + j];
  692. for(let col = sels[i].col; col <= maxCol; col++){
  693. if(me.setting.header[col].dataCode === 'basePrice'){
  694. //如果类型不为混凝土、砂浆、配合比、机械,才可删除单价 basePrice = 0
  695. if(!allowComponent.includes(updateObj.gljType)){
  696. canUpdate = true;
  697. updateObj[me.setting.header[col].dataCode] = 0;
  698. updateBasePrcArr.push({gljId: updateObj.ID, gljType: updateObj.gljType, basePrice: 0});
  699. }
  700. }
  701. else{
  702. canUpdate = true;
  703. updateObj[me.setting.header[col].dataCode] = '';
  704. }
  705. }
  706. if(canUpdate){
  707. updateArr.push(updateObj);
  708. }
  709. }
  710. }
  711. }
  712. //编号、名称、类型不可为空
  713. else{
  714. if(sels[i].row < cacheSection.length){
  715. let text = '', cantNullStr =['编码', '名称', '类型'];
  716. for(let col = sels[i].col; col <= sels[i].col + sels[i].colCount -1; col++){
  717. if(cantNullStr.indexOf(me.setting.header[col].headerName) !== -1){
  718. text += me.setting.header[col].headerName + " ";
  719. }
  720. }
  721. $('#alertText').text(text + "不可为空!");
  722. $('#codeAlertBtn').click();
  723. $('#codAleConfBtn').click(function () {
  724. });
  725. $('#codAleClose').click(function () {
  726. });
  727. }
  728. }
  729. }
  730. }
  731. if(removeArr.length > 0 || updateArr.length > 0){
  732. //删除警告
  733. $('#alertGljTxt').text('可能已有定额引用了当前工料机,导致定额查找不到此工料机。确定要删除吗?');
  734. $('#gljAlertBtn').click();
  735. //确认
  736. $('#aleConfBtn').unbind('click');
  737. $('#aleConfBtn').bind('click', function () {
  738. me.mixUpdateRequest(updateArr, [], removeArr);
  739. /*if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  740. me.updateRationBasePrcRq(updateBasePrcArr);
  741. }*/
  742. });
  743. }
  744. }
  745. },
  746. repositoryGljDelOpr: function () {
  747. let me = repositoryGljObj;
  748. me.workBook.commandManager().register('repositoryGljDel', function () {
  749. let sels = me.workBook.getActiveSheet().getSelections();
  750. me.delGljs(sels);
  751. });
  752. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  753. me.workBook.commandManager().setShortcutKey('repositoryGljDel', GC.Spread.Commands.Key.del, false, false, false, false);
  754. },
  755. onContextmenuOpr: function () {
  756. let me = repositoryGljObj;
  757. $.contextMenu({
  758. selector: '#GLJListSheet',
  759. build: function($triggerElement, e){
  760. //控制允许右键菜单在哪个位置出现
  761. let sheet = me.workBook.getSheet(0);
  762. let offset = $("#GLJListSheet").offset(),
  763. x = e.pageX - offset.left,
  764. y = e.pageY - offset.top;
  765. let target = sheet.hitTest(x, y);
  766. let sel = sheet.getSelections()[0];
  767. if(sel.row === -1){
  768. sel.row = 0;
  769. }
  770. if(sel.col === -1){
  771. sel.col = 0;
  772. }
  773. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  774. me.initSel(target.row);
  775. if(sel.row > target.row || sel.row + sel.rowCount - 1 < target.row ||
  776. sel.col > target.col || sel.col + sel.colCount - 1 < target.col ){
  777. sheet.setActiveCell(target.row, target.col);
  778. }
  779. return {
  780. callback: function(){},
  781. items: {
  782. "delete": {
  783. name: "删除",
  784. disabled: function () {
  785. return !(me.currentCache && me.currentCache[target.row]);
  786. },
  787. icon: "fa-remove",
  788. callback: function (key, opt) {
  789. let curSel = _.cloneDeep(sheet.getSelections()[0]);
  790. curSel.colCount = me.setting.header.length;
  791. me.delGljs([curSel]);
  792. }}
  793. }
  794. };
  795. }
  796. else{
  797. return false;
  798. }
  799. }
  800. });
  801. },
  802. validUpdateObj: function (pasteObj, rowIdx) {
  803. let rst = {updateGlj: [], updateBasePrcArr: []}, backUpObj = {},
  804. me = repositoryGljObj,
  805. that = gljComponentOprObj,
  806. tempObj = me.currentCache[rowIdx],
  807. reCalBasePrc = false,
  808. isValid = true;
  809. //备份原始数据
  810. for(let atr in tempObj){
  811. backUpObj[atr] = tempObj[atr];
  812. }
  813. if(typeof pasteObj.code !== 'undefined'){
  814. if(pasteObj.code.trim().length !== 0){
  815. let isExist = false;
  816. for(let i = 0; i < me.stdGljList.length; i++){
  817. if(me.stdGljList[i].code === pasteObj.code){
  818. isExist = true;
  819. break;
  820. }
  821. }
  822. if(!isExist){
  823. for(let i = 0; i < me.complementaryGljList.length; i++){
  824. if(me.complementaryGljList[i].code === pasteObj.code){
  825. isExist = true;
  826. break;
  827. }
  828. }
  829. }
  830. if(!isExist){
  831. tempObj.code = pasteObj.code;
  832. }
  833. else isValid = false;
  834. }
  835. else isValid = false;
  836. }
  837. if(typeof pasteObj.name !== 'undefined'){
  838. if(pasteObj.name.trim().length === 0) isValid = false;
  839. else tempObj.name = pasteObj.name;
  840. }
  841. if(typeof pasteObj.specs !== 'undefined'){
  842. tempObj.specs = pasteObj.specs;
  843. }
  844. if(typeof pasteObj.unit !== 'undefined'){
  845. tempObj.unit = pasteObj.unit;
  846. }
  847. if(typeof pasteObj.gljType !== 'undefined'){
  848. let isExsit = false;
  849. for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
  850. if(pasteObj.gljType === me.distTypeTree.comboDatas[i].text){
  851. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  852. isExsit = true;
  853. reCalBasePrc = true;
  854. if(pasteObj.gljType !== 301 && tempObj.gljType === 301){
  855. tempObj.model = null;
  856. }
  857. if(componentType.includes(tempObj.gljType)&&
  858. !(machineComponent.includes(tempObj.gljType) && machineComponent.includes(pasteObj.gljType)) &&
  859. !(materialComponent.includes(tempObj.gljType) && materialComponent.includes(pasteObj.gljType))){//修改了原本是组成物的工料机
  860. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  861. let updateGljs = me.getUpdateGljs(tempObj, true);
  862. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  863. for(let i = 0; i < updateGljs.updateArr.length; i++){
  864. rst.updateGlj.push(updateGljs.updateArr[i]);
  865. }
  866. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  867. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  868. }
  869. }
  870. }
  871. tempObj.component = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.component : [];
  872. /*if(me.allowComponent.indexOf(tempObj.gljType) !== -1){
  873. tempObj.basePrice = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.basePrice : 0;
  874. }*/
  875. tempObj.gljType = me.distTypeTree.comboDatas[i].value;
  876. tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
  877. break;
  878. }
  879. }
  880. if(!isExsit) isValid = false;
  881. }
  882. //
  883. pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? scMathUtil.roundTo(parseFloat(pasteObj.basePrice), 2) :
  884. me.currentCache[rowIdx].basePrice;
  885. if(pasteObj.basePrice !== me.currentCache[rowIdx].basePrice){
  886. reCalBasePrc = true;
  887. tempObj.basePrice = pasteObj.basePrice;
  888. let updateGljs = me.getUpdateGljs(tempObj, false);
  889. if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
  890. for(let i = 0; i < updateGljs.updateArr.length; i++){
  891. rst.updateGlj.push(updateGljs.updateArr[i]);
  892. }
  893. for(let i = 0; i < updateGljs.updateBasePrcArr.length; i++){
  894. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  895. }
  896. }
  897. }
  898. if(typeof pasteObj.model !== 'undefined'){
  899. if(!me.machineModel.textArr.includes(pasteObj.model)){
  900. isValid = false;
  901. }
  902. else {
  903. let existsModel = false;
  904. if((typeof pasteObj.gljType !== 'undefined' && pasteObj.gljType === 301) ||
  905. (tempObj.gljType && tempObj.gljType === 301)){
  906. me.machineModel.comboItems.forEach(function (item) {
  907. if(item.text === pasteObj.model){
  908. tempObj.model = item.value;
  909. existsModel = true;
  910. }
  911. });
  912. if(!existsModel){
  913. isValid = false;
  914. }
  915. }
  916. else {
  917. isValid = false;
  918. }
  919. }
  920. }
  921. if(isValid){
  922. rst.updateGlj.push(tempObj);
  923. if(reCalBasePrc){
  924. //重新计算定额基价对象
  925. //rst.updateBasePrc = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
  926. let newReObj = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
  927. rst.updateBasePrcArr.push(newReObj);
  928. }
  929. }
  930. else {
  931. for(let attr in backUpObj){
  932. tempObj[attr] = backUpObj[attr];
  933. }
  934. }
  935. return rst;
  936. },
  937. //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
  938. isValidObj: function(pasteObj) {
  939. let me = repositoryGljObj;
  940. if(!(pasteObj.code && typeof pasteObj.code !== 'undefined') || !(pasteObj.name && typeof pasteObj.name !== 'undefined') ||
  941. !(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined')){
  942. return false;
  943. }
  944. if(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined'){
  945. let isExist = false;
  946. for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
  947. if(me.distTypeTree.comboDatas[i].text === pasteObj.gljType){
  948. isExist = true;
  949. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  950. pasteObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + pasteObj.gljType].data.shortName;
  951. break;
  952. }
  953. }
  954. if(!isExist){
  955. return false;
  956. }
  957. }
  958. if(pasteObj.code && typeof pasteObj.code !== 'undefined'){
  959. for(let i = 0; i < me.stdGljList.length; i++){
  960. if(me.stdGljList[i].code === pasteObj.code){
  961. return false;
  962. }
  963. }
  964. for(let i = 0; i < me.complementaryGljList.length; i++){
  965. if(me.complementaryGljList[i].code === pasteObj.code){
  966. return false;
  967. }
  968. }
  969. }
  970. if(typeof pasteObj.model !== 'undefined' && pasteObj.model){
  971. if(!me.machineModel.textArr.includes(pasteObj.model) || pasteObj.gljType !== 301){
  972. return false;
  973. }
  974. me.machineModel.comboItems.forEach(function (item) {
  975. if(item.text === pasteObj.model){
  976. pasteObj.model = item.value;
  977. }
  978. });
  979. }
  980. pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  981. if(!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  982. pasteObj.gljClass = me.gljCurTypeId;
  983. }
  984. return true;
  985. },
  986. canPasted: function (info) {
  987. let rst = true;
  988. let me = repositoryGljObj;
  989. if(me.gljCurTypeId < 0){
  990. return false;
  991. }
  992. if(info.cellRange.col + info.cellRange.colCount - 1 > me.setting.header.length - 2){
  993. return false;
  994. }
  995. if(info.cellRange.row < me.currentCache.length){
  996. if(info.cellRange.col === 0){
  997. return false;
  998. }
  999. else if(info.cellRange.col <= 4 && info.cellRange.col + info.cellRange.colCount - 1 >= 4){
  1000. for(let i = 0, len = info.cellRange.rowCount; i < len; i++){
  1001. let row = i + info.cellRange.row;
  1002. if(row < me.currentCache.length){
  1003. if(allowComponent.includes(me.currentCache[row].gljType)){
  1004. rst = false;
  1005. }
  1006. }
  1007. else {
  1008. break;
  1009. }
  1010. }
  1011. }
  1012. }
  1013. return rst;
  1014. },
  1015. onClipboardPasting: function(sender, args) {
  1016. let me = repositoryGljObj;
  1017. let maxCol = args.cellRange.col + args.cellRange.colCount - 1;
  1018. if (!me.canPasted(args)) {
  1019. args.cancel = true;
  1020. }
  1021. },
  1022. onClipboardPasted: function(e, info) {
  1023. // if(info.pasteData.text.trim().length > 0){
  1024. let me = repositoryGljObj;
  1025. let updateArr = [], addArr = [];
  1026. let items = sheetOpr.analyzePasteData(me.setting, info);
  1027. let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,//复制的起始行数和结束行数
  1028. maxRow = me.currentCache.length - 1,//当前数据最大行数
  1029. updateBasePrcArr = [] ,
  1030. updateCount, resumeArr = [];
  1031. if(endRow <= maxRow){
  1032. //updateItems = items;
  1033. for(let i = 0; i < items.length; i++){
  1034. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1035. if(updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0){
  1036. //updateArr = updateObj.updateGlj;
  1037. updateArr = updateArr.concat(updateObj.updateGlj);
  1038. if(typeof updateObj.updateBasePrcArr !== 'undefined'){
  1039. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1040. }
  1041. }
  1042. }
  1043. }
  1044. else if(beginRow <= maxRow && endRow > maxRow){
  1045. updateCount = maxRow - beginRow + 1;
  1046. for(let i = 0; i < updateCount; i++){
  1047. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1048. if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
  1049. //updateArr = updateObj.updateGlj;
  1050. updateArr = updateArr.concat(updateObj.updateGlj);
  1051. if(typeof updateObj.updateBasePrcArr !== 'undefined'){
  1052. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1053. }
  1054. }
  1055. }
  1056. if(info.cellRange.colCount === me.setting.header.length -1){
  1057. for(let i = updateCount ; i < items.length; i++){
  1058. if(me.isValidObj(items[i])){
  1059. items[i].component = [];
  1060. //类型为混凝土、砂浆、配合比、机械时,基价只能组成物计算
  1061. /* if(me.allowComponent.indexOf(items[i].gljType) !== -1){
  1062. items[i].basePrice = 0;
  1063. }*/
  1064. addArr.push(items[i]);
  1065. }
  1066. }
  1067. }
  1068. }
  1069. else{
  1070. if(info.cellRange.colCount === me.setting.header.length -1){
  1071. for(let i = 0; i < items.length; i++){
  1072. if(me.isValidObj(items[i])){
  1073. items[i].component = [];
  1074. /*if(me.allowComponent.indexOf(items[i].gljType) !== -1){
  1075. items[i].basePrice = 0;
  1076. }*/
  1077. addArr.push(items[i]);
  1078. }
  1079. }
  1080. }
  1081. }
  1082. //repaint
  1083. for(let i = 0; i < info.cellRange.rowCount; i++){
  1084. resumeArr.push(info.cellRange.row + i);
  1085. }
  1086. if(resumeArr.length > 0){
  1087. let sheet = me.workBook.getActiveSheet();
  1088. sheet.suspendPaint();
  1089. for(let i = 0; i < resumeArr.length ; i++){
  1090. if(resumeArr[i] < me.currentCache.length){
  1091. for(let col = 0; col < me.setting.header.length -1; col++){
  1092. if(me.setting.header[col].dataCode === 'gljType'){
  1093. let gljType = me.currentCache[resumeArr[i]][me.setting.header[col].dataCode];
  1094. sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
  1095. }
  1096. else if(me.setting.header[col].dataCode === 'model'){
  1097. 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]]: '');
  1098. }
  1099. else{
  1100. sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]);
  1101. }
  1102. }
  1103. }
  1104. else{
  1105. for(let col = 0; col < me.setting.header.length - 1; col++){
  1106. sheet.setValue(resumeArr[i], col, '', GC.Spread.Sheets.SheetArea.viewport);
  1107. }
  1108. }
  1109. }
  1110. sheet.resumePaint();
  1111. }
  1112. if (updateArr.length > 0 || addArr.length > 0) {
  1113. me.mixUpdateRequest(updateArr, addArr, []);
  1114. }
  1115. if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  1116. me.updateRationBasePrcRq(updateBasePrcArr);
  1117. }
  1118. // }
  1119. },
  1120. updateRationBasePrcRq: function (basePrcArr) {
  1121. CommonAjax.post('complementartGlj/api/updateRationBasePrc', {basePrcArr: basePrcArr}, function (rstData) {
  1122. });
  1123. },
  1124. /* getRationGljIds: function (repId) {
  1125. let me = repositoryGljObj;
  1126. $.ajax({
  1127. type: 'post',
  1128. url: 'api/getRationGljIds',
  1129. data: {data: JSON.stringify({repId: repId})},
  1130. dataType: 'json',
  1131. success: function(result){
  1132. if(!result.error){
  1133. me.rationGljIds = result.data;
  1134. }
  1135. }
  1136. });
  1137. },*/
  1138. mixUpdateRequest: function(updateArr, addArr, removeIds) {
  1139. let me = repositoryGljObj;
  1140. if(updateArr.length > 0){
  1141. me.saveInString(updateArr);
  1142. }
  1143. if(addArr.length > 0){
  1144. me.saveInString(addArr);
  1145. }
  1146. let url = 'complementartGlj/api/mixUpdateGljItems';
  1147. let post = {updateItems: updateArr, addItems: addArr, removeIds: removeIds};
  1148. let scCaller = function (rstData) {
  1149. me.updateCache(addArr, updateArr, removeIds, rstData);
  1150. me.sortGlj(me.complementaryGljList);
  1151. if(me.currentOprParent === 1){
  1152. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  1153. }
  1154. else{
  1155. me.currentCache = me.getCache();
  1156. }
  1157. me.showGljItems(me.complementaryGljList, me.gljCurTypeId);
  1158. //getCurrentGlj
  1159. let row = me.workBook.getSheet(0).getSelections()[0].row;
  1160. me.currentGlj = row < me.currentCache.length ? me.currentCache[row] : null;
  1161. me.currentComponent = me.currentGlj ? me.getCurrentComponent(me.currentGlj.component) : [];
  1162. sheetOpr.cleanData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, -1);
  1163. sheetOpr.showData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, me.currentComponent);
  1164. }
  1165. let errCaller = function (err) {
  1166. alert('保存失败');
  1167. };
  1168. CommonAjax.post(url, post, scCaller, errCaller);
  1169. },
  1170. saveInString: function (datas) {
  1171. for(let i = 0, len = datas.length; i < len; i++){
  1172. let data = datas[i];
  1173. if(_exist(data, 'basePrice')){
  1174. data['basePrice'] = data['basePrice'].toString();
  1175. }
  1176. if(_exist(data, 'component')){
  1177. for(let j = 0, jLen = data['component'].length; j < jLen; j++){
  1178. let comGljObj = data['component'][j];
  1179. if(_exist(comGljObj, 'consumeAmt')){
  1180. comGljObj['consumeAmt'] = comGljObj['consumeAmt'].toString();
  1181. }
  1182. }
  1183. }
  1184. }
  1185. function _exist(data, attr){
  1186. return data && data[attr] !== undefined && data[attr];
  1187. }
  1188. },
  1189. getParentCache: function (nodes) {
  1190. let me = repositoryGljObj, rst = [];
  1191. for(let i = 0; i < me.complementaryGljList.length; i++){
  1192. if(nodes.indexOf(me.complementaryGljList[i].gljClass) !== -1){
  1193. rst.push(me.complementaryGljList[i]);
  1194. }
  1195. }
  1196. rst.sort(function (a, b) {
  1197. let rst = 0;
  1198. if(a.code > b.code) rst = 1;
  1199. else if(a.code < b.code)rst = -1;
  1200. return rst;
  1201. });
  1202. return rst;
  1203. },
  1204. getCache: function() {
  1205. let me = this, rst = [];
  1206. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1207. if (me.complementaryGljList[i].gljClass == me.gljCurTypeId) {
  1208. rst.push(me.complementaryGljList[i]);
  1209. }
  1210. }
  1211. return rst;
  1212. },
  1213. updateCache: function(addArr, updateArr, removeIds, rstData) {
  1214. let me = this, cacheSection = me.complementaryGljList;
  1215. if (addArr.length > 0) {
  1216. me.complementaryGljList = me.complementaryGljList.concat(addArr);
  1217. cacheSection = me.complementaryGljList;
  1218. }
  1219. for (let i = removeIds.length - 1; i >= 0; i--) {
  1220. for (let j = cacheSection.length - 1; j >= 0 ; j--) {
  1221. if (cacheSection[j]["ID"] == removeIds[i]) {
  1222. cacheSection.splice(j,1);
  1223. }
  1224. }
  1225. }
  1226. if (rstData && rstData.ops && rstData.ops.length > 0) {
  1227. for (let i = 0; i < rstData.ops.length; i++) {
  1228. for (let j = 0; j < cacheSection.length; j++) {
  1229. if (cacheSection[j][me.setting.header[0].dataCode] == rstData.ops[i][me.setting.header[0].dataCode]) {
  1230. cacheSection[j]["ID"] = rstData.ops[i]["ID"];
  1231. }
  1232. }
  1233. }
  1234. }
  1235. for (let i = 0; i < updateArr.length; i++) {
  1236. for (let j = 0; j < cacheSection.length; j++) {
  1237. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  1238. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  1239. cacheSection[j] = updateArr[i];
  1240. }
  1241. } else {
  1242. if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
  1243. cacheSection[j] = updateArr[i];
  1244. }
  1245. }
  1246. }
  1247. }
  1248. //allgljs
  1249. },
  1250. updateParentNodeIds: function (nodes, caller) {
  1251. let private_build_parentNodeIds = function(pNodeId, nodesArr){
  1252. let rst = [];
  1253. for (let i = 0; i < nodesArr.length; i++) {
  1254. if (nodesArr[i].children.length > 0) {
  1255. rst = rst.concat(private_build_parentNodeIds(nodesArr[i].data.ID, nodesArr[i].children));
  1256. } else {
  1257. rst.push(nodesArr[i].data.ID);
  1258. }
  1259. }
  1260. if (pNodeId && rst.length > 0) {
  1261. caller.parentNodeIds["_pNodeId_" + pNodeId] = rst;
  1262. }
  1263. return rst;
  1264. };
  1265. if (caller.parentNodeIds) {
  1266. private_build_parentNodeIds(null, nodes);
  1267. }
  1268. },
  1269. setProp: function (prop, value, gljList) {
  1270. let me = this;
  1271. for(let i = 0, len = gljList.length; i < len; i++){
  1272. gljList[i][prop] = value;
  1273. }
  1274. },
  1275. sortGlj: function(gljList) {
  1276. let me = this;
  1277. gljList.sort(function(a, b){
  1278. let rst = 0;
  1279. if (a.code > b.code) rst = 1
  1280. else if (a.code < b.code) rst = -1;
  1281. return rst;
  1282. });
  1283. }
  1284. }
  1285. let gljTypeTreeOprObj = {
  1286. onClick: function(event,treeId,treeNode) {
  1287. let me = repositoryGljObj,
  1288. that = gljComponentOprObj,
  1289. gljTypeId = treeNode.ID;
  1290. me.gljCurTypeId = treeNode.ID;
  1291. //消除新增到一半的数据
  1292. me.addGljObj = null;
  1293. //me.currentCache = me.getCache();
  1294. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, 5);
  1295. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  1296. me.currentOprParent = 1;
  1297. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  1298. me.workBook.getSheet(0).setRowCount(me.currentCache.length);
  1299. } else {
  1300. me.currentOprParent = 0;
  1301. me.currentCache = me.getCache();
  1302. }
  1303. me.showGljItems(me.complementaryGljList, gljTypeId);
  1304. }
  1305. }