ration_assist.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. /*var carryBit = new GC.Spread.Sheets.CellTypes.ComboBox();
  29. carryBit.items(["四舍五入","进一"]);
  30. me.sheet.getRange(-1, 5, -1, 1).cellType(carryBit);*/
  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.EditEnded, me.onEditEnded);
  34. me.sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  35. //me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  36. },
  37. onEnterCell: function (sender, args) {
  38. args.sheet.repaint();
  39. },
  40. onClipboardPasting: function(sender, args) {
  41. var me = rationAssistOprObj;
  42. if (!me.ration) {
  43. args.cancel = true;
  44. }
  45. },
  46. onClipboardPasted: function(e, info) {
  47. var me = rationAssistOprObj;
  48. if (!me.ration) {return;};
  49. var tempArr = sheetCommonObj.analyzePasteData(me.setting, info);
  50. var assList = me.ration.rationAssList;
  51. if (assList == undefined) {
  52. me.ration.rationAssList = tempArr;
  53. }else{
  54. assList = assList.concat(tempArr);
  55. me.ration.rationAssList = assList;
  56. };
  57. rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
  58. me.sheet.getParent().focus(true);
  59. });
  60. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  61. sheetCommonObj.setStaticCombo(me.sheet, 0, 5, me.ration.rationAssList.length, me.setting.comboItems, false, false);
  62. sheetCommonObj.setDynamicCombo(me.sheet, me.ration.rationAssList.length, 5, me.sheet.getRowCount() - me.ration.rationAssList.length, me.setting.comboItems, false, false);
  63. sheetCommonObj.showData(me.sheet, me.setting, me.ration.rationAssList);
  64. },
  65. onEditEnded: function(sender, args){
  66. var me = rationAssistOprObj;
  67. if (!me.ration) {return;};
  68. var assList = me.ration.rationAssList;
  69. if(assList == undefined) assList = [];
  70. //var assObj = sheetCommonObj.combineRowData(me.sheet, me.setting, args.row);
  71. var assObj = sheetsOprObj.combineRationRowData(me.sheet, me.setting, args.row);
  72. let dataCode = me.setting.header[args.col].dataCode;
  73. if((args.col === 2 || args.col === 3 || args.col === 6 || args.col === 7)
  74. && args.editingText && args.editingText.toString().trim().length > 0 && isNaN(args.editingText)){
  75. args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : '');
  76. alert(me.setting.header[args.col].headerName + '只能为数值!');
  77. return;
  78. }
  79. else if(args.col === 4 && args.editingText && (args.editingText.toString().trim().length === 0 ||
  80. isNaN(args.editingText) || args.editingText % 1 !== 0)){
  81. args.sheet.setValue(args.row, args.col, args.row < assList.length ? assList[args.row][dataCode] : 0);
  82. alert(me.setting.header[args.col].headerName + '只能为整数!');
  83. return;
  84. }
  85. // 新增
  86. if ((assList == undefined) || (assList && args.row >= assList.length)) {
  87. if (assObj.decimal == undefined || assObj.decimal == null){assObj.decimal = '0';};
  88. if (assObj.carryBit == undefined || assObj.carryBit == null){assObj.carryBit = '四舍五入';};
  89. assList.push(assObj);
  90. }
  91. // 修改
  92. else{ assList[args.row] = assObj; };
  93. rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
  94. me.sheet.getParent().focus(true);
  95. });
  96. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  97. sheetCommonObj.setStaticCombo(me.sheet, 0, 5, assList.length, me.setting.comboItems, false, false);
  98. sheetCommonObj.setDynamicCombo(me.sheet, assList.length, 5, me.sheet.getRowCount() - assList.length, me.setting.comboItems, false, false);
  99. sheetCommonObj.showData(me.sheet, me.setting, assList);
  100. },
  101. onRangeChanged: function(sender, args) {
  102. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  103. if (!confirm(`确定要删除选中的 ${args.rowCount} 条辅助定额吗?`)){return; }
  104. var me = rationAssistOprObj;
  105. if (!me.ration) {return;};
  106. var assList = me.ration.rationAssList;
  107. for (var i = args.rowCount - 1; i >= 0; i--) {
  108. if (args.row + i < assList.length) {
  109. assList.splice(args.row + i, 1);
  110. };
  111. };
  112. rationOprObj.mixUpdateRequest([me.ration], [], []);
  113. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  114. sheetCommonObj.showData(me.sheet, me.setting, assList);
  115. };
  116. },
  117. bindRationAssDel: function () {
  118. let me = rationAssistOprObj;
  119. let workBook = me.sheet.getParent();
  120. workBook.commandManager().register('rationAssDel', function () {
  121. let sels = me.sheet.getSelections(), isUpdate = false;
  122. if(me.ration){
  123. let curCahe = me.ration.rationAssList;
  124. for(let i = 0, len = sels.length; i < len; i ++ ){
  125. if(sels[i].colCount === me.setting.header.length){
  126. if(sels[i].row < curCahe.length){
  127. isUpdate = true;
  128. curCahe.splice(sels[i].row, sels[i].rowCount);
  129. }
  130. }
  131. }
  132. if(isUpdate){
  133. rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
  134. workBook.focus(true);
  135. });
  136. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  137. sheetCommonObj.setStaticCombo(me.sheet, 0, 5, curCahe.length, me.setting.comboItems, false);
  138. sheetCommonObj.setDynamicCombo(me.sheet, curCahe.length, 5, me.sheet.getRowCount() - curCahe.length, me.setting.comboItems, false);
  139. sheetCommonObj.showData(me.sheet, me.setting, curCahe);
  140. }
  141. }
  142. });
  143. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  144. workBook.commandManager().setShortcutKey('rationAssDel', GC.Spread.Commands.Key.del, false, false, false, false);
  145. },
  146. getAssItems: function(ration) {
  147. var me = this;
  148. me.ration = ration;
  149. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  150. sheetCommonObj.unShieldAllCells(me.sheet);
  151. if (ration == undefined || ration.rationAssList == undefined ||
  152. ration.rationAssList.length == 0){
  153. sheetCommonObj.setStaticCombo(me.sheet, 0, 5, 0, me.setting.comboItems, false);
  154. sheetCommonObj.setDynamicCombo(me.sheet, 0, 5, me.sheet.getRowCount(), me.setting.comboItems, false, false);
  155. return;
  156. }
  157. else {
  158. sheetCommonObj.setStaticCombo(me.sheet, 0, 5, ration.rationAssList.length, me.setting.comboItems, false);
  159. sheetCommonObj.setDynamicCombo(me.sheet, ration.rationAssList.length, 5, me.sheet.getRowCount() - ration.rationAssList.length, me.setting.comboItems, false, false);
  160. }
  161. sheetCommonObj.showData(me.sheet, me.setting, ration.rationAssList);
  162. }
  163. }