sub_fee_rate_views.js 6.7 KB

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