coe.js 38 KB

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