ration_glj.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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:80,dataCode:"code", dataType: "String", formatter: "@"},
  15. {headerName:"名称",headerWidth:160,dataCode:"name", dataType: "String"},
  16. {headerName:"规格型号",headerWidth:100,dataCode:"specs", dataType: "String"},
  17. {headerName:"单位",headerWidth:60,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
  18. {headerName:"定额价",headerWidth:80, dataCode:"basePrice", dataType: "Number", formatter:"0.00", precision: 2},
  19. {headerName:"定额消耗",headerWidth:80, dataCode:"consumeAmt", dataType: "Number", formatter: "0.000", precision: 3},
  20. {headerName:"类型",headerWidth:70,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"},
  21. {headerName:"配合比",headerWidth:70,dataCode:"proportion", dataType: "Number", formatter:"0.00", precision: 2}
  22. ],
  23. view:{
  24. comboBox:[],
  25. lockColumns:[1,2,3,4,6]
  26. }
  27. },
  28. getDistTypeTree: function (gljDistType) {
  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. initGljDistType: function (gljDistTypeList) {
  65. this.distTypeTree = this.getDistTypeTree(gljDistTypeList);
  66. },
  67. buildSheet: function(sheet) {
  68. this.sheet = sheet;
  69. sheetCommonObj.initSheet(this.sheet, this.setting, 30);
  70. this.onContextmenuOpr();
  71. this.bindRationGljDelOpr();
  72. this.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, this.onClipboardPasting);
  73. this.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, this.onClipboardPasted);
  74. this.sheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onEditStarting);
  75. this.sheet.bind(GC.Spread.Sheets.Events.EditEnded, this.onCellEditEnd);
  76. },
  77. bindRationGljDelOpr: function () {
  78. const me = rationGLJOprObj;
  79. const spreadBook = me.sheet.getParent();
  80. spreadBook.commandManager().register('rationGljDelete', function () {
  81. const cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID];
  82. const sels = me.sheet.getSelections();
  83. if (!cacheSection || !sels.length) {
  84. return;
  85. }
  86. let isUpdate = false;
  87. for (const sel of sels) {
  88. const deleteRow = sel.colCount === me.setting.header.length && sel.row < cacheSection.length;
  89. if (deleteRow) {
  90. isUpdate = true;
  91. cacheSection.splice(sel.row, sel.rowCount);
  92. }
  93. }
  94. if (isUpdate) {
  95. me.updateRationItem(function () {
  96. me.sheet.getParent().focus(true);
  97. });
  98. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  99. me.showGljItems(me.currentRationItem.ID);
  100. }
  101. });
  102. spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  103. spreadBook.commandManager().setShortcutKey('rationGljDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  104. },
  105. onClipboardPasting: function(sender, args) {
  106. const me = rationGLJOprObj;
  107. const rationCache = rationOprObj.getCache();
  108. const rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  109. me.currentRationItem = rationRow < rationCache.length ? rationCache[rationRow] : null;
  110. if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
  111. me.cache["_GLJ_" + me.currentRationItem.ID] = [];
  112. }
  113. const field = me.setting.header[args.cellRange.col].dataCode;
  114. const canPasteFields = ['code', 'consumeAmt', 'proportion'];
  115. if (!me.currentRationItem || !(canPasteFields.includes(field) && args.cellRange.colCount === 1)) {
  116. args.cancel = true;
  117. }
  118. },
  119. onClipboardPasted: function(e, info) {
  120. const me = rationGLJOprObj;
  121. me.tempCacheArr = [];
  122. const gljCache = me.cache["_GLJ_" + me.currentRationItem.ID];
  123. const field = me.setting.header[info.cellRange.col].dataCode;
  124. if (field === 'code') {
  125. const pasteList = sheetCommonObj.analyzePasteData({header:[{dataCode: "code"}] }, info);
  126. const codes = [];
  127. for (let i = 0; i < pasteList.length; i++) {
  128. let rowIdx = info.cellRange.row + i;
  129. if(rowIdx < gljCache.length){//更新
  130. me.tempCacheArr.push({org: gljCache[rowIdx], newCode: pasteList[i].code});
  131. gljCache.splice(rowIdx--, 1);
  132. }
  133. codes.push(pasteList[i].code);
  134. }
  135. me.addGljItems(codes, pageOprObj.gljLibId, info.cellRange);
  136. } else if (gljCache && info.cellRange.row < gljCache.length) {
  137. const pasteList = sheetCommonObj.analyzePasteData(me.setting, info);
  138. const maxCount = info.cellRange.row + info.cellRange.rowCount -1 > gljCache.length -1 ?
  139. gljCache.length - info.cellRange.row : info.cellRange.rowCount;
  140. const precision = me.setting.header[info.cellRange.col].precision;
  141. for (let i = 0; i < maxCount; i++) {
  142. let roundCons = scMathUtil.roundTo(pasteList[i][field], -precision);
  143. gljCache[info.cellRange.row + i][field] = roundCons;
  144. }
  145. me.updateRationItem(function () {
  146. me.sheet.getParent().focus(true);
  147. });
  148. if (info.cellRange.row + info.cellRange.rowCount -1 >= gljCache.length -1) {
  149. me.sheet.suspendPaint();
  150. for(let rowIdx = gljCache.length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
  151. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  152. }
  153. me.sheet.resumePaint();
  154. }
  155. } else if (info.cellRange.row >= gljCache.length) {
  156. me.sheet.suspendPaint();
  157. for(let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx ++){
  158. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  159. }
  160. me.sheet.resumePaint();
  161. }
  162. },
  163. onEditStarting: function (sender, args) {
  164. const me = rationGLJOprObj;
  165. const rationSection = rationOprObj.getCache();
  166. const rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  167. me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
  168. if(me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined'){
  169. me.cache["_GLJ_" + me.currentRationItem.ID] = [];
  170. }
  171. const isEmptyRation = !me.currentRationItem;
  172. if (isEmptyRation) {
  173. return args.cancel = true;
  174. }
  175. const canEditFields = ['code', 'consumeAmt', 'proportion'];
  176. const emptyGLJCanEditFields = ['code'];
  177. const isEmptyGLJ = args.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length;
  178. const editingField = me.setting.header[args.col].dataCode;
  179. const isValidField = isEmptyGLJ && emptyGLJCanEditFields.includes(editingField) || !isEmptyGLJ && canEditFields.includes(editingField);
  180. if (!isValidField) {
  181. return args.cancel = true;
  182. }
  183. },
  184. onCellEditEnd: function(sender, args) {
  185. const me = rationGLJOprObj;
  186. me.tempCacheArr = [];
  187. const cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  188. const editingField = me.setting.header[args.col].dataCode;
  189. const trimText = args.editingText ? args.editingText.trim() : '';
  190. const curGLJ = cacheArr[args.row];
  191. const originText = curGLJ && !_commonUtil.isEmptyVal(curGLJ[editingField]) ? String(curGLJ[editingField]) : '';
  192. if (!trimText || trimText === originText) {
  193. args.sheet.setValue(args.row, args.col, originText);
  194. return;
  195. }
  196. if (editingField === 'code') {
  197. const matchGLJ = cacheArr.find((item, index) => item.code === trimText && index !== args.row);
  198. if (matchGLJ) {
  199. alert("该人材机已存在!");
  200. args.sheet.setValue(args.row, args.col, originText);
  201. return;
  202. }
  203. if (args.row < cacheArr.length) { // 替换人材机
  204. me.tempCacheArr.push({org: cacheArr[args.row], newCode: args.editingText.toString().trim()});
  205. cacheArr.splice(args.row, 1);
  206. }
  207. me.addGljItems([trimText], pageOprObj.gljLibId)
  208. } else {
  209. const fieldName = me.setting.header[args.col].headerName;
  210. if (isNaN(trimText)) {
  211. $('#alertText').text(`${fieldName}只能输入数值。`);
  212. $('#alertModal').modal('show');
  213. args.sheet.setValue(args.row, args.col, originText);
  214. } else {
  215. const precision = me.setting.header[args.col].precision;
  216. const roundText = scMathUtil.roundTo(trimText, -precision);
  217. curGLJ[editingField] = roundText;
  218. me.updateRationItem(function () {
  219. me.sheet.getParent().focus(true);
  220. });
  221. }
  222. }
  223. },
  224. onContextmenuOpr: function () {//右键菜单
  225. let me = this;
  226. let raCoe = rationCoeOprObj;
  227. $.contextMenu({
  228. selector: '#rdSpread',
  229. build: function($triggerElement, e){
  230. //控制允许右键菜单在哪个位置出现
  231. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.sheet.getParent());
  232. let sheet = me.sheet;
  233. let addDis = false, delDis = false;
  234. let rationGlj = [];
  235. if(me.sheet.getParent().getActiveSheetIndex() === 0 && target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  236. //rationGlj表
  237. if(typeof target.row !== 'undefined'){
  238. //控制按钮是否可用
  239. sheet.setActiveCell(target.row, target.col);
  240. console.log(me.currentRationItem);
  241. if(me.currentRationItem){
  242. rationGlj = me.cache['_GLJ_' + me.currentRationItem.ID];
  243. if(!rationGlj ||target.row >= rationGlj.length){//右键定位在有数据的行,删除键才显示可用
  244. delDis = true;
  245. }
  246. else{//有数据
  247. if(typeof target.col === 'undefined'){//定位不在表格内
  248. delDis = true;
  249. }
  250. }
  251. }
  252. else{
  253. addDis = true;
  254. delDis = true;
  255. }
  256. }
  257. else{
  258. addDis = true;
  259. delDis = true;
  260. }
  261. return {
  262. callback: function(){},
  263. items: {
  264. "add": {name: "添加人材机", disabled: addDis, icon: "fa-plus", callback: function (key, opt) {
  265. //默认radio所有工料机
  266. gljSelOprObj.initRadio();
  267. gljSelOprObj.gljCurTypeId = null;
  268. //默认点击树根节点
  269. if(gljSelOprObj.rootNode){
  270. gljSelOprObj.treeObj.selectNode(gljSelOprObj.rootNode);
  271. gljSelTreeOprObj.setting.callback.onClick(null, 'componentTree', gljSelOprObj.rootNode);
  272. }
  273. //弹出窗口
  274. $('#selGlj').modal('show');
  275. }},
  276. "delete": {name: "删除人材机", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  277. rationGlj.splice(target.row, 1);
  278. me.updateRationItem(function(){
  279. me.sheet.getParent().focus();
  280. });
  281. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  282. me.showGljItems(me.currentRationItem.ID);
  283. }},
  284. }
  285. };
  286. }
  287. //rationCoe表
  288. else if(me.sheet.getParent().getActiveSheetIndex() === 2 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){
  289. let currentCache = raCoe.curRation && raCoe.isDef(raCoe.cache["_Coe_" + raCoe.curRation.ID]) ? raCoe.cache["_Coe_" + raCoe.curRation.ID] : [];
  290. sheet.setActiveCell(target.row, target.col);
  291. //控制按钮是否可用
  292. let upDis = false,
  293. downDis = false,
  294. refDis = false;
  295. if(target.row >= currentCache.length){
  296. upDis = true;
  297. downDis = true;
  298. refDis = true;
  299. }
  300. else {
  301. if(!raCoe.isDef(currentCache[target.row - 1])){
  302. upDis = true;
  303. }
  304. if(!raCoe.isDef(currentCache[target.row + 1])){
  305. downDis = true;
  306. }
  307. }
  308. return {
  309. callback: function(){},
  310. items: {
  311. "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
  312. raCoe.upMove(currentCache[target.row], currentCache[target.row - 1], {row: target.row - 1, col: target.col});
  313. }},
  314. "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
  315. raCoe.downMove(currentCache[target.row], currentCache[target.row + 1], {row: target.row + 1, col: target.col});
  316. }},
  317. "ref": {name: "添加到本节其他定额", disabled: refDis, icon: "fa-arrow-left", callback: function (key, opt) {
  318. raCoe.updateSectionRation(rationOprObj.currentRations["_SEC_ID_" + rationOprObj.currentSectionId], currentCache[target.row], function (updateArr) {
  319. for(let i = 0, len = updateArr.length; i < len; i++){
  320. let ration = updateArr[i];
  321. let rationCoeList = updateArr[i].rationCoeList;
  322. let newNo = 1;
  323. for(let j = 0, jLen = rationCoeList.length; j < jLen; j++){
  324. if(rationCoeList[j].no >= newNo){
  325. newNo = rationCoeList[j].no + 1;
  326. }
  327. }
  328. let theCache = raCoe.cache["_Coe_" + ration.ID];
  329. if(theCache !== undefined && theCache !== null){
  330. let newCoe = {};
  331. for(let attr in currentCache[target.row]){
  332. newCoe[attr] = currentCache[target.row][attr];
  333. }
  334. newCoe.no = newNo;
  335. theCache.push(newCoe);
  336. }
  337. }
  338. });
  339. }}
  340. }
  341. };
  342. }
  343. else{
  344. return false;
  345. }
  346. }
  347. });
  348. },
  349. getRecoveryArr: function (tempDelArr, newArr) {//获得更新的code不存在,恢复删除的被更新数据
  350. let rst = [];
  351. for(let i = 0, len = tempDelArr.length; i < len; i++){
  352. let isExist = false;
  353. for(let j = 0, jLen = newArr.length; j < jLen; j++){
  354. if(tempDelArr[i].newCode == newArr[j].code){
  355. isExist = true;
  356. break;
  357. }
  358. }
  359. if(!isExist){
  360. rst.push(tempDelArr[i].org);
  361. }
  362. }
  363. return rst;
  364. },
  365. addGljItems: function(codes, repId) {
  366. var me = this;
  367. $.ajax({
  368. type:"POST",
  369. url:"api/getGljItemsByCodes",
  370. data:{"gljCodes": JSON.stringify(codes), repId: repId},
  371. dataType:"json",
  372. cache:false,
  373. timeout:5000,
  374. success:function(result){
  375. if (result) {
  376. if(result.data.length > 0){
  377. if(priceProperties && priceProperties.length > 0){
  378. let priceField = priceProperties[0].price.dataCode;
  379. for(let glj of result.data){
  380. glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
  381. }
  382. }
  383. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  384. var rstArr = [], dummyR = {gljId: 0, consumeAmt:0},
  385. newAddArr = [],
  386. validGlj = [];
  387. for (var i = 0; i < result.data.length; i++) {
  388. dummyR.gljId = result.data[i].ID;
  389. rstArr.push(me.createRationGljDisplayItem(dummyR, result.data[i]));
  390. }
  391. if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
  392. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  393. for (var i = 0; i < rstArr.length; i++) {
  394. var hasDup = false;
  395. for (var j = 0; j < cacheArr.length; j++) {
  396. if (cacheArr[j].gljId == rstArr[i].gljId) {
  397. hasDup = true;
  398. break;
  399. }
  400. }
  401. if (!hasDup) {
  402. newAddArr.push(rstArr[i]);
  403. }
  404. }
  405. //新增的定额人材机,按照输入的编码排序
  406. for (let code of codes) {
  407. let fGlj = _.find(newAddArr, function (glj) {
  408. return glj.code === code;
  409. });
  410. if (fGlj) {
  411. validGlj.push(fGlj);
  412. }
  413. }
  414. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(validGlj);
  415. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, result.data);
  416. if(recoveryArr.length > 0){
  417. me.cache["_GLJ_" + me.currentRationItem.ID] = me.cache["_GLJ_" + me.currentRationItem.ID].concat(recoveryArr);
  418. }
  419. }
  420. me.showGljItems(me.currentRationItem.ID);
  421. if (validGlj.length > 0) {
  422. me.updateRationItem(function () {
  423. me.sheet.getParent().focus(true);
  424. });
  425. }
  426. }
  427. else{
  428. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID]? me.cache["_GLJ_" + me.currentRationItem.ID] : [];
  429. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, []);
  430. if(recoveryArr.length > 0){
  431. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(recoveryArr);
  432. }
  433. //更新的工料机不存在
  434. $('#alertModalBtn').click();
  435. $('#alertText').text("人材机"+ codes + "不存在,请查找你所需要的人材机,或新增人材机");
  436. $('#alertModalCls').click(function () {
  437. me.showGljItems(me.currentRationItem.ID);
  438. });
  439. $('#alertModalCof').click(function () {
  440. me.showGljItems(me.currentRationItem.ID);
  441. })
  442. }
  443. }
  444. },
  445. error:function(err){
  446. alert(err);
  447. }
  448. })
  449. },
  450. round(v, e){
  451. var t=1;
  452. for(;e>0;t*=10,e--);
  453. for(;e<0;t/=10,e++);
  454. return Math.round(v*t)/t;
  455. },
  456. rationCal: function () {
  457. let me = rationGLJOprObj;
  458. let rationBasePrc = 0;
  459. if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
  460. let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
  461. cacheArr.forEach(function (gljData) {
  462. if(gljData.gljType && gljData.basePrice && gljData.consumeAmt){
  463. rationBasePrc += gljData.basePrice * gljData.consumeAmt;
  464. }
  465. });
  466. rationBasePrc = scMathUtil.roundTo(rationBasePrc, 0);
  467. }
  468. return rationBasePrc;
  469. },
  470. updateRationItem: function(callback) {
  471. var me = this, updateArr = [];
  472. if (me.currentRationItem) {
  473. me.currentRationItem.rationGljList = me.buildRationItemGlj();
  474. //recalculate ration basePrice
  475. let price = me.rationCal();
  476. me.currentRationItem.basePrice = price;
  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. if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
  486. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  487. for (var i = 0; i < cacheArr.length; i++) {
  488. rst.push({
  489. gljId: cacheArr[i].gljId,
  490. consumeAmt: cacheArr[i].consumeAmt,
  491. proportion: cacheArr[i].proportion
  492. });
  493. }
  494. }
  495. return rst;
  496. },
  497. createRationGljDisplayItem: function(rItem, repGlj) {
  498. var rst = {};
  499. rst.gljId = rItem.gljId;
  500. rst.consumeAmt = rItem.consumeAmt;
  501. rst.proportion = rItem.proportion;
  502. rst.code = repGlj.code;
  503. rst.name = repGlj.name;
  504. rst.specs = repGlj.specs;
  505. rst.unit = repGlj.unit;
  506. rst.basePrice = repGlj.basePrice;
  507. rst.gljType = repGlj.gljType;
  508. return rst;
  509. },
  510. getGljItems: function(rationItem, callback) {
  511. var me = this, rationID = rationItem.ID, rationGljList = rationItem.rationGljList ? rationItem.rationGljList : [];
  512. me.currentRationItem = rationItem;
  513. if (me.cache["_GLJ_" + rationID]) {
  514. me.showGljItems(rationID);
  515. } else {
  516. var gljIds = [];
  517. for (var i = 0; i < rationGljList.length; i++) {
  518. gljIds.push(rationGljList[i].gljId);
  519. }
  520. $.ajax({
  521. type:"POST",
  522. url:"api/getGljItemsByIds",
  523. data:{"gljIds": JSON.stringify(gljIds)},
  524. dataType:"json",
  525. cache:false,
  526. timeout:5000,
  527. success:function(result){
  528. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  529. if (result) {
  530. if(priceProperties && priceProperties.length > 0){
  531. let priceField = priceProperties[0].price.dataCode;
  532. for(let glj of result.data){
  533. glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
  534. }
  535. }
  536. var cacheArr = [];
  537. for (var j = 0; j < rationGljList.length; j++) {
  538. for (var i = 0; i < result.data.length; i++) {
  539. if (rationGljList[j].gljId == result.data[i].ID) {
  540. cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], result.data[i]));
  541. break;
  542. }
  543. }
  544. }
  545. me.cache["_GLJ_" + rationID] = cacheArr;
  546. me.showGljItems(rationID);
  547. }
  548. if(callback) callback();
  549. },
  550. error:function(err){
  551. alert(err);
  552. }
  553. })
  554. }
  555. },
  556. showGljItems: function(rationID) {
  557. var me = this;
  558. if (me.cache["_GLJ_" + rationID]) {
  559. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  560. sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
  561. }
  562. }
  563. }