coe.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. $("#anzhuang").click(function(){
  16. $(this).attr('href', "/rationRepository/installation" + "?repository=" + getQueryString("repository"))
  17. });
  18. var libID = getQueryString("repository");
  19. var libName = storageUtil.getSessionCache("RationGrp","repositoryID_" + libID);
  20. if (libName) {
  21. var html = $("#rationname")[0].outerHTML;
  22. html = html.replace("XXX定额库", libName);
  23. $("#rationname")[0].outerHTML = html;
  24. };
  25. this.gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + libID);
  26. this.libID = libID;
  27. coeOprObj.buildSheet($('#mainSpread')[0]);
  28. gljAdjOprObj.buildSheet($('#contentSpread')[0]);
  29. coeOprObj.getCoeList();
  30. gljAdjOprObj.getGljItemsOcc();
  31. },
  32. showData: function(sheet, setting, data) {
  33. let me = pageObj, ch = GC.Spread.Sheets.SheetArea.viewport;
  34. sheet.suspendPaint();
  35. sheet.suspendEvent();
  36. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  37. sheet.setRowCount(data.length + 3);
  38. for (let col = 0; col < setting.header.length; col++) {
  39. var hAlign = "left", vAlign = "center";
  40. if (setting.header[col].hAlign) {
  41. hAlign = setting.header[col].hAlign;
  42. } else if (setting.header[col].dataType !== "String"){
  43. hAlign = "right";
  44. }
  45. if(setting.header[col].readOnly){
  46. sheet.getRange(-1, col, -1, 1).locked(true);
  47. }
  48. else{
  49. sheet.getRange(-1, col, -1, 1).locked(false);
  50. }
  51. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  52. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  53. if (setting.header[col].formatter) {
  54. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  55. }
  56. for (let row = 0; row < data.length; row++) {
  57. let val = data[row][setting.header[col].dataCode];
  58. sheet.setValue(row, col, val, ch);
  59. }
  60. }
  61. sheet.resumeEvent();
  62. sheet.resumePaint();
  63. }
  64. };
  65. let coeOprObj = {
  66. workBook: null,
  67. workSheet: null,
  68. currentCoeList: [],
  69. currentCoe: null,
  70. currentMaxNo: null,
  71. setting: {
  72. header: [
  73. {headerName:"编号", headerWidth:60, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  74. {headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  75. {headerName:"内容", headerWidth:250, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  76. ]
  77. },
  78. buildSheet: function (container) {
  79. let me = coeOprObj;
  80. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  81. me.workSheet = me.workBook.getSheet(0);
  82. me.workSheet.options.isProtected = true;
  83. me.onDelOpr(me.workBook, me.setting);
  84. me.workSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  85. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  86. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  87. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  88. },
  89. onSelectionChanged: function (sender, info) {
  90. let me = coeOprObj, that = gljAdjOprObj;
  91. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  92. let row = info.newSelections[0].row;
  93. if(row < me.currentCoeList.length){
  94. me.currentCoe = me.currentCoeList[row];
  95. that.currentGljAdjList = me.currentCoe.coes;
  96. that.buildDynamicComboBox(that.workSheet);
  97. }
  98. else{
  99. me.currentCoe = null;
  100. that.currentGljAdjList = [];
  101. that.buildBaseCell(that.workSheet);
  102. }
  103. //refresh & show coes
  104. sheetCommonObj.cleanSheet(that.workSheet, that.setting, -1);
  105. me.workBook.focus(true);
  106. that.show(that.currentGljAdjList);
  107. }
  108. },
  109. onEditEnded: function (sender, args) {
  110. let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode;
  111. if(args.editingText && args.editingText.toString().trim().length > 0){
  112. let inputT = args.editingText.toString().trim();
  113. //update
  114. if(args.row < me.currentCoeList.length){
  115. let updateObj = me.currentCoeList[args.row];
  116. if(updateObj[dataCode] != inputT){
  117. if(dataCode === 'serialNo'){
  118. if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
  119. me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  120. updateObj[dataCode] = inputT;
  121. updateArr.push(updateObj);
  122. me.save([], updateArr, [], true);
  123. }
  124. else if(!me.isInt(inputT)){
  125. alert('编号只能为整数!');
  126. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
  127. }
  128. else if(me.hasTisNo(me.currentCoeList, inputT)){
  129. alert('该编号已存在!');
  130. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
  131. }
  132. }
  133. else {
  134. updateObj[dataCode] = inputT;
  135. updateArr.push(updateObj);
  136. me.save([], updateArr, [], true);
  137. }
  138. }
  139. }
  140. //insert
  141. else{
  142. let newCoe = {};
  143. newCoe.libID = pageObj.libID;
  144. if(dataCode === 'serialNo'){
  145. if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
  146. me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  147. newCoe[dataCode] = inputT;
  148. addArr.push(newCoe);
  149. me.save(addArr, [], [], true, function (result) {
  150. me.updateCurrentCoeList(result);
  151. });
  152. }
  153. else if(!me.isInt(inputT)){
  154. args.sheet.setValue(args.row, args.col, '');
  155. alert('编号只能为整数!');
  156. }
  157. else if(me.hasTisNo(me.currentCoeList, inputT)){
  158. args.sheet.setValue(args.row, args.col, '');
  159. alert('该编号已存在!');
  160. }
  161. }
  162. else{
  163. newCoe.serialNo = ++me.currentMaxNo;
  164. newCoe[dataCode] = inputT;
  165. addArr.push(newCoe);
  166. me.save(addArr, [], [], true, function (result) {
  167. me.updateCurrentCoeList(result);
  168. });
  169. }
  170. }
  171. }
  172. },
  173. onClipboardPasting: function (sender, info) {
  174. let me = coeOprObj, maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  175. if(maxCol > me.setting.header.length){
  176. info.cancel = true;
  177. }
  178. },
  179. onClipboardPasted: function (sender, info) {
  180. let me = coeOprObj, addArr = [], updateArr = [];
  181. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  182. let uniqItems = me.makeUniqItems(items);
  183. for(let i = 0, len = uniqItems.length; i < len; i++){
  184. let row = i + info.cellRange.row;
  185. //update
  186. if(row < me.currentCoeList.length){
  187. let updateObj = me.currentCoeList[row];
  188. for(let attr in uniqItems[i]){
  189. if(attr === 'serialNo'){
  190. if(me.isInt(uniqItems[i][attr]) && !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])){
  191. me.currentMaxNo = me.currentMaxNo >= uniqItems[i][attr] ? me.currentMaxNo : uniqItems[i][attr];
  192. updateObj[attr] = uniqItems[i][attr];
  193. }
  194. }
  195. else {
  196. updateObj[attr] = uniqItems[i][attr];
  197. }
  198. }
  199. updateArr.push(updateObj);
  200. }
  201. //insert
  202. else {
  203. if(typeof uniqItems[i].serialNo !== 'undefined' && uniqItems[i] && me.isInt(uniqItems[i].serialNo) && !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)){
  204. me.currentMaxNo = me.currentMaxNo >= uniqItems[i].serialNo ? me.currentMaxNo : uniqItems[i].serialNo;
  205. }
  206. else {
  207. uniqItems[i].serialNo = ++me.currentMaxNo;
  208. }
  209. uniqItems[i].libID = pageObj.libID;
  210. addArr.push(uniqItems[i]);
  211. }
  212. }
  213. if(addArr.length > 0 || updateArr.length > 0){
  214. me.save(addArr, updateArr, [], true, function (result) {
  215. me.updateCurrentCoeList(result);
  216. });
  217. }
  218. },
  219. onDelOpr: function (workBook, setting) {
  220. let me = coeOprObj, that = gljAdjOprObj;
  221. workBook.commandManager().register('coeListDel', function () {
  222. let deleteArr = [];
  223. let sheet = workBook.getSheet(0);
  224. let sels = sheet.getSelections();
  225. let idx = sels[0].row;
  226. for(let i = 0, len = sels.length; i < len; i++){
  227. if(idx > sels[i].row){
  228. idx = sels[i].row;
  229. }
  230. if(sels[i].colCount === setting.header.length){//can del
  231. for(let r = 0, rLen = sels[i].rowCount; r < rLen; r++){
  232. let row = sels[i].row + r;
  233. if(row < me.currentCoeList.length){
  234. deleteArr.push({libID: me.currentCoeList[row].libID, ID: me.currentCoeList[row].ID});
  235. }
  236. }
  237. me.currentCoeList.splice(sels[i].row, sels[i].rowCount);
  238. }
  239. }
  240. if(deleteArr.length > 0){
  241. me.save([], [], deleteArr, true);
  242. me.currentCoe = typeof me.currentCoeList[idx] !== 'undefined' ? me.currentCoeList[idx] : null;
  243. that.currentGljAdjList = me.currentCoe ? me.currentCoe.coes : [];
  244. gljAdjOprObj.show(that.currentGljAdjList);
  245. }
  246. });
  247. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  248. workBook.commandManager().setShortcutKey('coeListDel', GC.Spread.Commands.Key.del, false, false, false, false);
  249. },
  250. //粘贴的数据,编号唯一化,去除编号重复的项
  251. makeUniqItems: function (items) {
  252. let rst = [];
  253. for(let i = 0, len = items.length; i < len; i++){
  254. if(typeof items[i].serialNo !== 'undefined' && items[i].serialNo){
  255. if(rst.length === 0){
  256. rst.push(items[i]);
  257. }
  258. else{
  259. let isExist = false;
  260. for(let j = 0, jLen = rst.length; j < jLen; j++){
  261. if(items[i].serialNo === rst[j].serialNo){
  262. isExist = true;
  263. break;
  264. }
  265. }
  266. if(!isExist){
  267. rst.push(items[i]);
  268. }
  269. }
  270. }
  271. else {
  272. rst.push(items[i]);
  273. }
  274. }
  275. return rst;
  276. },
  277. isInt: function (num) {
  278. return !isNaN(num) && num % 1 === 0;
  279. },
  280. hasTisNo: function (coeList, newSerialNo) {
  281. let rst = false;
  282. for(let i = 0, len = coeList.length; i < len; i++){
  283. if(coeList[i].serialNo == newSerialNo){
  284. rst = true;
  285. break;
  286. }
  287. }
  288. return rst;
  289. },
  290. updateCurrentCoeList: function (newCoeList) {
  291. let me = coeOprObj;
  292. if(newCoeList){
  293. me.currentCoeList = me.currentCoeList.concat(newCoeList);
  294. }
  295. },
  296. sortCoeList: function (coeList) {
  297. coeList.sort(function (a, b) {
  298. let rst = 0;
  299. if(a.serialNo > b.serialNo) rst = 1;
  300. else if(a.serialNo < b.serialNo) rst = -1;
  301. return rst;
  302. });
  303. },
  304. getCoeList: function () {
  305. let me = coeOprObj;
  306. $.ajax({
  307. type: 'post',
  308. url: '/rationRepository/api/getCoeList',
  309. data: {libID: pageObj.libID},
  310. dataType: 'json',
  311. timeout:20000,
  312. success: function (result) {
  313. if(!result.error){
  314. me.currentCoeList = result.data;
  315. me.sortCoeList(me.currentCoeList);
  316. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  317. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  318. me.workSheet.clearSelection();
  319. }
  320. },
  321. error:function(err){
  322. alert("内部程序错误!");
  323. }
  324. });
  325. },
  326. save: function (addArr, updateArr, deleteArr, refresh, callback) {
  327. let me = coeOprObj;
  328. $.ajax({
  329. type:"POST",
  330. url:"api/saveCoeList",
  331. data: {data: JSON.stringify({addArr: addArr, updateArr: updateArr, deleteArr: deleteArr})},
  332. dataType:"json",
  333. timeout:5000,
  334. success:function(result){
  335. if (result.error) {
  336. alert(result.message);
  337. } else{
  338. if(callback){
  339. if(result.message === 'mixed'){
  340. for(let i = 0, len = result.data.length; i < len; i++){
  341. if(result.data[i][0] === 'addSc'){
  342. result.data = result.data[i][1];
  343. break;
  344. }
  345. }
  346. }
  347. callback(result.data);
  348. }
  349. if(refresh){
  350. me.sortCoeList(me.currentCoeList);
  351. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  352. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  353. }
  354. }
  355. },
  356. error:function(err){
  357. alert("内部程序错误!");
  358. }
  359. });
  360. }
  361. };
  362. let gljAdjOprObj = {
  363. workBook: null,
  364. workSheet: null,
  365. currentGljAdjList: [],
  366. gljList: [],//只含编号和名称的总工料机列表
  367. setting: {
  368. header: [
  369. {headerName:"调整类型", headerWidth:100, dataCode:"coeType", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  370. {headerName:"工料机编码", headerWidth:100, dataCode:"gljCode", dataType: "String", formatter: '@', hAlign: "center", vAlign: "center", readOnly: false},
  371. {headerName:"名称", headerWidth:100, dataCode:"gljName", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
  372. {headerName:"操作符", headerWidth:60, dataCode:"operator", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  373. {headerName:"数量", headerWidth:80, dataCode:"amount", dataType: "String", hAlign: "center", vAlign: "center" , readOnly: false},
  374. ],
  375. comboItems: {
  376. //调整类型下拉菜单
  377. coeType: ['定额子目', '人工类', '材料类', '机械类', '主材类', '设备类', '单个工料机'],
  378. //操作符下拉菜单
  379. operator: ['+', '-', '*', '/', '=']
  380. }
  381. },
  382. buildSheet: function (container) {
  383. let me = gljAdjOprObj;
  384. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
  385. me.workSheet = me.workBook.getSheet(0);
  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 !== 'gljCode') {
  453. isUpdate = true;
  454. updateObj[dataCode] = args.editingText;
  455. }
  456. }
  457. //insert
  458. else if(args.row >= me.currentGljAdjList.length){
  459. isUpdate = true;
  460. let newAdjGlj = {};
  461. newAdjGlj[dataCode] = args.editingText;
  462. me.currentGljAdjList.push(newAdjGlj);
  463. }
  464. if(isUpdate){
  465. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  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. };