coe.js 29 KB

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