gljComponent.js 35 KB

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