ration_assist.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**
  2. * Created by CSL on 2017-06-14.
  3. */
  4. var rationAssistOprObj = {
  5. sheet: null,
  6. libID: null,
  7. ration: null,
  8. setting: {
  9. header:[
  10. {headerName:"调整名称",headerWidth:110,dataCode:"name", dataType: "String", hAlign: "left"},
  11. {headerName:"辅助定额号",headerWidth:90,dataCode:"assistCode", dataType: "String", hAlign: "center", formatter: "@"},
  12. {headerName:"标准值",headerWidth:60,dataCode:"stdValue", dataType: "String", hAlign: "right"},
  13. {headerName:"步距",headerWidth:60,dataCode:"stepValue", dataType: "String", hAlign: "right"},
  14. {headerName:"精度",headerWidth:60,dataCode:"decimal", dataType: "String", hAlign: "right"},
  15. {headerName:"进位方式",headerWidth:80,dataCode:"carryBit", dataType: "String", hAlign: "center"},
  16. {headerName:"最小值",headerWidth:70,dataCode:"minValue", dataType: "String", hAlign: "right"},
  17. {headerName:"最大值",headerWidth:70,dataCode:"maxValue", dataType: "String", hAlign: "right"}
  18. ],
  19. view:{},
  20. comboItems: ["四舍五入", "进一"]
  21. },
  22. buildSheet: function(sheet) {
  23. var me = this;
  24. me.sheet = sheet;
  25. //me.libID = storageUtil.getSessionCache("RationGrp","repositoryID"); // 不可靠,有时取不到
  26. me.libID = pageOprObj.rationLibId; // 不可靠,有时取不到
  27. if (me.libID == undefined){me.libID = getQueryString('repository')};
  28. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  29. me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  30. me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  31. me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
  32. me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  33. me.sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  34. },
  35. onEnterCell: function (sender, args) {
  36. let me = rationAssistOprObj;
  37. args.sheet.repaint();
  38. let cellType = args.sheet.getCellType(args.row, 5);
  39. if(cellType.typeName !== 'undefined' && cellType.typeName === '1'){
  40. // sheetCommonObj.setStaticCombo(args.sheet, 0, 5, 0, me.setting.comboItems, false);
  41. sheetCommonObj.setDynamicCombo(args.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
  42. }
  43. },
  44. onClipboardPasting: function(sender, args) {
  45. let me = rationAssistOprObj;
  46. let rationSection = rationOprObj.getCache();
  47. let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  48. me.ration = rationRow < rationSection.length ? rationSection[rationRow] : null;
  49. if (!me.ration) {
  50. args.cancel = true;
  51. }
  52. },
  53. onClipboardPasted: function(e, info) {
  54. var me = rationAssistOprObj;
  55. if (!me.ration) {return;};
  56. var tempArr = sheetCommonObj.analyzePasteData(me.setting, info);
  57. var assList = me.ration.rationAssList;
  58. if (assList == undefined) {
  59. me.ration.rationAssList = tempArr;
  60. }else{
  61. assList = assList.concat(tempArr);
  62. me.ration.rationAssList = assList;
  63. };
  64. rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
  65. me.sheet.getParent().focus(true);
  66. });
  67. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  68. //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, me.ration.rationAssList.length, me.setting.comboItems, false, false);
  69. sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
  70. sheetCommonObj.showData(me.sheet, me.setting, me.ration.rationAssList);
  71. },
  72. onEditStarting: function (sender, args) {
  73. let me = rationAssistOprObj;
  74. let rationSection = rationOprObj.getCache();
  75. let rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  76. me.ration = rationRow < rationSection.length ? rationSection[rationRow] : null;
  77. if(!me.ration){
  78. args.cancel = true;
  79. }
  80. },
  81. onEditEnded: function(sender, args){
  82. var me = rationAssistOprObj;
  83. if (!me.ration) {return;};
  84. if(typeof me.ration.rationAssList === 'undefined'){
  85. me.ration.rationAssList = [];
  86. }
  87. var assList = me.ration.rationAssList;
  88. var assObj = sheetsOprObj.combineRationRowData(me.sheet, me.setting, args.row);
  89. let dataCode = me.setting.header[args.col].dataCode;
  90. if((args.col === 2 || args.col === 3 || args.col === 6 || args.col === 7)
  91. && args.editingText && args.editingText.toString().trim().length > 0 && isNaN(args.editingText)){
  92. args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : '');
  93. alert(me.setting.header[args.col].headerName + '只能为数值!');
  94. return;
  95. }
  96. else if(args.col === 4 && args.editingText && (args.editingText.toString().trim().length === 0 ||
  97. isNaN(args.editingText) || args.editingText % 1 !== 0)){
  98. args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : 0);
  99. alert(me.setting.header[args.col].headerName + '只能为整数!');
  100. return;
  101. }
  102. // 新增
  103. if (args.row >= assList.length) {
  104. if (assObj.decimal == undefined || assObj.decimal == null){assObj.decimal = '0';};
  105. if (assObj.carryBit == undefined || assObj.carryBit == null){assObj.carryBit = '进一';};
  106. assList.push(assObj);
  107. }
  108. // 修改
  109. else{ assList[args.row] = assObj; };
  110. rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
  111. me.sheet.getParent().focus(true);
  112. });
  113. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  114. //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, assList.length, me.setting.comboItems, false, false);
  115. sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
  116. sheetCommonObj.showData(me.sheet, me.setting, assList);
  117. },
  118. onRangeChanged: function(sender, args) {
  119. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  120. if (!confirm(`确定要删除选中的 ${args.rowCount} 条辅助定额吗?`)){return; }
  121. var me = rationAssistOprObj;
  122. if (!me.ration) {return;};
  123. var assList = me.ration.rationAssList;
  124. for (var i = args.rowCount - 1; i >= 0; i--) {
  125. if (args.row + i < assList.length) {
  126. assList.splice(args.row + i, 1);
  127. };
  128. };
  129. rationOprObj.mixUpdateRequest([me.ration], [], []);
  130. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  131. sheetCommonObj.showData(me.sheet, me.setting, assList);
  132. };
  133. },
  134. bindRationAssDel: function () {
  135. let me = rationAssistOprObj;
  136. let workBook = me.sheet.getParent();
  137. workBook.commandManager().register('rationAssDel', function () {
  138. let sels = me.sheet.getSelections(), isUpdate = false;
  139. if(me.ration){
  140. let curCahe = me.ration.rationAssList;
  141. for(let i = 0, len = sels.length; i < len; i ++ ){
  142. if(sels[i].colCount === me.setting.header.length){
  143. if(sels[i].row < curCahe.length){
  144. isUpdate = true;
  145. curCahe.splice(sels[i].row, sels[i].rowCount);
  146. }
  147. }
  148. }
  149. if(isUpdate){
  150. rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
  151. workBook.focus(true);
  152. });
  153. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  154. //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, curCahe.length, me.setting.comboItems, false);
  155. sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false);
  156. sheetCommonObj.showData(me.sheet, me.setting, curCahe);
  157. }
  158. }
  159. });
  160. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  161. workBook.commandManager().setShortcutKey('rationAssDel', GC.Spread.Commands.Key.del, false, false, false, false);
  162. },
  163. getAssItems: function(ration) {
  164. var me = this;
  165. me.ration = ration;
  166. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  167. sheetCommonObj.unShieldAllCells(me.sheet);
  168. if (ration == undefined || ration.rationAssList == undefined ||
  169. ration.rationAssList.length == 0){
  170. //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, 0, me.setting.comboItems, false);
  171. sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
  172. return;
  173. }
  174. else {
  175. //sheetCommonObj.setStaticCombo(me.sheet, 0, 5, ration.rationAssList.length, me.setting.comboItems, false);
  176. sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
  177. }
  178. sheetCommonObj.showData(me.sheet, me.setting, ration.rationAssList);
  179. }
  180. }