coe.js 28 KB

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