gljComponent.js 28 KB

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