coe.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * Created by CSL on 2017-05-18.
  3. */
  4. //modiyied by zhong on 2017/9/21
  5. var pageObj = {
  6. libID: null,
  7. gljLibID: null,
  8. initPage: function (){
  9. var libID = getQueryString("repository");
  10. let me = this;
  11. CommonAjax.post('/complementaryRation/api/getRationLibs', {ids: [libID]}, function (rstData) {
  12. if(rstData.length > 0){
  13. let libName = rstData[0].dispName;
  14. if (libName) {
  15. let $rationName = $(`<div id='rationname' class='navbar-text'>${libName}</div>`);
  16. $('.header-logo').after($rationName);
  17. };
  18. me.gljLibID = rstData[0].gljLib;
  19. me.libID = libID;
  20. coeOprObj.buildSheet($('#mainSpread')[0]);
  21. gljAdjOprObj.buildSheet($('#contentSpread')[0]);
  22. coeOprObj.getCoeList();
  23. gljAdjOprObj.getGljItemsOcc();
  24. }
  25. });
  26. },
  27. showData: function(sheet, setting, data) {
  28. let me = pageObj, ch = GC.Spread.Sheets.SheetArea.viewport;
  29. sheet.suspendPaint();
  30. sheet.suspendEvent();
  31. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  32. sheet.setRowCount(data.length + 3);
  33. for (let col = 0; col < setting.header.length; col++) {
  34. var hAlign = "left", vAlign = "center";
  35. if (setting.header[col].hAlign) {
  36. hAlign = setting.header[col].hAlign;
  37. } else if (setting.header[col].dataType !== "String"){
  38. hAlign = "right";
  39. }
  40. if(setting.header[col].readOnly){
  41. sheet.getRange(-1, col, -1, 1).locked(true);
  42. }
  43. else{
  44. sheet.getRange(-1, col, -1, 1).locked(false);
  45. }
  46. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  47. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  48. if (setting.header[col].formatter) {
  49. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  50. }
  51. for (let row = 0; row < data.length; row++) {
  52. let val = data[row][setting.header[col].dataCode];
  53. sheet.setValue(row, col, val, ch);
  54. }
  55. }
  56. sheet.resumeEvent();
  57. sheet.resumePaint();
  58. }
  59. };
  60. let coeOprObj = {
  61. workBook: null,
  62. workSheet: null,
  63. currentCoeList: [],
  64. currentCoe: null,
  65. currentMaxNo: null,
  66. setting: {
  67. header: [
  68. {headerName:"编号", headerWidth:60, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  69. {headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  70. {headerName:"内容", headerWidth:250, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  71. ]
  72. },
  73. buildSheet: function (container) {
  74. let me = coeOprObj;
  75. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  76. sheetCommonObj.spreadDefaultStyle(me.workBook);
  77. me.workSheet = me.workBook.getSheet(0);
  78. me.workSheet.options.isProtected = true;
  79. me.workSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  80. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
  81. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  82. },
  83. onSelectionChanged: function (sender, info) {
  84. let me = coeOprObj, that = gljAdjOprObj;
  85. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  86. let row = info.newSelections[0].row;
  87. if(row < me.currentCoeList.length){
  88. me.currentCoe = me.currentCoeList[row];
  89. that.currentGljAdjList = me.currentCoe.coes;
  90. that.buildDynamicComboBox(that.workSheet);
  91. }
  92. else{
  93. me.currentCoe = null;
  94. that.currentGljAdjList = [];
  95. that.buildBaseCell(that.workSheet);
  96. }
  97. //refresh & show coes
  98. sheetCommonObj.cleanSheet(that.workSheet, that.setting, -1);
  99. me.workBook.focus(true);
  100. that.show(that.currentGljAdjList);
  101. }
  102. },
  103. onEditStarting: function (sender, args) {
  104. args.cancel = true;
  105. },
  106. onClipboardPasting: function (sender, info) {
  107. info.cancel = true;
  108. },
  109. isInt: function (num) {
  110. return !isNaN(num) && num % 1 === 0;
  111. },
  112. sortCoeList: function (coeList) {
  113. coeList.sort(function (a, b) {
  114. let rst = 0;
  115. if(a.serialNo > b.serialNo) rst = 1;
  116. else if(a.serialNo < b.serialNo) rst = -1;
  117. return rst;
  118. });
  119. },
  120. getCoeList: function () {
  121. let me = coeOprObj;
  122. CommonAjax.post('api/getCoeList', {libID: pageObj.libID}, function (rstData) {
  123. me.currentCoeList = rstData;
  124. me.sortCoeList(me.currentCoeList);
  125. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  126. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  127. me.workSheet.clearSelection();
  128. });
  129. }
  130. };
  131. let gljAdjOprObj = {
  132. workBook: null,
  133. workSheet: null,
  134. currentGljAdjList: [],
  135. gljList: [],//只含编号和名称的总工料机列表
  136. setting: {
  137. header: [
  138. {headerName:"调整类型", headerWidth:100, dataCode:"coeType", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  139. {headerName:"人材机编码", headerWidth:100, dataCode:"gljCode", dataType: "String", formatter: '@', hAlign: "center", vAlign: "center", readOnly: false},
  140. {headerName:"名称", headerWidth:100, dataCode:"gljName", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
  141. {headerName:"操作符", headerWidth:60, dataCode:"operator", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  142. {headerName:"数量", headerWidth:80, dataCode:"amount", dataType: "String", hAlign: "center", vAlign: "center" , readOnly: false},
  143. ],
  144. comboItems: {
  145. //调整类型下拉菜单
  146. coeType: ['定额子目', '人工类', '材料类', '机械类', '主材类', '设备类', '单个工料机'],
  147. //操作符下拉菜单
  148. operator: ['+', '-', '*', '/', '=']
  149. }
  150. },
  151. buildSheet: function (container) {
  152. let me = gljAdjOprObj;
  153. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
  154. sheetCommonObj.spreadDefaultStyle(me.workBook);
  155. me.workSheet = me.workBook.getSheet(0);
  156. me.workSheet.options.isProtected = true;
  157. me.workSheet.clearSelection();
  158. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStart);
  159. me.workSheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  160. me.workSheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  161. },
  162. buildBaseCell: function (sheet) {
  163. let me = gljAdjOprObj;
  164. sheet.suspendPaint();
  165. sheet.suspendEvent();
  166. let baseCell = GC.Spread.Sheets.CellTypes.Base();
  167. sheet.getCell(-1, 0).cellType(baseCell);
  168. sheet.getCell(-1, 3).cellType(baseCell);
  169. sheet.resumePaint();
  170. sheet.resumeEvent();
  171. },
  172. buildDynamicComboBox: function (sheet) {
  173. let me = gljAdjOprObj;
  174. sheet.suspendPaint();
  175. sheet.suspendEvent();
  176. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  177. dynamicCombo.items(me.setting.comboItems.coeType);
  178. let dynamicOprCombo = sheetCommonObj.getDynamicCombo();
  179. dynamicOprCombo.items(me.setting.comboItems.operator);
  180. sheet.getCell(-1, 0).cellType(dynamicCombo);
  181. sheet.getCell(-1, 3).cellType(dynamicOprCombo);
  182. sheet.resumePaint();
  183. sheet.resumeEvent();
  184. },
  185. onEnterCell: function (sender, args) {
  186. args.sheet.repaint();
  187. },
  188. onEditStart: function (sender, args) {
  189. let me = gljAdjOprObj;
  190. args.cancel = true;
  191. },
  192. onClipboardPasting: function (sender, info) {
  193. info.cancel = true;
  194. },
  195. show: function (coes) {
  196. let me = gljAdjOprObj;
  197. pageObj.showData(me.workSheet, me.setting, coes)
  198. },
  199. getGljItemsOcc: function () {
  200. let me = gljAdjOprObj;
  201. CommonAjax.post('api/getGljItemsOccupied', {gljLibId: pageObj.gljLibID, occupation: '-_id code name'}, function (rstData) {
  202. me.gljList = rstData;
  203. });
  204. }
  205. };