tm-radio-group.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="tm-radio-group">
  3. <view v-if="true" class="label-view">
  4. <text>改善工具</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. setting: {
  38. type: Object,
  39. default: {
  40. value: 'value', // 设置当前选中的值(默认取value)
  41. name: 'name' // 当前显示的文字(默认取name)
  42. }
  43. }
  44. },
  45. methods: {
  46. /**
  47. * 选中变化调用
  48. * @param {Object} selectData 当前选中的对象
  49. * @param {Object} index 当前选中下标
  50. *
  51. * 返回的参数
  52. * selectData[this.setting.value]: 当前选中的值
  53. * selectData: 当前选中的整条数据
  54. * index: 当前选中的下标
  55. */
  56. toggleSelect(selectData, index){
  57. this.$emit(
  58. 'change',
  59. selectData ? selectData[this.setting.value] : '',
  60. selectData,
  61. index
  62. );
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="less">
  68. .tm-radio-group {
  69. .label-view {
  70. height: 47.5rpx;
  71. line-height: 45rpx;
  72. padding-left: 25rpx;
  73. >text {
  74. font-size: 22.5rpx;
  75. color: #666F80;
  76. }
  77. }
  78. .radio-group {
  79. padding-left: 25rpx;
  80. background-color: #fff;
  81. .radio-item {
  82. display: flex;
  83. align-items: center;
  84. justify-content: space-between;
  85. height: 87.5rpx;
  86. border-bottom: 0.62rpx solid #DADEE6;
  87. padding-right: 25rpx;
  88. .text {
  89. font-size: 22.5rpx;
  90. color: #292C33;
  91. }
  92. .icon {
  93. width: 25rpx;
  94. height: 25rpx;
  95. }
  96. }
  97. }
  98. }
  99. </style>