coe.js 9.0 KB

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