sub_fee_rate_views.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. console.log(subRateObject.datas);
  94. console.log(subRateObject.valueMap);
  95. subRateObject.showSubRateData();
  96. disableRightMenu("subRate",this.subRateSpread);
  97. },
  98. showSubRateData:function () {
  99. this.subRateSheet.setRowCount(0);
  100. sheetCommonObj.showData(this.subRateSheet, this.subRateSetting, this.datas);
  101. this.subRateSheet.setRowCount(this.datas.length);
  102. for(let row =0; row < this.datas.length;row++){
  103. this.setComboOptionCell(row,1,this.datas[row],this.subRateSheet);
  104. }
  105. },
  106. onSubRateSelectChanged:function (e,info) {
  107. info.sheet.repaint();
  108. },
  109. setComboOptionCell:function(row,col,subRate,sheet){
  110. let options=[];
  111. for(let op of subRate.optionList){
  112. options.push({text:op.name,value:op.value});
  113. }
  114. let dynamicCombo = sheetCommonObj.getDynamicCombo();//new GC.Spread.Sheets.CellTypes.ComboBox();
  115. dynamicCombo.items(options);
  116. dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  117. sheet.setCellType(row, col, dynamicCombo, GC.Spread.Sheets.SheetArea.viewport);
  118. },
  119. addComboboxOption:function (datas) {
  120. //<option value ="volvo">Volvo</option> <option value ="saab">Saab</option> <option value="opel">Opel</option> <option value="audi">Audi</option>
  121. _.forEach(datas,function (item) {
  122. var selectvalue = 0;
  123. _.forEach(item.optionList,function (o) {
  124. var option = $("<option>").val(o.value).text(o.name);
  125. $('#'+item.ID).append(option);
  126. if(o.selected){
  127. selectvalue = o.value;
  128. }
  129. })
  130. $('#'+item.ID).val(selectvalue);
  131. })
  132. },
  133. subRateChange:function(select){
  134. var me = subRateObject;
  135. var selectValueList=[];
  136. var selectMap={};
  137. if(me.datas&&me.datas.length>0){
  138. $.bootstrapLoading.start();
  139. _.forEach(me.datas,function (d,key) {
  140. var selectValue = $('#'+d.ID).val();
  141. selectValueList.push(selectValue);
  142. selectMap[key]=selectValue;
  143. })
  144. var mapID =selectValueList.join('-');
  145. var rate = me.valueMap[mapID];
  146. feeRateObject.updateBySelect(rate,selectMap,mapID);
  147. }
  148. },
  149. onSubRateValueChange:function (e,info) {
  150. console.info(info);
  151. let me = subRateObject, selectValueList=[],selectMap={};
  152. if(me.datas&&me.datas.length>0){
  153. _.forEach(me.datas,function (d,key) {
  154. if(info.row == key){
  155. selectMap[key]=info.newValue;
  156. }else {
  157. let o = _.find(d.optionList,{'selected':true});
  158. selectMap[key]=o.value;
  159. }
  160. selectValueList.push(selectMap[key]);
  161. })
  162. var mapID =selectValueList.join('-');
  163. var rate = me.valueMap[mapID];
  164. feeRateObject.updateBySelect(rate,selectMap,mapID);
  165. }
  166. },
  167. destorySpreadView:function () {
  168. if(this.views){
  169. this.views.destroy();
  170. this.views = null;
  171. }
  172. subRateObject.datas=null;
  173. subRateObject.valueMap=null;
  174. }
  175. }