ration_glj.js 28 KB

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