sub_fee_rate_views.js 6.4 KB

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