glj.js 60 KB

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