鸿宇研学生前端代码
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.

149 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.currentPrice) }}</text>
  19. <text>{{ `${priceFrac(item.currentPrice)}` }}</text>
  20. </view>
  21. <view class="price-bef" v-if="item.originalPrice">¥<text>{{ item.originalPrice }}</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(currentPrice) {
  60. return parseInt(currentPrice)
  61. },
  62. priceFrac(currentPrice) {
  63. return (currentPrice % this.priceInt(currentPrice)).toFixed(2).slice(1)
  64. },
  65. },
  66. }
  67. </script>
  68. <style scoped lang="scss">
  69. .option {
  70. width: 100%;
  71. overflow-x: auto;
  72. flex-wrap: nowrap;
  73. justify-content: flex-start;
  74. column-gap: 16rpx;
  75. &-item {
  76. min-width: 238rpx;
  77. flex: none;
  78. font-size: 0;
  79. border: 2rpx solid #EEEEEE;
  80. border-radius: 12rpx;
  81. overflow: hidden;
  82. &-content {
  83. padding: 16rpx 12rpx;
  84. }
  85. &-bottom {
  86. padding: 12rpx 0;
  87. font-size: 28rpx;
  88. font-weight: 500;
  89. color: #191919;
  90. background: #E4E7EB;
  91. }
  92. &.is-active {
  93. background: #E9F8FF;
  94. border-color: #00A9FF;
  95. .option-item-bottom {
  96. color: #FFFFFF;
  97. background: #00A9FF;
  98. }
  99. }
  100. }
  101. }
  102. .time {
  103. column-gap: 8rpx;
  104. &-val {
  105. font-size: 28rpx;
  106. font-weight: 500;
  107. color: #000000;
  108. }
  109. &-split {
  110. font-size: 24rpx;
  111. color: #8B8B8B;
  112. }
  113. }
  114. .price {
  115. margin-top: 4rpx;
  116. justify-content: flex-start;
  117. align-items: baseline;
  118. column-gap: 8rpx;
  119. white-space: nowrap;
  120. &-val {
  121. font-size: 24rpx;
  122. font-weight: 500;
  123. color: #FF4800;
  124. .highlight {
  125. font-size: 32rpx;
  126. }
  127. }
  128. &-bef {
  129. text-decoration: line-through;
  130. font-size: 24rpx;
  131. color: #8B8B8B;
  132. }
  133. }
  134. </style>