ration_glj.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. var rationGLJOprObj = {
  5. sheet: null,
  6. currentRationItem: null,
  7. distTypeTree: null,
  8. activeCell: null,
  9. tempCacheArr: [],//被更新的工料机,若更新的工料机不存在,则恢复
  10. cache: {},
  11. setting: {
  12. header:[
  13. {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
  14. {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
  15. {headerName:"规格",headerWidth:120,dataCode:"specs", dataType: "String"},
  16. {headerName:"单位",headerWidth:160,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
  17. {headerName:"基价单价",headerWidth:160, dataCode:"basePrice", dataType: "Number", formatter:"0.00", precision: 2},
  18. {headerName:"定额消耗",headerWidth:160, dataCode:"consumeAmt", dataType: "Number", formatter: "0.000", precision: 3},
  19. {headerName:"类型",headerWidth:160,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
  20. ],
  21. view:{
  22. comboBox:[],
  23. lockColumns:[1,2,3,4,6]
  24. }
  25. },
  26. getDistTypeTree: function (gljDistType) {
  27. let me = this;
  28. let distType;
  29. let distTypeTree = {
  30. prefix : 'gljDistType',
  31. distTypes: {},
  32. comboDatas: [],
  33. distTypesArr: []
  34. };
  35. gljDistType.forEach(function (typeData) {
  36. let typeObj = {
  37. data: typeData,
  38. children: [],
  39. parent: null
  40. }
  41. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  42. distTypeTree.distTypesArr.push(typeObj);
  43. });
  44. gljDistType.forEach(function (typeData) {
  45. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  46. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  47. if(parent){
  48. distType.parent = parent;
  49. parent.children.push(distType);
  50. }
  51. });
  52. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  53. if(distTypeObj.children.length === 0 && distTypeObj.data.fullName !== '普通机械' &&distTypeObj.data.fullName !== '机械组成物'
  54. && distTypeObj.data.fullName !== '机上人工'){
  55. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  56. }
  57. if(distTypeObj.data.fullName === '机械'){
  58. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  59. }
  60. });
  61. return distTypeTree;
  62. },
  63. getGljDistType: function (callback) {
  64. let me = this;
  65. $.ajax({
  66. type: 'post',
  67. url: "api/getGljDistType",
  68. dataType: 'json',
  69. success: function (result) {
  70. if(!result.error && callback){
  71. me.distTypeTree = me.getDistTypeTree(result.data);
  72. callback();
  73. }
  74. }
  75. })
  76. },
  77. buildSheet: function(sheet) {
  78. var me = this;
  79. me.sheet = sheet;
  80. me.getGljDistType(function () {
  81. me.onContextmenuOpr();
  82. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  83. me.rationGljDelOpr();
  84. me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  85. me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  86. me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  87. //me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  88. });
  89. },
  90. rationGljDelOpr: function () {
  91. let me = rationGLJOprObj, spreadBook = me.sheet.getParent();
  92. spreadBook.commandManager().register('rationGljDelete', function () {
  93. let sels = me.sheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
  94. let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID], isUpdate = false;
  95. if(sels.length > 0){
  96. for(let sel = 0; sel < sels.length; sel++){
  97. if(sels[sel].colCount === me.setting.header.length){
  98. if(cacheSection){
  99. for(let i = 0; i < sels[sel].rowCount; i++){
  100. if(sels[sel].row + i < cacheSection.length){
  101. isUpdate = true;
  102. cacheSection.splice(sels[sel].row + i, 1);
  103. }
  104. }
  105. }
  106. }
  107. else{
  108. if(sels[sel].col === 0){
  109. $('#alertText').text("编号不能为空,修改失败!");
  110. $('#alertModalBtn').click();
  111. me.sheet.options.isProtected = true;
  112. $('#alertModalCls').click(function () {
  113. me.sheet.options.isProtected = false;
  114. });
  115. $('#alertModalCof').click(function () {
  116. me.sheet.options.isProtected = false;
  117. });
  118. }
  119. else if(sels[sel].col !== 0 && sels[sel].col !== 5 && !(sels[sel].col === 1 && sels.col + sels[sel].colCount -1 === 3)){
  120. if(cacheSection){
  121. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  122. if(sels[sel].row + i < cacheSection.length){
  123. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  124. if(lockCols.indexOf(col) === -1){
  125. isUpdate = true;
  126. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = 0;
  127. me.sheet.setValue(sels[sel].row + i, col, 0.00);
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
  137. if(isUpdate){
  138. me.updateRationItem();
  139. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  140. me.showGljItems(me.currentRationItem.ID);
  141. }
  142. /* if(updateArr.length > 0 || removeArr.length > 0){
  143. me.mixUpdateRequest(updateArr, [], removeArr);
  144. }*/
  145. });
  146. spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  147. spreadBook.commandManager().setShortcutKey('rationGljDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  148. },
  149. onRangeChanged: function(sender, args) {
  150. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  151. var me = rationGLJOprObj, updateArr = [], removeArr = [];
  152. if (args.col == 0) {
  153. if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
  154. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  155. for (var i = args.rowCount - 1; i >= 0; i--) {
  156. if (args.row + i < cacheArr.length) {
  157. cacheArr.splice(args.row + i, 1);
  158. }
  159. }
  160. me.updateRationItem();
  161. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  162. me.showGljItems(me.currentRationItem.ID);
  163. }
  164. }
  165. }
  166. },
  167. onClipboardPasting: function(sender, args) {
  168. var me = rationGLJOprObj;
  169. if (!(args.cellRange.col === 0 || args.cellRange.col === 5) || !(me.currentRationItem)) {
  170. args.cancel = true;
  171. }
  172. },
  173. onClipboardPasted: function(e, info) {
  174. var me = rationGLJOprObj, repId = storageUtil.getSessionCache("RationGrp","repositoryID");
  175. me.tempCacheArr = [];
  176. if (repId) {
  177. let gljLibId = storageUtil.getSessionCache("gljLib", "repositoryID_" + repId);
  178. if(gljLibId){
  179. if (info.cellRange.col == 0) {
  180. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  181. var tmpCodes = sheetCommonObj.analyzePasteData({header:[{dataCode: "code"}] }, info);
  182. var codes = [];
  183. for (var i = 0; i < tmpCodes.length; i++) {
  184. let rowIdx = info.cellRange.row + i;
  185. if(rowIdx < cacheArr.length){//更新
  186. me.tempCacheArr.push(cacheArr[rowIdx]);
  187. cacheArr.splice(rowIdx--, 1);
  188. }
  189. codes.push(tmpCodes[i].code);
  190. }
  191. me.addGljItems(codes, gljLibId, info.cellRange);
  192. } else {
  193. //修改用量
  194. if(me.cache["_GLJ_" + me.currentRationItem.ID] && info.cellRange.row < me.cache["_GLJ_" + me.currentRationItem.ID].length){
  195. let tempConsumes = sheetCommonObj.analyzePasteData(me.setting, info);
  196. let maxCount = info.cellRange.row + info.cellRange.rowCount -1 > me.cache["_GLJ_" + me.currentRationItem.ID].length -1 ?
  197. me.cache["_GLJ_" + me.currentRationItem.ID].length - info.cellRange.row : info.cellRange.rowCount;
  198. for(let i = 0; i < maxCount; i++){
  199. let roundCons = me.round(tempConsumes[i].consumeAmt, 3);
  200. me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = roundCons;
  201. }
  202. me.updateRationItem();
  203. if(info.cellRange.row + info.cellRange.rowCount -1 >= me.cache["_GLJ_" + me.currentRationItem.ID].length -1){
  204. me.sheet.suspendPaint();
  205. for(let rowIdx = me.cache["_GLJ_" + me.currentRationItem.ID].length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
  206. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  207. }
  208. me.sheet.resumePaint();
  209. }
  210. }
  211. else if(info.cellRange.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
  212. me.sheet.suspendPaint();
  213. for(let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx ++){
  214. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  215. }
  216. me.sheet.resumePaint();
  217. }
  218. }
  219. }
  220. }
  221. },
  222. onCellEditEnd: function(sender, args){
  223. var me = rationGLJOprObj;
  224. if(me.currentRationItem) {
  225. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  226. me.tempCacheArr = [];
  227. if (args.col != 0) {
  228. if (args.row < cacheArr.length) {
  229. var editGlj = cacheArr[args.row];
  230. if (editGlj["consumeAmt"] != args.editingText) {
  231. let parseNum = parseFloat(args.editingText);
  232. if (isNaN(parseFloat(args.editingText))) {
  233. $('#alertModalBtn').click();
  234. $('#alertText').text("定额消耗只能输入数值!");
  235. args.sheet.options.isProtected = true;
  236. $('#alertModalCls').click(function () {
  237. args.sheet.options.isProtected = false;
  238. args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
  239. });
  240. $('#alertModalCof').click(function () {
  241. args.sheet.options.isProtected = false;
  242. args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
  243. })
  244. }
  245. else {
  246. args.sheet.setValue(args.row, args.col, parseNum);
  247. let roundNum = me.round(parseNum, 3);
  248. editGlj["consumeAmt"] = roundNum;
  249. me.updateRationItem();
  250. }
  251. }
  252. }
  253. } else {
  254. if (args.editingText && args.editingText.toString().trim().length !== 0) {
  255. let isExist = false;
  256. for (let i = 0, len = cacheArr.length; i < len; i++) {
  257. if (cacheArr[i].code === args.editingText && i !== args.row) {
  258. isExist = true;
  259. break;
  260. }
  261. }
  262. if (isExist) {
  263. alert("该工料机已存在!");
  264. args.sheet.setValue(args.row, args.col, typeof cacheArr[args.row] !== 'undefined' ? cacheArr[args.row].code + '' : '');
  265. }
  266. else {
  267. if (args.row < cacheArr.length && args.editingText !== cacheArr[args.row].code) {//更新
  268. me.tempCacheArr.push(cacheArr[args.row]);
  269. cacheArr.splice(args.row, 1);
  270. let rationRepId = storageUtil.getSessionCache("RationGrp", "repositoryID");
  271. let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
  272. let codes = [];
  273. codes.push(args.editingText.toString().trim());
  274. me.addGljItems(codes, gljLibID, args);
  275. }
  276. else if (args.row >= cacheArr.length) {//新增
  277. let rationRepId = storageUtil.getSessionCache("RationGrp", "repositoryID");
  278. let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
  279. if (gljLibID) {
  280. var codes = [];
  281. codes.push(args.editingText.toString().trim());
  282. me.addGljItems(codes, gljLibID, args);
  283. }
  284. }
  285. }
  286. }
  287. }
  288. }
  289. else {
  290. args.sheet.setValue(args.row, args.col, '');
  291. }
  292. },
  293. onContextmenuOpr: function () {
  294. let me = rationGLJOprObj;
  295. $.contextMenu({
  296. selector: '#rdSpread',
  297. build: function ($triggerElement, e) {
  298. //控制允许右键菜单在哪个位置出现
  299. let sheet = me.sheet;
  300. let offset = $triggerElement.offset(),
  301. x = e.pageX - offset.left,
  302. y = e.pageY - offset.top;
  303. let target = sheet.hitTest(x, y);
  304. if(sheet.parent.getActiveSheetIndex() === 0 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){
  305. let delDis = true, cacheSection;
  306. sheet.setActiveCell(target.row, target.col);
  307. if(me.currentRationItem){
  308. let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID];
  309. if(target.row < cacheSection.length){
  310. delDis = false;
  311. }
  312. }
  313. return {
  314. callback: function(key, options) {
  315. },
  316. items: {
  317. /*"insert": {name: "插入", callback: function (key, opt) {
  318. }},*/
  319. "delete": {name: "删除", icon: 'fa-remove', disabled: delDis, callback: function (key, opt) {
  320. cacheSection.splice(target.row, 1);
  321. me.updateRationItem();
  322. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  323. me.showGljItems(me.currentRationItem.ID);
  324. }}
  325. }
  326. };
  327. }
  328. else{
  329. return false;
  330. }
  331. }
  332. });
  333. },
  334. addGljItems: function(codes, repId, args) {
  335. var me = this;
  336. sheetCommonObj.setLockCol(me.sheet, 0, true);
  337. $.ajax({
  338. type:"POST",
  339. url:"api/getGljItemsByCodes",
  340. data:{"gljCodes": JSON.stringify(codes), repId: repId},
  341. dataType:"json",
  342. cache:false,
  343. timeout:5000,
  344. success:function(result){
  345. //sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  346. if (result) {
  347. if(result.data.length > 0){
  348. console.log(`enter1`);
  349. //sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  350. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  351. var rstArr = [], dummyR = {gljId: 0, consumeAmt:0}, newAddArr = [];
  352. for (var i = 0; i < result.data.length; i++) {
  353. dummyR.gljId = result.data[i].ID;
  354. rstArr.push(me.createRationGljDisplayItem(dummyR, result.data[i]));
  355. }
  356. if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
  357. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  358. for (var i = 0; i < rstArr.length; i++) {
  359. var hasDup = false;
  360. for (var j = 0; j < cacheArr.length; j++) {
  361. if (cacheArr[j].gljId == rstArr[i].gljId) {
  362. hasDup = true;
  363. break;
  364. }
  365. }
  366. if (!hasDup) {
  367. newAddArr.push(rstArr[i]);
  368. }
  369. }
  370. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(newAddArr);
  371. me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
  372. var rst = 0;
  373. if (a.code > b.code) rst = 1
  374. else if (a.code < b.code) rst = -1;
  375. return rst;
  376. });
  377. }
  378. me.showGljItems(me.currentRationItem.ID);
  379. if (newAddArr.length > 0) {
  380. me.updateRationItem();
  381. }
  382. }
  383. else{
  384. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID]? me.cache["_GLJ_" + me.currentRationItem.ID] : [];
  385. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(me.tempCacheArr);
  386. //更新的工料机不存在
  387. me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
  388. var rst = 0;
  389. if (a.code > b.code) rst = 1
  390. else if (a.code < b.code) rst = -1;
  391. return rst;
  392. });
  393. $('#alertModalBtn').click();
  394. $('#alertText').text("工料机"+ codes + "不存在,请查找你所需要的工料机,或新增工料机");
  395. me.sheet.options.isProtected = true;
  396. $('#alertModalCls').click(function () {
  397. sheetCommonObj.lockCells(me.sheet, me.setting);
  398. me.showGljItems(me.currentRationItem.ID);
  399. });
  400. $('#alertModalCof').click(function () {
  401. sheetCommonObj.lockCells(me.sheet, me.setting);
  402. me.showGljItems(me.currentRationItem.ID);
  403. })
  404. }
  405. }
  406. sheetCommonObj.lockCells(me.sheet, me.setting);
  407. sheetCommonObj.setLockCol(me.sheet, 0, false);
  408. },
  409. error:function(err){
  410. alert(err);
  411. }
  412. })
  413. },
  414. round(v, e){
  415. var t=1;
  416. for(;e>0;t*=10,e--);
  417. for(;e<0;t/=10,e++);
  418. return Math.round(v*t)/t;
  419. },
  420. rationCal: function () {
  421. let me = rationGLJOprObj;
  422. let price = {gljType1: [], gljType2: [], gljType3: []}, rst = {labourPrice: 0, materialPrice: 0, machinePrice: 0}, rationBasePrc = 0;
  423. if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
  424. let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
  425. cacheArr.forEach(function (gljData) {
  426. if(gljData.gljType && gljData.basePrice && gljData.consumeAmt){
  427. let parent = me.distTypeTree.distTypes[me.distTypeTree.prefix + gljData.gljType].parent;
  428. if(parent && parent.data.ID <= 3){
  429. price['gljType' + parent.data.ID].push(me.round( gljData.basePrice * gljData.consumeAmt, 3));//取三位
  430. }
  431. if(!parent && gljData.gljType <= 3){
  432. price['gljType' + gljData.gljType].push(me.round( gljData.basePrice * gljData.consumeAmt, 3));//取三位
  433. }
  434. }
  435. });
  436. if(price.gljType1.length > 0){
  437. let labourPrice = 0;
  438. price.gljType1.forEach(function (singlePrc) {
  439. labourPrice += singlePrc;
  440. });
  441. let roundPrice = me.round(labourPrice, 2);
  442. rst.labourPrice = roundPrice;
  443. rationBasePrc += roundPrice;
  444. }
  445. if(price.gljType2.length > 0){
  446. let materialPrice = 0;
  447. price.gljType2.forEach(function (singlePrc) {
  448. materialPrice += singlePrc;
  449. });
  450. let roundPrice = me.round(materialPrice, 2);
  451. rst.materialPrice = roundPrice;
  452. rationBasePrc += roundPrice;
  453. }
  454. if(price.gljType3.length > 0){
  455. let machinePrice = 0;
  456. price.gljType3.forEach(function (singlePrc) {
  457. machinePrice += singlePrc;
  458. });
  459. let roundPrice = me.round(machinePrice, 2);
  460. rst.machinePrice = roundPrice;
  461. rationBasePrc += roundPrice;
  462. }
  463. rst.rationBasePrc = rationBasePrc;
  464. }
  465. return rst;
  466. },
  467. updateRationItem: function() {
  468. var me = this, updateArr = [];
  469. if (me.currentRationItem) {
  470. me.currentRationItem.rationGljList = me.buildRationItemGlj();
  471. //recalculate ration basePrice
  472. let price = me.rationCal();
  473. me.currentRationItem.labourPrice = price.labourPrice;
  474. me.currentRationItem.materialPrice = price.materialPrice;
  475. me.currentRationItem.machinePrice = price.machinePrice;
  476. me.currentRationItem.basePrice = price.rationBasePrc;
  477. updateArr.push(me.currentRationItem);
  478. rationOprObj.mixUpdateRequest(updateArr, [], []);
  479. }
  480. },
  481. buildRationItemGlj: function(){
  482. var me = this, rst = [];
  483. if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
  484. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  485. for (var i = 0; i < cacheArr.length; i++) {
  486. rst.push({gljId: cacheArr[i].gljId, consumeAmt: cacheArr[i].consumeAmt, proportion: 0});
  487. }
  488. }
  489. return rst;
  490. },
  491. createRationGljDisplayItem: function(rItem, repGlj) {
  492. var rst = {};
  493. rst.gljId = rItem.gljId;
  494. rst.consumeAmt = rItem.consumeAmt;
  495. rst.code = repGlj.code;
  496. rst.name = repGlj.name;
  497. rst.specs = repGlj.specs;
  498. rst.unit = repGlj.unit;
  499. rst.basePrice = repGlj.basePrice;
  500. rst.gljType = repGlj.gljType;
  501. return rst;
  502. },
  503. getGljItems: function(rationItem, callback) {
  504. var me = this, rationID = rationItem.ID, rationGljList = rationItem.rationGljList;
  505. me.currentRationItem = rationItem;
  506. if (me.cache["_GLJ_" + rationID]) {
  507. me.showGljItems(rationID);
  508. sheetCommonObj.lockCells(me.sheet, me.setting);
  509. } else {
  510. var gljIds = [];
  511. for (var i = 0; i < rationGljList.length; i++) {
  512. gljIds.push(rationGljList[i].gljId);
  513. }
  514. $.ajax({
  515. type:"POST",
  516. url:"api/getGljItemsByIds",
  517. data:{"gljIds": JSON.stringify(gljIds)},
  518. dataType:"json",
  519. cache:false,
  520. timeout:5000,
  521. success:function(result){
  522. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  523. if (result) {
  524. var cacheArr = [];
  525. for (var i = 0; i < result.data.length; i++) {
  526. for (var j = 0; j < rationGljList.length; j++) {
  527. if (rationGljList[j].gljId == result.data[i].ID) {
  528. cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], result.data[i]));
  529. break;
  530. }
  531. }
  532. }
  533. function compare(){
  534. return function (a, b) {
  535. let rst = 0;
  536. if (a.code > b.code) {
  537. rst = 1;
  538. }
  539. else if (a.code < b.code) {
  540. rst = -1;
  541. }
  542. return rst;
  543. }
  544. }
  545. cacheArr.sort(compare());
  546. me.cache["_GLJ_" + rationID] = cacheArr;
  547. me.showGljItems(rationID);
  548. }
  549. sheetCommonObj.lockCells(me.sheet, me.setting);
  550. callback();
  551. },
  552. error:function(err){
  553. alert(err);
  554. }
  555. })
  556. }
  557. },
  558. showGljItems: function(rationID) {
  559. var me = this;
  560. if (me.cache["_GLJ_" + rationID]) {
  561. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  562. sheetCommonObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
  563. //lock
  564. me.sheet.suspendPaint();
  565. me.sheet.suspendEvent();
  566. for(let i = 0, len = me.sheet.getRowCount(); i < len; i++){
  567. me.sheet.getCell(i, 4).locked(true);
  568. }
  569. me.sheet.resumePaint();
  570. me.sheet.resumeEvent();
  571. }
  572. }
  573. }