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. 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.bindRationGljDelOpr();
  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.EditStarting, me.onEditStarting);
  87. me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  88. });
  89. },
  90. bindRationGljDelOpr: function () {
  91. let me = rationGLJOprObj, spreadBook = me.sheet.getParent();
  92. spreadBook.commandManager().register('rationGljDelete', function () {
  93. if(!me.currentRationItem || me.currentRationItem.type === rationOprObj.type.std){
  94. return;
  95. }
  96. let sels = me.sheet.getSelections(), lockCols = me.setting.view.lockColumns;
  97. let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID], isUpdate = false;
  98. if(sels.length > 0){
  99. for(let sel = 0; sel < sels.length; sel++){
  100. if(sels[sel].colCount === me.setting.header.length){
  101. if(cacheSection && sels[sel].row < cacheSection.length){
  102. isUpdate = true;
  103. cacheSection.splice(sels[sel].row, sels[sel].rowCount);
  104. }
  105. }
  106. else{
  107. if(sels[sel].col !== 0 && sels[sel].col !== 5 && !(sels[sel].col === 1 && sels.col + sels[sel].colCount -1 === 3)){
  108. if(cacheSection){
  109. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  110. if(sels[sel].row + i < cacheSection.length){
  111. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  112. if(lockCols.indexOf(col) === -1){
  113. isUpdate = true;
  114. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = 0;
  115. me.sheet.setValue(sels[sel].row + i, col, 0.00);
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. if(isUpdate){
  126. me.updateRationItem(function () {
  127. me.sheet.getParent().focus(true);
  128. });
  129. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  130. me.showGljItems(me.currentRationItem.ID);
  131. }
  132. });
  133. spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  134. spreadBook.commandManager().setShortcutKey('rationGljDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  135. },
  136. onClipboardPasting: function(sender, args) {
  137. var me = rationGLJOprObj;
  138. let rationSection = rationOprObj.getCache();
  139. let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  140. me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
  141. if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
  142. me.cache["_GLJ_" + me.currentRationItem.ID] = [];
  143. }
  144. if (!(args.cellRange.col === 0 || args.cellRange.col === 5) || !(me.currentRationItem) || (me.currentRationItem && me.currentRationItem.type === rationOprObj.type.std)) {
  145. args.cancel = true;
  146. }
  147. },
  148. onClipboardPasted: function(e, info) {
  149. var me = rationGLJOprObj, repId = pageOprObj.rationLibId;
  150. me.tempCacheArr = [];
  151. if (repId) {
  152. let gljLibId = pageOprObj.gljLibId;
  153. console.log(gljLibId);
  154. if(gljLibId){
  155. if (info.cellRange.col == 0) {
  156. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  157. var tmpCodes = sheetCommonObj.analyzePasteData({header:[{dataCode: "code"}] }, info);
  158. var codes = [];
  159. for (var i = 0; i < tmpCodes.length; i++) {
  160. let rowIdx = info.cellRange.row + i;
  161. if(rowIdx < cacheArr.length){//更新
  162. me.tempCacheArr.push({org: cacheArr[rowIdx], newCode: tmpCodes[i].code});
  163. cacheArr.splice(rowIdx--, 1);
  164. }
  165. codes.push(tmpCodes[i].code);
  166. }
  167. me.addGljItems(codes, gljLibId, info.cellRange);
  168. } else {
  169. //修改用量
  170. if(me.cache["_GLJ_" + me.currentRationItem.ID] && info.cellRange.row < me.cache["_GLJ_" + me.currentRationItem.ID].length){
  171. let tempConsumes = sheetCommonObj.analyzePasteData(me.setting, info);
  172. let maxCount = info.cellRange.row + info.cellRange.rowCount -1 > me.cache["_GLJ_" + me.currentRationItem.ID].length -1 ?
  173. me.cache["_GLJ_" + me.currentRationItem.ID].length - info.cellRange.row : info.cellRange.rowCount;
  174. for(let i = 0; i < maxCount; i++){
  175. let roundCons = scMathUtil.roundTo(tempConsumes[i].consumeAmt, -3);
  176. me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = roundCons;
  177. }
  178. me.updateRationItem(function () {
  179. me.sheet.getParent().focus(true);
  180. });
  181. if(info.cellRange.row + info.cellRange.rowCount -1 >= me.cache["_GLJ_" + me.currentRationItem.ID].length -1){
  182. me.sheet.suspendPaint();
  183. for(let rowIdx = me.cache["_GLJ_" + me.currentRationItem.ID].length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
  184. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  185. }
  186. me.sheet.resumePaint();
  187. }
  188. }
  189. else if(info.cellRange.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
  190. me.sheet.suspendPaint();
  191. for(let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx ++){
  192. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  193. }
  194. me.sheet.resumePaint();
  195. }
  196. }
  197. }
  198. }
  199. },
  200. onEditStarting: function (sender, args) {
  201. let me = rationGLJOprObj;
  202. let rationSection = rationOprObj.getCache();
  203. let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  204. me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
  205. if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
  206. me.cache["_GLJ_" + me.currentRationItem.ID] = [];
  207. }
  208. if(!me.currentRationItem){
  209. args.cancel = true;
  210. }
  211. else {
  212. if(args.col !== 0 && args.col !== 5 || args.col === 5 && args.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length
  213. || me.currentRationItem.type === rationOprObj.type.std){
  214. args.cancel = true;
  215. }
  216. }
  217. },
  218. onCellEditEnd: function(sender, args){
  219. var me = rationGLJOprObj;
  220. if(me.currentRationItem) {
  221. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  222. me.tempCacheArr = [];
  223. if (args.col != 0) {
  224. if (args.row < cacheArr.length) {
  225. var editGlj = cacheArr[args.row];
  226. if (editGlj["consumeAmt"] != args.editingText) {
  227. let parseNum = parseFloat(args.editingText);
  228. if (isNaN(parseFloat(args.editingText))) {
  229. $('#alertModalBtn').click();
  230. $('#alertText').text("定额消耗只能输入数值!");
  231. $('#alertModalCls').click(function () {
  232. args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
  233. });
  234. $('#alertModalCof').click(function () {
  235. args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
  236. })
  237. }
  238. else {
  239. args.sheet.setValue(args.row, args.col, parseNum);
  240. let roundNum = scMathUtil.roundTo(parseNum, -3);
  241. editGlj["consumeAmt"] = roundNum;
  242. me.updateRationItem(function () {
  243. me.sheet.getParent().focus(true);
  244. });
  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. me.tempCacheArr.push({org: cacheArr[args.row], newCode: args.editingText.toString().trim()});
  264. cacheArr.splice(args.row, 1);
  265. let gljLibID = pageOprObj.gljLibId;
  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 gljLibID = pageOprObj.gljLibId;
  272. if (gljLibID) {
  273. var codes = [];
  274. codes.push(args.editingText.toString().trim());
  275. me.addGljItems(codes, gljLibID, args);
  276. }
  277. }
  278. }
  279. }
  280. else {
  281. args.sheet.setValue(args.row, args.col, args.row < cacheArr.length ? cacheArr[args.row].code : '');
  282. }
  283. }
  284. }
  285. else {
  286. args.sheet.setValue(args.row, args.col, '');
  287. }
  288. },
  289. onContextmenuOpr: function () {
  290. let me = rationGLJOprObj;
  291. $.contextMenu({
  292. selector: '#rdSpread',
  293. build: function ($triggerElement, e) {
  294. //控制允许右键菜单在哪个位置出现
  295. let sheet = me.sheet;
  296. let offset = $triggerElement.offset(),
  297. x = e.pageX - offset.left,
  298. y = e.pageY - offset.top;
  299. let target = sheet.hitTest(x, y);
  300. if(sheet.parent.getActiveSheetIndex() === 0 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){
  301. let delDis = true, cacheSection;
  302. sheet.setActiveCell(target.row, target.col);
  303. if(me.currentRationItem){
  304. let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID];
  305. if(target.row < cacheSection.length){
  306. delDis = false;
  307. }
  308. }
  309. return {
  310. callback: function(key, options) {
  311. },
  312. items: {
  313. "delete": {name: "删除", icon: 'fa-remove', disabled: delDis, callback: function (key, opt) {
  314. cacheSection.splice(target.row, 1);
  315. me.updateRationItem(function () {
  316. me.sheet.getParent().focus(true);
  317. });
  318. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  319. me.showGljItems(me.currentRationItem.ID);
  320. }}
  321. }
  322. };
  323. }
  324. else{
  325. return false;
  326. }
  327. }
  328. });
  329. },
  330. getRecoveryArr: function (tempDelArr, newArr) {//获得更新的code不存在,恢复删除的被更新数据
  331. let rst = [];
  332. for(let i = 0, len = tempDelArr.length; i < len; i++){
  333. let isExist = false;
  334. for(let j = 0, jLen = newArr.length; j < jLen; j++){
  335. if(tempDelArr[i].newCode == newArr[j].code){
  336. isExist = true;
  337. break;
  338. }
  339. }
  340. if(!isExist){
  341. rst.push(tempDelArr[i].org);
  342. }
  343. }
  344. return rst;
  345. },
  346. addGljItems: function(codes, repId, args) {
  347. let me = this;
  348. CommonAjax.post('api/getGljItemsByCodes', {gljCodes: codes, rationRepId: repId}, function (rstData) {
  349. if(rstData.length > 0){
  350. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  351. let rstArr = [], dummyR = {gljId: 0, consumeAmt:0}, newAddArr = [];
  352. for (let i = 0; i < rstData.length; i++) {
  353. dummyR.gljId = rstData[i].ID;
  354. dummyR.type = rstData[i].type;
  355. rstArr.push(me.createRationGljDisplayItem(dummyR, rstData[i]));
  356. }
  357. if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
  358. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  359. for (var i = 0; i < rstArr.length; i++) {
  360. var hasDup = false;
  361. for (var j = 0; j < cacheArr.length; j++) {
  362. if (cacheArr[j].gljId == rstArr[i].gljId) {
  363. hasDup = true;
  364. break;
  365. }
  366. }
  367. if (!hasDup) {
  368. newAddArr.push(rstArr[i]);
  369. }
  370. }
  371. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(newAddArr);
  372. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, rstData);
  373. if(recoveryArr.length > 0){
  374. me.cache["_GLJ_" + me.currentRationItem.ID] = me.cache["_GLJ_" + me.currentRationItem.ID].concat(recoveryArr);
  375. }
  376. me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
  377. var rst = 0;
  378. if (a.code > b.code) rst = 1
  379. else if (a.code < b.code) rst = -1;
  380. return rst;
  381. });
  382. }
  383. me.showGljItems(me.currentRationItem.ID);
  384. if (newAddArr.length > 0) {
  385. me.updateRationItem(function () {
  386. me.sheet.getParent().focus(true);
  387. });
  388. }
  389. }
  390. else{
  391. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID]? me.cache["_GLJ_" + me.currentRationItem.ID] : [];
  392. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, []);
  393. if(recoveryArr.length > 0){
  394. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(recoveryArr);
  395. }
  396. //更新的工料机不存在
  397. me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
  398. var rst = 0;
  399. if (a.code > b.code) rst = 1
  400. else if (a.code < b.code) rst = -1;
  401. return rst;
  402. });
  403. $('#alertModalBtn').click();
  404. $('#alertText').text("工料机"+ codes + "不存在,请查找你所需要的工料机,或新增工料机");
  405. $('#alertModalCls').click(function () {
  406. me.showGljItems(me.currentRationItem.ID);
  407. });
  408. $('#alertModalCof').click(function () {
  409. me.showGljItems(me.currentRationItem.ID);
  410. })
  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(scMathUtil.roundTo( gljData.basePrice * gljData.consumeAmt, -3));//取三位
  430. }
  431. if(!parent && gljData.gljType <= 3){
  432. price['gljType' + gljData.gljType].push(scMathUtil.roundTo( 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 = scMathUtil.roundTo(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 = scMathUtil.roundTo(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 = scMathUtil.roundTo(machinePrice, -2);
  460. rst.machinePrice = roundPrice;
  461. rationBasePrc += roundPrice;
  462. }
  463. rst.rationBasePrc = rationBasePrc;
  464. }
  465. return rst;
  466. },
  467. updateRationItem: function(callback) {
  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, [], [], function () {
  479. if(callback) callback();
  480. });
  481. }
  482. },
  483. buildRationItemGlj: function(){
  484. var me = this, rst = [];
  485. console.log(me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]);
  486. if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
  487. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  488. for (var i = 0; i < cacheArr.length; i++) {
  489. rst.push({gljId: cacheArr[i].gljId, consumeAmt: cacheArr[i].consumeAmt, type: cacheArr[i].type});
  490. }
  491. }
  492. return rst;
  493. },
  494. createRationGljDisplayItem: function(rItem, repGlj) {
  495. var rst = {};
  496. rst.gljId = rItem.gljId;
  497. rst.type = rItem.type;
  498. rst.consumeAmt = rItem.consumeAmt;
  499. rst.code = repGlj.code;
  500. rst.name = repGlj.name;
  501. rst.specs = repGlj.specs;
  502. rst.unit = repGlj.unit;
  503. rst.basePrice = repGlj.basePrice;
  504. rst.gljType = repGlj.gljType;
  505. return rst;
  506. },
  507. getGljItems: function(rationItem, callback) {
  508. let me = this, rationID = rationItem.ID, rationGljList = rationItem.rationGljList, rationType = rationItem.type;
  509. me.currentRationItem = rationItem;
  510. if (me.cache["_GLJ_" + rationID]) {
  511. me.showGljItems(rationID);
  512. } else {
  513. let gljIds = [];
  514. for (let i = 0; i < rationGljList.length; i++) {
  515. let idObj = Object.create(null);
  516. idObj.type = rationType === rationOprObj.type.std ? rationOprObj.type.std : rationGljList[i].type;
  517. idObj.id = rationGljList[i].gljId;
  518. gljIds.push(idObj);
  519. }
  520. CommonAjax.post('api/getGljItemsByIds', {ids: gljIds}, function (rstData) {
  521. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  522. var cacheArr = [];
  523. for (let i = 0; i < rstData.length; i++) {
  524. for (let j = 0; j < rationGljList.length; j++) {
  525. if (rationGljList[j].gljId == rstData[i].ID) {
  526. cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], rstData[i]));
  527. break;
  528. }
  529. }
  530. }
  531. function compare(){
  532. return function (a, b) {
  533. let rst = 0;
  534. if (a.code > b.code) {
  535. rst = 1;
  536. }
  537. else if (a.code < b.code) {
  538. rst = -1;
  539. }
  540. return rst;
  541. }
  542. }
  543. cacheArr.sort(compare());
  544. me.cache["_GLJ_" + rationID] = cacheArr;
  545. me.showGljItems(rationID);
  546. if(callback) callback();
  547. });
  548. }
  549. },
  550. showGljItems: function(rationID) {
  551. var me = this;
  552. if (me.cache["_GLJ_" + rationID]) {
  553. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  554. sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
  555. }
  556. }
  557. }