gljComponent.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. //生成列头(多单价)(多消耗量)
  21. initHeaders: function (priceProperties, consumeAmtProperties) {
  22. let headers = [
  23. { headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  24. { headerName: "名称", headerWidth: 90, dataCode: "name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  25. { headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center" },
  26. ];
  27. //生成消耗量列
  28. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  29. headers.push({ headerName: "消耗量", headerWidth: 70, dataCode: "consumeAmt", dataType: "Number", formatter: "0.000", hAlign: "right", vAlign: "center" });
  30. }
  31. else {
  32. for (let consumeAmtProp of consumeAmtProperties) {
  33. let colData = {
  34. headerName: consumeAmtProp.consumeAmt.dataName,
  35. headerWidth: 60,
  36. dataCode: consumeAmtProp.consumeAmt.dataCode,
  37. dataType: 'Number',
  38. formatter: '0.000',
  39. hAlign: 'right',
  40. vAlign: 'center'
  41. };
  42. headers.push(colData);
  43. }
  44. }
  45. //生成单价列
  46. if (!priceProperties || priceProperties.length === 0) {
  47. headers.push({ headerName: "定额价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center" });
  48. }
  49. else {
  50. for (let priceProp of priceProperties) {
  51. let colData = {
  52. headerName: priceProp.price.dataName,
  53. headerWidth: 100,
  54. dataCode: priceProp.price.dataCode,
  55. dataType: 'Number',
  56. formatter: '0.00',
  57. hAlign: 'right',
  58. vAlign: 'center'
  59. };
  60. headers.push(colData);
  61. }
  62. }
  63. return headers;
  64. },
  65. setFrozen: function (sheet) {
  66. const fixedHeadersLen = 3;
  67. let frozenCol = 0;
  68. if (consumeAmtProperties && consumeAmtProperties.length > 0) {
  69. frozenCol = fixedHeadersLen + consumeAmtProperties.length;
  70. }
  71. else if (priceProperties && priceProperties.length > 0) {
  72. frozenCol = fixedHeadersLen + 1;
  73. }
  74. if (frozenCol > 0) {
  75. sheet.frozenColumnCount(frozenCol);
  76. }
  77. },
  78. buildHeader: function (sheet, header) {
  79. sheet.setRowCount(2, GC.Spread.Sheets.SheetArea.colHeader);
  80. for (let i = 0; i < header.length; i++) {
  81. sheet.setValue(1, i, header[i].headerName, GC.Spread.Sheets.SheetArea.colHeader);
  82. sheet.setColumnWidth(i, header[i].headerWidth ? header[i].headerWidth : 100);
  83. }
  84. sheet.setValue(0, 0, '组成物信息', GC.Spread.Sheets.SheetArea.colHeader);
  85. sheet.addSpan(0, 0, 1, header.length, GC.Spread.Sheets.SheetArea.colHeader);
  86. },
  87. buildSheet: function (container) {
  88. let me = gljComponentOprObj;
  89. //生成人材机组成物表格列头
  90. me.setting.header = me.initHeaders(priceProperties, consumeAmtProperties);
  91. //生成人材机组成物列映射
  92. sheetCommonObj.initColMapping(me, me.setting.header);
  93. repositoryGljObj.initPriceCols.call(me, priceProperties, me.colMapping);
  94. me.initConsumeAmtCols(consumeAmtProperties, me.colMapping);
  95. me.workBook = sheetOpr.buildSheet(container, me.setting, 30, false);
  96. me.setFrozen(me.workBook.getSheet(0));
  97. me.buildHeader(me.workBook.getSheet(0), me.setting.header);
  98. sheetCommonObj.spreadDefaultStyle(me.workBook);
  99. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  100. me.workBook.getSheet(0).setFormatter(-1, 0, "@", GC.Spread.Sheets.SheetArea.viewport);
  101. sheetOpr.cleanData(me.workBook.getSheet(0), me.setting, -1);
  102. if (isReadOnly) {
  103. sheetCommonObj.disableSpread(me.workBook);
  104. }
  105. me.onContextmenuOpr();//右键菜单
  106. me.gljComponentDelOpr();
  107. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  108. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  109. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  110. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  111. },
  112. getRowData: function (sheet, row, setting) {
  113. let rst = { priceProperty: {}, consumeAmtProperty: {} };
  114. for (let i = 0; i < setting.header.length; i++) {
  115. let v = sheet.getValue(row, i);
  116. if (this.pricePropertyCols.includes(i)) {
  117. rst.priceProperty[setting.header[i].dataCode] = v && v !== '' ? v : 0;
  118. }
  119. else if (this.consumeAmtPropertyCols.includes(i)) {
  120. rst.consumeAmtProperty[setting.header[i].dataCode] = v && v !== '' ? v : 0;
  121. }
  122. else {
  123. rst[setting.header[i].dataCode] = v;
  124. }
  125. }
  126. return rst;
  127. },
  128. getComponent: function (sheet, rowCount) {
  129. let component = [];
  130. for (let row = 0; row < rowCount; row++) {
  131. let obj = {};
  132. obj.consumeAmt = sheet.getValue(row, 4);
  133. obj.ID = sheet.getTag(row, 0);
  134. component.push(obj);
  135. }
  136. return component;
  137. },
  138. //根据消耗量字段设置组成物消耗量
  139. setConsumeAmt: function (component, field, value) {
  140. const compareStr = 'consumeAmt';
  141. if (field.includes(compareStr)) {
  142. if (field === compareStr) {
  143. component[field] = value;
  144. }
  145. else {
  146. component['consumeAmtProperty'][field] = value;
  147. }
  148. }
  149. },
  150. initConsumeAmtCols: function (consumeAmtProperties, colMapping) {
  151. let consumeAmtCols = [],
  152. consumeAmtPropertyCols = [];
  153. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  154. consumeAmtCols.push(colMapping.fieldToCol['consumeAmt']);
  155. }
  156. for (let consumeAmtProp of consumeAmtProperties) {
  157. consumeAmtPropertyCols.push(colMapping.fieldToCol[consumeAmtProp.consumeAmt.dataCode]);
  158. consumeAmtCols.push(colMapping.fieldToCol[consumeAmtProp.consumeAmt.dataCode]);
  159. }
  160. this.consumeAmtCols = consumeAmtCols;
  161. this.consumeAmtPropertyCols = consumeAmtPropertyCols;
  162. },
  163. //消耗量赋初值
  164. initConsumeAmt: function (component) {
  165. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  166. component.consumeAmt = 0;
  167. } else {
  168. let consumeAmtProperty = {};
  169. for (let consumeAmtProp of consumeAmtProperties) {
  170. consumeAmtProperty[consumeAmtProp.consumeAmt.dataCode] = 0;
  171. }
  172. component.consumeAmtProperty = consumeAmtProperty;
  173. }
  174. },
  175. copyConsumeAmt: function (gljA, gljB) {
  176. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  177. gljA.consumeAmt = gljB.consumeAmt;
  178. } else {
  179. gljA.consumeAmtProperty = _.cloneDeep(gljB.consumeAmtProperty);
  180. }
  181. },
  182. consumeAmtChanged: function (component, consumeAmt, col) {
  183. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  184. if (consumeAmt !== component.consumeAmt) {
  185. return true;
  186. }
  187. }
  188. else {
  189. if (consumeAmt !== component.consumeAmtProperty[this.colMapping.colToField[col]]) {
  190. return true;
  191. }
  192. }
  193. return false;
  194. },
  195. consumeAmtIsEqual: function (consumeAmtA, consumeAmtB) {
  196. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  197. return consumeAmtA.consumeAmt === consumeAmtB.consumeAmt;
  198. }
  199. return _.isEqual(consumeAmtA.consumeAmtProperty, consumeAmtB.consumeAmtProperty);
  200. },
  201. onContextmenuOpr: function () {
  202. let me = gljComponentOprObj, that = repositoryGljObj, co = componentOprObj;
  203. $.contextMenu({
  204. selector: '#gljComponentSheet',
  205. build: function ($triggerElement, e) {
  206. //控制允许右键菜单在哪个位置出现
  207. let sheet = me.workBook.getSheet(0);
  208. let offset = $("#gljComponentSheet").offset(),
  209. x = e.pageX - offset.left,
  210. y = e.pageY - offset.top;
  211. let target = sheet.hitTest(x, y);
  212. if (target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined') {//在表格内
  213. sheet.setActiveCell(target.row, target.col);
  214. //getCurrentGlj
  215. let thatRow = that.workBook.getSheet(0).getSelections()[0].row
  216. that.currentGlj = thatRow < that.currentCache.length ? that.currentCache[thatRow] : null;
  217. that.currentComponent = that.currentGlj ? that.getCurrentComponent(that.currentGlj.component) : [];
  218. //控制按钮是否可用
  219. let insertDis = false,
  220. delDis = false;
  221. if (!(that.currentGlj && allowComponent.includes(that.currentGlj.gljType)) || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.stdGljList.concat(that.complementaryGljList)))) {
  222. insertDis = true;
  223. }
  224. if (!that.currentGlj || typeof that.currentComponent === 'undefined' || (typeof that.currentComponent !== 'undefined' && target.row >= that.currentComponent.length)) {//右键定位在有组成物的行,删除键才显示可用
  225. delDis = true;
  226. }
  227. return {
  228. callback: function () { },
  229. items: {
  230. "insert": {
  231. name: "插入", disabled: isReadOnly || insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  232. let oprFunc = function () {
  233. //默认radio所有工料机
  234. co.initRadio();
  235. co.gljCurTypeId = null;
  236. //默认点击树根节点
  237. co.initClassTree('std', gljClassTreeObj.treeData.std);
  238. //弹出窗口
  239. $('#component').modal('show');
  240. };
  241. if (repositoryGljObj.pullCompleteData) {
  242. oprFunc();
  243. } else {
  244. repositoryGljObj.getStdItems(pageOprObj.stdGljLibId, oprFunc);
  245. }
  246. }
  247. },
  248. "delete": {
  249. name: "删除", disabled: isReadOnly || delDis, icon: "fa-remove", callback: function (key, opt) {
  250. //删除
  251. let deleteObj = that.currentComponent[target.row];
  252. let gljComponent = that.currentGlj.component;
  253. let updateArr = [];
  254. //更新当前工料机的组成物列表
  255. for (let i = 0, len = gljComponent.length; i < len; i++) {
  256. if (gljComponent[i].ID === deleteObj.ID) {
  257. gljComponent.splice(i, 1);
  258. break;
  259. }
  260. }
  261. //重新计算工料机
  262. let gljBasePrc = me.reCalGljBasePrc(that.getCurrentComponent(gljComponent));
  263. if (that.isGljPriceChange(that.currentGlj, gljBasePrc)) {
  264. that.setPrice(that.currentGlj, gljBasePrc);
  265. that.reshowGljBasePrc(that.currentGlj);
  266. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  267. }
  268. /* if (gljBasePrc !== that.currentGlj.basePrice) {
  269. that.currentGlj.basePrice = gljBasePrc;
  270. that.reshowGljBasePrc(that.currentGlj);
  271. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  272. } */
  273. updateArr.push(that.currentGlj);
  274. me.updateComponent(updateArr);
  275. }
  276. }
  277. }
  278. };
  279. }
  280. else {
  281. return false;
  282. }
  283. }
  284. });
  285. },
  286. gljComponentDelOpr: function () {
  287. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [], removeArr = [], isUpdate = false, updateBasePrc = [];
  288. /* me.workBook.commandManager().register('gljComponentDel', function () {
  289. let sels = me.workBook.getSheet(0).getSelections();
  290. if (sels.length > 0 && that.currentComponent.length > 0) {
  291. let component = that.currentGlj.component;
  292. for (let i = 0; i < sels.length > 0; i++) {
  293. if (sels[i].colCount === me.setting.header.length) {//可删除
  294. for (let j = 0; j < sels[i].rowCount; j++) {
  295. if (sels[i].row + j < that.currentComponent.length) {
  296. removeArr.push(that.currentComponent[sels[i].row + j].ID);
  297. }
  298. }
  299. }
  300. else if (sels[i].col === 0) {
  301. //编码不可为空
  302. alert("编码不可为空!");
  303. }
  304. else if (sels[i].col === 4) {//消耗量修改为0
  305. if (sels[i].row === -1) {//全修改
  306. for (let j = 0; j < that.currentComponent.length; j++) {
  307. isUpdate = true;
  308. that.currentComponent[j].consumeAmt = 0;
  309. for (let k = 0; k < component.length; k++) {
  310. if (component[k].ID === that.currentComponent[j].ID) {
  311. component[k].consumeAmt = 0;
  312. break;
  313. }
  314. }
  315. }
  316. }
  317. else {//部分修改
  318. for (let j = 0; j < sels[i].rowCount; j++) {
  319. if (sels[i].row + j < that.currentComponent.length) {
  320. isUpdate = true;
  321. that.currentComponent[sels[i].row + j].consumeAmt = 0;
  322. for (let k = 0; k < component.length; k++) {
  323. if (component[k].ID === that.currentComponent[sels[i].row + j].ID) {
  324. component[k].consumeAmt = 0;
  325. break;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. }
  333. if (removeArr.length > 0 || isUpdate) {
  334. for (let i = 0; i < removeArr.length; i++) {
  335. for (let j = 0; j < that.currentComponent.length; j++) {
  336. if (that.currentComponent[j].ID === removeArr[i]) {
  337. that.currentComponent.splice(j--, 1);
  338. }
  339. }
  340. for (let j = 0; j < component.length; j++) {
  341. if (component[j].ID === removeArr[i]) {
  342. component.splice(j--, 1);
  343. }
  344. }
  345. }
  346. //重新计算工料机
  347. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  348. if (gljBasePrc !== that.currentGlj.basePrice) {
  349. that.currentGlj.basePrice = gljBasePrc;
  350. that.reshowGljBasePrc(that.currentGlj);
  351. updateBasePrc.push({ gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice });
  352. }
  353. updateArr.push(that.currentGlj);
  354. me.updateComponent(updateArr);
  355. if (updateBasePrc.length > 0) {
  356. that.updateRationBasePrcRq(updateBasePrc);
  357. }
  358. }
  359. }
  360. }); */
  361. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  362. //me.workBook.commandManager().setShortcutKey('gljComponentDel', GC.Spread.Commands.Key.del, false, false, false, false);
  363. },
  364. onCellEditStart: function (sender, args) {
  365. let me = gljComponentOprObj, that = repositoryGljObj;
  366. let rObj = me.getRowData(args.sheet, args.row, me.setting);
  367. me.currentEditingComponent = rObj;
  368. let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
  369. if (thatRow < that.currentCache.length) {
  370. that.currentGlj = that.currentCache[thatRow];
  371. //消耗量可编辑
  372. if (!(me.colMapping.colToField[args.col].includes('consumeAmt')) || !allowComponent.includes(that.currentGlj.gljType) ||
  373. (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList)) ||
  374. (args.col === 4 && (!that.currentComponent || args.row >= that.currentComponent.length))) {
  375. args.cancel = true;
  376. }
  377. }
  378. else {
  379. args.cancel = true;
  380. }
  381. },
  382. onCellEditEnd: function (sender, args) {
  383. let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
  384. let updateArr = [];
  385. let dataCode = me.colMapping.colToField[args.col];
  386. if (dataCode.includes('consumeAmt') && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0) {//消耗量
  387. let consumeAmt = parseFloat(args.editingText);
  388. if (!isNaN(consumeAmt) && me.consumeAmtChanged(me.currentEditingComponent, consumeAmt, args.col)) {
  389. let roundCons = scMathUtil.roundTo(parseFloat(consumeAmt), -3);
  390. let component = that.currentGlj.component;
  391. for (let i = 0; i < component.length; i++) {
  392. if (component[i].ID === that.currentComponent[args.row].ID) {
  393. me.setConsumeAmt(component[i], dataCode, roundCons);
  394. //component[i].consumeAmt = roundCons;
  395. }
  396. }
  397. //that.currentComponent[args.row].consumeAmt = roundCons;
  398. me.setConsumeAmt(that.currentComponent[args.row], dataCode, roundCons);
  399. //计算工料机单价
  400. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  401. if (that.isGljPriceChange(that.currentGlj, gljBasePrc)) {
  402. that.setPrice(that.currentGlj, gljBasePrc);
  403. that.reshowGljBasePrc(that.currentGlj);
  404. //工料机单价改变,重算引用了该工料机的定额单价
  405. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  406. }
  407. updateArr.push(that.currentGlj);
  408. }
  409. else {
  410. //只能输入数值
  411. sheetOpr.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  412. /* args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  413. me.currentEditingComponent[me.setting.header[args.col].dataCode] : 0); */
  414. }
  415. }
  416. else {
  417. //args.sheet.setValue(args.row, args.col, me.currentEditingComponent.consumeAmt);
  418. sheetOpr.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  419. }
  420. if (updateArr.length > 0) {
  421. me.updateComponent(updateArr);
  422. /*if(updateBasePrc.length > 0){
  423. that.updateRationBasePrcRq(updateBasePrc)
  424. }*/
  425. }
  426. },
  427. onClipboardPasting: function (sender, info) {
  428. let me = gljComponentOprObj, that = repositoryGljObj;
  429. let maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  430. /* if (info.cellRange.col !== 4 && info.cellRange.colCount > 1 || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.stdGljList.concat(that.complementaryGljList)))) {
  431. args.cancel = true;
  432. } */
  433. //复制的列数超过正确的列数,不可复制
  434. if (maxCol > me.setting.header.length - 1) {
  435. return info.cancel = true;
  436. }
  437. if (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.stdGljList.concat(that.complementaryGljList))) {
  438. return info.cancel = true;
  439. }
  440. //粘贴的字段只能是消耗量
  441. for (let i = 0; i < info.cellRange.colCount; i++) {
  442. let col = info.cellRange.col + i;
  443. let dataCode = me.colMapping.colToField[col];
  444. if (!dataCode.includes('consumeAmt')) {
  445. return info.cancel = true;
  446. }
  447. }
  448. },
  449. onClipboardPasted: function (sender, info) {
  450. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [], materialComponent = [202, 203, 204], machineComponent = [302, 303],
  451. component = that.currentGlj.component, newComponent = [], concatComponent = [], isChange = false, updateBasePrc = [];
  452. let gljCache = that.gljList;
  453. //消耗量
  454. if (me.colMapping.colToField[info.cellRange.col].includes('consumeAmt')) {
  455. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  456. let row = info.cellRange.row;
  457. for (let i = 0; i < items.length; i++) {
  458. if (row + i < that.currentComponent.length) {
  459. let currentObj = that.currentComponent[row + i];
  460. if (!me.consumeAmtIsEqual(items[i], currentObj)) {
  461. isChange = true;
  462. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  463. let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
  464. currentObj.consumeAmt = roundCons;
  465. for (let j = 0; j < component.length; j++) {
  466. if (component[j].ID === currentObj.ID) {
  467. component[j].consumeAmt = currentObj.consumeAmt;
  468. break;
  469. }
  470. }
  471. } else {
  472. for (let attr in items[i]) {
  473. //是消耗量字段
  474. if (attr.includes('consumeAmt') && items[i][attr] && !isNaN(parseFloat(items[i][attr]))) {
  475. let roundCons = scMathUtil.roundTo(parseFloat(items[i][attr]), -3);
  476. currentObj.consumeAmtProperty[attr] = roundCons;
  477. }
  478. }
  479. for (let j = 0; j < component.length; j++) {
  480. if (component[j].ID === currentObj.ID) {
  481. component[j].consumeAmtProperty = currentObj.consumeAmtProperty;
  482. break;
  483. }
  484. }
  485. }
  486. } else {
  487. sheetOpr.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  488. //me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, currentObj.consumeAmt);
  489. }
  490. } else {
  491. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, '');
  492. }
  493. }
  494. if (isChange) {
  495. //计算工料机单价
  496. let gljBasePrc = me.reCalGljBasePrc(that.currentComponent);
  497. if (that.isGljPriceChange(that.currentGlj, gljBasePrc)) {
  498. that.setPrice(that.currentGlj, gljBasePrc);
  499. that.reshowGljBasePrc(that.currentGlj);
  500. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  501. }
  502. updateArr.push(that.currentGlj);
  503. }
  504. }
  505. if (updateArr.length > 0) {
  506. me.updateComponent(updateArr);
  507. /* if(updateBasePrc.length > 0){
  508. that.updateRationBasePrcRq(updateBasePrc);
  509. }*/
  510. }
  511. },
  512. updateComponent: function (updateArr) {
  513. let me = gljComponentOprObj, that = repositoryGljObj;
  514. that.saveInString(updateArr);
  515. $.ajax({
  516. type: 'post',
  517. url: '/complementartGlj/api/updateComponent',
  518. data: { "userId": pageOprObj.userId, "updateArr": JSON.stringify(updateArr) },
  519. dataType: 'json',
  520. success: function (result) {
  521. if (!result.error) {
  522. that.currentComponent = that.getCurrentComponent(result.data[0].component);
  523. sheetOpr.cleanData(me.workBook.getSheet(0), me.setting, -1);
  524. sheetOpr.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  525. }
  526. else {
  527. sheetOpr.cleanData(me.workBook.getSheet(0), me.setting, -1);
  528. }
  529. $('#componentsCacnel').click();
  530. }
  531. })
  532. },
  533. round: function (v, e) {
  534. let t = 1;
  535. for (; e > 0; t *= 10, e--);
  536. for (; e < 0; t /= 10, e++);
  537. return Math.round(v * t) / t;
  538. },
  539. reCalGljBasePrc: function (components) {
  540. /* let me = gljComponentOprObj;
  541. let gljBasePrc = 0;
  542. for(let i = 0; i < component.length; i++){
  543. let roundBasePrc = scMathUtil.roundTo(parseFloat(component[i].basePrice), -2);
  544. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component[i].consumeAmt), -3);
  545. gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
  546. }
  547. return gljBasePrc;
  548. */
  549. let me = gljComponentOprObj, re = repositoryGljObj;
  550. // 只有一个单价的情况,只有一个单价则只有一个消耗量
  551. if (!priceProperties || priceProperties.length === 0) {
  552. let gljBasePrc = 0;
  553. for (let i = 0; i < components.length; i++) {
  554. let roundBasePrc = scMathUtil.roundTo(parseFloat(components[i].basePrice), -2);
  555. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(components[i].consumeAmt), -3);
  556. gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
  557. }
  558. return scMathUtil.roundTo(gljBasePrc, -2);
  559. } else { // 多单价的情况
  560. let gljPriceProperty = re.getPriceProperty(priceProperties);
  561. for (let priceProp in gljPriceProperty) {
  562. let consumeAmtField = re.getConsumeAmtField(consumeAmtProperties, priceProp);
  563. for (let component of components) {
  564. let roundBasePrc = scMathUtil.roundTo(parseFloat(component['priceProperty'][priceProp]), -2);
  565. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component['consumeAmtProperty'][consumeAmtField]), -3);
  566. gljPriceProperty[priceProp] = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljPriceProperty[priceProp], me.processDecimal);
  567. }
  568. scMathUtil.roundTo(gljPriceProperty[priceProp], -2);
  569. }
  570. return gljPriceProperty;
  571. }
  572. }
  573. };