gljComponent.js 30 KB

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