coe.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /**
  2. * Created by CSL on 2017-05-18.
  3. */
  4. //modiyied by zhong on 2017/9/21
  5. $('#zmhs').click(function () {
  6. if(!$(this).hasClass('active')){
  7. $(this).addClass('active');
  8. $('#mainContent').css('width', '50%');
  9. $('#zmhsContent').show();
  10. /* loadSize(sideResizeEles, 'width', function(){
  11. });*/
  12. if(!coeOprObj.workBook){
  13. pageObj.initPage();
  14. }
  15. coeOprObj.workBook.refresh();
  16. gljAdjOprObj.workBook.refresh();
  17. rationOprObj.workBook.refresh();
  18. rationGLJOprObj.sheet.getParent().refresh();
  19. } else {
  20. $(this).removeClass('active');
  21. $('#mainContent').css('width', '75%')
  22. $('#zmhsContent').hide();
  23. rationOprObj.workBook.refresh();
  24. rationGLJOprObj.sheet.getParent().refresh();
  25. }
  26. });
  27. var pageObj = {
  28. initPage: function (){
  29. let me = this;
  30. coeOprObj.buildSheet($('#mainSpread')[0]);
  31. gljAdjOprObj.buildSheet($('#contentSpread')[0]);
  32. coeOprObj.getCoeList();
  33. //gljAdjOprObj.getGljItemsOcc();
  34. },
  35. showData: function(sheet, setting, data) {
  36. let me = pageObj, ch = GC.Spread.Sheets.SheetArea.viewport;
  37. sheet.suspendPaint();
  38. sheet.suspendEvent();
  39. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  40. sheet.setRowCount(data.length + 3);
  41. for (let col = 0; col < setting.header.length; col++) {
  42. var hAlign = "left", vAlign = "center";
  43. if (setting.header[col].hAlign) {
  44. hAlign = setting.header[col].hAlign;
  45. } else if (setting.header[col].dataType !== "String"){
  46. hAlign = "right";
  47. }
  48. if(setting.header[col].readOnly){
  49. sheet.getRange(-1, col, -1, 1).locked(true);
  50. }
  51. else{
  52. sheet.getRange(-1, col, -1, 1).locked(false);
  53. }
  54. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  55. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  56. if (setting.header[col].formatter) {
  57. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  58. }
  59. for (let row = 0; row < data.length; row++) {
  60. let val = data[row][setting.header[col].dataCode];
  61. sheet.setValue(row, col, val, ch);
  62. }
  63. }
  64. sheet.resumeEvent();
  65. sheet.resumePaint();
  66. }
  67. };
  68. let coeOprObj = {
  69. workBook: null,
  70. workSheet: null,
  71. currentCoeList: [],
  72. currentCoe: null,
  73. currentMaxNo: null,
  74. setting: {
  75. header: [
  76. {headerName:"编号", headerWidth:50, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  77. {headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  78. {headerName:"内容", headerWidth:150, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  79. ]
  80. },
  81. buildSheet: function (container) {
  82. let me = coeOprObj;
  83. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  84. sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: null, editEnded: me.onEditEnded}]);
  85. me.workSheet = me.workBook.getSheet(0);
  86. me.workSheet.options.isProtected = true;
  87. me.onDelOpr(me.workBook, me.setting);
  88. me.workSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  89. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  90. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  91. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  92. },
  93. onSelectionChanged: function (sender, info) {
  94. let me = coeOprObj, that = gljAdjOprObj;
  95. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  96. let row = info.newSelections[0].row;
  97. if(row < me.currentCoeList.length){
  98. me.currentCoe = me.currentCoeList[row];
  99. that.currentGljAdjList = me.currentCoe.coes;
  100. that.buildDynamicComboBox(that.workSheet);
  101. }
  102. else{
  103. me.currentCoe = null;
  104. that.currentGljAdjList = [];
  105. that.buildBaseCell(that.workSheet);
  106. }
  107. //refresh & show coes
  108. sheetCommonObj.cleanSheet(that.workSheet, that.setting, -1);
  109. me.workBook.focus(true);
  110. that.show(that.currentGljAdjList);
  111. }
  112. },
  113. onEditEnded: function (sender, args) {
  114. let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode;
  115. if(args.editingText && args.editingText.toString().trim().length > 0){
  116. let inputT = args.editingText.toString().trim();
  117. //update
  118. if(args.row < me.currentCoeList.length){
  119. let updateObj = me.currentCoeList[args.row];
  120. if(updateObj[dataCode] != inputT){
  121. if(dataCode === 'serialNo'){
  122. if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
  123. me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  124. updateObj[dataCode] = inputT;
  125. updateArr.push(updateObj);
  126. me.save([], updateArr, [], true);
  127. }
  128. else if(!me.isInt(inputT)){
  129. alert('编号只能为整数!');
  130. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
  131. }
  132. else if(me.hasTisNo(me.currentCoeList, inputT)){
  133. alert('该编号已存在!');
  134. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
  135. }
  136. }
  137. else {
  138. updateObj[dataCode] = inputT;
  139. updateArr.push(updateObj);
  140. me.save([], updateArr, [], true);
  141. }
  142. }
  143. }
  144. //insert
  145. else{
  146. let newCoe = {};
  147. if(dataCode === 'serialNo'){
  148. if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
  149. me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  150. newCoe[dataCode] = inputT;
  151. addArr.push(newCoe);
  152. me.save(addArr, [], [], true, function (result) {
  153. me.updateCurrentCoeList(result);
  154. });
  155. }
  156. else if(!me.isInt(inputT)){
  157. args.sheet.setValue(args.row, args.col, '');
  158. alert('编号只能为整数!');
  159. }
  160. else if(me.hasTisNo(me.currentCoeList, inputT)){
  161. args.sheet.setValue(args.row, args.col, '');
  162. alert('该编号已存在!');
  163. }
  164. }
  165. else{
  166. newCoe.serialNo = ++me.currentMaxNo;
  167. newCoe[dataCode] = inputT;
  168. addArr.push(newCoe);
  169. me.save(addArr, [], [], true, function (result) {
  170. me.updateCurrentCoeList(result);
  171. });
  172. }
  173. }
  174. }
  175. },
  176. onClipboardPasting: function (sender, info) {
  177. let me = coeOprObj, maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  178. if(maxCol > me.setting.header.length){
  179. info.cancel = true;
  180. }
  181. },
  182. onClipboardPasted: function (sender, info) {
  183. let me = coeOprObj, addArr = [], updateArr = [];
  184. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  185. let uniqItems = me.makeUniqItems(items);
  186. for(let i = 0, len = uniqItems.length; i < len; i++){
  187. let row = i + info.cellRange.row;
  188. //update
  189. if(row < me.currentCoeList.length){
  190. let updateObj = me.currentCoeList[row];
  191. for(let attr in uniqItems[i]){
  192. if(attr === 'serialNo'){
  193. if(me.isInt(uniqItems[i][attr]) && !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])){
  194. me.currentMaxNo = me.currentMaxNo >= uniqItems[i][attr] ? me.currentMaxNo : uniqItems[i][attr];
  195. updateObj[attr] = uniqItems[i][attr];
  196. }
  197. }
  198. else {
  199. updateObj[attr] = uniqItems[i][attr];
  200. }
  201. }
  202. updateArr.push(updateObj);
  203. }
  204. //insert
  205. else {
  206. if(typeof uniqItems[i].serialNo !== 'undefined' && uniqItems[i] && me.isInt(uniqItems[i].serialNo) && !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)){
  207. me.currentMaxNo = me.currentMaxNo >= uniqItems[i].serialNo ? me.currentMaxNo : uniqItems[i].serialNo;
  208. }
  209. else {
  210. uniqItems[i].serialNo = ++me.currentMaxNo;
  211. }
  212. addArr.push(uniqItems[i]);
  213. }
  214. }
  215. if(addArr.length > 0 || updateArr.length > 0){
  216. me.save(addArr, updateArr, [], true, function (result) {
  217. me.updateCurrentCoeList(result);
  218. });
  219. }
  220. },
  221. onDelOpr: function (workBook, setting) {
  222. let me = coeOprObj, that = gljAdjOprObj;
  223. workBook.commandManager().register('coeListDel', function () {
  224. let deleteArr = [];
  225. let sheet = workBook.getSheet(0);
  226. let sels = sheet.getSelections();
  227. let idx = sels[0].row;
  228. for(let i = 0, len = sels.length; i < len; i++){
  229. if(idx > sels[i].row){
  230. idx = sels[i].row;
  231. }
  232. if(sels[i].colCount === setting.header.length){//can del
  233. for(let r = 0, rLen = sels[i].rowCount; r < rLen; r++){
  234. let row = sels[i].row + r;
  235. if(row < me.currentCoeList.length){
  236. deleteArr.push({userId: me.currentCoeList[row].userId, compilationId: me.currentCoeList[row].compilationId, ID: me.currentCoeList[row].ID});
  237. }
  238. }
  239. me.currentCoeList.splice(sels[i].row, sels[i].rowCount);
  240. }
  241. }
  242. if(deleteArr.length > 0){
  243. me.save([], [], deleteArr, true);
  244. me.currentCoe = typeof me.currentCoeList[idx] !== 'undefined' ? me.currentCoeList[idx] : null;
  245. that.currentGljAdjList = me.currentCoe ? me.currentCoe.coes : [];
  246. gljAdjOprObj.show(that.currentGljAdjList);
  247. }
  248. });
  249. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  250. workBook.commandManager().setShortcutKey('coeListDel', GC.Spread.Commands.Key.del, false, false, false, false);
  251. },
  252. //粘贴的数据,编号唯一化,去除编号重复的项
  253. makeUniqItems: function (items) {
  254. let rst = [];
  255. for(let i = 0, len = items.length; i < len; i++){
  256. if(typeof items[i].serialNo !== 'undefined' && items[i].serialNo){
  257. if(rst.length === 0){
  258. rst.push(items[i]);
  259. }
  260. else{
  261. let isExist = false;
  262. for(let j = 0, jLen = rst.length; j < jLen; j++){
  263. if(items[i].serialNo === rst[j].serialNo){
  264. isExist = true;
  265. break;
  266. }
  267. }
  268. if(!isExist){
  269. rst.push(items[i]);
  270. }
  271. }
  272. }
  273. else {
  274. rst.push(items[i]);
  275. }
  276. }
  277. return rst;
  278. },
  279. isInt: function (num) {
  280. return !isNaN(num) && num % 1 === 0;
  281. },
  282. hasTisNo: function (coeList, newSerialNo) {
  283. let rst = false;
  284. for(let i = 0, len = coeList.length; i < len; i++){
  285. if(coeList[i].serialNo == newSerialNo){
  286. rst = true;
  287. break;
  288. }
  289. }
  290. return rst;
  291. },
  292. updateCurrentCoeList: function (newCoeList) {
  293. let me = coeOprObj;
  294. if(newCoeList){
  295. me.currentCoeList = me.currentCoeList.concat(newCoeList);
  296. }
  297. },
  298. sortCoeList: function (coeList) {
  299. coeList.sort(function (a, b) {
  300. let rst = 0;
  301. if(a.serialNo > b.serialNo) rst = 1;
  302. else if(a.serialNo < b.serialNo) rst = -1;
  303. return rst;
  304. });
  305. },
  306. getCoeList: function () {
  307. let me = coeOprObj;
  308. $.ajax({
  309. type: 'post',
  310. url: 'api/getCoeList',
  311. dataType: 'json',
  312. timeout:20000,
  313. success: function (result) {
  314. if(!result.error){
  315. me.currentCoeList = result.data;
  316. me.sortCoeList(me.currentCoeList);
  317. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  318. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  319. me.workSheet.clearSelection();
  320. }
  321. },
  322. error:function(err){
  323. alert("内部程序错误!");
  324. }
  325. });
  326. },
  327. save: function (addArr, updateArr, deleteArr, refresh, callback) {
  328. let me = coeOprObj;
  329. $.ajax({
  330. type:"POST",
  331. url:"api/saveCoeList",
  332. data: {data: JSON.stringify({addArr: addArr, updateArr: updateArr, deleteArr: deleteArr})},
  333. dataType:"json",
  334. timeout:5000,
  335. success:function(result){
  336. if (result.error) {
  337. alert(result.message);
  338. } else{
  339. if(callback){
  340. callback(result.data);
  341. }
  342. if(refresh){
  343. me.sortCoeList(me.currentCoeList);
  344. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  345. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  346. }
  347. }
  348. },
  349. error:function(err){
  350. alert("内部程序错误!");
  351. }
  352. });
  353. }
  354. };
  355. let gljAdjOprObj = {
  356. workBook: null,
  357. workSheet: null,
  358. currentGljAdjList: [],
  359. gljList: [],//总工料机列表, gljSelect中获取
  360. setting: {
  361. header: [
  362. {headerName:"调整类型", headerWidth:80, dataCode:"coeType", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  363. {headerName:"人材机编码", headerWidth:80, dataCode:"gljCode", dataType: "String", formatter: '@', hAlign: "center", vAlign: "center", readOnly: false},
  364. {headerName:"名称", headerWidth:100, dataCode:"gljName", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
  365. {headerName:"操作符", headerWidth:60, dataCode:"operator", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  366. {headerName:"数量", headerWidth:80, dataCode:"amount", dataType: "String", hAlign: "center", vAlign: "center" , readOnly: false},
  367. ],
  368. comboItems: {
  369. //调整类型下拉菜单
  370. coeType: ['定额', '人工', '材料', '机械', '主材', '设备', '单个工料机'],
  371. //操作符下拉菜单
  372. operator: ['+', '-', '*', '/', '=']
  373. }
  374. },
  375. buildSheet: function (container) {
  376. let me = gljAdjOprObj;
  377. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
  378. me.workSheet = me.workBook.getSheet(0);
  379. sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onEditStart, editEnded: me.onEditEnded}]);
  380. me.workSheet.options.isProtected = true;
  381. me.onDelOpr(me.workBook, me.setting);
  382. me.workSheet.clearSelection();
  383. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStart);
  384. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  385. me.workSheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  386. me.workSheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  387. me.workSheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  388. },
  389. buildBaseCell: function (sheet) {
  390. let me = gljAdjOprObj;
  391. sheet.suspendPaint();
  392. sheet.suspendEvent();
  393. let baseCell = GC.Spread.Sheets.CellTypes.Base();
  394. sheet.getCell(-1, 0).cellType(baseCell);
  395. sheet.getCell(-1, 3).cellType(baseCell);
  396. sheet.resumePaint();
  397. sheet.resumeEvent();
  398. },
  399. buildDynamicComboBox: function (sheet) {
  400. let me = gljAdjOprObj;
  401. sheet.suspendPaint();
  402. sheet.suspendEvent();
  403. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  404. dynamicCombo.items(me.setting.comboItems.coeType);
  405. let dynamicOprCombo = sheetCommonObj.getDynamicCombo();
  406. dynamicOprCombo.items(me.setting.comboItems.operator);
  407. sheet.getCell(-1, 0).cellType(dynamicCombo);
  408. sheet.getCell(-1, 3).cellType(dynamicOprCombo);
  409. sheet.resumePaint();
  410. sheet.resumeEvent();
  411. },
  412. onEnterCell: function (sender, args) {
  413. args.sheet.repaint();
  414. },
  415. onEditStart: function (sender, args) {
  416. let me = gljAdjOprObj;
  417. if(!coeOprObj.currentCoe || args.row >= me.currentGljAdjList.length && args.col === 1
  418. || args.row < me.currentGljAdjList.length && args.col === 1 && me.currentGljAdjList[args.row].coeType !== '单个工料机'){
  419. args.cancel = true;
  420. }
  421. },
  422. onEditEnded: function (sender, args) {
  423. let me = gljAdjOprObj, isUpdate = false,
  424. dataCode = me.setting.header[args.col].dataCode;
  425. if(args.editingText && args.editingText.toString().trim().length > 0){
  426. if(dataCode === 'amount' && isNaN(args.editingText)){
  427. alert("只能输入数值!");
  428. args.sheet.setValue(args.row, args.col, typeof me.currentGljAdjList[args.row] !== 'undefined' && typeof me.currentGljAdjList[args.row][dataCode] !== 'undefined'
  429. ? me.currentGljAdjList[args.row][dataCode] + '' : '');
  430. }
  431. else {
  432. //update
  433. if(args.row < me.currentGljAdjList.length && args.editingText.toString().trim() !== me.currentGljAdjList[args.row][dataCode]){
  434. let updateObj = me.currentGljAdjList[args.row];
  435. if(dataCode === 'gljCode' && typeof updateObj.coeType !== 'undefined' && updateObj.coeType === '单个工料机'){
  436. let gljName = me.getGljName(args.editingText, me.gljList);
  437. if(gljName){
  438. updateObj.gljCode = args.editingText;
  439. updateObj.gljName = gljName;
  440. isUpdate = true;
  441. }
  442. else {
  443. alert("不存在编号为"+ args.editingText +"的工料机");
  444. }
  445. }
  446. else if(dataCode === 'coeType'){
  447. isUpdate = true;
  448. updateObj[dataCode] = args.editingText;
  449. updateObj.gljCode = '';
  450. updateObj.gljName = '';
  451. }
  452. else if(dataCode !== 'gljCode') {
  453. isUpdate = true;
  454. updateObj[dataCode] = args.editingText;
  455. }
  456. }
  457. //insert
  458. else if(args.row >= me.currentGljAdjList.length){
  459. isUpdate = true;
  460. let newAdjGlj = {};
  461. newAdjGlj[dataCode] = args.editingText;
  462. me.currentGljAdjList.push(newAdjGlj);
  463. }
  464. if(isUpdate){
  465. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  466. console.log(me.currentGljAdjList);
  467. me.show(me.currentGljAdjList);
  468. });
  469. }
  470. else {
  471. args.sheet.setValue(args.row, args.col, typeof me.currentGljAdjList[args.row] !== 'undefined' && typeof me.currentGljAdjList[args.row][dataCode] !== 'undefined'
  472. ? me.currentGljAdjList[args.row][dataCode] + '' : '');
  473. }
  474. }
  475. }
  476. },
  477. onClipboardPasting: function (sender, info) {
  478. },
  479. getValidPasteDatas: function (pasteItems, info) {
  480. let me = gljAdjOprObj;
  481. let rst = [];
  482. for(let i = 0, len = pasteItems.length; i < len; i++){
  483. let row = i + info.cellRange.row;
  484. let validObj = {};
  485. //update
  486. if(row < me.currentGljAdjList.length){
  487. let updateObj = me.currentGljAdjList[row];
  488. if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
  489. let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
  490. if(pasteItems[i].coeType === '单个工料机' && gljName){
  491. validObj.coeType = pasteItems[i].coeType;
  492. validObj.gljCode = pasteItems[i].gljCode;
  493. validObj.gljName = gljName;
  494. }
  495. else if(pasteItems[i].coeType !== '单个工料机' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
  496. validObj.coeType = pasteItems[i].coeType;
  497. }
  498. }
  499. else if(typeof pasteItems[i].coeType === 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
  500. let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
  501. if(typeof updateObj.coeType !== 'undefined' && updateObj.coeType === '单个工料机' && gljName){
  502. validObj.gljCode = pasteItems[i].gljCode;
  503. validObj.gljName = gljName;
  504. }
  505. }
  506. else if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode === 'undefined'){
  507. if(me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
  508. validObj.coeType = pasteItems[i].coeType;
  509. if(validObj.coeType !== '单个工料机' && typeof updateObj.gljCode !== '单个工料机' && updateObj.gljCode.toString().trim().length > 0){
  510. validObj.gljCode = '';
  511. validObj.gljName = '';
  512. }
  513. }
  514. }
  515. else {
  516. if(typeof pasteItems[i].operator !== 'undefined' && me.setting.comboItems.operator.indexOf(pasteItems[i].operator) !== -1){
  517. validObj.operator = pasteItems[i].operator;
  518. }
  519. if(typeof pasteItems[i].amount !== 'undefined' && !isNaN(pasteItems[i].amount)){
  520. validObj.amount = pasteItems[i].amount;
  521. }
  522. }
  523. }
  524. else {
  525. if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
  526. let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
  527. if(pasteItems[i].coeType === '单个工料机' && gljName){
  528. validObj.coeType = pasteItems[i].coeType;
  529. validObj.gljCode = pasteItems[i].gljCode;
  530. validObj.gljName = gljName;
  531. }
  532. else if(pasteItems[i].coeType !== '单个工料机' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
  533. validObj.coeType = pasteItems[i].coeType;
  534. }
  535. }
  536. else if(typeof pasteItems[i].gljCode === 'undefined') {
  537. if(typeof pasteItems[i].coeType !== 'undefined' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
  538. validObj.coeType = pasteItems[i].coeType;
  539. }
  540. if(typeof pasteItems[i].operator !== 'undefined' && me.setting.comboItems.operator.indexOf(pasteItems[i].operator) !== -1){
  541. validObj.operator = pasteItems[i].operator;
  542. }
  543. if(typeof pasteItems[i].amount !== 'undefined' && !isNaN(pasteItems[i].amount)){
  544. validObj.amount = pasteItems[i].amount;
  545. }
  546. }
  547. }
  548. if(Object.keys(validObj).length > 0){
  549. rst.push(validObj);
  550. }
  551. }
  552. return rst;
  553. },
  554. onClipboardPasted: function (sender, info) {
  555. let me = gljAdjOprObj, row;
  556. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  557. let validDatas = me.getValidPasteDatas(items, info);
  558. for(let i = 0, len = validDatas.length; i < len; i++){
  559. row = i + info.cellRange.row;
  560. //update
  561. if(row < me.currentGljAdjList.length){
  562. let updateObj = me.currentGljAdjList[row];
  563. for(let attr in validDatas[i]){
  564. updateObj[attr] = validDatas[i][attr];
  565. }
  566. }
  567. //insert
  568. else{
  569. me.currentGljAdjList.push(validDatas[i]);
  570. }
  571. }
  572. if(validDatas.length > 0){
  573. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  574. me.show(me.currentGljAdjList);
  575. });
  576. }
  577. else {
  578. me.show(me.currentGljAdjList);
  579. }
  580. },
  581. onDelOpr: function (workBook, setting) {
  582. let me = gljAdjOprObj;
  583. workBook.commandManager().register('gljAdjDel', function () {
  584. let sheet = workBook.getSheet(0);
  585. let sels = sheet.getSelections();
  586. let isUpdate = false;
  587. for(let i = 0, len = sels.length; i < len; i++){
  588. if(sels[i].colCount === setting.header.length){//can del
  589. if(sels[i].row < me.currentGljAdjList.length){
  590. isUpdate = true;
  591. me.currentGljAdjList.splice(sels[i].row, sels[i].rowCount);
  592. }
  593. }
  594. }
  595. if(isUpdate){
  596. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  597. me.show(me.currentGljAdjList);
  598. });
  599. }
  600. });
  601. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  602. workBook.commandManager().setShortcutKey('gljAdjDel', GC.Spread.Commands.Key.del, false, false, false, false);
  603. },
  604. getGljName: function (gljCode, gljList) {
  605. let rst = null;
  606. for(let i = 0, len = gljList.length; i < len; i++){
  607. if(gljCode === gljList[i].code){
  608. rst = gljList[i].name;
  609. break;
  610. }
  611. }
  612. return rst;
  613. },
  614. show: function (coes) {
  615. let me = gljAdjOprObj;
  616. pageObj.showData(me.workSheet, me.setting, coes)
  617. },
  618. getGljItemsOcc: function () {
  619. let me = gljAdjOprObj;
  620. $.ajax({
  621. type: 'post',
  622. url: '/stdGljRepository/api/getGljItemsOccupied',
  623. data: {repId: pageObj.gljLibID, occupation: '-_id code name'},
  624. dataType: 'json',
  625. timeout: 5000,
  626. success:function(result){
  627. if (result.error) {
  628. alert(result.message);
  629. } else{
  630. me.gljList = result.data;
  631. }
  632. },
  633. error:function(err){
  634. alert("内部程序错误!");
  635. }
  636. });
  637. }
  638. };