app-radio.vue 2.6 KB

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