coe.js 34 KB

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