gljComponent.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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)) || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList))){
  276. insertDis = true;
  277. }
  278. if(!that.currentGlj || typeof that.currentComponent === 'undefined' || (typeof that.currentComponent !== 'undefined' && target.row >= that.currentComponent.length)){//右键定位在有组成物的行,删除键才显示可用
  279. delDis = true;
  280. }
  281. return {
  282. callback: function(){},
  283. items: {
  284. "batchInsert": {name: '批量插入', disabled: insertDis, icon: 'fa-sign-in', callback: function (key, opt) {
  285. co.initRadio();
  286. co.gljCurTypeId = null;
  287. if(co.rootNode){
  288. co.treeObj.selectNode(co.rootNode);
  289. componentTypeTreeOprObj.onClick(null, 'componentTree', co.rootNode);
  290. }
  291. co.insertType = 'batch';
  292. $('#component').modal('show');
  293. }},
  294. "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  295. //默认radio所有工料机
  296. co.initRadio();
  297. co.gljCurTypeId = null;
  298. //默认点击树根节点
  299. if(co.rootNode){
  300. co.treeObj.selectNode(co.rootNode);
  301. componentTypeTreeOprObj.onClick(null, 'componentTree', co.rootNode);
  302. }
  303. co.insertType = 'single';
  304. //弹出窗口
  305. $('#componentBtn').click();
  306. }},
  307. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  308. //删除
  309. let deleteObj = that.currentComponent[target.row];
  310. let gljComponent = that.currentGlj.component;
  311. let updateArr = [], updateBasePrcArr = [];
  312. //更新当前工料机的组成物列表
  313. for(let i = 0, len = gljComponent.length; i < len; i++){
  314. if(gljComponent[i].ID === deleteObj.ID){
  315. gljComponent.splice(i, 1);
  316. break;
  317. }
  318. }
  319. updateArr.push(that.currentGlj);
  320. me.updateComponent(updateArr);
  321. }},
  322. "batchClear": {name: '批量删除消耗量为0的组成物', disabled: insertDis, icon: 'fa-remove', callback: function (key, opt) {
  323. co.insertType = 'batchClear';
  324. co.batchUpdateComponent();
  325. }}
  326. }
  327. };
  328. }
  329. else{
  330. return false;
  331. }
  332. }
  333. });
  334. },
  335. onCellEditStart: function(sender, args) {
  336. let me = gljComponentOprObj, that = repositoryGljObj;
  337. console.log(me.colMapping);
  338. if(me.isPending){
  339. args.cancel = true;
  340. }
  341. let rObj = me.getRowData(args.sheet, args.row, me.setting);
  342. me.currentEditingComponent = rObj;
  343. let thatRow = that.workBook.getSheet(0).getSelections()[0].row;
  344. if(thatRow < that.currentCache.length){
  345. that.currentGlj = that.currentCache[thatRow];
  346. //编码和消耗量可编辑
  347. /* if(me.setting.view.lockedCols.indexOf(args.col) !== -1 || !allowComponent.includes(that.currentGlj.gljType) ||
  348. (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList)) ||
  349. (args.col === 4 && (!that.currentComponent|| args.row >= that.currentComponent.length))){
  350. args.cancel = true;
  351. }*/
  352. if(!(me.colMapping.colToField[args.col] === 'code' || me.colMapping.colToField[args.col].includes('consumeAmt')) || !allowComponent.includes(that.currentGlj.gljType) ||
  353. (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList)) ||
  354. (args.col === 4 && (!that.currentComponent|| args.row >= that.currentComponent.length))){
  355. args.cancel = true;
  356. }
  357. }
  358. else {
  359. args.cancel = true;
  360. }
  361. },
  362. onCellEditEnd: function (sender, args) {
  363. let me = gljComponentOprObj, that = repositoryGljObj, updateBasePrc = [];
  364. let gljList = that.gljList, updateArr = [];
  365. let dataCode = me.colMapping.colToField[args.col];
  366. //if(args.editingText !== me.currentEditingComponent.code){
  367. //编辑编码
  368. if(dataCode === 'code' && args.editingText && args.editingText.trim().length > 0 && args.editingText !== me.currentEditingComponent.code){
  369. let component = that.currentGlj.component, hasCode = false;
  370. for(let i = 0; i < gljList.length; i++){
  371. if(gljList[i].code === args.editingText){//有效的组成物
  372. hasCode = true;
  373. if((materialAllowComponent.includes(that.currentGlj.gljType) && gljList[i].gljType === 201)
  374. || (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljList[i].gljType))
  375. || (that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && that.currentGlj.ID !== gljList[i].ID)){//普通材料
  376. //是否与原有组成物不同
  377. let isExist = false;
  378. for(let j = 0; j < component.length; j++){
  379. if(component[j].ID === gljList[i].ID){
  380. isExist = true;
  381. break;
  382. }
  383. }
  384. if(!isExist){
  385. let rObj = {};
  386. rObj.ID = gljList[i].ID;
  387. //rObj.basePrice = gljList[i].basePrice;
  388. if(typeof that.currentComponent[args.row] !== 'undefined'){
  389. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  390. rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
  391. }
  392. else{
  393. rObj.consumeAmtProperty = that.currentComponent[args.row].consumeAmtProperty;
  394. }
  395. //rObj.consumeAmt = that.currentComponent[args.row].consumeAmt;
  396. let index;
  397. for(let j = 0; j < component.length; j++){
  398. if(component[j].ID === that.currentComponent[args.row].ID){
  399. index = j;
  400. break;
  401. }
  402. }
  403. component.splice(index, 1);
  404. component.splice(index, 0, rObj);
  405. updateArr.push(that.currentGlj);
  406. }
  407. else{
  408. me.initConsumeAmt(rObj);
  409. //rObj.consumeAmt = 0;
  410. component.push(rObj);
  411. updateArr.push(that.currentGlj);
  412. }
  413. break;
  414. }
  415. else{
  416. //已存在
  417. alert("已存在!");
  418. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  419. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  420. }
  421. }
  422. else{
  423. if(materialAllowComponent.includes(that.currentGlj.gljType)){
  424. alert("无效的组成物!");
  425. }
  426. else if(machineAllowComponent.includes(that.currentGlj.gljType)){
  427. alert("无效的组成物!")
  428. }
  429. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  430. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
  431. //无效
  432. }
  433. }
  434. }
  435. if(!hasCode){
  436. alert("不存在此人材机,请先添加!");
  437. args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  438. me.currentEditingComponent[me.setting.header[args.col].dataCode] : '');
  439. //不存在
  440. }
  441. }
  442. //编辑消耗量
  443. else if(dataCode.includes('consumeAmt') && me.currentEditingComponent.code && args.editingText && args.editingText.trim().length > 0){//消耗量
  444. let consumeAmt = parseFloat(args.editingText);
  445. if(!isNaN(consumeAmt) && me.consumeAmtChanged(me.currentEditingComponent, consumeAmt, args.col)){
  446. let roundCons = scMathUtil.roundTo(parseFloat(consumeAmt), -3);
  447. let component = that.currentGlj.component;
  448. for(let i = 0; i < component.length; i++){
  449. if(component[i].ID === that.currentComponent[args.row].ID){
  450. me.setConsumeAmt(component[i], dataCode, roundCons);
  451. //component[i].consumeAmt = roundCons;
  452. }
  453. }
  454. //that.currentComponent[args.row].consumeAmt = roundCons;
  455. me.setConsumeAmt(that.currentComponent[args.row], dataCode, roundCons);
  456. updateArr.push(that.currentGlj);
  457. }
  458. else{
  459. //只能输入数值
  460. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  461. /* args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  462. me.currentEditingComponent[me.setting.header[args.col].dataCode]: 0);*/
  463. }
  464. }
  465. else{
  466. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  467. /* args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
  468. me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');*/
  469. }
  470. if(updateArr.length > 0){
  471. me.updateComponent(updateArr);
  472. if(updateBasePrc.length > 0 && that.rationLibs.length > 0){
  473. me.isPending = true;
  474. that.updateRationBasePrcRq(updateBasePrc, me.workBook, function () {
  475. me.isPending = false;
  476. });
  477. }
  478. }
  479. let focusInter = setInterval(function () {
  480. if(!$('#loadingPage').is(':visible')){
  481. me.workBook.focus(true);
  482. clearInterval(focusInter);
  483. }
  484. }, 100);
  485. },
  486. onClipboardPasting: function (sender, info) {
  487. let me = gljComponentOprObj;
  488. if(me.isPending){
  489. info.cancel = true
  490. }
  491. let that = repositoryGljObj;
  492. let maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  493. //粘贴的字段只能含有编码和消耗量
  494. for(let i = 0; i < info.cellRange.colCount; i++){
  495. let col = info.cellRange.col + i;
  496. let dataCode = me.colMapping.colToField[col];
  497. if(dataCode !== 'code' && !dataCode.includes('consumeAmt')){
  498. info.cancel = true;
  499. return;
  500. }
  501. }
  502. //复制的列数超过正确的列数,不可复制
  503. if(maxCol > me.setting.header.length - 1){
  504. info.cancel = true;
  505. }
  506. /* if(beginDataCode !== 'code' && !beginDataCode.include('consumeAmt') || info.cellRange.colCount > 1 || (that.currentGlj.gljType === 4 && that.isComponent(that.currentGlj.ID, that.gljList))){
  507. info.cancel = true;
  508. }*/
  509. },
  510. onClipboardPasted: function (sender, info) {
  511. let me = gljComponentOprObj, that = repositoryGljObj, updateArr = [],
  512. component = that.currentGlj.component, isChange = false, updateBasePrc = [];
  513. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  514. let gljCache = that.gljList;
  515. if(info.cellRange.col === 0){
  516. for(let i = 0; i < items.length; i++){
  517. let existCode = false;
  518. for(let j = 0; j < gljCache.length; j++){
  519. if(items[i].code === gljCache[j].code){
  520. existCode = true;
  521. if((materialAllowComponent.includes(that.currentGlj.gljType) && gljCache[j].gljType === 201)
  522. || (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljCache[j].gljType))
  523. || (that.currentGlj.gljType === 4 && gljCache[j].gljType === 4 && that.currentGlj.ID !== gljCache[i].ID)){
  524. //是否与原有组成物不同
  525. let isExist = false;
  526. for(let k = 0; k < component.length; k++){
  527. if(component[k].ID === gljCache[j].ID){
  528. isExist = true;
  529. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  530. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  531. break;
  532. }
  533. }
  534. if(!isExist){
  535. isChange = true;
  536. let obj = {};
  537. obj.ID = gljCache[j].ID;
  538. if(typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'){//更新
  539. //obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
  540. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  541. obj.consumeAmt = that.currentComponent[info.cellRange.row + i].consumeAmt;
  542. }
  543. else{
  544. obj.consumeAmtProperty = that.currentComponent[info.cellRange.row + i].consumeAmtProperty;
  545. }
  546. let index;
  547. for(let k = 0; k < component.length; k++){
  548. if(that.currentComponent[info.cellRange.row + i].ID === component[k].ID){
  549. index = k;
  550. break;
  551. }
  552. }
  553. component.splice(index, 1);
  554. component.splice(index, 0, obj);
  555. }
  556. else{//新增
  557. me.initConsumeAmt(obj);
  558. component.push(obj);
  559. }
  560. break;
  561. }
  562. }
  563. else{
  564. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  565. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  566. }
  567. }
  568. /* else{
  569. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  570. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  571. }*/
  572. }
  573. if(!existCode){
  574. me.workBook.getSheet(0).setValue(info.cellRange.row + i, info.cellRange.col,
  575. typeof that.currentComponent[info.cellRange.row + i] !== 'undefined'? that.currentComponent[info.cellRange.row + i].code : '');
  576. }
  577. }
  578. if(isChange){
  579. updateArr.push(that.currentGlj);
  580. }
  581. }
  582. //消耗量
  583. else if(me.colMapping.colToField[info.cellRange.col].includes('consumeAmt')){
  584. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  585. let row = info.cellRange.row;
  586. for(let i = 0; i < items.length; i++){
  587. if(row + i < that.currentComponent.length){
  588. let currentObj = that.currentComponent[row + i];
  589. if(!me.consumeAmtIsEqual(items[i], currentObj)){
  590. isChange = true;
  591. if(!consumeAmtProperties || consumeAmtProperties.length === 0){
  592. let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
  593. currentObj.consumeAmt = roundCons;
  594. for(let j = 0; j < component.length; j++){
  595. if(component[j].ID === currentObj.ID){
  596. component[j].consumeAmt = currentObj.consumeAmt;
  597. break;
  598. }
  599. }
  600. }
  601. else{
  602. for(let attr in items[i]){
  603. //是消耗量字段
  604. if(attr.includes('consumeAmt') && items[i][attr] && !isNaN(parseFloat(items[i][attr]))){
  605. let roundCons = scMathUtil.roundTo(parseFloat(items[i][attr]), -3);
  606. currentObj.consumeAmtProperty[attr] =roundCons;
  607. }
  608. }
  609. for(let j = 0; j < component.length; j++){
  610. if(component[j].ID === currentObj.ID){
  611. component[j].consumeAmtProperty = currentObj.consumeAmtProperty;
  612. break;
  613. }
  614. }
  615. }
  616. }
  617. /*if(items[i].consumeAmt.trim().length > 0 && items[i].consumeAmt !== currentObj.consumeAmt){
  618. let roundCons = scMathUtil.roundTo(parseFloat(items[i].consumeAmt), -3);
  619. isChange = true;
  620. currentObj.consumeAmt = roundCons;
  621. for(let j = 0; j < component.length; j++){
  622. if(component[j].ID === currentObj.ID){
  623. component[j].consumeAmt = currentObj.consumeAmt;
  624. break;
  625. }
  626. }
  627. }*/
  628. else{
  629. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  630. //me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, currentObj.consumeAmt);
  631. }
  632. }
  633. else{
  634. me.workBook.getSheet(0).setValue(row + i, info.cellRange.col, '');
  635. }
  636. }
  637. if(isChange){
  638. updateArr.push(that.currentGlj);
  639. }
  640. }
  641. if(updateArr.length > 0){
  642. me.updateComponent(updateArr);
  643. if(updateBasePrc.length > 0){
  644. me.isPending = true;
  645. that.updateRationBasePrcRq(updateBasePrc, me.workBook, function () {
  646. me.isPending = false;
  647. });
  648. }
  649. }
  650. else {
  651. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  652. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  653. }
  654. let focusInter = setInterval(function () {
  655. if(!$('#loadingPage').is(':visible')){
  656. me.workBook.focus(true);
  657. clearInterval(focusInter);
  658. }
  659. }, 100);
  660. },
  661. updateComponent: function (updateArr) {
  662. let me = gljComponentOprObj, that = repositoryGljObj;
  663. repositoryGljObj.saveInString(updateArr);
  664. $.ajax({
  665. type: 'post',
  666. url: 'api/updateComponent',
  667. data: {libId: pageOprObj.gljLibId, updateArr: updateArr, oprtor: userAccount},
  668. dataType: 'json',
  669. success: function (result) {
  670. if(result.data.length > 0){
  671. if(result.data[0]){
  672. that.currentComponent = that.getCurrentComponent(result.data[0].component);
  673. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  674. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, that.currentComponent);
  675. }
  676. }
  677. }
  678. })
  679. },
  680. reCalGljBasePrc: function (components) {
  681. let me = gljComponentOprObj, re = repositoryGljObj;
  682. //只有一个单价的情况,只有一个单价则只有一个消耗量
  683. if(!priceProperties || priceProperties.length === 0){
  684. let gljBasePrc = 0;
  685. for(let i = 0; i < components.length; i++){
  686. let roundBasePrc = scMathUtil.roundTo(parseFloat(components[i].basePrice), -2);
  687. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(components[i].consumeAmt), -3);
  688. gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
  689. }
  690. return scMathUtil.roundTo(gljBasePrc, -2);
  691. }
  692. //多单价的情况
  693. else {
  694. let gljPriceProperty = re.getPriceProperty(priceProperties);
  695. for(let priceProp in gljPriceProperty){
  696. let consumeAmtField = re.getConsumeAmtField(consumeAmtProperties, priceProp);
  697. for(let component of components){
  698. let roundBasePrc = scMathUtil.roundTo(parseFloat(component['priceProperty'][priceProp]), -2);
  699. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component['consumeAmtProperty'][consumeAmtField]), -3);
  700. gljPriceProperty[priceProp] = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljPriceProperty[priceProp], me.processDecimal);
  701. }
  702. scMathUtil.roundTo(gljPriceProperty[priceProp], -2);
  703. }
  704. return gljPriceProperty;
  705. }
  706. }
  707. /* reCalGljBasePrc: function (component) {
  708. let me = gljComponentOprObj, gljBasePrc = 0;
  709. for(let i = 0; i < component.length; i++){
  710. let roundBasePrc = scMathUtil.roundTo(parseFloat(component[i].basePrice), -2);
  711. let roundConsumeAmt = scMathUtil.roundTo(parseFloat(component[i].consumeAmt), -3);
  712. //gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * parseFloat(component[i].consumeAmt), -2) + gljBasePrc, -2); 旧算法
  713. gljBasePrc = scMathUtil.roundTo(scMathUtil.roundTo(roundBasePrc * roundConsumeAmt, me.processDecimal) + gljBasePrc, me.processDecimal);
  714. }
  715. return scMathUtil.roundTo(gljBasePrc, -2);
  716. }*/
  717. };