gljComponent.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. /**
  2. * Created by Zhong on 2017/8/15.
  3. */
  4. let gljComponentOprObj = {
  5. workBook: null,
  6. processDecimal: -6,
  7. setting: {
  8. owner: "gljComponent",
  9. header:[
  10. {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  11. {headerName:"名称",headerWidth:90,dataCode:"name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  12. {headerName:"单位",headerWidth:45,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
  13. {headerName:"单价",headerWidth:60,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  14. {headerName:"消耗量",headerWidth:70,dataCode:"consumeAmt", dataType: "Number", formatter: "0.000", hAlign: "right", vAlign: "center"}
  15. ],
  16. view: {
  17. lockedCols:[1, 2, 3]
  18. }
  19. },
  20. buildSheet: function(container) {
  21. let me = gljComponentOprObj;
  22. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30, me);
  23. sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd}]);
  24. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  25. me.workBook.getSheet(0).setFormatter(-1, 0, "@", GC.Spread.Sheets.SheetArea.viewport);
  26. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  27. me.gljComponentDelOpr();
  28. me.onContextmenuOpr();
  29. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  30. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  31. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  32. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  33. },
  34. getRowData: function (sheet, row, setting) {
  35. let rst = {};
  36. for(let i = 0; i < setting.header.length; i++){
  37. rst[setting.header[i].dataCode] = sheet.getValue(row, i);
  38. }
  39. return rst;
  40. },
  41. getComponent: function (sheet, rowCount) {
  42. let component = [];
  43. for(let row = 0; row < rowCount; row++){
  44. let obj = {};
  45. obj.consumeAmt = sheet.getValue(row, 4);
  46. obj.ID = sheet.getTag(row, 0);
  47. component.push(obj);
  48. }
  49. return component;
  50. },
  51. gljComponentDelOpr: function () {
  52. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [], removeArr = [], isUpdate = false, updateBasePrc= [];
  53. me.workBook.commandManager().register('gljComponentDel', function () {
  54. let sels = me.workBook.getSheet(0).getSelections();
  55. if(sels.length > 0 && that.currentComponent.length > 0){
  56. let component = that.currentGlj.component;
  57. for(let i = 0; i < sels.length > 0; i++){
  58. if(sels[i].colCount === me.setting.header.length){//可删除
  59. for(let j = 0; j < sels[i].rowCount; j++){
  60. if(sels[i].row + j < that.currentComponent.length){
  61. removeArr.push(that.currentComponent[sels[i].row + j].ID);
  62. }
  63. }
  64. }
  65. else if(sels[i].col === 0){
  66. //编码不可为空
  67. alert("编码不可为空!");
  68. }
  69. else if(sels[i].col === 4){//消耗量修改为0
  70. if(sels[i].row === -1){//全修改
  71. for(let j = 0; j < that.currentComponent.length; j++){
  72. isUpdate = true;
  73. that.currentComponent[j].consumeAmt = 0;
  74. for(let k = 0; k < component.length; k++){
  75. if(component[k].ID === that.currentComponent[j].ID){
  76. component[k].consumeAmt = 0;
  77. break;
  78. }
  79. }
  80. }
  81. }
  82. else{//部分修改
  83. for(let j = 0; j < sels[i].rowCount; j++){
  84. if(sels[i].row + j < that.currentComponent.length){
  85. isUpdate = true;
  86. that.currentComponent[sels[i].row + j].consumeAmt = 0;
  87. for(let k = 0; k < component.length; k++){
  88. if(component[k].ID === that.currentComponent[sels[i].row + j].ID){
  89. component[k].consumeAmt = 0;
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. if(removeArr.length > 0 || isUpdate){
  99. for(let i = 0; i < removeArr.length; i++){
  100. for(let j = 0; j < that.currentComponent.length; j++){
  101. if(that.currentComponent[j].ID === removeArr[i]){
  102. that.currentComponent.splice(j--, 1);
  103. }
  104. }
  105. for(let j = 0; j < component.length; j++){
  106. if(component[j].ID === removeArr[i]){
  107. component.splice(j--, 1);
  108. }
  109. }
  110. }
  111. //重新计算工料机
  112. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  113. if(gljBasePrc !== that.currentGlj.basePrice){
  114. that.currentGlj.basePrice = gljBasePrc;
  115. that.reshowGljBasePrc(that.currentGlj);
  116. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  117. }
  118. updateArr.push(that.currentGlj);
  119. me.updateComponent(updateArr);
  120. if(updateBasePrc.length > 0){
  121. that.updateRationBasePrcRq(updateBasePrc);
  122. }
  123. }
  124. }
  125. });
  126. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  127. me.workBook.commandManager().setShortcutKey('gljComponentDel', GC.Spread.Commands.Key.del, false, false, false, false);
  128. },
  129. onContextmenuOpr: function () {
  130. let me = gljComponentOprObj, that = repositoryGljObj, co = componentOprObj;
  131. $.contextMenu({
  132. selector: '#gljComponentSheet',
  133. build: function($triggerElement, e){
  134. //控制允许右键菜单在哪个位置出现
  135. let sheet = me.workBook.getSheet(0);
  136. let offset = $("#gljComponentSheet").offset(),
  137. x = e.pageX - offset.left,
  138. y = e.pageY - offset.top;
  139. let target = sheet.hitTest(x, y);
  140. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  141. sheet.setActiveCell(target.row, target.col);
  142. //getCurrentGlj
  143. let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
  144. that.currentGlj = thatRow < that.currentCache.length ? that.currentCache[thatRow] : null;
  145. that.currentComponent = that.currentGlj ? that.getCurrentComponent(that.currentGlj.component) : [];
  146. //控制按钮是否可用
  147. let insertDis = false,
  148. delDis = false;
  149. if(!(that.currentGlj && that.allowComponent.indexOf(that.currentGlj.gljType) !== -1) || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList))){
  150. insertDis = true;
  151. }
  152. if(!that.currentGlj || typeof that.currentComponent === 'undefined' || (typeof that.currentComponent !== 'undefined' && target.row >= that.currentComponent.length)){//右键定位在有组成物的行,删除键才显示可用
  153. delDis = true;
  154. }
  155. return {
  156. callback: function(){},
  157. items: {
  158. "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  159. //默认radio所有工料机
  160. co.initRadio();
  161. co.gljCurTypeId = null;
  162. //默认点击树根节点
  163. if(co.rootNode){
  164. co.treeObj.selectNode(co.rootNode);
  165. componentTypeTreeOprObj.onClick(null, 'componentTree', co.rootNode);
  166. }
  167. //弹出窗口
  168. $('#componentBtn').click();
  169. }},
  170. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  171. //删除
  172. let deleteObj = that.currentComponent[target.row];
  173. let gljComponent = that.currentGlj.component;
  174. let updateArr = [], updateBasePrcArr = [];
  175. //更新当前工料机的组成物列表
  176. for(let i = 0, len = gljComponent.length; i < len; i++){
  177. if(gljComponent[i].ID === deleteObj.ID){
  178. gljComponent.splice(i, 1);
  179. break;
  180. }
  181. }
  182. //重新计算工料机
  183. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(gljComponent));
  184. if(gljBasePrc !== that.currentGlj.basePrice){
  185. that.currentGlj.basePrice = gljBasePrc;
  186. that.reshowGljBasePrc(that.currentGlj);
  187. updateBasePrcArr.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  188. }
  189. updateArr.push(that.currentGlj);
  190. me.updateComponent(updateArr);
  191. if(updateBasePrcArr.length > 0 && that.rationLibs.length > 0){
  192. that.updateRationBasePrcRq(updateBasePrcArr);
  193. }
  194. }}
  195. }
  196. };
  197. }
  198. else{
  199. return false;
  200. }
  201. }
  202. });
  203. },
  204. onCellEditStart: function(sender, args) {
  205. let me = gljComponentOprObj, that = repositoryGljObj;
  206. let rObj = me.getRowData(args.sheet, args.row, me.setting);
  207. me.currentEditingComponent = rObj;
  208. let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
  209. if(thatRow < that.currentCache.length){
  210. that.currentGlj = that.currentCache[thatRow];
  211. if(me.setting.view.lockedCols.indexOf(args.col) !== -1 || that.allowComponent.indexOf(that.currentGlj.gljType) === -1 ||
  212. (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList)) ||
  213. (args.col === 4 && (!that.currentComponent|| args.row >= that.currentComponent.length))){
  214. args.cancel = true;
  215. }
  216. }
  217. else {
  218. args.cancel = true;
  219. }
  220. },
  221. onCellEditEnd: function (sender, args) {
  222. let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
  223. let gljList = that.gljList, updateArr = [], materialComponent = [202, 203, 204], machineComponent = [302, 303];
  224. //if(args.editingText !== me.currentEditingComponent.code){
  225. if(args.col === 0 && args.editingText && args.editingText.trim().length > 0 && args.editingText !== me.currentEditingComponent.code){
  226. let component = that.currentGlj.component, hasCode = false;
  227. for(let i = 0; i < gljList.length; i++){
  228. if(gljList[i].code === args.editingText){//有效的组成物
  229. hasCode = true;
  230. if((materialComponent.indexOf(that.currentGlj.gljType) !== -1 && gljList[i].gljType === 201)
  231. || (that.currentGlj.gljType === 301 && machineComponent.indexOf(gljList[i].gljType) !== -1 )
  232. || (that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && that.currentGlj.ID !== gljList[i].ID)){//普通材料
  233. //是否与原有组成物不同
  234. let isExist = false;
  235. for(let j = 0; j < component.length; j++){
  236. if(component[j].ID === gljList[i].ID){
  237. isExist = true;
  238. break;
  239. }
  240. }
  241. if(!isExist){
  242. let rObj = {};
  243. rObj.ID = gljList[i].ID;
  244. //rObj.basePrice = gljList[i].basePrice;
  245. if(typeof that.currentComponent[args.row] !== 'undefined'){
  246. rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
  247. let index;
  248. for(let j = 0; j < component.length; j++){
  249. if(component[j].ID === that.currentComponent[args.row].ID){
  250. index = j;
  251. break;
  252. }
  253. }
  254. component.splice(index, 1);
  255. component.splice(index, 0, rObj);
  256. //计算工料机单价
  257. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  258. if(gljBasePrc !== that.currentGlj.basePrice){
  259. that.currentGlj.basePrice = gljBasePrc;
  260. that.reshowGljBasePrc(that.currentGlj);
  261. //工料机单价改变,重算引用了该工料机的定额单价
  262. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  263. }
  264. updateArr.push(that.currentGlj);
  265. }
  266. else{
  267. rObj.consumeAmt = 0;
  268. component.push(rObj);
  269. //计算工料机单价
  270. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  271. if(gljBasePrc !== that.currentGlj.basePrice){
  272. that.currentGlj.basePrice = gljBasePrc;
  273. that.reshowGljBasePrc(that.currentGlj);
  274. //工料机单价改变,重算引用了该工料机的定额单价
  275. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  276. }
  277. updateArr.push(that.currentGlj);
  278. }
  279. break;
  280. }
  281. else{
  282. //已存在
  283. alert("已存在!");
  284. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  285. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  286. }
  287. }
  288. else{
  289. if(materialComponent.indexOf(that.currentGlj.gljType) === 1){
  290. alert("该组成物只能是普通材料!");
  291. }
  292. else if(that.currentGlj.gljType === 301){
  293. alert("该组成物只能是机械组成物或机上人工!")
  294. }
  295. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  296. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  297. //无效
  298. }
  299. }
  300. }
  301. if(!hasCode){
  302. alert("不存在此人材机,请先添加!");
  303. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  304. me.currentEditingComponent[me.setting.header[args.col].dataCode] : '');
  305. //不存在
  306. }
  307. }
  308. else if(args.col === 4 && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0){//消耗量
  309. let consumeAmt = parseFloat(args.editingText);
  310. if(!isNaN(consumeAmt) && consumeAmt !== me.currentEditingComponent.consumeAmt){
  311. let roundCons = scMathUtil.roundTo(parseFloat(consumeAmt), -3);
  312. let component = that.currentGlj.component;
  313. for(let i = 0; i < component.length; i++){
  314. if(component[i].ID === that.currentComponent[args.row].ID){
  315. component[i].consumeAmt = roundCons;
  316. }
  317. }
  318. that.currentComponent[args.row].consumeAmt = roundCons;
  319. //计算工料机单价
  320. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  321. if(gljBasePrc !== that.currentGlj.basePrice){
  322. that.currentGlj.basePrice = gljBasePrc;
  323. that.reshowGljBasePrc(that.currentGlj);
  324. //工料机单价改变,重算引用了该工料机的定额单价
  325. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  326. }
  327. updateArr.push(that.currentGlj);
  328. }
  329. else{
  330. //只能输入数值
  331. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  332. me.currentEditingComponent[me.setting.header[args.col].dataCode]: 0);
  333. }
  334. }
  335. else{
  336. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  337. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  338. }
  339. if(updateArr.length > 0){
  340. me.updateComponent(updateArr);
  341. if(updateBasePrc.length > 0){
  342. that.updateRationBasePrcRq(updateBasePrc)
  343. }
  344. }
  345. let focusInter = setInterval(function () {
  346. if(!$('#loadingPage').is(':visible')){
  347. me.workBook.focus(true);
  348. clearInterval(focusInter);
  349. }
  350. }, 100);
  351. },
  352. onClipboardPasting: function (sender, info) {
  353. let me = gljComponentOprObj;
  354. let that = repositoryGljObj;
  355. let maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  356. //复制的列数超过正确的列数,不可复制
  357. if(info.cellRange.col !== 0 && info.cellRange.col !== 4 || info.cellRange.colCount > 1 || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList))){
  358. args.cancel = true;
  359. }
  360. },
  361. onClipboardPasted: function (sender, info) {
  362. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [] ,materialComponent = [202, 203, 204], machineComponent = [302, 303],
  363. component = that.currentGlj.component, newComponent = [], concatComponent = [], isChange = false, updateBasePrc = [];
  364. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  365. let gljCache = that.gljList;
  366. let resumeArr = [];
  367. if(info.cellRange.col === 0){
  368. for(let i = 0; i < items.length; i++){
  369. let existCode = false;
  370. for(let j = 0; j < gljCache.length; j++){
  371. if(items[i].code === gljCache[j].code){
  372. existCode = true;
  373. if((materialComponent.indexOf(that.currentGlj.gljType) !== -1 && gljCache[j].gljType === 201)
  374. || (that.currentGlj.gljType === 301 && machineComponent.indexOf(gljCache[j].gljType) !== -1 )
  375. || (that.currentGlj.gljType === 4 && gljCache[j].gljType === 4 && that.currentGlj.ID !== gljCache[i].ID)){
  376. //是否与原有组成物不同
  377. let isExist = false;
  378. for(let k = 0; k < component.length; k++){
  379. if(component[k].ID === gljCache[j].ID){
  380. isExist = true;
  381. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  382. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  383. break;
  384. }
  385. }
  386. if(!isExist){
  387. isChange = true;
  388. let obj = {};
  389. obj.ID = gljCache[j].ID;
  390. if(typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'){//更新
  391. obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
  392. let index;
  393. for(let k = 0; k < component.length; k++){
  394. if(that.currentComponent[info.cellRange.row + i].ID === component[k].ID){
  395. index = k;
  396. break;
  397. }
  398. }
  399. component.splice(index, 1);
  400. component.splice(index, 0, obj);
  401. }
  402. else{//新增
  403. obj.consumeAmt = 0;
  404. component.push(obj);
  405. }
  406. break;
  407. }
  408. }
  409. else{
  410. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  411. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  412. }
  413. }
  414. /* else{
  415. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  416. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  417. }*/
  418. }
  419. if(!existCode){
  420. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  421. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  422. }
  423. }
  424. if(isChange){
  425. //计算工料机单价
  426. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  427. if(gljBasePrc !== that.currentGlj.basePrice){
  428. that.currentGlj.basePrice = gljBasePrc;
  429. that.reshowGljBasePrc(that.currentGlj);
  430. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  431. }
  432. updateArr.push(that.currentGlj);
  433. }
  434. }
  435. else if(info.cellRange.col === 4){
  436. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  437. let row = info.cellRange.row;
  438. for(let i = 0; i < items.length; i++){
  439. if(row + i < that.currentComponent.length){
  440. let currentObj = that.currentComponent[row + i];
  441. if(items[i].consumeAmt.trim().length > 0 && items[i].consumeAmt !== currentObj.consumeAmt){
  442. let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
  443. isChange = true;
  444. currentObj.consumeAmt = roundCons;
  445. for(let j = 0; j < component.length; j++){
  446. if(component[j].ID === currentObj.ID){
  447. component[j].consumeAmt = currentObj.consumeAmt;
  448. break;
  449. }
  450. }
  451. }
  452. else{
  453. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, currentObj.consumeAmt);
  454. }
  455. }
  456. else{
  457. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, '');
  458. }
  459. }
  460. if(isChange){
  461. //计算工料机单价
  462. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  463. if(gljBasePrc !== that.currentGlj.basePrice){
  464. that.currentGlj.basePrice = gljBasePrc;
  465. that.reshowGljBasePrc(that.currentGlj);
  466. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  467. }
  468. updateArr.push(that.currentGlj);
  469. }
  470. }
  471. if(updateArr.length > 0){
  472. me.updateComponent(updateArr);
  473. if(updateBasePrc.length > 0){
  474. that.updateRationBasePrcRq(updateBasePrc);
  475. }
  476. }
  477. else {
  478. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  479. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
  480. }
  481. let focusInter = setInterval(function () {
  482. if(!$('#loadingPage').is(':visible')){
  483. me.workBook.focus(true);
  484. clearInterval(focusInter);
  485. }
  486. }, 100);
  487. },
  488. updateComponent: function (updateArr) {
  489. let me = gljComponentOprObj, that = repositoryGljObj;
  490. repositoryGljObj.saveInString(updateArr);
  491. $.ajax({
  492. type: 'post',
  493. url: 'api/updateComponent',
  494. data: {libId: pageOprObj.gljLibId, updateArr: updateArr, oprtor: userAccount},
  495. dataType: 'json',
  496. success: function (result) {
  497. if(result.data.length > 0){
  498. if(result.data[0]){
  499. that.currentComponent = that.getCurrentComponent(result.data[0].component);
  500. me.workBook.getSheet(0).getSelections()[0]
  501. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  502. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
  503. }
  504. }
  505. }
  506. })
  507. },
  508. reCalGljBasePrc: function (component) {
  509. let me = gljComponentOprObj, gljBasePrc = 0;
  510. for(let i = 0; i < component.length; i++){
  511. let roundBasePrc = scMathUtil.roundTo(parseFloat(component[i].basePrice), -2);
  512. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component[i].consumeAmt), -3);
  513. //gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * parseFloat(component[i].consumeAmt), -2) + gljBasePrc, -2); 旧算法
  514. gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
  515. }
  516. return scMathUtil.roundTo(gljBasePrc, -2);
  517. }
  518. };