red-packet-item.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="red-packet-item" :class="{ 'is-disabled': isDisabled }">
  3. <view class="left-part">
  4. <view class="amount-box">
  5. <text class="symbol">¥</text>
  6. <text class="amount">{{ info.faceMoney || 0 }}</text>
  7. </view>
  8. <view class="condition" v-if="info.thresholdMoney === 0">无门槛使用</view>
  9. <view class="condition" v-else>满 ¥{{ info.thresholdMoney || 0 }} 使用</view>
  10. </view>
  11. <view class="right-part">
  12. <view class="info-top">
  13. <view class="title-row">
  14. <view class="tag" :class="info.type == 2 ? 'surprise' : 'normal'">
  15. {{ info.type == 2 ? '惊喜红包' : '普通红包' }}
  16. </view>
  17. <text class="title">{{ info.couponName }}</text>
  18. </view>
  19. <view class="date">{{ formatEndTime }}到期</view>
  20. </view>
  21. <view class="action-box">
  22. <view v-if="status === 0" class="btn-use" @click="onUse">立即使用</view>
  23. <view v-else-if="status === 1" class="stamp used">
  24. <text>已使用</text>
  25. </view>
  26. <view v-else-if="status === 2" class="stamp expired">
  27. <text>已过期</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. name: "red-packet-item",
  36. props: {
  37. info: {
  38. type: Object,
  39. default: () => ({})
  40. }
  41. },
  42. computed: {
  43. // 0: unused, 1: used, 2: expired
  44. status() {
  45. if (this.info.useTime) {
  46. return 1;
  47. } else if (this.info.effectEndTime && new Date(this.info.effectEndTime.replace(/-/g, '/')).getTime() < new Date().getTime()) {
  48. return 2;
  49. }
  50. return 0;
  51. },
  52. isDisabled() {
  53. return this.status !== 0;
  54. },
  55. formatEndTime() {
  56. let endTime = this.info.effectEndTime || '';
  57. if (endTime && endTime.length >= 10) {
  58. return endTime.substring(0, 10).replace(/-/g, '.');
  59. }
  60. return endTime;
  61. }
  62. },
  63. methods: {
  64. onUse() {
  65. this.$emit('use', this.info);
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. .red-packet-item {
  72. display: flex;
  73. background-color: #ffffff;
  74. border-radius: 16rpx;
  75. margin: 20rpx 24rpx;
  76. position: relative;
  77. overflow: hidden;
  78. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
  79. &.is-disabled {
  80. .left-part {
  81. color: #999;
  82. .amount-box {
  83. color: #999;
  84. }
  85. }
  86. .right-part {
  87. .title {
  88. color: #999;
  89. }
  90. .tag {
  91. background-color: #ccc;
  92. color: #fff;
  93. }
  94. }
  95. }
  96. .left-part {
  97. width: 200rpx;
  98. display: flex;
  99. flex-direction: column;
  100. justify-content: center;
  101. align-items: center;
  102. color: #e02020;
  103. border-right: 1px dashed #eeeeee;
  104. position: relative;
  105. padding: 30rpx 0;
  106. &::before, &::after {
  107. content: '';
  108. position: absolute;
  109. right: -10rpx;
  110. width: 20rpx;
  111. height: 20rpx;
  112. background-color: #f5f5f5; // Assume page bg is #f5f5f5
  113. border-radius: 50%;
  114. }
  115. &::before { top: -10rpx; }
  116. &::after { bottom: -10rpx; }
  117. .amount-box {
  118. display: flex;
  119. align-items: baseline;
  120. font-weight: bold;
  121. .symbol {
  122. font-size: 28rpx;
  123. }
  124. .amount {
  125. font-size: 60rpx;
  126. line-height: 1;
  127. }
  128. }
  129. .condition {
  130. font-size: 22rpx;
  131. margin-top: 10rpx;
  132. }
  133. }
  134. .right-part {
  135. flex: 1;
  136. padding: 30rpx 24rpx;
  137. display: flex;
  138. flex-direction: column;
  139. justify-content: space-between;
  140. position: relative;
  141. .info-top {
  142. .title-row {
  143. display: flex;
  144. align-items: center;
  145. flex-wrap: wrap;
  146. margin-bottom: 16rpx;
  147. .tag {
  148. font-size: 20rpx;
  149. padding: 2rpx 8rpx;
  150. border-radius: 4rpx;
  151. margin-right: 10rpx;
  152. &.normal {
  153. background-color: #fcebeb;
  154. color: #e02020;
  155. }
  156. &.surprise {
  157. background-color: #fff0e5;
  158. color: #ff6a00;
  159. }
  160. }
  161. .title {
  162. font-size: 28rpx;
  163. color: #333;
  164. font-weight: 500;
  165. }
  166. }
  167. .date {
  168. font-size: 22rpx;
  169. color: #999;
  170. }
  171. }
  172. .action-box {
  173. position: absolute;
  174. right: 24rpx;
  175. bottom: 30rpx;
  176. // For status buttons aligned with date or bottom right
  177. }
  178. .btn-use {
  179. background-color: #e02020;
  180. color: #fff;
  181. font-size: 24rpx;
  182. padding: 10rpx 24rpx;
  183. border-radius: 30rpx;
  184. }
  185. .stamp {
  186. width: 100rpx;
  187. height: 100rpx;
  188. border: 2rpx solid #ccc;
  189. border-radius: 50%;
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. transform: rotate(-30deg);
  194. opacity: 0.6;
  195. text {
  196. font-size: 24rpx;
  197. color: #999;
  198. font-weight: bold;
  199. }
  200. &.used {
  201. border-color: #999;
  202. text { color: #999; }
  203. }
  204. &.expired {
  205. border-color: #999;
  206. text { color: #999; }
  207. }
  208. }
  209. }
  210. }
  211. </style>