ration_glj.js 26 KB

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