couponCenter.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="coupon-center">
  3. <swiper class="swiper-box">
  4. <swiper-item class="swiper-item">
  5. <scroll-view class="scroll-v" enableBackToTop="true" scroll-y @scrolltolower="loadMore">
  6. <u-empty mode="coupon" text="没有优惠券了" v-if="whetherEmpty"></u-empty>
  7. <view v-else class="coupon-item" v-for="(item, index) in couponList" :key="index">
  8. <view class="left">
  9. <view class="wave-line">
  10. <view class="wave" v-for="(item, index) in 12" :key="index"></view>
  11. </view>
  12. <view class="message">
  13. <view>
  14. <!--判断当前优惠券类型 couponType PRICE || DISCOUNT -->
  15. <span v-if="item.couponType == 'DISCOUNT'">{{ item.couponDiscount }}折</span>
  16. <span v-else>{{ item.price }}元</span>
  17. </view>
  18. <view>满{{ item.consumeThreshold | unitPrice }}元可用</view>
  19. </view>
  20. <view class="circle circle-top"></view>
  21. <view class="circle circle-bottom"></view>
  22. </view>
  23. <view class="right">
  24. <view>
  25. <!-- 根据scopeType 判断是否是 平台、品类或店铺 -->
  26. <view v-if="item.scopeType">
  27. <span v-if="item.scopeType == 'ALL' && item.id == 'platform'">全平台</span>
  28. <span v-if="item.scopeType == 'PORTION_CATEGORY'">仅限品类</span>
  29. <view v-else>{{ item.storeName == 'platform' ? '全平台' :item.storeName+'店铺' }}使用</view>
  30. </view>
  31. <view>有效期至:{{ item.endTime.split(" ")[0] }}</view>
  32. </view>
  33. <view class="receive" @click="receive(item)">
  34. <text>点击</text><br />
  35. <text>领取</text>
  36. </view>
  37. <view class="bg-quan"> 券 </view>
  38. </view>
  39. </view>
  40. <uni-load-more :status="loadStatus"></uni-load-more>
  41. </scroll-view>
  42. </swiper-item>
  43. </swiper>
  44. </view>
  45. </template>
  46. <script>
  47. import { receiveCoupons } from "@/api/members.js";
  48. import { getAllCoupons } from "@/api/promotions.js";
  49. export default {
  50. data() {
  51. return {
  52. loadStatus: "more", //下拉状态
  53. whetherEmpty: false, //是否为空
  54. couponList: [], // 优惠券列表
  55. params: {
  56. pageNumber: 1,
  57. pageSize: 10,
  58. },
  59. storeId: "", //店铺 id
  60. };
  61. },
  62. onLoad(option) {
  63. this.storeId = option.storeId;
  64. this.getCoupon();
  65. },
  66. onPullDownRefresh() {
  67. //下拉刷新
  68. this.params.pageNumber = 1;
  69. this.couponList = [];
  70. this.getCoupon();
  71. },
  72. methods: {
  73. /**
  74. * 获取当前优惠券
  75. */
  76. getCoupon() {
  77. uni.showLoading({
  78. title: "加载中",
  79. });
  80. let submitData = { ...this.params };
  81. // 判断当前是否有店铺
  82. this.storeId ? (submitData = { ...this.params, storeId: this.storeId }): "",
  83. getAllCoupons(submitData)
  84. .then((res) => {
  85. uni.hideLoading();
  86. uni.stopPullDownRefresh();
  87. if (res.data.code == 200) {
  88. // 如果请求成功,展示数据并进行展示
  89. let data = res.data.result;
  90. if (data.total == 0) {
  91. // 当本次请求数据为空展示空信息
  92. this.whetherEmpty = true;
  93. } else {
  94. this.couponList.push(...data.records);
  95. this.loadStatus = "noMore";
  96. }
  97. }
  98. })
  99. .catch((err) => {
  100. uni.hideLoading();
  101. });
  102. },
  103. /**
  104. * 领取优惠券
  105. */
  106. receive(item) {
  107. receiveCoupons(item.id).then((res) => {
  108. if (res.data.code == 200) {
  109. uni.showToast({
  110. title: "领取成功",
  111. icon: "none",
  112. });
  113. } else {
  114. uni.showToast({
  115. title: res.data.message,
  116. icon: "none",
  117. });
  118. }
  119. });
  120. },
  121. /**
  122. * 加载更多
  123. */
  124. loadMore() {
  125. if (this.loadStatus != "noMore") {
  126. this.params.pageNumber++;
  127. this.getAllCoupons();
  128. }
  129. },
  130. },
  131. onNavigationBarButtonTap(e) {
  132. uni.navigateTo({
  133. url: "/pages/cart/coupon/couponIntro",
  134. });
  135. },
  136. };
  137. </script>
  138. <style>
  139. page {
  140. height: 100%;
  141. }
  142. </style>
  143. <style lang="scss" scoped>
  144. .coupon-center {
  145. height: 100%;
  146. .couponList-scroll-content {
  147. position: relative;
  148. width: 100%;
  149. display: flex;
  150. white-space: nowrap;
  151. align-items: center;
  152. justify-content: space-between;
  153. align-items: center;
  154. background-color: $main-color;
  155. color: #ffffff;
  156. .tab-item {
  157. width: 160rpx;
  158. height: 80rpx;
  159. line-height: 60rpx;
  160. text-align: center;
  161. display: inline-block;
  162. }
  163. .active {
  164. border-bottom: 2px solid #ffffff;
  165. broder-width: 60rpx;
  166. font-size: 30rpx;
  167. font-weight: 700;
  168. padding-bottom: 4rpx;
  169. }
  170. }
  171. .swiper-box {
  172. height: 100%;
  173. .scroll-v {
  174. height: 100%;
  175. }
  176. .coupon-item {
  177. display: flex;
  178. align-items: center;
  179. height: 220rpx;
  180. margin: 20rpx;
  181. .left {
  182. height: 100%;
  183. width: 260rpx;
  184. background-color: $light-color;
  185. position: relative;
  186. .message {
  187. color: $font-color-white;
  188. display: flex;
  189. justify-content: center;
  190. align-items: center;
  191. flex-direction: column;
  192. margin-top: 40rpx;
  193. view:nth-child(1) {
  194. font-weight: bold;
  195. font-size: 60rpx;
  196. }
  197. view:nth-child(2) {
  198. font-size: $font-sm;
  199. }
  200. }
  201. .wave-line {
  202. height: 220rpx;
  203. width: 8rpx;
  204. position: absolute;
  205. top: 0;
  206. left: 0;
  207. background-color: $light-color;
  208. overflow: hidden;
  209. .wave {
  210. width: 8rpx;
  211. height: 16rpx;
  212. background-color: #ffffff;
  213. border-radius: 0 16rpx 16rpx 0;
  214. margin-top: 4rpx;
  215. }
  216. }
  217. .circle {
  218. width: 40rpx;
  219. height: 40rpx;
  220. background-color: $bg-color;
  221. position: absolute;
  222. border-radius: 50%;
  223. z-index: 111;
  224. }
  225. .circle-top {
  226. top: -20rpx;
  227. right: -20rpx;
  228. }
  229. .circle-bottom {
  230. bottom: -20rpx;
  231. right: -20rpx;
  232. }
  233. }
  234. .right {
  235. display: flex;
  236. justify-content: space-between;
  237. align-items: center;
  238. width: 450rpx;
  239. font-size: $font-sm;
  240. height: 100%;
  241. background-color: #ffffff;
  242. overflow: hidden;
  243. position: relative;
  244. > view:nth-child(1) {
  245. color: #666666;
  246. margin-left: 20rpx;
  247. line-height: 3em;
  248. > view:nth-child(1) {
  249. color: #ff6262;
  250. font-size: 30rpx;
  251. }
  252. }
  253. .receive {
  254. color: #ffffff;
  255. background-color: $main-color;
  256. border-radius: 50%;
  257. width: 86rpx;
  258. height: 86rpx;
  259. text-align: center;
  260. margin-right: 30rpx;
  261. vertical-align: middle;
  262. padding-top: 8rpx;
  263. position: relative;
  264. z-index: 2;
  265. }
  266. .bg-quan {
  267. width: 244rpx;
  268. height: 244rpx;
  269. border: 6rpx solid $main-color;
  270. border-radius: 50%;
  271. opacity: 0.1;
  272. color: $main-color;
  273. text-align: center;
  274. padding-top: 30rpx;
  275. font-size: 130rpx;
  276. position: absolute;
  277. right: -54rpx;
  278. bottom: -60rpx;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. </style>