coe.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /**
  2. * Created by CSL on 2017-05-18.
  3. */
  4. //modiyied by zhong on 2017/9/21
  5. $(document).ready(function () {
  6. let moduleName = 'compleRation';
  7. function refreshALlWorkBook() {
  8. if (sectionTreeObj.workBook) {
  9. sectionTreeObj.workBook.refresh();
  10. }
  11. if (rationOprObj.workBook) {
  12. rationOprObj.workBook.refresh();
  13. }
  14. if (rationGLJOprObj.sheet && rationGLJOprObj.sheet.getParent()) {
  15. rationGLJOprObj.sheet.getParent().refresh();
  16. }
  17. if (coeOprObj.workBook) {
  18. coeOprObj.workBook.refresh();
  19. }
  20. if (gljAdjOprObj.workBook) {
  21. gljAdjOprObj.workBook.refresh();
  22. }
  23. }
  24. //定额章节树与定额表
  25. let leftElesObj = {};
  26. leftElesObj.module = moduleName;
  27. leftElesObj.resize = $('#slideResizeLeft');
  28. leftElesObj.parent = $('#dataRow');
  29. leftElesObj.left = $('#leftContent');
  30. leftElesObj.right = $('#mainContent');
  31. let maxEval = `$('#zmhsContent').is(':visible') ? $('#dataRow').width() - $('#zmhsContent').width() - 300 : $('#dataRow').width() - 300`;
  32. SlideResize.horizontalSlide(leftElesObj, {min: 300, max: maxEval}, function () {
  33. refreshALlWorkBook();
  34. });
  35. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft')], [$('#leftContent'), $('#mainContent')], function () {
  36. //refreshAfterZmhs(false);
  37. let leftContentWidth = parseFloat($('#leftContent')[0].style.width.replace('%', '')),
  38. mainContentWidth = parseFloat($('#mainContent')[0].style.width.replace('%', ''));
  39. let surplus = 100 - leftContentWidth - mainContentWidth;
  40. $('#leftContent').css('width', `${leftContentWidth + surplus / 2}%`);
  41. $('#mainContent').css('width', `${mainContentWidth + surplus / 2}%`);
  42. refreshALlWorkBook();
  43. });
  44. //定额表与子目换算表
  45. let rightElesObj = {};
  46. rightElesObj.module = moduleName;
  47. rightElesObj.resize = $('#slideResizeRight');
  48. rightElesObj.parent = $('#dataRow');
  49. rightElesObj.left = $('#mainContent');
  50. rightElesObj.right = $('#zmhsContent');
  51. let maxEvalRight = `$('#dataRow').width() - $('#leftContent').width() - 200`;
  52. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: maxEvalRight}, function () {
  53. refreshALlWorkBook();
  54. });
  55. //设置水平拖动条的宽度
  56. //@param {Object dom}resize滚动条
  57. function setResizeWidth (resize) {
  58. const fixedWidth = 10;
  59. //跟滚动条同层的其他节点
  60. let bros = resize.parent().children();
  61. //滚动条节点 及 同层非滚动条节点的索引
  62. let index = bros.index(resize),
  63. otherIndex = index ? 0 : 1;
  64. const other = resize.parent().children(`:eq(${otherIndex})`);
  65. let resizeParentWidth = resize.parent().width();
  66. let resizeDecimalWidth = fixedWidth / resizeParentWidth,
  67. otherDecimalWidth = 1 - resizeDecimalWidth;
  68. let resizePercentWidth = resizeDecimalWidth * 100 + '%',
  69. otherPercentWidth = otherDecimalWidth * 100 + '%';
  70. resize.css('width', resizePercentWidth);
  71. other.css('width', otherPercentWidth);
  72. }
  73. function refreshAfterZmhs(visible) {
  74. const min = 20;
  75. //宽度比例localstorage key
  76. let leftContentKey = `${moduleName}${$('#leftContent').attr('id')}Width`,
  77. mainContentKey = `${moduleName}${$('#mainContent').attr('id')}Width`,
  78. zmhsContentKey = `${moduleName}${$('#zmhsContent').attr('id')}Width`;
  79. let zmhsWidth = getLocalCache(zmhsContentKey) ? getLocalCache(zmhsContentKey) :$('#zmhsContent')[0].style.width,
  80. mainContentWidth = $('#mainContent')[0].style.width,
  81. leftContentWidth;
  82. zmhsWidth = parseFloat(zmhsWidth.replace('%', ''));
  83. mainContentWidth = parseFloat(mainContentWidth.replace('%', ''));
  84. if (visible) {
  85. mainContentWidth = mainContentWidth - zmhsWidth / 2 < min ? min : mainContentWidth - zmhsWidth / 2;
  86. if (100 - mainContentWidth - zmhsWidth < min) {
  87. leftContentWidth = min;
  88. zmhsWidth = 100 - mainContentWidth - leftContentWidth;
  89. } else {
  90. leftContentWidth = 100 - mainContentWidth - zmhsWidth;
  91. }
  92. } else {
  93. mainContentWidth += zmhsWidth / 2;
  94. leftContentWidth = 100 - mainContentWidth;
  95. }
  96. $('#leftContent').css('width', `${leftContentWidth}%`);
  97. setLocalCache(leftContentKey, `${leftContentWidth}%`);
  98. $('#mainContent').css('width', `${mainContentWidth}%`);
  99. setLocalCache(mainContentKey, `${mainContentWidth}%`);
  100. $('#zmhsContent').css('width', `${zmhsWidth}%`);
  101. setLocalCache(zmhsContentKey, `${zmhsWidth}%`);
  102. let resizes = [$('#slideResizeLeft'), $('#slideResizeRight')];
  103. for (let resize of resizes) {
  104. setResizeWidth(resize);
  105. }
  106. }
  107. $('#zmhs').click(function () {
  108. if(!$(this).hasClass('active')){
  109. $(this).addClass('active');
  110. refreshAfterZmhs(true);
  111. $('#zmhsContent').show();
  112. if(!coeOprObj.workBook){
  113. pageObj.initPage();
  114. }
  115. refreshALlWorkBook();
  116. } else {
  117. $(this).removeClass('active');
  118. refreshAfterZmhs(false);
  119. $('#zmhsContent').hide();
  120. refreshALlWorkBook();
  121. }
  122. });
  123. //子目换算和调整表上下拖动
  124. let zmhsAdjResize = getZmhsAdjResize();
  125. SlideResize.verticalSlide(zmhsAdjResize.eleObj, zmhsAdjResize.limit, function () {
  126. if (coeOprObj.workBook) {
  127. coeOprObj.workBook.refresh();
  128. }
  129. if (gljAdjOprObj.workBook) {
  130. gljAdjOprObj.workBook.refresh();
  131. }
  132. });
  133. loadZmhsAdjSize(zmhsAdjResize);
  134. });
  135. function getZmhsAdjResize() {
  136. let zmhsAdjResize = {};
  137. zmhsAdjResize.eleObj = {
  138. module: 'compleRation',
  139. resize: $('#zmhsAdjResize'),
  140. top: $('#mainSpread'),
  141. topSpread: $('#mainSpread'),
  142. bottom: $('#contentSpread'),
  143. bottomSpread: $('#contentSpread')
  144. };
  145. zmhsAdjResize.limit = {
  146. min: 150,
  147. max: `$(window).height()-$('.header').height()-150-10`,
  148. totalHeight: `$(window).height()-$('.header').height()-10`,
  149. notTopSpread: 0,
  150. notBottomSpread: 0,
  151. };
  152. return zmhsAdjResize;
  153. }
  154. function loadZmhsAdjSize(resizeObj) {
  155. if (!resizeObj) {
  156. resizeObj = getZmhsAdjResize();
  157. }
  158. SlideResize.loadVerticalHeight(resizeObj.eleObj.module, resizeObj.eleObj, resizeObj.limit, function () {
  159. if (coeOprObj.workBook) {
  160. coeOprObj.workBook.refresh();
  161. }
  162. if (gljAdjOprObj.workBook) {
  163. gljAdjOprObj.workBook.refresh();
  164. }
  165. });
  166. }
  167. var pageObj = {
  168. initPage: function (){
  169. let me = this;
  170. coeOprObj.buildSheet($('#mainSpread')[0]);
  171. gljAdjOprObj.buildSheet($('#contentSpread')[0]);
  172. coeOprObj.getCoeList();
  173. //gljAdjOprObj.getGljItemsOcc();
  174. },
  175. showData: function(sheet, setting, data) {
  176. let me = pageObj, ch = GC.Spread.Sheets.SheetArea.viewport;
  177. sheet.suspendPaint();
  178. sheet.suspendEvent();
  179. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  180. sheet.setRowCount(data.length + 3);
  181. for (let col = 0; col < setting.header.length; col++) {
  182. var hAlign = "left", vAlign = "center";
  183. if (setting.header[col].hAlign) {
  184. hAlign = setting.header[col].hAlign;
  185. } else if (setting.header[col].dataType !== "String"){
  186. hAlign = "right";
  187. }
  188. if(setting.header[col].readOnly){
  189. sheet.getRange(-1, col, -1, 1).locked(true);
  190. }
  191. else{
  192. sheet.getRange(-1, col, -1, 1).locked(false);
  193. }
  194. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  195. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  196. if (setting.header[col].formatter) {
  197. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  198. }
  199. for (let row = 0; row < data.length; row++) {
  200. let val = data[row][setting.header[col].dataCode];
  201. sheet.setValue(row, col, val, ch);
  202. }
  203. }
  204. sheet.resumeEvent();
  205. sheet.resumePaint();
  206. }
  207. };
  208. let coeOprObj = {
  209. workBook: null,
  210. workSheet: null,
  211. currentCoeList: [],
  212. currentCoe: null,
  213. currentMaxNo: null,
  214. setting: {
  215. header: [
  216. {headerName:"编号", headerWidth:50, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  217. {headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  218. {headerName:"内容", headerWidth:150, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  219. ]
  220. },
  221. buildSheet: function (container) {
  222. let me = coeOprObj;
  223. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  224. sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: null, editEnded: me.onEditEnded}]);
  225. me.workSheet = me.workBook.getSheet(0);
  226. me.workSheet.options.isProtected = true;
  227. me.onDelOpr(me.workBook, me.setting);
  228. me.workSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  229. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  230. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  231. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  232. },
  233. onSelectionChanged: function (sender, info) {
  234. let me = coeOprObj, that = gljAdjOprObj;
  235. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  236. let row = info.newSelections[0].row;
  237. if(row < me.currentCoeList.length){
  238. me.currentCoe = me.currentCoeList[row];
  239. that.currentGljAdjList = me.currentCoe.coes;
  240. that.buildDynamicComboBox(that.workSheet);
  241. }
  242. else{
  243. me.currentCoe = null;
  244. that.currentGljAdjList = [];
  245. that.buildBaseCell(that.workSheet);
  246. }
  247. //refresh & show coes
  248. sheetCommonObj.cleanSheet(that.workSheet, that.setting, -1);
  249. me.workBook.focus(true);
  250. that.show(that.currentGljAdjList);
  251. }
  252. },
  253. onEditEnded: function (sender, args) {
  254. let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode;
  255. if(args.editingText && args.editingText.toString().trim().length > 0){
  256. let inputT = args.editingText.toString().trim();
  257. //update
  258. if(args.row < me.currentCoeList.length){
  259. let updateObj = me.currentCoeList[args.row];
  260. if(updateObj[dataCode] != inputT){
  261. if(dataCode === 'serialNo'){
  262. if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
  263. me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  264. updateObj[dataCode] = inputT;
  265. updateArr.push(updateObj);
  266. me.save([], updateArr, [], true);
  267. }
  268. else if(!me.isInt(inputT)){
  269. alert('编号只能为整数!');
  270. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
  271. }
  272. else if(me.hasTisNo(me.currentCoeList, inputT)){
  273. alert('该编号已存在!');
  274. args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
  275. }
  276. }
  277. else {
  278. updateObj[dataCode] = inputT;
  279. updateArr.push(updateObj);
  280. me.save([], updateArr, [], true);
  281. }
  282. }
  283. }
  284. //insert
  285. else{
  286. let newCoe = {};
  287. if(dataCode === 'serialNo'){
  288. if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
  289. me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
  290. newCoe[dataCode] = inputT;
  291. addArr.push(newCoe);
  292. me.save(addArr, [], [], true, function (result) {
  293. me.updateCurrentCoeList(result);
  294. });
  295. }
  296. else if(!me.isInt(inputT)){
  297. args.sheet.setValue(args.row, args.col, '');
  298. alert('编号只能为整数!');
  299. }
  300. else if(me.hasTisNo(me.currentCoeList, inputT)){
  301. args.sheet.setValue(args.row, args.col, '');
  302. alert('该编号已存在!');
  303. }
  304. }
  305. else{
  306. newCoe.serialNo = ++me.currentMaxNo;
  307. newCoe[dataCode] = inputT;
  308. addArr.push(newCoe);
  309. me.save(addArr, [], [], true, function (result) {
  310. me.updateCurrentCoeList(result);
  311. });
  312. }
  313. }
  314. }
  315. },
  316. onClipboardPasting: function (sender, info) {
  317. let me = coeOprObj, maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  318. if(maxCol > me.setting.header.length){
  319. info.cancel = true;
  320. }
  321. },
  322. onClipboardPasted: function (sender, info) {
  323. let me = coeOprObj, addArr = [], updateArr = [];
  324. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  325. let uniqItems = me.makeUniqItems(items);
  326. for(let i = 0, len = uniqItems.length; i < len; i++){
  327. let row = i + info.cellRange.row;
  328. //update
  329. if(row < me.currentCoeList.length){
  330. let updateObj = me.currentCoeList[row];
  331. for(let attr in uniqItems[i]){
  332. if(attr === 'serialNo'){
  333. if(me.isInt(uniqItems[i][attr]) && !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])){
  334. me.currentMaxNo = me.currentMaxNo >= uniqItems[i][attr] ? me.currentMaxNo : uniqItems[i][attr];
  335. updateObj[attr] = uniqItems[i][attr];
  336. }
  337. }
  338. else {
  339. updateObj[attr] = uniqItems[i][attr];
  340. }
  341. }
  342. updateArr.push(updateObj);
  343. }
  344. //insert
  345. else {
  346. if(typeof uniqItems[i].serialNo !== 'undefined' && uniqItems[i] && me.isInt(uniqItems[i].serialNo) && !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)){
  347. me.currentMaxNo = me.currentMaxNo >= uniqItems[i].serialNo ? me.currentMaxNo : uniqItems[i].serialNo;
  348. }
  349. else {
  350. uniqItems[i].serialNo = ++me.currentMaxNo;
  351. }
  352. addArr.push(uniqItems[i]);
  353. }
  354. }
  355. if(addArr.length > 0 || updateArr.length > 0){
  356. me.save(addArr, updateArr, [], true, function (result) {
  357. me.updateCurrentCoeList(result);
  358. });
  359. }
  360. },
  361. onDelOpr: function (workBook, setting) {
  362. let me = coeOprObj, that = gljAdjOprObj;
  363. workBook.commandManager().register('coeListDel', function () {
  364. let deleteArr = [];
  365. let sheet = workBook.getSheet(0);
  366. let sels = sheet.getSelections();
  367. let idx = sels[0].row;
  368. for(let i = 0, len = sels.length; i < len; i++){
  369. if(idx > sels[i].row){
  370. idx = sels[i].row;
  371. }
  372. if(sels[i].colCount === setting.header.length){//can del
  373. for(let r = 0, rLen = sels[i].rowCount; r < rLen; r++){
  374. let row = sels[i].row + r;
  375. if(row < me.currentCoeList.length){
  376. deleteArr.push({userId: me.currentCoeList[row].userId, compilationId: me.currentCoeList[row].compilationId, ID: me.currentCoeList[row].ID});
  377. }
  378. }
  379. me.currentCoeList.splice(sels[i].row, sels[i].rowCount);
  380. }
  381. }
  382. if(deleteArr.length > 0){
  383. me.save([], [], deleteArr, true);
  384. me.currentCoe = typeof me.currentCoeList[idx] !== 'undefined' ? me.currentCoeList[idx] : null;
  385. that.currentGljAdjList = me.currentCoe ? me.currentCoe.coes : [];
  386. gljAdjOprObj.show(that.currentGljAdjList);
  387. }
  388. });
  389. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  390. workBook.commandManager().setShortcutKey('coeListDel', GC.Spread.Commands.Key.del, false, false, false, false);
  391. },
  392. //粘贴的数据,编号唯一化,去除编号重复的项
  393. makeUniqItems: function (items) {
  394. let rst = [];
  395. for(let i = 0, len = items.length; i < len; i++){
  396. if(typeof items[i].serialNo !== 'undefined' && items[i].serialNo){
  397. if(rst.length === 0){
  398. rst.push(items[i]);
  399. }
  400. else{
  401. let isExist = false;
  402. for(let j = 0, jLen = rst.length; j < jLen; j++){
  403. if(items[i].serialNo === rst[j].serialNo){
  404. isExist = true;
  405. break;
  406. }
  407. }
  408. if(!isExist){
  409. rst.push(items[i]);
  410. }
  411. }
  412. }
  413. else {
  414. rst.push(items[i]);
  415. }
  416. }
  417. return rst;
  418. },
  419. isInt: function (num) {
  420. return !isNaN(num) && num % 1 === 0;
  421. },
  422. hasTisNo: function (coeList, newSerialNo) {
  423. let rst = false;
  424. for(let i = 0, len = coeList.length; i < len; i++){
  425. if(coeList[i].serialNo == newSerialNo){
  426. rst = true;
  427. break;
  428. }
  429. }
  430. return rst;
  431. },
  432. updateCurrentCoeList: function (newCoeList) {
  433. let me = coeOprObj;
  434. if(newCoeList){
  435. me.currentCoeList = me.currentCoeList.concat(newCoeList);
  436. }
  437. },
  438. sortCoeList: function (coeList) {
  439. coeList.sort(function (a, b) {
  440. let rst = 0;
  441. if(a.serialNo > b.serialNo) rst = 1;
  442. else if(a.serialNo < b.serialNo) rst = -1;
  443. return rst;
  444. });
  445. },
  446. getCoeList: function () {
  447. let me = coeOprObj;
  448. $.ajax({
  449. type: 'post',
  450. url: 'api/getCoeList',
  451. dataType: 'json',
  452. timeout:20000,
  453. success: function (result) {
  454. if(!result.error){
  455. me.currentCoeList = result.data;
  456. me.sortCoeList(me.currentCoeList);
  457. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  458. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  459. me.workSheet.clearSelection();
  460. }
  461. },
  462. error:function(err){
  463. alert("内部程序错误!");
  464. }
  465. });
  466. },
  467. save: function (addArr, updateArr, deleteArr, refresh, callback) {
  468. let me = coeOprObj;
  469. $.ajax({
  470. type:"POST",
  471. url:"api/saveCoeList",
  472. data: {data: JSON.stringify({addArr: addArr, updateArr: updateArr, deleteArr: deleteArr})},
  473. dataType:"json",
  474. timeout:5000,
  475. success:function(result){
  476. if (result.error) {
  477. alert(result.message);
  478. } else{
  479. if(callback){
  480. callback(result.data);
  481. }
  482. if(refresh){
  483. me.sortCoeList(me.currentCoeList);
  484. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  485. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  486. }
  487. }
  488. },
  489. error:function(err){
  490. alert("内部程序错误!");
  491. }
  492. });
  493. }
  494. };
  495. let gljAdjOprObj = {
  496. workBook: null,
  497. workSheet: null,
  498. currentGljAdjList: [],
  499. gljList: [],//总工料机列表, gljSelect中获取
  500. setting: {
  501. header: [
  502. {headerName:"调整类型", headerWidth:80, dataCode:"coeType", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  503. {headerName:"人材机编码", headerWidth:80, dataCode:"gljCode", dataType: "String", formatter: '@', hAlign: "center", vAlign: "center", readOnly: false},
  504. {headerName:"名称", headerWidth:100, dataCode:"gljName", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
  505. {headerName:"操作符", headerWidth:60, dataCode:"operator", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  506. {headerName:"数量", headerWidth:80, dataCode:"amount", dataType: "String", hAlign: "center", vAlign: "center" , readOnly: false},
  507. ],
  508. comboItems: {
  509. //调整类型下拉菜单
  510. coeType: ['定额', '人工', '材料', '机械', '主材', '设备', '单个工料机'],
  511. //操作符下拉菜单
  512. operator: ['+', '-', '*', '/', '=']
  513. }
  514. },
  515. buildSheet: function (container) {
  516. let me = gljAdjOprObj;
  517. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
  518. me.workSheet = me.workBook.getSheet(0);
  519. sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onEditStart, editEnded: me.onEditEnded}]);
  520. me.workSheet.options.isProtected = true;
  521. me.onDelOpr(me.workBook, me.setting);
  522. me.workSheet.clearSelection();
  523. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStart);
  524. me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  525. me.workSheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  526. me.workSheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  527. me.workSheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  528. },
  529. buildBaseCell: function (sheet) {
  530. let me = gljAdjOprObj;
  531. sheet.suspendPaint();
  532. sheet.suspendEvent();
  533. let baseCell = GC.Spread.Sheets.CellTypes.Base();
  534. sheet.getCell(-1, 0).cellType(baseCell);
  535. sheet.getCell(-1, 3).cellType(baseCell);
  536. sheet.resumePaint();
  537. sheet.resumeEvent();
  538. },
  539. buildDynamicComboBox: function (sheet) {
  540. let me = gljAdjOprObj;
  541. sheet.suspendPaint();
  542. sheet.suspendEvent();
  543. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  544. dynamicCombo.items(me.setting.comboItems.coeType);
  545. let dynamicOprCombo = sheetCommonObj.getDynamicCombo();
  546. dynamicOprCombo.items(me.setting.comboItems.operator);
  547. sheet.getCell(-1, 0).cellType(dynamicCombo);
  548. sheet.getCell(-1, 3).cellType(dynamicOprCombo);
  549. sheet.resumePaint();
  550. sheet.resumeEvent();
  551. },
  552. onEnterCell: function (sender, args) {
  553. args.sheet.repaint();
  554. },
  555. onEditStart: function (sender, args) {
  556. let me = gljAdjOprObj;
  557. if(!coeOprObj.currentCoe || args.row >= me.currentGljAdjList.length && args.col === 1
  558. || args.row < me.currentGljAdjList.length && args.col === 1 && me.currentGljAdjList[args.row].coeType !== '单个工料机'){
  559. args.cancel = true;
  560. }
  561. },
  562. onEditEnded: function (sender, args) {
  563. let me = gljAdjOprObj, isUpdate = false,
  564. dataCode = me.setting.header[args.col].dataCode;
  565. if(args.editingText && args.editingText.toString().trim().length > 0){
  566. if(dataCode === 'amount' && isNaN(args.editingText)){
  567. alert("只能输入数值!");
  568. args.sheet.setValue(args.row, args.col, typeof me.currentGljAdjList[args.row] !== 'undefined' && typeof me.currentGljAdjList[args.row][dataCode] !== 'undefined'
  569. ? me.currentGljAdjList[args.row][dataCode] + '' : '');
  570. }
  571. else {
  572. //update
  573. if(args.row < me.currentGljAdjList.length && args.editingText.toString().trim() !== me.currentGljAdjList[args.row][dataCode]){
  574. let updateObj = me.currentGljAdjList[args.row];
  575. if(dataCode === 'gljCode' && typeof updateObj.coeType !== 'undefined' && updateObj.coeType === '单个工料机'){
  576. let gljName = me.getGljName(args.editingText, me.gljList);
  577. if(gljName){
  578. updateObj.gljCode = args.editingText;
  579. updateObj.gljName = gljName;
  580. isUpdate = true;
  581. }
  582. else {
  583. alert("不存在编号为"+ args.editingText +"的工料机");
  584. }
  585. }
  586. else if(dataCode === 'coeType'){
  587. isUpdate = true;
  588. updateObj[dataCode] = args.editingText;
  589. updateObj.gljCode = '';
  590. updateObj.gljName = '';
  591. }
  592. else if(dataCode !== 'gljCode') {
  593. isUpdate = true;
  594. updateObj[dataCode] = args.editingText;
  595. }
  596. }
  597. //insert
  598. else if(args.row >= me.currentGljAdjList.length){
  599. isUpdate = true;
  600. let newAdjGlj = {};
  601. newAdjGlj[dataCode] = args.editingText;
  602. me.currentGljAdjList.push(newAdjGlj);
  603. }
  604. if(isUpdate){
  605. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  606. console.log(me.currentGljAdjList);
  607. me.show(me.currentGljAdjList);
  608. });
  609. }
  610. else {
  611. args.sheet.setValue(args.row, args.col, typeof me.currentGljAdjList[args.row] !== 'undefined' && typeof me.currentGljAdjList[args.row][dataCode] !== 'undefined'
  612. ? me.currentGljAdjList[args.row][dataCode] + '' : '');
  613. }
  614. }
  615. }
  616. },
  617. onClipboardPasting: function (sender, info) {
  618. },
  619. getValidPasteDatas: function (pasteItems, info) {
  620. let me = gljAdjOprObj;
  621. let rst = [];
  622. for(let i = 0, len = pasteItems.length; i < len; i++){
  623. let row = i + info.cellRange.row;
  624. let validObj = {};
  625. //update
  626. if(row < me.currentGljAdjList.length){
  627. let updateObj = me.currentGljAdjList[row];
  628. if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
  629. let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
  630. if(pasteItems[i].coeType === '单个工料机' && gljName){
  631. validObj.coeType = pasteItems[i].coeType;
  632. validObj.gljCode = pasteItems[i].gljCode;
  633. validObj.gljName = gljName;
  634. }
  635. else if(pasteItems[i].coeType !== '单个工料机' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
  636. validObj.coeType = pasteItems[i].coeType;
  637. }
  638. }
  639. else if(typeof pasteItems[i].coeType === 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
  640. let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
  641. if(typeof updateObj.coeType !== 'undefined' && updateObj.coeType === '单个工料机' && gljName){
  642. validObj.gljCode = pasteItems[i].gljCode;
  643. validObj.gljName = gljName;
  644. }
  645. }
  646. else if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode === 'undefined'){
  647. if(me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
  648. validObj.coeType = pasteItems[i].coeType;
  649. if(validObj.coeType !== '单个工料机' && typeof updateObj.gljCode !== '单个工料机' && updateObj.gljCode.toString().trim().length > 0){
  650. validObj.gljCode = '';
  651. validObj.gljName = '';
  652. }
  653. }
  654. }
  655. else {
  656. if(typeof pasteItems[i].operator !== 'undefined' && me.setting.comboItems.operator.indexOf(pasteItems[i].operator) !== -1){
  657. validObj.operator = pasteItems[i].operator;
  658. }
  659. if(typeof pasteItems[i].amount !== 'undefined' && !isNaN(pasteItems[i].amount)){
  660. validObj.amount = pasteItems[i].amount;
  661. }
  662. }
  663. }
  664. else {
  665. if(typeof pasteItems[i].coeType !== 'undefined' && typeof pasteItems[i].gljCode !== 'undefined'){
  666. let gljName = me.getGljName(pasteItems[i].gljCode, me.gljList);
  667. if(pasteItems[i].coeType === '单个工料机' && gljName){
  668. validObj.coeType = pasteItems[i].coeType;
  669. validObj.gljCode = pasteItems[i].gljCode;
  670. validObj.gljName = gljName;
  671. }
  672. else if(pasteItems[i].coeType !== '单个工料机' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
  673. validObj.coeType = pasteItems[i].coeType;
  674. }
  675. }
  676. else if(typeof pasteItems[i].gljCode === 'undefined') {
  677. if(typeof pasteItems[i].coeType !== 'undefined' && me.setting.comboItems.coeType.indexOf(pasteItems[i].coeType) !== -1){
  678. validObj.coeType = pasteItems[i].coeType;
  679. }
  680. if(typeof pasteItems[i].operator !== 'undefined' && me.setting.comboItems.operator.indexOf(pasteItems[i].operator) !== -1){
  681. validObj.operator = pasteItems[i].operator;
  682. }
  683. if(typeof pasteItems[i].amount !== 'undefined' && !isNaN(pasteItems[i].amount)){
  684. validObj.amount = pasteItems[i].amount;
  685. }
  686. }
  687. }
  688. if(Object.keys(validObj).length > 0){
  689. rst.push(validObj);
  690. }
  691. }
  692. return rst;
  693. },
  694. onClipboardPasted: function (sender, info) {
  695. let me = gljAdjOprObj, row;
  696. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  697. let validDatas = me.getValidPasteDatas(items, info);
  698. for(let i = 0, len = validDatas.length; i < len; i++){
  699. row = i + info.cellRange.row;
  700. //update
  701. if(row < me.currentGljAdjList.length){
  702. let updateObj = me.currentGljAdjList[row];
  703. for(let attr in validDatas[i]){
  704. updateObj[attr] = validDatas[i][attr];
  705. }
  706. }
  707. //insert
  708. else{
  709. me.currentGljAdjList.push(validDatas[i]);
  710. }
  711. }
  712. if(validDatas.length > 0){
  713. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  714. me.show(me.currentGljAdjList);
  715. });
  716. }
  717. else {
  718. me.show(me.currentGljAdjList);
  719. }
  720. },
  721. onDelOpr: function (workBook, setting) {
  722. let me = gljAdjOprObj;
  723. workBook.commandManager().register('gljAdjDel', function () {
  724. let sheet = workBook.getSheet(0);
  725. let sels = sheet.getSelections();
  726. let isUpdate = false;
  727. for(let i = 0, len = sels.length; i < len; i++){
  728. if(sels[i].colCount === setting.header.length){//can del
  729. if(sels[i].row < me.currentGljAdjList.length){
  730. isUpdate = true;
  731. me.currentGljAdjList.splice(sels[i].row, sels[i].rowCount);
  732. }
  733. }
  734. }
  735. if(isUpdate){
  736. coeOprObj.save([], [coeOprObj.currentCoe], [], false, function () {
  737. me.show(me.currentGljAdjList);
  738. });
  739. }
  740. });
  741. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  742. workBook.commandManager().setShortcutKey('gljAdjDel', GC.Spread.Commands.Key.del, false, false, false, false);
  743. },
  744. getGljName: function (gljCode, gljList) {
  745. let rst = null;
  746. for(let i = 0, len = gljList.length; i < len; i++){
  747. if(gljCode === gljList[i].code){
  748. rst = gljList[i].name;
  749. break;
  750. }
  751. }
  752. return rst;
  753. },
  754. show: function (coes) {
  755. let me = gljAdjOprObj;
  756. pageObj.showData(me.workSheet, me.setting, coes)
  757. },
  758. getGljItemsOcc: function () {
  759. let me = gljAdjOprObj;
  760. $.ajax({
  761. type: 'post',
  762. url: '/stdGljRepository/api/getGljItemsOccupied',
  763. data: {repId: pageObj.gljLibID, occupation: '-_id code name'},
  764. dataType: 'json',
  765. timeout: 5000,
  766. success:function(result){
  767. if (result.error) {
  768. alert(result.message);
  769. } else{
  770. me.gljList = result.data;
  771. }
  772. },
  773. error:function(err){
  774. alert("内部程序错误!");
  775. }
  776. });
  777. }
  778. };