en-radio.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="row-justify-sb center p-tb30 size-28" :class="{'bor-bottom-1':is_border}">
  3. <view class="wh-text" :class="{'wh-text-long':isLong}"><text>{{name?name:label}}</text></view>
  4. <view class="row-c">
  5. <view class="row-c radiu-item m-l20" :class="{'active-radiu':radioValue === item.value}"
  6. v-for="(item,index) in list" :key="index" @click="onSelect(item.value)">
  7. <image class="wh-30 m-r20"
  8. :src="radioValue == item.value?'https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/new-xcx/information/correct.png':'https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/new-xcx/information/error.png'"
  9. mode="aspectFill"></image>
  10. <text>{{item.text}}</text>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. props: {
  18. name: {
  19. type: String,
  20. default: ''
  21. },
  22. label: {
  23. type: String,
  24. default: ''
  25. },
  26. value: {
  27. type: Number,
  28. default: 0
  29. },
  30. disabled: {
  31. default: false
  32. },
  33. is_border: {
  34. default: true
  35. },
  36. list: {
  37. type: Array,
  38. default: () => []
  39. }
  40. },
  41. watch: {
  42. value: {
  43. handler(value) {
  44. this.radioValue = value
  45. },
  46. immediate: true
  47. },
  48. },
  49. data() {
  50. return {
  51. radioValue: 0,
  52. isLong:false
  53. }
  54. },
  55. mounted() {
  56. this.setLabelWidth()
  57. },
  58. methods: {
  59. setLabelWidth(){
  60. this.isLong=this.label.length>4
  61. },
  62. onSelect(value) {
  63. if (this.disabled) {
  64. return
  65. }
  66. this.$emit('updateData')
  67. this.radioValue = value
  68. this.$emit('input', value)
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .wh-text {
  75. width: 110rpx;
  76. text-align: justify;
  77. text-align-last: justify;
  78. vertical-align: top;
  79. height: 38rpx;
  80. }
  81. .wh-text:after {
  82. content: '';
  83. width: 110rpx;
  84. height: 0;
  85. display: inline-block;
  86. overflow: hidden;
  87. }
  88. .radiu-item {
  89. padding: 6rpx 30rpx;
  90. border-radius: 100rpx;
  91. border: 1rpx solid #CCCCCC;
  92. }
  93. .active-radiu {
  94. color: #0FB160;
  95. border: 1rpx solid #0FB160;
  96. }
  97. .wh-text-long {
  98. width: 170rpx;
  99. }
  100. .wh-text-long:after{
  101. width: 170rpx;
  102. }
  103. </style>