ration_glj.js 27 KB

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