glj.js 61 KB

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