coe.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. var libID = getQueryString("repository");
  16. var libName = storageUtil.getSessionCache("RationGrp","repositoryID_" + libID);
  17. if (libName) {
  18. var html = $("#rationname")[0].outerHTML;
  19. html = html.replace("XXX定额库", libName);
  20. $("#rationname")[0].outerHTML = html;
  21. };
  22. this.gljLibID = storageUtil.getSessionCache("gljLib", "repositoryID_" + libID);
  23. this.libID = libID;
  24. coeOprObj.buildSheet($('#mainSpread')[0]);
  25. gljAdjOprObj.buildSheet($('#contentSpread')[0]);
  26. coeOprObj.getCoeList();
  27. gljAdjOprObj.getGljItemsOcc();
  28. },
  29. showData: function(sheet, setting, data) {
  30. let me = pageObj, ch = GC.Spread.Sheets.SheetArea.viewport;
  31. sheet.suspendPaint();
  32. sheet.suspendEvent();
  33. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  34. sheet.setRowCount(data.length + 3);
  35. for (let col = 0; col < setting.header.length; col++) {
  36. var hAlign = "left", vAlign = "center";
  37. if (setting.header[col].hAlign) {
  38. hAlign = setting.header[col].hAlign;
  39. } else if (setting.header[col].dataType !== "String"){
  40. hAlign = "right";
  41. }
  42. if(setting.header[col].readOnly){
  43. sheet.getRange(-1, col, -1, 1).locked(true);
  44. }
  45. else{
  46. sheet.getRange(-1, col, -1, 1).locked(false);
  47. }
  48. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  49. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  50. if (setting.header[col].formatter) {
  51. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  52. }
  53. for (let row = 0; row < data.length; row++) {
  54. let val = data[row][setting.header[col].dataCode];
  55. sheet.setValue(row, col, val, ch);
  56. }
  57. }
  58. sheet.resumeEvent();
  59. sheet.resumePaint();
  60. }
  61. };
  62. let coeOprObj = {
  63. workBook: null,
  64. workSheet: null,
  65. currentCoeList: [],
  66. currentCoe: null,
  67. currentMaxNo: null,
  68. setting: {
  69. header: [
  70. {headerName:"编号", headerWidth:60, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  71. {headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  72. {headerName:"内容", headerWidth:250, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
  73. ]
  74. },
  75. buildSheet: function (container) {
  76. let me = coeOprObj;
  77. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  78. me.workSheet = me.workBook.getSheet(0);
  79. me.workSheet.options.isProtected = true;
  80. me.workSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  81. me.workSheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
  82. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  83. },
  84. onSelectionChanged: function (sender, info) {
  85. let me = coeOprObj, that = gljAdjOprObj;
  86. if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
  87. let row = info.newSelections[0].row;
  88. if(row < me.currentCoeList.length){
  89. me.currentCoe = me.currentCoeList[row];
  90. that.currentGljAdjList = me.currentCoe.coes;
  91. that.buildDynamicComboBox(that.workSheet);
  92. }
  93. else{
  94. me.currentCoe = null;
  95. that.currentGljAdjList = [];
  96. that.buildBaseCell(that.workSheet);
  97. }
  98. //refresh & show coes
  99. sheetCommonObj.cleanSheet(that.workSheet, that.setting, -1);
  100. me.workBook.focus(true);
  101. that.show(that.currentGljAdjList);
  102. }
  103. },
  104. onEditStarting: function (sender, args) {
  105. args.cancel = true;
  106. },
  107. onClipboardPasting: function (sender, info) {
  108. info.cancel = true;
  109. },
  110. isInt: function (num) {
  111. return !isNaN(num) && num % 1 === 0;
  112. },
  113. sortCoeList: function (coeList) {
  114. coeList.sort(function (a, b) {
  115. let rst = 0;
  116. if(a.serialNo > b.serialNo) rst = 1;
  117. else if(a.serialNo < b.serialNo) rst = -1;
  118. return rst;
  119. });
  120. },
  121. getCoeList: function () {
  122. let me = coeOprObj;
  123. CommonAjax.post('api/getCoeList', {libID: pageObj.libID}, function (rstData) {
  124. me.currentCoeList = rstData;
  125. me.sortCoeList(me.currentCoeList);
  126. me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
  127. pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
  128. me.workSheet.clearSelection();
  129. });
  130. }
  131. };
  132. let gljAdjOprObj = {
  133. workBook: null,
  134. workSheet: null,
  135. currentGljAdjList: [],
  136. gljList: [],//只含编号和名称的总工料机列表
  137. setting: {
  138. header: [
  139. {headerName:"调整类型", headerWidth:100, dataCode:"coeType", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  140. {headerName:"工料机编码", headerWidth:100, dataCode:"gljCode", dataType: "String", formatter: '@', hAlign: "center", vAlign: "center", readOnly: false},
  141. {headerName:"名称", headerWidth:100, dataCode:"gljName", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
  142. {headerName:"操作符", headerWidth:60, dataCode:"operator", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
  143. {headerName:"数量", headerWidth:80, dataCode:"amount", dataType: "String", hAlign: "center", vAlign: "center" , readOnly: false},
  144. ],
  145. comboItems: {
  146. //调整类型下拉菜单
  147. coeType: ['定额子目', '人工类', '材料类', '机械类', '主材类', '设备类', '单个工料机'],
  148. //操作符下拉菜单
  149. operator: ['+', '-', '*', '/', '=']
  150. }
  151. },
  152. buildSheet: function (container) {
  153. let me = gljAdjOprObj;
  154. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 3);
  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. };