ration_assist.js 9.2 KB

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