coe.js 29 KB

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