s-coupon-block.vue 5.5 KB

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