radio-group.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="radio-group-view">
  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:属性说明看tm-radio-gruop.vue
  23. */
  24. export default {
  25. props: ['list', 'defaultValue', 'label', 'setting'],
  26. methods: {
  27. /**
  28. * 选中变化调用
  29. * @param {Object} selectData 当前选中的对象
  30. * @param {Object} index 当前选中下标
  31. *
  32. * 返回的参数
  33. * selectData[this.setting.value]: 当前选中的值
  34. * selectData: 当前选中的整条数据
  35. * index: 当前选中的下标
  36. */
  37. toggleSelect(selectData, index){
  38. this.$emit(
  39. 'change',
  40. selectData ? selectData[this.setting.value] : '',
  41. selectData,
  42. index
  43. );
  44. }
  45. }
  46. }
  47. </script>
  48. <style lang="less">
  49. .radio-group-view {
  50. .label-view {
  51. height: 47.5rpx;
  52. line-height: 45rpx;
  53. padding-left: 25rpx;
  54. >text {
  55. font-size: 22.5rpx;
  56. color: #666F80;
  57. }
  58. }
  59. .radio-group {
  60. padding-left: 25rpx;
  61. background-color: #fff;
  62. .radio-item {
  63. display: flex;
  64. align-items: center;
  65. justify-content: space-between;
  66. height: 87.5rpx;
  67. border-bottom: 0.62rpx solid #DADEE6;
  68. padding-right: 25rpx;
  69. .text {
  70. font-size: 22.5rpx;
  71. color: #292C33;
  72. }
  73. .icon {
  74. width: 25rpx;
  75. height: 25rpx;
  76. }
  77. }
  78. }
  79. }
  80. </style>