glj.js 60 KB

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