glj.js 62 KB

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