gljComponent.js 30 KB

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