sub_fee_rate_views.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. columns: [
  10. {
  11. id: 'name',
  12. caption: '参数名称',
  13. dataField: 'name',
  14. width: 250,
  15. allowEditing: false
  16. },
  17. {
  18. id: 'typeName',
  19. caption: '参数值',
  20. dataField: 'typeName',
  21. width: 200,
  22. minWidth: 50,
  23. allowEditing: true,
  24. presenter:'<div><select class="form-control form-control-sm" id="{{=it.ID}}" onchange="subRateObject.subRateChange(this)" style="width: 100%"> </select></div>'
  25. },
  26. {
  27. id: 'ID',
  28. caption: 'ID',
  29. dataField: 'ID',
  30. width: 80,
  31. visible: false,
  32. allowEditing: false
  33. }
  34. ],
  35. options :{
  36. allowSorting: false,
  37. showRowHeader: true,
  38. colMinWidth: 80,
  39. rowHeight: 33,
  40. allowEditing: this.canEdit,
  41. editMode: 'inline',
  42. editUnit: 'cell',
  43. selectionUnit:(this.canEdit == true) ? "cell" : "row"
  44. },
  45. createSpreadView:function () {
  46. if (this.views) {
  47. this.views.destroy();
  48. this.views = null;
  49. }
  50. this.views = new GC.Spread.Views.DataView($('#subRate')[0],
  51. this.datas, this.columns, new GC.Spread.Views.Plugins.GridLayout(this.options));
  52. this.views["rowDbClick"].addHandler(function () {
  53. console.log('hh')
  54. });
  55. this.views.invalidate();
  56. document.querySelector('#subRate').focus();
  57. this.addComboboxOption(this.datas);
  58. },
  59. reFreshRateViews:function(sender,args) {
  60. subRateObject.datas = projectObj.project.FeeRate.getSubViewData(args.item);
  61. subRateObject.valueMap=projectObj.project.FeeRate.getValueMap(args.item);
  62. subRateObject.createSpreadView();
  63. },
  64. addComboboxOption:function (datas) {
  65. //<option value ="volvo">Volvo</option> <option value ="saab">Saab</option> <option value="opel">Opel</option> <option value="audi">Audi</option>
  66. _.forEach(datas,function (item) {
  67. var selectvalue = 0;
  68. _.forEach(item.optionList,function (o) {
  69. var option = $("<option>").val(o.value).text(o.name);
  70. $('#'+item.ID).append(option);
  71. if(o.selected){
  72. selectvalue = o.value;
  73. }
  74. })
  75. $('#'+item.ID).val(selectvalue);
  76. })
  77. },
  78. subRateChange:function(select){
  79. var me = subRateObject;
  80. var selectValueList=[];
  81. var selectMap={};
  82. if(me.datas&&me.datas.length>0){
  83. $.bootstrapLoading.start();
  84. _.forEach(me.datas,function (d,key) {
  85. var selectValue = $('#'+d.ID).val();
  86. selectValueList.push(selectValue);
  87. selectMap[key]=selectValue;
  88. })
  89. var mapID =selectValueList.join('-');
  90. var rate = me.valueMap[mapID];
  91. feeRateObject.updateBySelect(rate,selectMap,mapID);
  92. }
  93. },
  94. destorySpreadView:function () {
  95. if(this.views){
  96. this.views.destroy();
  97. this.views = null;
  98. }
  99. subRateObject.datas=null;
  100. subRateObject.valueMap=null;
  101. }
  102. }