coe.js 28 KB

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