coe.js 9.1 KB

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