coe.js 29 KB

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