coe.js 8.9 KB

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