ration_assist.js 9.0 KB

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