ration_glj.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. if (gljSelOprObj.workBook) {
  276. gljSelOprObj.workBook.refresh();
  277. }
  278. }},
  279. "delete": {name: "删除人材机", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  280. rationGlj.splice(target.row, 1);
  281. me.updateRationItem(function(){
  282. me.sheet.getParent().focus();
  283. });
  284. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  285. me.showGljItems(me.currentRationItem.ID);
  286. }},
  287. }
  288. };
  289. }
  290. //rationCoe表
  291. else if(me.sheet.getParent().getActiveSheetIndex() === 2 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){
  292. let currentCache = raCoe.curRation && raCoe.isDef(raCoe.cache["_Coe_" + raCoe.curRation.ID]) ? raCoe.cache["_Coe_" + raCoe.curRation.ID] : [];
  293. sheet.setActiveCell(target.row, target.col);
  294. //控制按钮是否可用
  295. let upDis = false,
  296. downDis = false,
  297. refDis = false;
  298. if(target.row >= currentCache.length){
  299. upDis = true;
  300. downDis = true;
  301. refDis = true;
  302. }
  303. else {
  304. if(!raCoe.isDef(currentCache[target.row - 1])){
  305. upDis = true;
  306. }
  307. if(!raCoe.isDef(currentCache[target.row + 1])){
  308. downDis = true;
  309. }
  310. }
  311. return {
  312. callback: function(){},
  313. items: {
  314. "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
  315. raCoe.upMove(currentCache[target.row], currentCache[target.row - 1], {row: target.row - 1, col: target.col});
  316. }},
  317. "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
  318. raCoe.downMove(currentCache[target.row], currentCache[target.row + 1], {row: target.row + 1, col: target.col});
  319. }},
  320. "ref": {name: "添加到本节其他定额", disabled: refDis, icon: "fa-arrow-left", callback: function (key, opt) {
  321. raCoe.updateSectionRation(rationOprObj.currentRations["_SEC_ID_" + rationOprObj.currentSectionId], currentCache[target.row], function (updateArr) {
  322. for(let i = 0, len = updateArr.length; i < len; i++){
  323. let ration = updateArr[i];
  324. let rationCoeList = updateArr[i].rationCoeList;
  325. let newNo = 1;
  326. for(let j = 0, jLen = rationCoeList.length; j < jLen; j++){
  327. if(rationCoeList[j].no >= newNo){
  328. newNo = rationCoeList[j].no + 1;
  329. }
  330. }
  331. let theCache = raCoe.cache["_Coe_" + ration.ID];
  332. if(theCache !== undefined && theCache !== null){
  333. let newCoe = {};
  334. for(let attr in currentCache[target.row]){
  335. newCoe[attr] = currentCache[target.row][attr];
  336. }
  337. newCoe.no = newNo;
  338. theCache.push(newCoe);
  339. }
  340. }
  341. });
  342. }}
  343. }
  344. };
  345. }
  346. else{
  347. return false;
  348. }
  349. }
  350. });
  351. },
  352. getRecoveryArr: function (tempDelArr, newArr) {//获得更新的code不存在,恢复删除的被更新数据
  353. let rst = [];
  354. for(let i = 0, len = tempDelArr.length; i < len; i++){
  355. let isExist = false;
  356. for(let j = 0, jLen = newArr.length; j < jLen; j++){
  357. if(tempDelArr[i].newCode == newArr[j].code){
  358. isExist = true;
  359. break;
  360. }
  361. }
  362. if(!isExist){
  363. rst.push(tempDelArr[i].org);
  364. }
  365. }
  366. return rst;
  367. },
  368. addGljItems: function(codes, repId) {
  369. var me = this;
  370. $.ajax({
  371. type:"POST",
  372. url:"api/getGljItemsByCodes",
  373. data:{"gljCodes": JSON.stringify(codes), repId: repId},
  374. dataType:"json",
  375. cache:false,
  376. timeout:5000,
  377. success:function(result){
  378. if (result) {
  379. if(result.data.length > 0){
  380. if(priceProperties && priceProperties.length > 0){
  381. let priceField = priceProperties[0].price.dataCode;
  382. for(let glj of result.data){
  383. glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
  384. }
  385. }
  386. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  387. var rstArr = [], dummyR = {gljId: 0, consumeAmt:0},
  388. newAddArr = [],
  389. validGlj = [];
  390. for (var i = 0; i < result.data.length; i++) {
  391. dummyR.gljId = result.data[i].ID;
  392. rstArr.push(me.createRationGljDisplayItem(dummyR, result.data[i]));
  393. }
  394. if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
  395. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  396. for (var i = 0; i < rstArr.length; i++) {
  397. var hasDup = false;
  398. for (var j = 0; j < cacheArr.length; j++) {
  399. if (cacheArr[j].gljId == rstArr[i].gljId) {
  400. hasDup = true;
  401. break;
  402. }
  403. }
  404. if (!hasDup) {
  405. newAddArr.push(rstArr[i]);
  406. }
  407. }
  408. //新增的定额人材机,按照输入的编码排序
  409. for (let code of codes) {
  410. let fGlj = _.find(newAddArr, function (glj) {
  411. return glj.code === code;
  412. });
  413. if (fGlj) {
  414. validGlj.push(fGlj);
  415. }
  416. }
  417. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(validGlj);
  418. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, result.data);
  419. if(recoveryArr.length > 0){
  420. me.cache["_GLJ_" + me.currentRationItem.ID] = me.cache["_GLJ_" + me.currentRationItem.ID].concat(recoveryArr);
  421. }
  422. }
  423. me.showGljItems(me.currentRationItem.ID);
  424. if (validGlj.length > 0) {
  425. me.updateRationItem(function () {
  426. me.sheet.getParent().focus(true);
  427. });
  428. }
  429. }
  430. else{
  431. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID]? me.cache["_GLJ_" + me.currentRationItem.ID] : [];
  432. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, []);
  433. if(recoveryArr.length > 0){
  434. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(recoveryArr);
  435. }
  436. //更新的工料机不存在
  437. $('#alertModalBtn').click();
  438. $('#alertText').text("人材机"+ codes + "不存在,请查找你所需要的人材机,或新增人材机");
  439. $('#alertModalCls').click(function () {
  440. me.showGljItems(me.currentRationItem.ID);
  441. });
  442. $('#alertModalCof').click(function () {
  443. me.showGljItems(me.currentRationItem.ID);
  444. })
  445. }
  446. }
  447. },
  448. error:function(err){
  449. alert(err);
  450. }
  451. })
  452. },
  453. round(v, e){
  454. var t=1;
  455. for(;e>0;t*=10,e--);
  456. for(;e<0;t/=10,e++);
  457. return Math.round(v*t)/t;
  458. },
  459. rationCal: function () {
  460. let me = rationGLJOprObj;
  461. let rationBasePrc = 0;
  462. if(me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]){
  463. let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
  464. cacheArr.forEach(function (gljData) {
  465. if(gljData.gljType && gljData.basePrice && gljData.consumeAmt){
  466. rationBasePrc += gljData.basePrice * gljData.consumeAmt;
  467. }
  468. });
  469. rationBasePrc = scMathUtil.roundTo(rationBasePrc, 0);
  470. }
  471. return rationBasePrc;
  472. },
  473. updateRationItem: function(callback) {
  474. var me = this, updateArr = [];
  475. if (me.currentRationItem) {
  476. me.currentRationItem.rationGljList = me.buildRationItemGlj();
  477. //recalculate ration basePrice
  478. let price = me.rationCal();
  479. me.currentRationItem.basePrice = price;
  480. updateArr.push(me.currentRationItem);
  481. rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
  482. if(callback) callback();
  483. });
  484. }
  485. },
  486. buildRationItemGlj: function(){
  487. var me = this, rst = [];
  488. if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
  489. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  490. for (var i = 0; i < cacheArr.length; i++) {
  491. rst.push({
  492. gljId: cacheArr[i].gljId,
  493. consumeAmt: cacheArr[i].consumeAmt,
  494. proportion: cacheArr[i].proportion
  495. });
  496. }
  497. }
  498. return rst;
  499. },
  500. createRationGljDisplayItem: function(rItem, repGlj) {
  501. var rst = {};
  502. rst.gljId = rItem.gljId;
  503. rst.consumeAmt = rItem.consumeAmt;
  504. rst.proportion = rItem.proportion;
  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 ? 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. if(priceProperties && priceProperties.length > 0){
  534. let priceField = priceProperties[0].price.dataCode;
  535. for(let glj of result.data){
  536. glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
  537. }
  538. }
  539. var cacheArr = [];
  540. for (var j = 0; j < rationGljList.length; j++) {
  541. for (var i = 0; i < result.data.length; i++) {
  542. if (rationGljList[j].gljId == result.data[i].ID) {
  543. cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], result.data[i]));
  544. break;
  545. }
  546. }
  547. }
  548. me.cache["_GLJ_" + rationID] = cacheArr;
  549. me.showGljItems(rationID);
  550. }
  551. if(callback) callback();
  552. },
  553. error:function(err){
  554. alert(err);
  555. }
  556. })
  557. }
  558. },
  559. showGljItems: function(rationID) {
  560. var me = this;
  561. if (me.cache["_GLJ_" + rationID]) {
  562. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  563. sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
  564. }
  565. }
  566. }