sub_fee_rate_views.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * Created by chen on 2017/8/1.
  3. */
  4. var subRateObject={
  5. views:null,
  6. datas:null,
  7. valueMap:null,
  8. canEdit:true,
  9. subRateSpread:null,
  10. subRateSheet:null,
  11. subRateSetting:{
  12. header: [
  13. {headerName: "参数名称", headerWidth: 110, dataCode: "name", dataType: "String"},
  14. {headerName: "参数值", headerWidth: 150, dataCode: "optionValue", dataType: "String",getText:'forOption'}
  15. ],
  16. view: {
  17. lockColumns: [0]
  18. },
  19. getText:{
  20. forOption:function (item,val) {
  21. let o = _.find(item.optionList,{'selected':true});
  22. return o?o.value:'';
  23. }
  24. }
  25. },
  26. columns: [
  27. {
  28. id: 'name',
  29. caption: '参数名称',
  30. dataField: 'name',
  31. width: 250,
  32. allowEditing: false
  33. },
  34. {
  35. id: 'typeName',
  36. caption: '参数值',
  37. dataField: 'typeName',
  38. width: 200,
  39. minWidth: 50,
  40. allowEditing: true,
  41. presenter:'<div><select class="form-control form-control-sm" id="{{=it.ID}}" onchange="subRateObject.subRateChange(this)" style="width: 100%"> </select></div>'
  42. },
  43. {
  44. id: 'ID',
  45. caption: 'ID',
  46. dataField: 'ID',
  47. width: 80,
  48. visible: false,
  49. allowEditing: false
  50. }
  51. ],
  52. options :{
  53. allowSorting: false,
  54. showRowHeader: true,
  55. colMinWidth: 80,
  56. rowHeight: 33,
  57. allowEditing: this.canEdit,
  58. editMode: 'inline',
  59. editUnit: 'cell',
  60. selectionUnit:(this.canEdit == true) ? "cell" : "row"
  61. },
  62. createSpreadView:function () {
  63. if (this.views) {
  64. this.views.destroy();
  65. this.views = null;
  66. }
  67. this.views = new GC.Spread.Views.DataView($('#subRate')[0],
  68. this.datas, this.columns, new GC.Spread.Views.Plugins.GridLayout(this.options));
  69. this.views["rowDbClick"].addHandler(function () {
  70. console.log('hh')
  71. });
  72. this.views.invalidate();
  73. document.querySelector('#subRate').focus();
  74. this.addComboboxOption(this.datas);
  75. },
  76. reFreshRateViews:function(sender,args) {
  77. subRateObject.datas = projectObj.project.FeeRate.getSubViewData(args.item);
  78. subRateObject.valueMap=projectObj.project.FeeRate.getValueMap(args.item);
  79. subRateObject.createSpreadView();
  80. },
  81. initSubRateSpread:function (item) {
  82. if(this.subRateSpread == null){
  83. this.subRateSpread = SheetDataHelper.createNewSpread($("#subRate")[0]);
  84. this.subRateSheet = this.subRateSpread.getSheet(0);
  85. sheetCommonObj.initSheet(this.subRateSheet, this.subRateSetting, 30);
  86. this.subRateSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, this.onSubRateSelectChanged);
  87. this.subRateSheet.bind(GC.Spread.Sheets.Events.ValueChanged, this.onSubRateValueChange);
  88. //this.subRateSheet.bind(GC.Spread.Sheets.Events.ValueChanged, me.onSheetValueChange);
  89. this.subRateSheet.name('subRateSheet');
  90. }
  91. subRateObject.datas = projectObj.project.FeeRate.getSubViewData(item);
  92. subRateObject.valueMap=projectObj.project.FeeRate.getValueMap(item);
  93. subRateObject.showSubRateData();
  94. disableRightMenu("subRate",this.subRateSpread);
  95. },
  96. showSubRateData:function () {
  97. this.subRateSheet.setRowCount(0);
  98. sheetCommonObj.showData(this.subRateSheet, this.subRateSetting, this.datas);
  99. this.subRateSheet.setRowCount(this.datas.length);
  100. for(let row =0; row < this.datas.length;row++){
  101. this.setComboOptionCell(row,1,this.datas[row],this.subRateSheet);
  102. }
  103. },
  104. onSubRateSelectChanged:function (e,info) {
  105. info.sheet.repaint();
  106. },
  107. setComboOptionCell:function(row,col,subRate,sheet){
  108. let options=[];
  109. for(let op of subRate.optionList){
  110. options.push({text:op.name,value:op.value});
  111. }
  112. let dynamicCombo = sheetCommonObj.getDynamicCombo();//new GC.Spread.Sheets.CellTypes.ComboBox();
  113. dynamicCombo.items(options);
  114. dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  115. sheet.setCellType(row, col, dynamicCombo, GC.Spread.Sheets.SheetArea.viewport);
  116. },
  117. addComboboxOption:function (datas) {
  118. //<option value ="volvo">Volvo</option> <option value ="saab">Saab</option> <option value="opel">Opel</option> <option value="audi">Audi</option>
  119. _.forEach(datas,function (item) {
  120. var selectvalue = 0;
  121. _.forEach(item.optionList,function (o) {
  122. var option = $("<option>").val(o.value).text(o.name);
  123. $('#'+item.ID).append(option);
  124. if(o.selected){
  125. selectvalue = o.value;
  126. }
  127. })
  128. $('#'+item.ID).val(selectvalue);
  129. })
  130. },
  131. subRateChange:function(select){
  132. var me = subRateObject;
  133. var selectValueList=[];
  134. var selectMap={};
  135. if(me.datas&&me.datas.length>0){
  136. $.bootstrapLoading.start();
  137. _.forEach(me.datas,function (d,key) {
  138. var selectValue = $('#'+d.ID).val();
  139. selectValueList.push(selectValue);
  140. selectMap[key]=selectValue;
  141. })
  142. var mapID =selectValueList.join('-');
  143. var rate = me.valueMap[mapID];
  144. feeRateObject.updateBySelect(rate,selectMap,mapID);
  145. }
  146. },
  147. onSubRateValueChange:function (e,info) {
  148. console.info(info);
  149. let me = subRateObject, selectValueList=[],selectMap={};
  150. if(me.datas&&me.datas.length>0){
  151. _.forEach(me.datas,function (d,key) {
  152. if(info.row == key){
  153. selectMap[key]=info.newValue;
  154. }else {
  155. let o = _.find(d.optionList,{'selected':true});
  156. selectMap[key]=o.value;
  157. }
  158. selectValueList.push(selectMap[key]);
  159. })
  160. var mapID =selectValueList.join('-');
  161. var rate = me.valueMap[mapID];
  162. feeRateObject.updateBySelect(rate,selectMap,mapID);
  163. }
  164. },
  165. destorySpreadView:function () {
  166. if(this.views){
  167. this.views.destroy();
  168. this.views = null;
  169. }
  170. subRateObject.datas=null;
  171. subRateObject.valueMap=null;
  172. }
  173. }