ration_glj.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. let sels = me.sheet.getSelections(), 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 && sels[sel].row < cacheSection.length){
  99. isUpdate = true;
  100. cacheSection.splice(sels[sel].row, sels[sel].rowCount);
  101. }
  102. }
  103. else{
  104. if(sels[sel].col !== 0 && sels[sel].col !== 5 && !(sels[sel].col === 1 && sels.col + sels[sel].colCount -1 === 3)){
  105. if(cacheSection){
  106. for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
  107. if(sels[sel].row + i < cacheSection.length){
  108. for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
  109. if(lockCols.indexOf(col) === -1){
  110. isUpdate = true;
  111. cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = 0;
  112. me.sheet.setValue(sels[sel].row + i, col, 0.00);
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. if(isUpdate){
  123. me.updateRationItem(function () {
  124. me.sheet.getParent().focus(true);
  125. });
  126. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  127. me.showGljItems(me.currentRationItem.ID);
  128. }
  129. });
  130. spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  131. spreadBook.commandManager().setShortcutKey('rationGljDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  132. },
  133. onClipboardPasting: function(sender, args) {
  134. var me = rationGLJOprObj;
  135. let rationSection = rationOprObj.getCache();
  136. let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  137. me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
  138. if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
  139. me.cache["_GLJ_" + me.currentRationItem.ID] = [];
  140. }
  141. if (!(args.cellRange.col === 0 || args.cellRange.col === 5) || !(me.currentRationItem)) {
  142. args.cancel = true;
  143. }
  144. },
  145. onClipboardPasted: function(e, info) {
  146. var me = rationGLJOprObj, repId = storageUtil.getSessionCache("RationGrp","repositoryID");
  147. me.tempCacheArr = [];
  148. if (repId) {
  149. let gljLibId = storageUtil.getSessionCache("gljLib", "repositoryID_" + repId);
  150. if(gljLibId){
  151. if (info.cellRange.col == 0) {
  152. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  153. var tmpCodes = sheetCommonObj.analyzePasteData({header:[{dataCode: "code"}] }, info);
  154. var codes = [];
  155. for (var i = 0; i < tmpCodes.length; i++) {
  156. let rowIdx = info.cellRange.row + i;
  157. if(rowIdx < cacheArr.length){//更新
  158. me.tempCacheArr.push({org: cacheArr[rowIdx], newCode: tmpCodes[i].code});
  159. cacheArr.splice(rowIdx--, 1);
  160. }
  161. codes.push(tmpCodes[i].code);
  162. }
  163. me.addGljItems(codes, gljLibId, info.cellRange);
  164. } else {
  165. //修改用量
  166. if(me.cache["_GLJ_" + me.currentRationItem.ID] && info.cellRange.row < me.cache["_GLJ_" + me.currentRationItem.ID].length){
  167. let tempConsumes = sheetCommonObj.analyzePasteData(me.setting, info);
  168. let maxCount = info.cellRange.row + info.cellRange.rowCount -1 > me.cache["_GLJ_" + me.currentRationItem.ID].length -1 ?
  169. me.cache["_GLJ_" + me.currentRationItem.ID].length - info.cellRange.row : info.cellRange.rowCount;
  170. for(let i = 0; i < maxCount; i++){
  171. let roundCons = me.round(tempConsumes[i].consumeAmt, 3);
  172. me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = roundCons;
  173. }
  174. me.updateRationItem(function () {
  175. me.sheet.getParent().focus(true);
  176. });
  177. if(info.cellRange.row + info.cellRange.rowCount -1 >= me.cache["_GLJ_" + me.currentRationItem.ID].length -1){
  178. me.sheet.suspendPaint();
  179. for(let rowIdx = me.cache["_GLJ_" + me.currentRationItem.ID].length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
  180. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  181. }
  182. me.sheet.resumePaint();
  183. }
  184. }
  185. else if(info.cellRange.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
  186. me.sheet.suspendPaint();
  187. for(let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx ++){
  188. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  189. }
  190. me.sheet.resumePaint();
  191. }
  192. }
  193. }
  194. }
  195. },
  196. onEditStarting: function (sender, args) {
  197. let me = rationGLJOprObj;
  198. let rationSection = rationOprObj.getCache();
  199. let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  200. me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
  201. if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
  202. me.cache["_GLJ_" + me.currentRationItem.ID] = [];
  203. }
  204. if(!me.currentRationItem){
  205. args.cancel = true;
  206. }
  207. else {
  208. if(args.col !== 0 && args.col !== 5 || args.col === 5 && args.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
  209. args.cancel = true;
  210. }
  211. }
  212. },
  213. onCellEditEnd: function(sender, args){
  214. var me = rationGLJOprObj;
  215. if(me.currentRationItem) {
  216. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  217. me.tempCacheArr = [];
  218. if (args.col != 0) {
  219. if (args.row < cacheArr.length) {
  220. var editGlj = cacheArr[args.row];
  221. if (editGlj["consumeAmt"] != args.editingText) {
  222. let parseNum = parseFloat(args.editingText);
  223. if (isNaN(parseFloat(args.editingText))) {
  224. $('#alertModalBtn').click();
  225. $('#alertText').text("定额消耗只能输入数值!");
  226. $('#alertModalCls').click(function () {
  227. args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
  228. });
  229. $('#alertModalCof').click(function () {
  230. args.sheet.setValue(args.row, args.col, editGlj['consumeAmt']);
  231. })
  232. }
  233. else {
  234. args.sheet.setValue(args.row, args.col, parseNum);
  235. let roundNum = me.round(parseNum, 3);
  236. editGlj["consumeAmt"] = roundNum;
  237. me.updateRationItem(function () {
  238. me.sheet.getParent().focus(true);
  239. });
  240. }
  241. }
  242. }
  243. } else {
  244. if (args.editingText && args.editingText.toString().trim().length !== 0) {
  245. let isExist = false;
  246. for (let i = 0, len = cacheArr.length; i < len; i++) {
  247. if (cacheArr[i].code === args.editingText && i !== args.row) {
  248. isExist = true;
  249. break;
  250. }
  251. }
  252. if (isExist) {
  253. alert("该工料机已存在!");
  254. args.sheet.setValue(args.row, args.col, typeof cacheArr[args.row] !== 'undefined' ? cacheArr[args.row].code + '' : '');
  255. }
  256. else {
  257. if (args.row < cacheArr.length && args.editingText !== cacheArr[args.row].code) {//更新
  258. me.tempCacheArr.push({org: cacheArr[args.row], newCode: args.editingText.toString().trim()});
  259. cacheArr.splice(args.row, 1);
  260. let rationRepId = storageUtil.getSessionCache("RationGrp", "repositoryID");
  261. let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
  262. let codes = [];
  263. codes.push(args.editingText.toString().trim());
  264. me.addGljItems(codes, gljLibID, args);
  265. }
  266. else if (args.row >= cacheArr.length) {//新增
  267. let rationRepId = storageUtil.getSessionCache("RationGrp", "repositoryID");
  268. let gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + rationRepId);
  269. if (gljLibID) {
  270. var codes = [];
  271. codes.push(args.editingText.toString().trim());
  272. me.addGljItems(codes, gljLibID, args);
  273. }
  274. }
  275. }
  276. }
  277. else {
  278. args.sheet.setValue(args.row, args.col, args.row < cacheArr.length ? cacheArr[args.row].code : '');
  279. }
  280. }
  281. }
  282. else {
  283. args.sheet.setValue(args.row, args.col, '');
  284. }
  285. },
  286. onContextmenuOpr: function () {
  287. let me = rationGLJOprObj;
  288. $.contextMenu({
  289. selector: '#rdSpread',
  290. build: function ($triggerElement, e) {
  291. //控制允许右键菜单在哪个位置出现
  292. let sheet = me.sheet;
  293. let offset = $triggerElement.offset(),
  294. x = e.pageX - offset.left,
  295. y = e.pageY - offset.top;
  296. let target = sheet.hitTest(x, y);
  297. if(sheet.parent.getActiveSheetIndex() === 0 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){
  298. let delDis = true, cacheSection;
  299. sheet.setActiveCell(target.row, target.col);
  300. if(me.currentRationItem){
  301. let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID];
  302. if(target.row < cacheSection.length){
  303. delDis = false;
  304. }
  305. }
  306. return {
  307. callback: function(key, options) {
  308. },
  309. items: {
  310. "delete": {name: "删除", icon: 'fa-remove', disabled: delDis, callback: function (key, opt) {
  311. cacheSection.splice(target.row, 1);
  312. me.updateRationItem(function () {
  313. me.sheet.getParent().focus(true);
  314. });
  315. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  316. me.showGljItems(me.currentRationItem.ID);
  317. }}
  318. }
  319. };
  320. }
  321. else{
  322. return false;
  323. }
  324. }
  325. });
  326. },
  327. getRecoveryArr: function (tempDelArr, newArr) {//获得更新的code不存在,恢复删除的被更新数据
  328. let rst = [];
  329. for(let i = 0, len = tempDelArr.length; i < len; i++){
  330. let isExist = false;
  331. for(let j = 0, jLen = newArr.length; j < jLen; j++){
  332. if(tempDelArr[i].newCode == newArr[j].code){
  333. isExist = true;
  334. break;
  335. }
  336. }
  337. if(!isExist){
  338. rst.push(tempDelArr[i].org);
  339. }
  340. }
  341. return rst;
  342. },
  343. addGljItems: function(codes, repId, args) {
  344. var me = this;
  345. $.ajax({
  346. type:"POST",
  347. url:"api/getGljItemsByCodes",
  348. data:{"gljCodes": JSON.stringify(codes), repId: repId},
  349. dataType:"json",
  350. cache:false,
  351. timeout:5000,
  352. success:function(result){
  353. if (result) {
  354. if(result.data.length > 0){
  355. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  356. var rstArr = [], dummyR = {gljId: 0, consumeAmt:0}, newAddArr = [];
  357. for (var i = 0; i < result.data.length; i++) {
  358. dummyR.gljId = result.data[i].ID;
  359. rstArr.push(me.createRationGljDisplayItem(dummyR, result.data[i]));
  360. }
  361. if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
  362. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  363. for (var i = 0; i < rstArr.length; i++) {
  364. var hasDup = false;
  365. for (var j = 0; j < cacheArr.length; j++) {
  366. if (cacheArr[j].gljId == rstArr[i].gljId) {
  367. hasDup = true;
  368. break;
  369. }
  370. }
  371. if (!hasDup) {
  372. newAddArr.push(rstArr[i]);
  373. }
  374. }
  375. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(newAddArr);
  376. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, result.data);
  377. if(recoveryArr.length > 0){
  378. me.cache["_GLJ_" + me.currentRationItem.ID] = me.cache["_GLJ_" + me.currentRationItem.ID].concat(recoveryArr);
  379. }
  380. me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
  381. var rst = 0;
  382. if (a.code > b.code) rst = 1
  383. else if (a.code < b.code) rst = -1;
  384. return rst;
  385. });
  386. }
  387. me.showGljItems(me.currentRationItem.ID);
  388. if (newAddArr.length > 0) {
  389. me.updateRationItem(function () {
  390. me.sheet.getParent().focus(true);
  391. });
  392. }
  393. }
  394. else{
  395. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID]? me.cache["_GLJ_" + me.currentRationItem.ID] : [];
  396. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, []);
  397. if(recoveryArr.length > 0){
  398. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(recoveryArr);
  399. }
  400. //更新的工料机不存在
  401. me.cache["_GLJ_" + me.currentRationItem.ID].sort(function(a, b) {
  402. var rst = 0;
  403. if (a.code > b.code) rst = 1
  404. else if (a.code < b.code) rst = -1;
  405. return rst;
  406. });
  407. $('#alertModalBtn').click();
  408. $('#alertText').text("工料机"+ codes + "不存在,请查找你所需要的工料机,或新增工料机");
  409. $('#alertModalCls').click(function () {
  410. me.showGljItems(me.currentRationItem.ID);
  411. });
  412. $('#alertModalCof').click(function () {
  413. me.showGljItems(me.currentRationItem.ID);
  414. })
  415. }
  416. }
  417. },
  418. error:function(err){
  419. alert(err);
  420. }
  421. })
  422. },
  423. round(v, e){
  424. var t=1;
  425. for(;e>0;t*=10,e--);
  426. for(;e<0;t/=10,e++);
  427. return Math.round(v*t)/t;
  428. },
  429. rationCal: function () {
  430. let me = rationGLJOprObj;
  431. let price = {gljType1: [], gljType2: [], gljType3: []}, rst = {labourPrice: 0, materialPrice: 0, machinePrice: 0}, rationBasePrc = 0;
  432. if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
  433. let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
  434. cacheArr.forEach(function (gljData) {
  435. if(gljData.gljType && gljData.basePrice && gljData.consumeAmt){
  436. let parent = me.distTypeTree.distTypes[me.distTypeTree.prefix + gljData.gljType].parent;
  437. if(parent && parent.data.ID <= 3){
  438. price['gljType' + parent.data.ID].push(me.round( gljData.basePrice * gljData.consumeAmt, 3));//取三位
  439. }
  440. if(!parent && gljData.gljType <= 3){
  441. price['gljType' + gljData.gljType].push(me.round( gljData.basePrice * gljData.consumeAmt, 3));//取三位
  442. }
  443. }
  444. });
  445. if(price.gljType1.length > 0){
  446. let labourPrice = 0;
  447. price.gljType1.forEach(function (singlePrc) {
  448. labourPrice += singlePrc;
  449. });
  450. let roundPrice = me.round(labourPrice, 2);
  451. rst.labourPrice = roundPrice;
  452. rationBasePrc += roundPrice;
  453. }
  454. if(price.gljType2.length > 0){
  455. let materialPrice = 0;
  456. price.gljType2.forEach(function (singlePrc) {
  457. materialPrice += singlePrc;
  458. });
  459. let roundPrice = me.round(materialPrice, 2);
  460. rst.materialPrice = roundPrice;
  461. rationBasePrc += roundPrice;
  462. }
  463. if(price.gljType3.length > 0){
  464. let machinePrice = 0;
  465. price.gljType3.forEach(function (singlePrc) {
  466. machinePrice += singlePrc;
  467. });
  468. let roundPrice = me.round(machinePrice, 2);
  469. rst.machinePrice = roundPrice;
  470. rationBasePrc += roundPrice;
  471. }
  472. rst.rationBasePrc = rationBasePrc;
  473. }
  474. return rst;
  475. },
  476. updateRationItem: function(callback) {
  477. var me = this, updateArr = [];
  478. if (me.currentRationItem) {
  479. me.currentRationItem.rationGljList = me.buildRationItemGlj();
  480. //recalculate ration basePrice
  481. let price = me.rationCal();
  482. me.currentRationItem.labourPrice = price.labourPrice;
  483. me.currentRationItem.materialPrice = price.materialPrice;
  484. me.currentRationItem.machinePrice = price.machinePrice;
  485. me.currentRationItem.basePrice = price.rationBasePrc;
  486. updateArr.push(me.currentRationItem);
  487. rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
  488. if(callback) callback();
  489. });
  490. }
  491. },
  492. buildRationItemGlj: function(){
  493. var me = this, rst = [];
  494. if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
  495. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  496. for (var i = 0; i < cacheArr.length; i++) {
  497. rst.push({gljId: cacheArr[i].gljId, consumeAmt: cacheArr[i].consumeAmt, proportion: 0});
  498. }
  499. }
  500. return rst;
  501. },
  502. createRationGljDisplayItem: function(rItem, repGlj) {
  503. var rst = {};
  504. rst.gljId = rItem.gljId;
  505. rst.consumeAmt = rItem.consumeAmt;
  506. rst.code = repGlj.code;
  507. rst.name = repGlj.name;
  508. rst.specs = repGlj.specs;
  509. rst.unit = repGlj.unit;
  510. rst.basePrice = repGlj.basePrice;
  511. rst.gljType = repGlj.gljType;
  512. return rst;
  513. },
  514. getGljItems: function(rationItem, callback) {
  515. var me = this, rationID = rationItem.ID, rationGljList = rationItem.rationGljList;
  516. me.currentRationItem = rationItem;
  517. if (me.cache["_GLJ_" + rationID]) {
  518. me.showGljItems(rationID);
  519. } else {
  520. var gljIds = [];
  521. for (var i = 0; i < rationGljList.length; i++) {
  522. gljIds.push(rationGljList[i].gljId);
  523. }
  524. $.ajax({
  525. type:"POST",
  526. url:"api/getGljItemsByIds",
  527. data:{"gljIds": JSON.stringify(gljIds)},
  528. dataType:"json",
  529. cache:false,
  530. timeout:5000,
  531. success:function(result){
  532. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  533. if (result) {
  534. var cacheArr = [];
  535. for (var i = 0; i < result.data.length; i++) {
  536. for (var j = 0; j < rationGljList.length; j++) {
  537. if (rationGljList[j].gljId == result.data[i].ID) {
  538. cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], result.data[i]));
  539. break;
  540. }
  541. }
  542. }
  543. function compare(){
  544. return function (a, b) {
  545. let rst = 0;
  546. if (a.code > b.code) {
  547. rst = 1;
  548. }
  549. else if (a.code < b.code) {
  550. rst = -1;
  551. }
  552. return rst;
  553. }
  554. }
  555. cacheArr.sort(compare());
  556. me.cache["_GLJ_" + rationID] = cacheArr;
  557. me.showGljItems(rationID);
  558. }
  559. if(callback) callback();
  560. },
  561. error:function(err){
  562. alert(err);
  563. }
  564. })
  565. }
  566. },
  567. showGljItems: function(rationID) {
  568. var me = this;
  569. if (me.cache["_GLJ_" + rationID]) {
  570. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  571. sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
  572. }
  573. }
  574. }