鸿宇研学生前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.0 KiB

  1. <template>
  2. <view class="flex option" :style="style">
  3. <view
  4. :class="['option-item', item.id === selected ? 'is-active' : '']"
  5. v-for="item in options"
  6. :key="item.id"
  7. @click="selected = item.id"
  8. >
  9. <view class="option-item-content">
  10. <view class="flex time">
  11. <view class="time-val">{{ item.startDate }}</view>
  12. <view class="time-split">-</view>
  13. <view class="time-val">{{ item.endDate }}</view>
  14. </view>
  15. <view class="flex price">
  16. <view class="price-val">
  17. <text>¥</text>
  18. <text class="highlight">{{ priceInt(item.priceDiscount) }}</text>
  19. <text>{{ `${priceFrac(item.priceDiscount)}` }}</text>
  20. </view>
  21. <view class="price-bef" v-if="item.priceOrigin">¥<text>{{ item.priceOrigin }}</text></view>
  22. </view>
  23. </view>
  24. <view class="flex option-item-bottom">
  25. {{ item.id === selected ? '已选择' : '点击选择' }}
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. props: {
  33. value: {
  34. type: String | Number,
  35. default: null
  36. },
  37. options: {
  38. type: Array,
  39. default() {
  40. return []
  41. }
  42. },
  43. style: {
  44. type: String,
  45. default: ''
  46. },
  47. },
  48. computed: {
  49. selected: {
  50. set(val) {
  51. this.$emit('input', val)
  52. },
  53. get() {
  54. return this.value
  55. }
  56. },
  57. },
  58. methods: {
  59. priceInt(priceDiscount) {
  60. return Math.floor(priceDiscount)
  61. },
  62. priceFrac(priceDiscount) {
  63. let frac = priceDiscount % this.priceInt(priceDiscount)
  64. return frac > 0 ? frac.toFixed(2).slice(1) : ''
  65. },
  66. },
  67. }
  68. </script>
  69. <style scoped lang="scss">
  70. .option {
  71. width: 100%;
  72. overflow-x: auto;
  73. flex-wrap: nowrap;
  74. justify-content: flex-start;
  75. column-gap: 16rpx;
  76. &-item {
  77. min-width: 238rpx;
  78. flex: none;
  79. font-size: 0;
  80. border: 2rpx solid #EEEEEE;
  81. border-radius: 12rpx;
  82. overflow: hidden;
  83. &-content {
  84. padding: 16rpx 12rpx;
  85. }
  86. &-bottom {
  87. padding: 12rpx 0;
  88. font-size: 28rpx;
  89. font-weight: 500;
  90. color: #191919;
  91. background: #E4E7EB;
  92. }
  93. &.is-active {
  94. background: #E9F8FF;
  95. border-color: #00A9FF;
  96. .option-item-bottom {
  97. color: #FFFFFF;
  98. background: #00A9FF;
  99. }
  100. }
  101. }
  102. }
  103. .time {
  104. column-gap: 8rpx;
  105. &-val {
  106. font-size: 28rpx;
  107. font-weight: 500;
  108. color: #000000;
  109. }
  110. &-split {
  111. font-size: 24rpx;
  112. color: #8B8B8B;
  113. }
  114. }
  115. .price {
  116. margin-top: 4rpx;
  117. justify-content: flex-start;
  118. align-items: baseline;
  119. column-gap: 8rpx;
  120. white-space: nowrap;
  121. &-val {
  122. font-size: 24rpx;
  123. font-weight: 500;
  124. color: #FF4800;
  125. .highlight {
  126. font-size: 32rpx;
  127. }
  128. }
  129. &-bef {
  130. text-decoration: line-through;
  131. font-size: 24rpx;
  132. color: #8B8B8B;
  133. }
  134. }
  135. </style>