RedGreenSelect.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="btn-group" role="group">
  3. <button type="button" class="btn btn-default red-vouch" :class="{'active' : isRed}" @click="redButtonClick">红单</button>
  4. <button type="button" class="btn btn-default green-vouch" :class="{'active' : isGreen}" @click="greenButtonClick">蓝单</button>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. model: {
  10. prop: 'modelValue',
  11. event: 'input',
  12. },
  13. props: {
  14. // 绑定的值
  15. value: {
  16. type: String,
  17. default: null,
  18. },
  19. // string: 绑定的是字符串"true","false"
  20. type: {
  21. type: String,
  22. default: null,
  23. },
  24. // true: 控件可以使用; false: 控件不可以使用。
  25. disabled: {
  26. type: Boolean,
  27. default: null,
  28. },
  29. // true: 控件不可以使用; false: 控件可以使用。
  30. readonly: {
  31. type: Boolean,
  32. default: null,
  33. },
  34. },
  35. emits: ['input'],
  36. data: function(){
  37. return {
  38. };
  39. },
  40. computed:{
  41. 'isRed': function(){
  42. if(this.type == 'string'){
  43. return this.value == 'true';
  44. }else{
  45. return this.value == true;
  46. }
  47. },
  48. 'isGreen': function(){
  49. if(this.type == 'string'){
  50. return (this.value == undefined || this.value == 'false');
  51. }else{
  52. return (this.value == undefined || this.value == false);
  53. }
  54. },
  55. },
  56. methods: {
  57. /**
  58. * 红色的按钮被按下
  59. */
  60. redButtonClick: function(){
  61. if(this.disabled == true){
  62. return;
  63. }
  64. if(this.readonly == true){
  65. return;
  66. }
  67. if(this.type == 'string'){
  68. this.$emit('input', 'true');
  69. }else{
  70. this.$emit('input', true);
  71. }
  72. },
  73. /**
  74. * 绿色的按钮被按下
  75. */
  76. greenButtonClick: function(){
  77. if(this.disabled == true){
  78. return;
  79. }
  80. if(this.readonly == true){
  81. return;
  82. }
  83. if(this.type == 'string'){
  84. this.$emit('input', 'false');
  85. }else{
  86. this.$emit('input', false);
  87. }
  88. },
  89. },
  90. };
  91. </script>
  92. <style>
  93. .red-vouch{
  94. color: red !important;
  95. font-weight: bold;
  96. }
  97. .green-vouch{
  98. color: green !important;
  99. font-weight: bold;
  100. }
  101. </style>