tm-radio-group.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view class="tm-radio-group">
  3. <view v-if="label" class="label-view">
  4. <text>{{ label }}</text>
  5. </view>
  6. <view class="radio-group">
  7. <template v-for="(item, i) in list">
  8. <view class="radio-item" :key="i" @click="toggleSelect(item, i)">
  9. <text class="text">{{ item[setting.name] }}</text>
  10. <image class="icon"
  11. :src="`/static/${item[setting.value] === defaultValue ? 'check-radio' : 'check-no'}.png`"></image>
  12. </view>
  13. </template>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. /**
  19. * 单选列表组合
  20. * 芦荟
  21. * 2021.2.2
  22. * props:看下面,有注释说明
  23. */
  24. export default {
  25. props: {
  26. // 渲染的数据
  27. list: {
  28. type: Array,
  29. default: []
  30. },
  31. // 选中的数据
  32. defaultValue: {
  33. type: Number | String,
  34. default: ''
  35. },
  36. // 单选列表组合名字
  37. label: {
  38. type: String,
  39. default: ''
  40. },
  41. // 单选组配置
  42. setting: {
  43. type: Object,
  44. default: {
  45. value: 'value', // 设置当前选中的值(默认取value)
  46. name: 'name' // 当前显示的文字(默认取name)
  47. }
  48. }
  49. },
  50. methods: {
  51. /**
  52. * 选中变化调用
  53. * @param {Object} selectData 当前选中的对象
  54. * @param {Object} index 当前选中下标
  55. *
  56. * 返回的参数
  57. * selectData[this.setting.value]: 当前选中的值
  58. * selectData: 当前选中的整条数据
  59. * index: 当前选中的下标
  60. */
  61. toggleSelect(selectData, index){
  62. this.$emit(
  63. 'change',
  64. selectData ? selectData[this.setting.value] : '',
  65. selectData,
  66. index
  67. );
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="less">
  73. .tm-radio-group {
  74. .label-view {
  75. height: 47.5rpx;
  76. line-height: 45rpx;
  77. padding-left: 25rpx;
  78. >text {
  79. font-size: 22.5rpx;
  80. color: #666F80;
  81. }
  82. }
  83. .radio-group {
  84. padding-left: 25rpx;
  85. background-color: #fff;
  86. .radio-item {
  87. display: flex;
  88. align-items: center;
  89. justify-content: space-between;
  90. height: 87.5rpx;
  91. border-bottom: 0.62rpx solid #DADEE6;
  92. padding-right: 25rpx;
  93. .text {
  94. font-size: 22.5rpx;
  95. color: #292C33;
  96. }
  97. .icon {
  98. width: 25rpx;
  99. height: 25rpx;
  100. }
  101. }
  102. }
  103. }
  104. </style>