gljComponent.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. //生成列头(多单价)(多消耗量)
  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. buildSheet: function(container) {
  79. let me = gljComponentOprObj;
  80. //生成人材机组成物表格列头
  81. me.setting.header = me.initHeaders(priceProperties, consumeAmtProperties);
  82. //生成人材机组成物列映射
  83. sheetCommonObj.initColMapping(me, me.setting.header);
  84. repositoryGljObj.initPriceCols.call(me, priceProperties, me.colMapping);
  85. me.initConsumeAmtCols(consumeAmtProperties, me.colMapping);
  86. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30, me);
  87. me.setFrozen(me.workBook.getSheet(0));
  88. sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd}]);
  89. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  90. me.workBook.getSheet(0).setFormatter(-1, 0, "@", GC.Spread.Sheets.SheetArea.viewport);
  91. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  92. me.gljComponentDelOpr();
  93. me.onContextmenuOpr();
  94. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  95. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  96. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  97. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  98. },
  99. getRowData: function (sheet, row, setting) {
  100. let rst = {priceProperty: {}, consumeAmtProperty: {}};
  101. for(let i = 0; i < setting.header.length; i++){
  102. let v = sheet.getValue(row, i);
  103. if(this.pricePropertyCols.includes(i)){
  104. rst.priceProperty[setting.header[i].dataCode] = v && v !== '' ? v : 0;
  105. }
  106. else if(this.consumeAmtPropertyCols.includes(i)){
  107. rst.consumeAmtProperty[setting.header[i].dataCode] = v && v !== '' ? v : 0;
  108. }
  109. else {
  110. rst[setting.header[i].dataCode] = v;
  111. }
  112. }
  113. return rst;
  114. },
  115. getComponent: function (sheet, rowCount) {
  116. let component = [];
  117. for(let row = 0; row < rowCount; row++){
  118. let obj = {};
  119. obj.consumeAmt = sheet.getValue(row, 4);
  120. obj.ID = sheet.getTag(row, 0);
  121. component.push(obj);
  122. }
  123. return component;
  124. },
  125. //根据消耗量字段设置组成物消耗量
  126. setConsumeAmt: function (component, field, value) {
  127. const compareStr = 'consumeAmt';
  128. if(field.includes(compareStr)){
  129. if(field === compareStr){
  130. component[field] = value;
  131. }
  132. else {
  133. component['consumeAmtProperty'][field] = value;
  134. }
  135. }
  136. },
  137. initConsumeAmtCols: function (consumeAmtProperties, colMapping) {
  138. let consumeAmtCols = [],
  139. consumeAmtPropertyCols = [];
  140. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  141. consumeAmtCols.push(colMapping.fieldToCol['consumeAmt']);
  142. }
  143. for(let consumeAmtProp of consumeAmtProperties){
  144. consumeAmtPropertyCols.push(colMapping.fieldToCol[consumeAmtProp.consumeAmt.dataCode]);
  145. consumeAmtCols.push(colMapping.fieldToCol[consumeAmtProp.consumeAmt.dataCode]);
  146. }
  147. this.consumeAmtCols = consumeAmtCols;
  148. this.consumeAmtPropertyCols = consumeAmtPropertyCols;
  149. },
  150. //消耗量赋初值
  151. initConsumeAmt: function (component) {
  152. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  153. component.consumeAmt = 0;
  154. }
  155. else {
  156. let consumeAmtProperty = {};
  157. for(let consumeAmtProp of consumeAmtProperties){
  158. consumeAmtProperty[consumeAmtProp.consumeAmt.dataCode] = 0;
  159. }
  160. component.consumeAmtProperty = consumeAmtProperty;
  161. }
  162. },
  163. consumeAmtChanged: function (component, consumeAmt, col) {
  164. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  165. if(consumeAmt !== component.consumeAmt){
  166. return true;
  167. }
  168. }
  169. else {
  170. if(consumeAmt !== component.consumeAmtProperty[this.colMapping.colToField[col]]){
  171. return true;
  172. }
  173. }
  174. return false;
  175. },
  176. consumeAmtIsEqual: function (consumeAmtA, consumeAmtB) {
  177. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  178. return consumeAmtA.consumeAmt === consumeAmtB.consumeAmt;
  179. }
  180. return _.isEqual(consumeAmtA.consumeAmtProperty, consumeAmtB.consumeAmtProperty);
  181. },
  182. gljComponentDelOpr: function () {
  183. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [], removeArr = [], isUpdate = false, updateBasePrc= [];
  184. me.workBook.commandManager().register('gljComponentDel', function () {
  185. let sels = me.workBook.getSheet(0).getSelections();
  186. if(sels.length > 0 && that.currentComponent.length > 0){
  187. let component = that.currentGlj.component;
  188. for(let i = 0; i < sels.length > 0; i++){
  189. let selField = me.colMapping.colToField(sels[i].col);
  190. if(sels[i].colCount === me.setting.header.length){//可删除
  191. for(let j = 0; j < sels[i].rowCount; j++){
  192. if(sels[i].row + j < that.currentComponent.length){
  193. removeArr.push(that.currentComponent[sels[i].row + j].ID);
  194. }
  195. }
  196. }
  197. else if(selField === 'code'){
  198. //编码不可为空
  199. alert("编码不可为空!");
  200. }
  201. else if(selField.includes('consumeAmt')){//消耗量修改为0
  202. if(sels[i].row === -1){//全修改
  203. for(let j = 0; j < that.currentComponent.length; j++){
  204. isUpdate = true;
  205. //that.currentComponent[j].consumeAmt = 0;
  206. me.setConsumeAmt(that.currentComponent[j], selField, 0);
  207. for(let k = 0; k < component.length; k++){
  208. if(component[k].ID === that.currentComponent[j].ID){
  209. //component[k].consumeAmt = 0;
  210. me.setConsumeAmt(component[k], selField, 0);
  211. break;
  212. }
  213. }
  214. }
  215. }
  216. else{//部分修改
  217. for(let j = 0; j < sels[i].rowCount; j++){
  218. if(sels[i].row + j < that.currentComponent.length){
  219. isUpdate = true;
  220. me.setConsumeAmt(that.currentComponent[sels[i].row + j], selField, 0);
  221. //that.currentComponent[sels[i].row + j].consumeAmt = 0;
  222. for(let k = 0; k < component.length; k++){
  223. if(component[k].ID === that.currentComponent[sels[i].row + j].ID){
  224. //component[k].consumeAmt = 0;
  225. me.setConsumeAmt(component[k], selField, 0);
  226. break;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. if(removeArr.length > 0 || isUpdate){
  235. for(let i = 0; i < removeArr.length; i++){
  236. for(let j = 0; j < that.currentComponent.length; j++){
  237. if(that.currentComponent[j].ID === removeArr[i]){
  238. that.currentComponent.splice(j--, 1);
  239. }
  240. }
  241. for(let j = 0; j < component.length; j++){
  242. if(component[j].ID === removeArr[i]){
  243. component.splice(j--, 1);
  244. }
  245. }
  246. }
  247. updateArr.push(that.currentGlj);
  248. me.updateComponent(updateArr);
  249. }
  250. }
  251. });
  252. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  253. me.workBook.commandManager().setShortcutKey('gljComponentDel', GC.Spread.Commands.Key.del, false, false, false, false);
  254. },
  255. onContextmenuOpr: function () {
  256. let me = gljComponentOprObj, that = repositoryGljObj, co = componentOprObj;
  257. $.contextMenu({
  258. selector: '#gljComponentSheet',
  259. build: function($triggerElement, e){
  260. //控制允许右键菜单在哪个位置出现
  261. let sheet = me.workBook.getSheet(0);
  262. let offset = $("#gljComponentSheet").offset(),
  263. x = e.pageX - offset.left,
  264. y = e.pageY - offset.top;
  265. let target = sheet.hitTest(x, y);
  266. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  267. sheet.setActiveCell(target.row, target.col);
  268. //getCurrentGlj
  269. let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
  270. that.currentGlj = thatRow < that.currentCache.length ? that.currentCache[thatRow] : null;
  271. that.currentComponent = that.currentGlj ? that.getCurrentComponent(that.currentGlj.component) : [];
  272. //控制按钮是否可用
  273. let insertDis = false,
  274. delDis = false;
  275. if(!(that.currentGlj && allowComponent.includes(that.currentGlj.gljType)) || //机械组成物,应可选择无组成物的普通材料
  276. ([4].includes(that.currentGlj.gljType) && that.isComponent(that.currentGlj.ID, that.gljList))){
  277. insertDis = true;
  278. }
  279. if(!that.currentGlj || typeof that.currentComponent === 'undefined' ||
  280. (typeof that.currentComponent !== 'undefined' && target.row >= that.currentComponent.length)){//右键定位在有组成物的行,删除键才显示可用
  281. delDis = true;
  282. }
  283. return {
  284. callback: function(){},
  285. items: {
  286. "batchInsert": {name: '批量插入', disabled: insertDis, icon: 'fa-sign-in', callback: function (key, opt) {
  287. co.initRadio();
  288. co.gljCurTypeId = null;
  289. if(co.rootNode){
  290. co.treeObj.selectNode(co.rootNode);
  291. componentTypeTreeOprObj.onClick(null, 'componentTree', co.rootNode);
  292. }
  293. co.insertType = 'batch';
  294. $('#component').modal('show');
  295. }},
  296. "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  297. //默认radio所有工料机
  298. co.initRadio();
  299. co.gljCurTypeId = null;
  300. //默认点击树根节点
  301. if(co.rootNode){
  302. co.treeObj.selectNode(co.rootNode);
  303. componentTypeTreeOprObj.onClick(null, 'componentTree', co.rootNode);
  304. }
  305. co.insertType = 'single';
  306. //弹出窗口
  307. $('#componentBtn').click();
  308. }},
  309. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  310. //删除
  311. let deleteObj = that.currentComponent[target.row];
  312. let gljComponent = that.currentGlj.component;
  313. let updateArr = [], updateBasePrcArr = [];
  314. //更新当前工料机的组成物列表
  315. for(let i = 0, len = gljComponent.length; i < len; i++){
  316. if(gljComponent[i].ID === deleteObj.ID){
  317. gljComponent.splice(i, 1);
  318. break;
  319. }
  320. }
  321. updateArr.push(that.currentGlj);
  322. me.updateComponent(updateArr);
  323. }},
  324. "batchClear": {name: '批量删除消耗量为0的组成物', disabled: insertDis, icon: 'fa-remove', callback: function (key, opt) {
  325. co.insertType = 'batchClear';
  326. co.batchUpdateComponent();
  327. }}
  328. }
  329. };
  330. }
  331. else{
  332. return false;
  333. }
  334. }
  335. });
  336. },
  337. onCellEditStart: function(sender, args) {
  338. let me = gljComponentOprObj, that = repositoryGljObj;
  339. if(me.isPending){
  340. args.cancel = true;
  341. }
  342. let rObj = me.getRowData(args.sheet, args.row, me.setting);
  343. me.currentEditingComponent = rObj;
  344. let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
  345. if(thatRow < that.currentCache.length){
  346. that.currentGlj = that.currentCache[thatRow];
  347. //编码和消耗量可编辑
  348. if(!(me.colMapping.colToField[args.col] === 'code' || me.colMapping.colToField[args.col].includes('consumeAmt')) || !allowComponent.includes(that.currentGlj.gljType) ||
  349. (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList)) ||
  350. (args.col === 4 && (!that.currentComponent|| args.row >= that.currentComponent.length))){
  351. args.cancel = true;
  352. }
  353. }
  354. else {
  355. args.cancel = true;
  356. }
  357. },
  358. onCellEditEnd: function (sender, args) {
  359. let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
  360. let gljList = that.gljList, updateArr = [];
  361. let dataCode = me.colMapping.colToField[args.col];
  362. //if(args.editingText !== me.currentEditingComponent.code){
  363. //编辑编码
  364. if(dataCode === 'code' && args.editingText && args.editingText.trim().length > 0 && args.editingText !== me.currentEditingComponent.code){
  365. let component = that.currentGlj.component, hasCode = false;
  366. for(let i = 0; i < gljList.length; i++){
  367. if(gljList[i].code === args.editingText){//有效的组成物
  368. hasCode = true;
  369. if((materialAllowComponent.includes(that.currentGlj.gljType) && gljList[i].gljType === 201)
  370. || (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljList[i].gljType))){
  371. //是否与原有组成物不同
  372. let isExist = false;
  373. for(let j = 0; j < component.length; j++){
  374. if(component[j].ID === gljList[i].ID){
  375. isExist = true;
  376. break;
  377. }
  378. }
  379. if(!isExist){
  380. let rObj = {};
  381. rObj.ID = gljList[i].ID;
  382. //rObj.basePrice = gljList[i].basePrice;
  383. if(typeof that.currentComponent[args.row] !== 'undefined'){
  384. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  385. rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
  386. }
  387. else{
  388. rObj.consumeAmtProperty = that.currentComponent[args.row].consumeAmtProperty;
  389. }
  390. //rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
  391. let index;
  392. for(let j = 0; j < component.length; j++){
  393. if(component[j].ID === that.currentComponent[args.row].ID){
  394. index = j;
  395. break;
  396. }
  397. }
  398. component.splice(index, 1);
  399. component.splice(index, 0, rObj);
  400. updateArr.push(that.currentGlj);
  401. }
  402. else{
  403. me.initConsumeAmt(rObj);
  404. //rObj.consumeAmt = 0;
  405. component.push(rObj);
  406. updateArr.push(that.currentGlj);
  407. }
  408. break;
  409. }
  410. else{
  411. //已存在
  412. alert("已存在!");
  413. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  414. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  415. }
  416. }
  417. else{
  418. if(materialAllowComponent.includes(that.currentGlj.gljType)){
  419. alert("无效的组成物!");
  420. }
  421. else if(machineAllowComponent.includes(that.currentGlj.gljType)){
  422. alert("无效的组成物!")
  423. }
  424. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  425. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  426. //无效
  427. }
  428. }
  429. }
  430. if(!hasCode){
  431. alert("不存在此人材机,请先添加!");
  432. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  433. me.currentEditingComponent[me.setting.header[args.col].dataCode] : '');
  434. //不存在
  435. }
  436. }
  437. //编辑消耗量
  438. else if(dataCode.includes('consumeAmt') && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0){//消耗量
  439. let consumeAmt = parseFloat(args.editingText);
  440. if(!isNaN(consumeAmt) && me.consumeAmtChanged(me.currentEditingComponent, consumeAmt, args.col)){
  441. let roundCons = scMathUtil.roundTo(parseFloat(consumeAmt), -3);
  442. let component = that.currentGlj.component;
  443. for(let i = 0; i < component.length; i++){
  444. if(component[i].ID === that.currentComponent[args.row].ID){
  445. me.setConsumeAmt(component[i], dataCode, roundCons);
  446. //component[i].consumeAmt = roundCons;
  447. }
  448. }
  449. //that.currentComponent[args.row].consumeAmt = roundCons;
  450. me.setConsumeAmt(that.currentComponent[args.row], dataCode, roundCons);
  451. updateArr.push(that.currentGlj);
  452. }
  453. else{
  454. //只能输入数值
  455. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  456. }
  457. }
  458. else{
  459. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  460. }
  461. if(updateArr.length > 0){
  462. me.updateComponent(updateArr);
  463. if(updateBasePrc.length > 0 && that.rationLibs.length > 0){
  464. me.isPending = true;
  465. that.updateRationBasePrcRq(updateBasePrc, me.workBook, function () {
  466. me.isPending = false;
  467. });
  468. }
  469. }
  470. let focusInter = setInterval(function () {
  471. if(!$('#loadingPage').is(':visible')){
  472. me.workBook.focus(true);
  473. clearInterval(focusInter);
  474. }
  475. }, 100);
  476. },
  477. onClipboardPasting: function (sender, info) {
  478. let me = gljComponentOprObj;
  479. if(me.isPending){
  480. info.cancel = true
  481. }
  482. let that = repositoryGljObj;
  483. let maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  484. //粘贴的字段只能含有编码和消耗量
  485. for(let i = 0; i < info.cellRange.colCount; i++){
  486. let col = info.cellRange.col + i;
  487. let dataCode = me.colMapping.colToField[col];
  488. if(dataCode !== 'code' && !dataCode.includes('consumeAmt')){
  489. info.cancel = true;
  490. return;
  491. }
  492. }
  493. //复制的列数超过正确的列数,不可复制
  494. if(maxCol > me.setting.header.length - 1){
  495. info.cancel = true;
  496. }
  497. },
  498. onClipboardPasted: function (sender, info) {
  499. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [],
  500. component = that.currentGlj.component, isChange = false, updateBasePrc = [];
  501. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  502. let gljCache = that.gljList;
  503. if(info.cellRange.col === 0){
  504. for(let i = 0; i < items.length; i++){
  505. let existCode = false;
  506. for(let j = 0; j < gljCache.length; j++){
  507. if(items[i].code === gljCache[j].code){
  508. existCode = true;
  509. if((materialAllowComponent.includes(that.currentGlj.gljType) && gljCache[j].gljType === 201)
  510. || (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljCache[j].gljType))){
  511. //是否与原有组成物不同
  512. let isExist = false;
  513. for(let k = 0; k < component.length; k++){
  514. if(component[k].ID === gljCache[j].ID){
  515. isExist = true;
  516. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  517. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  518. break;
  519. }
  520. }
  521. if(!isExist){
  522. isChange = true;
  523. let obj = {};
  524. obj.ID = gljCache[j].ID;
  525. if(typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'){//更新
  526. //obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
  527. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  528. obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
  529. }
  530. else{
  531. obj.consumeAmtProperty = that.currentComponent[info.cellRange.row + i].consumeAmtProperty;
  532. }
  533. let index;
  534. for(let k = 0; k < component.length; k++){
  535. if(that.currentComponent[info.cellRange.row + i].ID === component[k].ID){
  536. index = k;
  537. break;
  538. }
  539. }
  540. component.splice(index, 1);
  541. component.splice(index, 0, obj);
  542. }
  543. else{//新增
  544. me.initConsumeAmt(obj);
  545. component.push(obj);
  546. }
  547. break;
  548. }
  549. }
  550. else{
  551. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  552. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  553. }
  554. }
  555. }
  556. if(!existCode){
  557. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  558. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  559. }
  560. }
  561. if(isChange){
  562. updateArr.push(that.currentGlj);
  563. }
  564. }
  565. //消耗量
  566. else if(me.colMapping.colToField[info.cellRange.col].includes('consumeAmt')){
  567. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  568. let row = info.cellRange.row;
  569. for(let i = 0; i < items.length; i++){
  570. if(row + i < that.currentComponent.length){
  571. let currentObj = that.currentComponent[row + i];
  572. if(!me.consumeAmtIsEqual(items[i], currentObj)){
  573. isChange = true;
  574. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  575. let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
  576. currentObj.consumeAmt = roundCons;
  577. for(let j = 0; j < component.length; j++){
  578. if(component[j].ID === currentObj.ID){
  579. component[j].consumeAmt = currentObj.consumeAmt;
  580. break;
  581. }
  582. }
  583. }
  584. else{
  585. for(let attr in items[i]){
  586. //是消耗量字段
  587. if(attr.includes('consumeAmt') && items[i][attr] && !isNaN(parseFloat(items[i][attr]))){
  588. let roundCons = scMathUtil.roundTo(parseFloat(items[i][attr]), -3);
  589. currentObj.consumeAmtProperty[attr] =roundCons;
  590. }
  591. }
  592. for(let j = 0; j < component.length; j++){
  593. if(component[j].ID === currentObj.ID){
  594. component[j].consumeAmtProperty = currentObj.consumeAmtProperty;
  595. break;
  596. }
  597. }
  598. }
  599. }
  600. else{
  601. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  602. //me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, currentObj.consumeAmt);
  603. }
  604. }
  605. else{
  606. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, '');
  607. }
  608. }
  609. if(isChange){
  610. updateArr.push(that.currentGlj);
  611. }
  612. }
  613. if(updateArr.length > 0){
  614. me.updateComponent(updateArr);
  615. if(updateBasePrc.length > 0){
  616. me.isPending = true;
  617. that.updateRationBasePrcRq(updateBasePrc, me.workBook, function () {
  618. me.isPending = false;
  619. });
  620. }
  621. }
  622. else {
  623. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  624. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  625. }
  626. let focusInter = setInterval(function () {
  627. if(!$('#loadingPage').is(':visible')){
  628. me.workBook.focus(true);
  629. clearInterval(focusInter);
  630. }
  631. }, 100);
  632. },
  633. updateComponent: function (updateArr) {
  634. let me = gljComponentOprObj, that = repositoryGljObj;
  635. repositoryGljObj.saveInString(updateArr);
  636. $.ajax({
  637. type: 'post',
  638. url: 'api/updateComponent',
  639. data: {libId: pageOprObj.gljLibId, updateArr: updateArr, oprtor: userAccount},
  640. dataType: 'json',
  641. success: function (result) {
  642. if(result.data.length > 0){
  643. if(result.data[0]){
  644. that.currentComponent = that.getCurrentComponent(result.data[0].component);
  645. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  646. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  647. }
  648. }
  649. }
  650. })
  651. },
  652. reCalGljBasePrc: function (components) {
  653. let me = gljComponentOprObj, re = repositoryGljObj;
  654. //只有一个单价的情况,只有一个单价则只有一个消耗量
  655. if(!priceProperties || priceProperties.length === 0){
  656. let gljBasePrc = 0;
  657. for(let i = 0; i < components.length; i++){
  658. let roundBasePrc = scMathUtil.roundTo(parseFloat(components[i].basePrice), -2);
  659. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(components[i].consumeAmt), -3);
  660. gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
  661. }
  662. return scMathUtil.roundTo(gljBasePrc, -2);
  663. }
  664. //多单价的情况
  665. else {
  666. let gljPriceProperty = re.getPriceProperty(priceProperties);
  667. for(let priceProp in gljPriceProperty){
  668. let consumeAmtField = re.getConsumeAmtField(consumeAmtProperties, priceProp);
  669. for(let component of components){
  670. let roundBasePrc = scMathUtil.roundTo(parseFloat(component['priceProperty'][priceProp]), -2);
  671. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component['consumeAmtProperty'][consumeAmtField]), -3);
  672. gljPriceProperty[priceProp] = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljPriceProperty[priceProp], me.processDecimal);
  673. }
  674. scMathUtil.roundTo(gljPriceProperty[priceProp], -2);
  675. }
  676. return gljPriceProperty;
  677. }
  678. }
  679. };