gljComponent.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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 && allowComponent.includes(that.currentGlj.gljType)) || (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. "batchInsert": {name: '批量插入', disabled: insertDis, icon: 'fa-sign-in', callback: function (key, opt) {
  159. co.initRadio();
  160. co.gljCurTypeId = null;
  161. if(co.rootNode){
  162. co.treeObj.selectNode(co.rootNode);
  163. componentTypeTreeOprObj.onClick(null, 'componentTree', co.rootNode);
  164. }
  165. co.insertType = 'batch';
  166. $('#component').modal('show');
  167. }},
  168. "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  169. //默认radio所有工料机
  170. co.initRadio();
  171. co.gljCurTypeId = null;
  172. //默认点击树根节点
  173. if(co.rootNode){
  174. co.treeObj.selectNode(co.rootNode);
  175. componentTypeTreeOprObj.onClick(null, 'componentTree', co.rootNode);
  176. }
  177. co.insertType = 'single';
  178. //弹出窗口
  179. $('#componentBtn').click();
  180. }},
  181. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  182. //删除
  183. let deleteObj = that.currentComponent[target.row];
  184. let gljComponent = that.currentGlj.component;
  185. let updateArr = [], updateBasePrcArr = [];
  186. //更新当前工料机的组成物列表
  187. for(let i = 0, len = gljComponent.length; i < len; i++){
  188. if(gljComponent[i].ID === deleteObj.ID){
  189. gljComponent.splice(i, 1);
  190. break;
  191. }
  192. }
  193. //重新计算工料机
  194. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(gljComponent));
  195. if(gljBasePrc !== that.currentGlj.basePrice){
  196. that.currentGlj.basePrice = gljBasePrc;
  197. that.reshowGljBasePrc(that.currentGlj);
  198. updateBasePrcArr.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  199. }
  200. updateArr.push(that.currentGlj);
  201. me.updateComponent(updateArr);
  202. if(updateBasePrcArr.length > 0 && that.rationLibs.length > 0){
  203. that.updateRationBasePrcRq(updateBasePrcArr);
  204. }
  205. }},
  206. "batchClear": {name: '批量删除消耗量为0的组成物', disabled: insertDis, icon: 'fa-remove', callback: function (key, opt) {
  207. co.insertType = 'batchClear';
  208. co.batchUpdateComponent();
  209. }}
  210. }
  211. };
  212. }
  213. else{
  214. return false;
  215. }
  216. }
  217. });
  218. },
  219. onCellEditStart: function(sender, args) {
  220. let me = gljComponentOprObj, that = repositoryGljObj;
  221. let rObj = me.getRowData(args.sheet, args.row, me.setting);
  222. me.currentEditingComponent = rObj;
  223. let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
  224. if(thatRow < that.currentCache.length){
  225. that.currentGlj = that.currentCache[thatRow];
  226. if(me.setting.view.lockedCols.indexOf(args.col) !== -1 || !allowComponent.includes(that.currentGlj.gljType) ||
  227. (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList)) ||
  228. (args.col === 4 && (!that.currentComponent|| args.row >= that.currentComponent.length))){
  229. args.cancel = true;
  230. }
  231. }
  232. else {
  233. args.cancel = true;
  234. }
  235. },
  236. onCellEditEnd: function (sender, args) {
  237. let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
  238. let gljList = that.gljList, updateArr = [];
  239. //if(args.editingText !== me.currentEditingComponent.code){
  240. if(args.col === 0 && args.editingText && args.editingText.trim().length > 0 && args.editingText !== me.currentEditingComponent.code){
  241. let component = that.currentGlj.component, hasCode = false;
  242. for(let i = 0; i < gljList.length; i++){
  243. if(gljList[i].code === args.editingText){//有效的组成物
  244. hasCode = true;
  245. if((materialAllowComponent.includes(that.currentGlj.gljType) && gljList[i].gljType === 201)
  246. || (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljList[i].gljType))
  247. || (that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && that.currentGlj.ID !== gljList[i].ID)){//普通材料
  248. //是否与原有组成物不同
  249. let isExist = false;
  250. for(let j = 0; j < component.length; j++){
  251. if(component[j].ID === gljList[i].ID){
  252. isExist = true;
  253. break;
  254. }
  255. }
  256. if(!isExist){
  257. let rObj = {};
  258. rObj.ID = gljList[i].ID;
  259. //rObj.basePrice = gljList[i].basePrice;
  260. if(typeof that.currentComponent[args.row] !== 'undefined'){
  261. rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
  262. let index;
  263. for(let j = 0; j < component.length; j++){
  264. if(component[j].ID === that.currentComponent[args.row].ID){
  265. index = j;
  266. break;
  267. }
  268. }
  269. component.splice(index, 1);
  270. component.splice(index, 0, rObj);
  271. //计算工料机单价
  272. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  273. if(gljBasePrc !== that.currentGlj.basePrice){
  274. that.currentGlj.basePrice = gljBasePrc;
  275. that.reshowGljBasePrc(that.currentGlj);
  276. //工料机单价改变,重算引用了该工料机的定额单价
  277. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  278. }
  279. updateArr.push(that.currentGlj);
  280. }
  281. else{
  282. rObj.consumeAmt = 0;
  283. component.push(rObj);
  284. //计算工料机单价
  285. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  286. if(gljBasePrc !== that.currentGlj.basePrice){
  287. that.currentGlj.basePrice = gljBasePrc;
  288. that.reshowGljBasePrc(that.currentGlj);
  289. //工料机单价改变,重算引用了该工料机的定额单价
  290. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  291. }
  292. updateArr.push(that.currentGlj);
  293. }
  294. break;
  295. }
  296. else{
  297. //已存在
  298. alert("已存在!");
  299. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  300. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  301. }
  302. }
  303. else{
  304. if(materialAllowComponent.includes(that.currentGlj.gljType)){
  305. alert("无效的组成物!");
  306. }
  307. else if(machineAllowComponent.includes(that.currentGlj.gljType)){
  308. alert("无效的组成物!")
  309. }
  310. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  311. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  312. //无效
  313. }
  314. }
  315. }
  316. if(!hasCode){
  317. alert("不存在此人材机,请先添加!");
  318. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  319. me.currentEditingComponent[me.setting.header[args.col].dataCode] : '');
  320. //不存在
  321. }
  322. }
  323. else if(args.col === 4 && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0){//消耗量
  324. let consumeAmt = parseFloat(args.editingText);
  325. if(!isNaN(consumeAmt) && consumeAmt !== me.currentEditingComponent.consumeAmt){
  326. let roundCons = scMathUtil.roundTo(parseFloat(consumeAmt), -3);
  327. let component = that.currentGlj.component;
  328. for(let i = 0; i < component.length; i++){
  329. if(component[i].ID === that.currentComponent[args.row].ID){
  330. component[i].consumeAmt = roundCons;
  331. }
  332. }
  333. that.currentComponent[args.row].consumeAmt = roundCons;
  334. //计算工料机单价
  335. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  336. if(gljBasePrc !== that.currentGlj.basePrice){
  337. that.currentGlj.basePrice = gljBasePrc;
  338. that.reshowGljBasePrc(that.currentGlj);
  339. //工料机单价改变,重算引用了该工料机的定额单价
  340. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  341. }
  342. updateArr.push(that.currentGlj);
  343. }
  344. else{
  345. //只能输入数值
  346. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  347. me.currentEditingComponent[me.setting.header[args.col].dataCode]: 0);
  348. }
  349. }
  350. else{
  351. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  352. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  353. }
  354. if(updateArr.length > 0){
  355. me.updateComponent(updateArr);
  356. if(updateBasePrc.length > 0){
  357. that.updateRationBasePrcRq(updateBasePrc)
  358. }
  359. }
  360. let focusInter = setInterval(function () {
  361. if(!$('#loadingPage').is(':visible')){
  362. me.workBook.focus(true);
  363. clearInterval(focusInter);
  364. }
  365. }, 100);
  366. },
  367. onClipboardPasting: function (sender, info) {
  368. let me = gljComponentOprObj;
  369. let that = repositoryGljObj;
  370. let maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  371. //复制的列数超过正确的列数,不可复制
  372. if(info.cellRange.col !== 0 && info.cellRange.col !== 4 || info.cellRange.colCount > 1 || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList))){
  373. args.cancel = true;
  374. }
  375. },
  376. onClipboardPasted: function (sender, info) {
  377. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [],
  378. component = that.currentGlj.component, isChange = false, updateBasePrc = [];
  379. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  380. let gljCache = that.gljList;
  381. if(info.cellRange.col === 0){
  382. for(let i = 0; i < items.length; i++){
  383. let existCode = false;
  384. for(let j = 0; j < gljCache.length; j++){
  385. if(items[i].code === gljCache[j].code){
  386. existCode = true;
  387. if((materialAllowComponent.includes(that.currentGlj.gljType) && gljCache[j].gljType === 201)
  388. || (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljCache[j].gljType))
  389. || (that.currentGlj.gljType === 4 && gljCache[j].gljType === 4 && that.currentGlj.ID !== gljCache[i].ID)){
  390. //是否与原有组成物不同
  391. let isExist = false;
  392. for(let k = 0; k < component.length; k++){
  393. if(component[k].ID === gljCache[j].ID){
  394. isExist = true;
  395. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  396. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  397. break;
  398. }
  399. }
  400. if(!isExist){
  401. isChange = true;
  402. let obj = {};
  403. obj.ID = gljCache[j].ID;
  404. if(typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'){//更新
  405. obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
  406. let index;
  407. for(let k = 0; k < component.length; k++){
  408. if(that.currentComponent[info.cellRange.row + i].ID === component[k].ID){
  409. index = k;
  410. break;
  411. }
  412. }
  413. component.splice(index, 1);
  414. component.splice(index, 0, obj);
  415. }
  416. else{//新增
  417. obj.consumeAmt = 0;
  418. component.push(obj);
  419. }
  420. break;
  421. }
  422. }
  423. else{
  424. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  425. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  426. }
  427. }
  428. /* else{
  429. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  430. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  431. }*/
  432. }
  433. if(!existCode){
  434. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  435. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  436. }
  437. }
  438. if(isChange){
  439. //计算工料机单价
  440. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  441. if(gljBasePrc !== that.currentGlj.basePrice){
  442. that.currentGlj.basePrice = gljBasePrc;
  443. that.reshowGljBasePrc(that.currentGlj);
  444. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  445. }
  446. updateArr.push(that.currentGlj);
  447. }
  448. }
  449. else if(info.cellRange.col === 4){
  450. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  451. let row = info.cellRange.row;
  452. for(let i = 0; i < items.length; i++){
  453. if(row + i < that.currentComponent.length){
  454. let currentObj = that.currentComponent[row + i];
  455. if(items[i].consumeAmt.trim().length > 0 && items[i].consumeAmt !== currentObj.consumeAmt){
  456. let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
  457. isChange = true;
  458. currentObj.consumeAmt = roundCons;
  459. for(let j = 0; j < component.length; j++){
  460. if(component[j].ID === currentObj.ID){
  461. component[j].consumeAmt = currentObj.consumeAmt;
  462. break;
  463. }
  464. }
  465. }
  466. else{
  467. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, currentObj.consumeAmt);
  468. }
  469. }
  470. else{
  471. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, '');
  472. }
  473. }
  474. if(isChange){
  475. //计算工料机单价
  476. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  477. if(gljBasePrc !== that.currentGlj.basePrice){
  478. that.currentGlj.basePrice = gljBasePrc;
  479. that.reshowGljBasePrc(that.currentGlj);
  480. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  481. }
  482. updateArr.push(that.currentGlj);
  483. }
  484. }
  485. if(updateArr.length > 0){
  486. me.updateComponent(updateArr);
  487. if(updateBasePrc.length > 0){
  488. that.updateRationBasePrcRq(updateBasePrc);
  489. }
  490. }
  491. else {
  492. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  493. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
  494. }
  495. let focusInter = setInterval(function () {
  496. if(!$('#loadingPage').is(':visible')){
  497. me.workBook.focus(true);
  498. clearInterval(focusInter);
  499. }
  500. }, 100);
  501. },
  502. updateComponent: function (updateArr) {
  503. let me = gljComponentOprObj, that = repositoryGljObj;
  504. repositoryGljObj.saveInString(updateArr);
  505. $.ajax({
  506. type: 'post',
  507. url: 'api/updateComponent',
  508. data: {libId: pageOprObj.gljLibId, updateArr: updateArr, oprtor: userAccount},
  509. dataType: 'json',
  510. success: function (result) {
  511. if(result.data.length > 0){
  512. if(result.data[0]){
  513. that.currentComponent = that.getCurrentComponent(result.data[0].component);
  514. me.workBook.getSheet(0).getSelections()[0]
  515. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  516. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
  517. }
  518. }
  519. }
  520. })
  521. },
  522. reCalGljBasePrc: function (component) {
  523. let me = gljComponentOprObj, gljBasePrc = 0;
  524. for(let i = 0; i < component.length; i++){
  525. let roundBasePrc = scMathUtil.roundTo(parseFloat(component[i].basePrice), -2);
  526. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component[i].consumeAmt), -3);
  527. //gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * parseFloat(component[i].consumeAmt), -2) + gljBasePrc, -2); 旧算法
  528. gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
  529. }
  530. return scMathUtil.roundTo(gljBasePrc, -2);
  531. }
  532. };