app-radio-group.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="app-radio-group">
  3. <view style="overflow-y:hidden;">
  4. <view class="dir-left-wrap">
  5. <template v-for="(item, index) in model">
  6. <view :key="index" class="item cross-center dir-left-nowrap" :style="{height: `${height}rpx`,}">
  7. <template v-if="type==='round'">
  8. <view class="item-round text-ellipsis"
  9. :class="[
  10. `white-background`,
  11. item.value?`background`:``,
  12. ]"
  13. :style="{color: color ? color: '#FF4544',
  14. borderColor: color ? color: '#FF4544',
  15. backgroundColor: item.value ? color: '#FFFFFF'}"
  16. @click="handleClick(index)">{{item.label}}
  17. </view>
  18. </template>
  19. <template v-else>
  20. <view class="checker">
  21. <app-radio v-model="item.value" type="round" @input="handleInput" :sign="index"></app-radio>
  22. </view>
  23. <view class="label text-ellipsis">{{item.label}}</view>
  24. </template>
  25. </view>
  26. </template>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import AppRadio from "./app-radio";
  33. export default {
  34. name: 'app-radio-group',
  35. components: {AppRadio},
  36. props: {
  37. type: {
  38. default: 'default',
  39. },
  40. value: {
  41. default: null,
  42. },
  43. list: {
  44. type: Array,
  45. default: [],
  46. },
  47. height: {
  48. type: Number,
  49. default: 88,
  50. },
  51. sign: {
  52. default: null,
  53. },
  54. color: {
  55. default: '#ff4544',
  56. }
  57. },
  58. data() {
  59. const list = this.list;
  60. for (let i in list) {
  61. if (list[i].label === this.value) {
  62. list[i].value = true;
  63. }
  64. }
  65. return {
  66. model: this.list,
  67. };
  68. },
  69. methods: {
  70. handleInput(e, index) {
  71. if (e === false) {
  72. this.model[index].value = true;
  73. return;
  74. }
  75. for (let i in this.model) {
  76. if (index != i) {
  77. this.model[i].value = false;
  78. }
  79. }
  80. this.$emit('input', this.model[index].label, this.sign);
  81. this.$emit('change', this.model, this.sign);
  82. },
  83. handleClick(index) {
  84. for (let i in this.model) {
  85. if (i == index) {
  86. if (!this.model[i].value) {
  87. this.model[i].value = true;
  88. this.$emit('input', this.model[index].label, this.sign);
  89. this.$emit('change', this.model, this.sign);
  90. }
  91. } else {
  92. this.model[i].value = false;
  93. }
  94. }
  95. },
  96. },
  97. }
  98. </script>
  99. <style scoped lang="scss">
  100. .label {
  101. color: #666666;
  102. }
  103. .item {
  104. margin-bottom: #{12rpx};
  105. margin-top: #{12rpx};
  106. margin-right: #{10rpx};
  107. }
  108. .item:last-child {
  109. margin-right: 0;
  110. }
  111. .checker {
  112. margin-right: #{16rpx};
  113. }
  114. .item-round {
  115. display: inline-block;
  116. height: #{56rpx};
  117. line-height: #{54rpx};
  118. border: #{2rpx} solid;
  119. padding: 0 #{24rpx};
  120. border-radius: #{1000rpx};
  121. font-size: $uni-font-size-general-one;
  122. }
  123. .background {
  124. background-color: #ff4544;
  125. color: #ffffff !important;
  126. }
  127. .border {
  128. border-color: #ff4544;
  129. }
  130. .color {
  131. color: #ff4544;
  132. }
  133. .text-ellipsis {
  134. white-space: nowrap;
  135. overflow: hidden;
  136. text-overflow: ellipsis;
  137. max-width: #{420rpx};
  138. }
  139. </style>