gljComponent.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. console.log('enterED');
  238. let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
  239. let gljList = that.gljList, updateArr = [];
  240. //if(args.editingText !== me.currentEditingComponent.code){
  241. if(args.col === 0 && args.editingText && args.editingText.trim().length > 0 && args.editingText !== me.currentEditingComponent.code){
  242. let component = that.currentGlj.component, hasCode = false;
  243. for(let i = 0; i < gljList.length; i++){
  244. if(gljList[i].code === args.editingText){//有效的组成物
  245. hasCode = true;
  246. if((materialAllowComponent.includes(that.currentGlj.gljType) && gljList[i].gljType === 201)
  247. || (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljList[i].gljType))
  248. || (that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && that.currentGlj.ID !== gljList[i].ID)){//普通材料
  249. //是否与原有组成物不同
  250. let isExist = false;
  251. for(let j = 0; j < component.length; j++){
  252. if(component[j].ID === gljList[i].ID){
  253. isExist = true;
  254. break;
  255. }
  256. }
  257. if(!isExist){
  258. let rObj = {};
  259. rObj.ID = gljList[i].ID;
  260. //rObj.basePrice = gljList[i].basePrice;
  261. if(typeof that.currentComponent[args.row] !== 'undefined'){
  262. rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
  263. let index;
  264. for(let j = 0; j < component.length; j++){
  265. if(component[j].ID === that.currentComponent[args.row].ID){
  266. index = j;
  267. break;
  268. }
  269. }
  270. component.splice(index, 1);
  271. component.splice(index, 0, rObj);
  272. //计算工料机单价
  273. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  274. if(gljBasePrc !== that.currentGlj.basePrice){
  275. that.currentGlj.basePrice = gljBasePrc;
  276. that.reshowGljBasePrc(that.currentGlj);
  277. //工料机单价改变,重算引用了该工料机的定额单价
  278. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  279. }
  280. updateArr.push(that.currentGlj);
  281. }
  282. else{
  283. rObj.consumeAmt = 0;
  284. component.push(rObj);
  285. //计算工料机单价
  286. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  287. if(gljBasePrc !== that.currentGlj.basePrice){
  288. that.currentGlj.basePrice = gljBasePrc;
  289. that.reshowGljBasePrc(that.currentGlj);
  290. //工料机单价改变,重算引用了该工料机的定额单价
  291. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  292. }
  293. updateArr.push(that.currentGlj);
  294. }
  295. break;
  296. }
  297. else{
  298. //已存在
  299. alert("已存在!");
  300. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  301. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  302. }
  303. }
  304. else{
  305. if(materialAllowComponent.includes(that.currentGlj.gljType)){
  306. alert("无效的组成物!");
  307. }
  308. else if(machineAllowComponent.includes(that.currentGlj.gljType)){
  309. alert("无效的组成物!")
  310. }
  311. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  312. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  313. //无效
  314. }
  315. }
  316. }
  317. if(!hasCode){
  318. alert("不存在此人材机,请先添加!");
  319. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  320. me.currentEditingComponent[me.setting.header[args.col].dataCode] : '');
  321. //不存在
  322. }
  323. }
  324. else if(args.col === 4 && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0){//消耗量
  325. let consumeAmt = parseFloat(args.editingText);
  326. if(!isNaN(consumeAmt) && consumeAmt !== me.currentEditingComponent.consumeAmt){
  327. let roundCons = scMathUtil.roundTo(parseFloat(consumeAmt), -3);
  328. let component = that.currentGlj.component;
  329. for(let i = 0; i < component.length; i++){
  330. if(component[i].ID === that.currentComponent[args.row].ID){
  331. component[i].consumeAmt = roundCons;
  332. }
  333. }
  334. that.currentComponent[args.row].consumeAmt = roundCons;
  335. //计算工料机单价
  336. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  337. if(gljBasePrc !== that.currentGlj.basePrice){
  338. that.currentGlj.basePrice = gljBasePrc;
  339. that.reshowGljBasePrc(that.currentGlj);
  340. //工料机单价改变,重算引用了该工料机的定额单价
  341. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  342. }
  343. updateArr.push(that.currentGlj);
  344. }
  345. else{
  346. //只能输入数值
  347. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  348. me.currentEditingComponent[me.setting.header[args.col].dataCode]: 0);
  349. }
  350. }
  351. else{
  352. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  353. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  354. }
  355. if(updateArr.length > 0){
  356. me.updateComponent(updateArr);
  357. if(updateBasePrc.length > 0){
  358. that.updateRationBasePrcRq(updateBasePrc)
  359. }
  360. }
  361. let focusInter = setInterval(function () {
  362. if(!$('#loadingPage').is(':visible')){
  363. me.workBook.focus(true);
  364. clearInterval(focusInter);
  365. }
  366. }, 100);
  367. },
  368. onClipboardPasting: function (sender, info) {
  369. let me = gljComponentOprObj;
  370. let that = repositoryGljObj;
  371. let maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  372. //复制的列数超过正确的列数,不可复制
  373. if(info.cellRange.col !== 0 && info.cellRange.col !== 4 || info.cellRange.colCount > 1 || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList))){
  374. args.cancel = true;
  375. }
  376. },
  377. onClipboardPasted: function (sender, info) {
  378. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [],
  379. component = that.currentGlj.component, isChange = false, updateBasePrc = [];
  380. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  381. let gljCache = that.gljList;
  382. if(info.cellRange.col === 0){
  383. for(let i = 0; i < items.length; i++){
  384. let existCode = false;
  385. for(let j = 0; j < gljCache.length; j++){
  386. if(items[i].code === gljCache[j].code){
  387. existCode = true;
  388. if((materialAllowComponent.includes(that.currentGlj.gljType) && gljCache[j].gljType === 201)
  389. || (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljCache[j].gljType))
  390. || (that.currentGlj.gljType === 4 && gljCache[j].gljType === 4 && that.currentGlj.ID !== gljCache[i].ID)){
  391. //是否与原有组成物不同
  392. let isExist = false;
  393. for(let k = 0; k < component.length; k++){
  394. if(component[k].ID === gljCache[j].ID){
  395. isExist = true;
  396. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  397. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  398. break;
  399. }
  400. }
  401. if(!isExist){
  402. isChange = true;
  403. let obj = {};
  404. obj.ID = gljCache[j].ID;
  405. if(typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'){//更新
  406. obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
  407. let index;
  408. for(let k = 0; k < component.length; k++){
  409. if(that.currentComponent[info.cellRange.row + i].ID === component[k].ID){
  410. index = k;
  411. break;
  412. }
  413. }
  414. component.splice(index, 1);
  415. component.splice(index, 0, obj);
  416. }
  417. else{//新增
  418. obj.consumeAmt = 0;
  419. component.push(obj);
  420. }
  421. break;
  422. }
  423. }
  424. else{
  425. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  426. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  427. }
  428. }
  429. /* else{
  430. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  431. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  432. }*/
  433. }
  434. if(!existCode){
  435. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  436. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  437. }
  438. }
  439. if(isChange){
  440. //计算工料机单价
  441. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(component));
  442. if(gljBasePrc !== that.currentGlj.basePrice){
  443. that.currentGlj.basePrice = gljBasePrc;
  444. that.reshowGljBasePrc(that.currentGlj);
  445. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  446. }
  447. updateArr.push(that.currentGlj);
  448. }
  449. }
  450. else if(info.cellRange.col === 4){
  451. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  452. let row = info.cellRange.row;
  453. for(let i = 0; i < items.length; i++){
  454. if(row + i < that.currentComponent.length){
  455. let currentObj = that.currentComponent[row + i];
  456. if(items[i].consumeAmt.trim().length > 0 && items[i].consumeAmt !== currentObj.consumeAmt){
  457. let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
  458. isChange = true;
  459. currentObj.consumeAmt = roundCons;
  460. for(let j = 0; j < component.length; j++){
  461. if(component[j].ID === currentObj.ID){
  462. component[j].consumeAmt = currentObj.consumeAmt;
  463. break;
  464. }
  465. }
  466. }
  467. else{
  468. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, currentObj.consumeAmt);
  469. }
  470. }
  471. else{
  472. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, '');
  473. }
  474. }
  475. if(isChange){
  476. //计算工料机单价
  477. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  478. if(gljBasePrc !== that.currentGlj.basePrice){
  479. that.currentGlj.basePrice = gljBasePrc;
  480. that.reshowGljBasePrc(that.currentGlj);
  481. updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  482. }
  483. updateArr.push(that.currentGlj);
  484. }
  485. }
  486. if(updateArr.length > 0){
  487. me.updateComponent(updateArr);
  488. if(updateBasePrc.length > 0){
  489. that.updateRationBasePrcRq(updateBasePrc);
  490. }
  491. }
  492. else {
  493. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  494. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
  495. }
  496. let focusInter = setInterval(function () {
  497. if(!$('#loadingPage').is(':visible')){
  498. me.workBook.focus(true);
  499. clearInterval(focusInter);
  500. }
  501. }, 100);
  502. },
  503. updateComponent: function (updateArr) {
  504. let me = gljComponentOprObj, that = repositoryGljObj;
  505. repositoryGljObj.saveInString(updateArr);
  506. $.ajax({
  507. type: 'post',
  508. url: 'api/updateComponent',
  509. data: {libId: pageOprObj.gljLibId, updateArr: updateArr, oprtor: userAccount},
  510. dataType: 'json',
  511. success: function (result) {
  512. if(result.data.length > 0){
  513. if(result.data[0]){
  514. that.currentComponent = that.getCurrentComponent(result.data[0].component);
  515. me.workBook.getSheet(0).getSelections()[0]
  516. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  517. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, that.currentComponent);
  518. }
  519. }
  520. }
  521. })
  522. },
  523. reCalGljBasePrc: function (component) {
  524. let me = gljComponentOprObj, gljBasePrc = 0;
  525. for(let i = 0; i < component.length; i++){
  526. let roundBasePrc = scMathUtil.roundTo(parseFloat(component[i].basePrice), -2);
  527. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component[i].consumeAmt), -3);
  528. //gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * parseFloat(component[i].consumeAmt), -2) + gljBasePrc, -2); 旧算法
  529. gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
  530. }
  531. console.log(`scMathUtil.roundTo(gljBasePrc, -2)`);
  532. console.log(scMathUtil.roundTo(gljBasePrc, -2));
  533. return scMathUtil.roundTo(gljBasePrc, -2);
  534. }
  535. };