coe.js 28 KB

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