sub_fee_rate_views.js 6.5 KB

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