app-radio.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="app-default" :style="{'width': `${width}rpx`, 'height': `${height}rpx`}" @click.stop="radioSelection">
  3. <view
  4. v-if="value"
  5. class="app-default-active"
  6. :class="[
  7. {'round-active' : type === 'round'},
  8. `${theme}-background`
  9. ]"
  10. ></view>
  11. <view v-if="!value" class="app-default-border"
  12. :class="{'round-border' : type === 'round'}"></view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. name: 'app-radio',
  18. props: {
  19. type: String,
  20. theme: {
  21. type: String,
  22. default: 'classic-red',
  23. },
  24. value: {
  25. default: false,
  26. type: Boolean,
  27. },
  28. width: {
  29. type: String,
  30. default: '40'
  31. },
  32. height: {
  33. type: String,
  34. default: '40'
  35. },
  36. item: {
  37. type: Object,
  38. default() {
  39. return {}
  40. }
  41. },
  42. sign: {
  43. default: null,
  44. },
  45. },
  46. data() {
  47. return {
  48. active: this.value,
  49. }
  50. },
  51. methods: {
  52. radioSelection() {
  53. this.active = !this.active;
  54. this.$emit('input', this.active, this.sign);
  55. this.$emit('click', this.active, this.item);
  56. }
  57. },
  58. watch: {
  59. value: {
  60. handler(value) {
  61. this.active = value;
  62. }
  63. }
  64. }
  65. }
  66. </script>
  67. <style scoped lang="scss">
  68. .round-active {
  69. border-radius: 50%;
  70. }
  71. .round-border {
  72. border-radius: 50%;
  73. }
  74. .app-default {
  75. position: relative;
  76. }
  77. .app-default-active {
  78. position: absolute;
  79. background-image: url("../../../static/image/icon/yes-radio.png");
  80. background-size: 100% 100%;
  81. top: 50%;
  82. left: 50%;
  83. transform: translate(-50%, -50%);
  84. background-repeat: no-repeat;
  85. background-color: transparent !important;
  86. width: #{40rpx};
  87. height: #{40rpx};
  88. }
  89. .app-default-border {
  90. position: absolute;
  91. border: #{1rpx} solid #dddddd;
  92. top: 50%;
  93. left: 50%;
  94. transform: translate(-50%, -50%);
  95. width: #{40rpx};
  96. height: #{40rpx};
  97. }
  98. </style>