ration_glj.js 28 KB

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