ration_assist.js 9.7 KB

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