coe.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. me.workSheet = me.workBook.getSheet(0);
  77. me.workSheet.options.isProtected = true;
  78. me.workSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  79. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
  80. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  81. },
  82. onSelectionChanged: function (sender, info) {
  83. let me = coeOprObj, that = gljAdjOprObj;
  84. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  85. let row = info.newSelections[0].row;
  86. if(row < me.currentCoeList.length){
  87. me.currentCoe = me.currentCoeList[row];
  88. that.currentGljAdjList = me.currentCoe.coes;
  89. that.buildDynamicComboBox(that.workSheet);
  90. }
  91. else{
  92. me.currentCoe = null;
  93. that.currentGljAdjList = [];
  94. that.buildBaseCell(that.workSheet);
  95. }
  96. //refresh & show coes
  97. sheetCommonObj.cleanSheet(that.workSheet, that.setting, -1);
  98. me.workBook.focus(true);
  99. that.show(that.currentGljAdjList);
  100. }
  101. },
  102. onEditStarting: function (sender, args) {
  103. args.cancel = true;
  104. },
  105. onClipboardPasting: function (sender, info) {
  106. info.cancel = true;
  107. },
  108. isInt: function (num) {
  109. return !isNaN(num) && num % 1 === 0;
  110. },
  111. sortCoeList: function (coeList) {
  112. coeList.sort(function (a, b) {
  113. let rst = 0;
  114. if(a.serialNo > b.serialNo) rst = 1;
  115. else if(a.serialNo < b.serialNo) rst = -1;
  116. return rst;
  117. });
  118. },
  119. getCoeList: function () {
  120. let me = coeOprObj;
  121. CommonAjax.post('api/getCoeList', {libID: pageObj.libID}, function (rstData) {
  122. me.currentCoeList = rstData;
  123. me.sortCoeList(me.currentCoeList);
  124. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  125. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  126. me.workSheet.clearSelection();
  127. });
  128. }
  129. };
  130. let gljAdjOprObj = {
  131. workBook: null,
  132. workSheet: null,
  133. currentGljAdjList: [],
  134. gljList: [],//只含编号和名称的总工料机列表
  135. setting: {
  136. header: [
  137. {headerName:"调整类型", headerWidth:100, dataCode:"coeType", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  138. {headerName:"人材机编码", headerWidth:100, dataCode:"gljCode", dataType: "String", formatter: '@', hAlign: "center", vAlign: "center", readOnly: false},
  139. {headerName:"名称", headerWidth:100, dataCode:"gljName", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
  140. {headerName:"操作符", headerWidth:60, dataCode:"operator", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  141. {headerName:"数量", headerWidth:80, dataCode:"amount", dataType: "String", hAlign: "center", vAlign: "center" , readOnly: false},
  142. ],
  143. comboItems: {
  144. //调整类型下拉菜单
  145. coeType: ['定额子目', '人工类', '材料类', '机械类', '主材类', '设备类', '单个工料机'],
  146. //操作符下拉菜单
  147. operator: ['+', '-', '*', '/', '=']
  148. }
  149. },
  150. buildSheet: function (container) {
  151. let me = gljAdjOprObj;
  152. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
  153. me.workSheet = me.workBook.getSheet(0);
  154. me.workSheet.options.isProtected = true;
  155. me.workSheet.clearSelection();
  156. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStart);
  157. me.workSheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  158. me.workSheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  159. },
  160. buildBaseCell: function (sheet) {
  161. let me = gljAdjOprObj;
  162. sheet.suspendPaint();
  163. sheet.suspendEvent();
  164. let baseCell = GC.Spread.Sheets.CellTypes.Base();
  165. sheet.getCell(-1, 0).cellType(baseCell);
  166. sheet.getCell(-1, 3).cellType(baseCell);
  167. sheet.resumePaint();
  168. sheet.resumeEvent();
  169. },
  170. buildDynamicComboBox: function (sheet) {
  171. let me = gljAdjOprObj;
  172. sheet.suspendPaint();
  173. sheet.suspendEvent();
  174. let dynamicCombo = sheetCommonObj.getDynamicCombo();
  175. dynamicCombo.items(me.setting.comboItems.coeType);
  176. let dynamicOprCombo = sheetCommonObj.getDynamicCombo();
  177. dynamicOprCombo.items(me.setting.comboItems.operator);
  178. sheet.getCell(-1, 0).cellType(dynamicCombo);
  179. sheet.getCell(-1, 3).cellType(dynamicOprCombo);
  180. sheet.resumePaint();
  181. sheet.resumeEvent();
  182. },
  183. onEnterCell: function (sender, args) {
  184. args.sheet.repaint();
  185. },
  186. onEditStart: function (sender, args) {
  187. let me = gljAdjOprObj;
  188. args.cancel = true;
  189. },
  190. onClipboardPasting: function (sender, info) {
  191. info.cancel = true;
  192. },
  193. show: function (coes) {
  194. let me = gljAdjOprObj;
  195. pageObj.showData(me.workSheet, me.setting, coes)
  196. },
  197. getGljItemsOcc: function () {
  198. let me = gljAdjOprObj;
  199. CommonAjax.post('api/getGljItemsOccupied', {gljLibId: pageObj.gljLibID, occupation: '-_id code name'}, function (rstData) {
  200. me.gljList = rstData;
  201. });
  202. }
  203. };