app-radio.vue 2.6 KB

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