ration_glj.js 29 KB

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