s-coupon-block.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!-- 优惠券组 -->
  2. <template>
  3. <view>
  4. <!-- 样式1 -->
  5. <view class="lg-coupon-wrap" v-if="mode == 1">
  6. <scroll-view class="scroll-box" scroll-x scroll-anchoring>
  7. <view class="coupon-box ss-flex">
  8. <view
  9. class="coupon-item"
  10. :style="[couponBg, { marginLeft: data.space + 'px' }]"
  11. v-for="(item, index) in couponList"
  12. :key="index"
  13. >
  14. <su-coupon
  15. size="lg"
  16. :textColor="data.fill.color"
  17. background=""
  18. :couponId="item.id"
  19. :title="item.amount_text"
  20. :value="item.amount"
  21. :surplus="item.stock"
  22. :sellBy="`${item.get_start_time.substring(0, 10)} 至 ${item.get_end_time.substring(
  23. 0,
  24. 10,
  25. )}`"
  26. >
  27. <template v-slot:btn>
  28. <button
  29. class="ss-reset-button card-btn"
  30. :style="[btnStyles]"
  31. @click.stop="onGetCoupon(item.id)"
  32. >
  33. {{ item.get_status_text }}
  34. </button>
  35. </template>
  36. </su-coupon>
  37. </view>
  38. </view>
  39. </scroll-view>
  40. </view>
  41. <!-- 样式2 -->
  42. <view class="md-coupon-wrap" v-if="mode == 2">
  43. <scroll-view class="scroll-box" scroll-x scroll-anchoring>
  44. <view class="coupon-box ss-flex">
  45. <view
  46. class="coupon-item"
  47. :style="[couponBg, { marginLeft: data.space + 'px' }]"
  48. v-for="(item, index) in couponList"
  49. :key="index"
  50. >
  51. <su-coupon
  52. size="md"
  53. :textColor="data.fill.color"
  54. background=""
  55. :title="item.amount_text"
  56. :value="item.amount"
  57. :surplus="item.stock"
  58. :couponId="item.id"
  59. :sellBy="`${item.get_start_time.substring(0, 10)} 至 ${item.get_end_time.substring(
  60. 0,
  61. 10,
  62. )}`"
  63. >
  64. <template v-slot:btn>
  65. <button
  66. @click.stop="onGetCoupon(item.id)"
  67. class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center"
  68. :style="[btnStyles]"
  69. >
  70. <view class="btn-text">{{ item.get_status_text }}</view>
  71. </button>
  72. </template>
  73. </su-coupon>
  74. </view>
  75. </view>
  76. </scroll-view>
  77. </view>
  78. <!-- 样式3 -->
  79. <view class="xs-coupon-wrap" v-if="mode == 3">
  80. <scroll-view class="scroll-box" scroll-x scroll-anchoring>
  81. <view class="coupon-box ss-flex">
  82. <view
  83. class="coupon-item"
  84. :style="[couponBg, { marginLeft: data.space + 'px' }]"
  85. v-for="(item, index) in couponList"
  86. :key="index"
  87. >
  88. <su-coupon
  89. size="xs"
  90. :textColor="data.fill.color"
  91. background=""
  92. :title="item.amount_text"
  93. :value="item.amount"
  94. :surplus="item.stock"
  95. :couponId="item.id"
  96. :sellBy="`${item.get_start_time.substring(0, 10)} 至 ${item.get_end_time.substring(
  97. 0,
  98. 10,
  99. )}`"
  100. >
  101. <template v-slot:btn>
  102. <button
  103. class="ss-reset-button card-btn"
  104. :style="[btnStyles]"
  105. @click.stop="onGetCoupon(item.id)"
  106. >
  107. {{ item.get_status_text }}
  108. </button>
  109. </template>
  110. </su-coupon>
  111. </view>
  112. </view>
  113. </scroll-view>
  114. </view>
  115. </view>
  116. </template>
  117. <script setup>
  118. import sheep from '@/sheep';
  119. import { ref, onMounted } from 'vue';
  120. const props = defineProps({
  121. data: {
  122. type: Object,
  123. default: () => ({}),
  124. },
  125. styles: {
  126. type: Object,
  127. default: () => ({}),
  128. },
  129. });
  130. const { mode, button } = props.data;
  131. const couponBg = {
  132. background: `url(${sheep.$url.cdn(props.data.fill.bgImage)}) no-repeat top center / 100% 100%`,
  133. };
  134. const btnStyles = {
  135. background: button.bgColor,
  136. color: button.color,
  137. };
  138. const couponList = ref([]);
  139. //立即领取优惠券
  140. async function onGetCoupon(id) {
  141. const { error, msg } = await sheep.$api.coupon.get(id);
  142. if (error === 0) {
  143. uni.showToast({
  144. title: msg,
  145. icon: 'none',
  146. });
  147. } else {
  148. let { data } = await sheep.$api.coupon.list({ ids: props.data.couponIds.join(',') });
  149. couponList.value = [...data.data];
  150. }
  151. }
  152. onMounted(async () => {
  153. let { data } = await sheep.$api.coupon.list({ ids: props.data.couponIds.join(',') });
  154. // couponList.value = [...data.data, ...data.data, ...data.data, ...data.data];
  155. couponList.value = [...data.data];
  156. });
  157. </script>
  158. <style lang="scss" scoped>
  159. .card-btn {
  160. width: 140rpx;
  161. height: 50rpx;
  162. border-radius: 25rpx;
  163. font-size: 24rpx;
  164. line-height: 50rpx;
  165. }
  166. .coupon-item {
  167. &:nth-of-type(1) {
  168. margin-left: 0 !important;
  169. }
  170. }
  171. .md-coupon-wrap {
  172. .card-btn {
  173. width: 50rpx;
  174. height: 140rpx;
  175. margin: auto 0;
  176. margin-right: 20rpx;
  177. .btn-text {
  178. font-size: 24rpx;
  179. text-align: center;
  180. writing-mode: vertical-lr;
  181. writing-mode: tb-lr;
  182. }
  183. }
  184. }
  185. </style>