index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view class="container" :style="appThemeStyle">
  3. <view v-if="list.length" class="coupon-list">
  4. <view class="coupon-item" v-for="(item, index) in list" :key="index">
  5. <view class="item-wrapper" :class="[ !item.state.value ? 'disable' : '' ]">
  6. <!-- 优惠券类型 (标签) -->
  7. <view class="coupon-tag">
  8. <text>{{ CouponTypeEnum[item.coupon_type].name }}</text>
  9. </view>
  10. <view class="coupon-left">
  11. <!-- 优惠额度/折扣 -->
  12. <view class="coupon-reduce">
  13. <view class="coupon-reduce-unit"><text>¥</text></view>
  14. <view class="coupon-reduce-amount">
  15. <text class="value">{{ item.reduce_price }}</text>
  16. </view>
  17. </view>
  18. <!-- 最低消费金额 -->
  19. <text class="coupon-hint">满{{ item.min_price }}元可用</text>
  20. </view>
  21. <view class="coupon-content">
  22. <view class="coupon-name">{{ item.name }}</view>
  23. <view class="coupon-middle">
  24. <view class="coupon-expire">
  25. <text v-if="item.expire_type == CouponTypeEnum.FULL_DISCOUNT.value">领取后{{ item.expire_day }}天内有效</text>
  26. <text v-if="item.expire_type == CouponTypeEnum.DISCOUNT.value">
  27. <block v-if="item.start_time === item.end_time">{{ item.start_time }} 当天有效</block>
  28. <block v-else>{{ item.start_time }}~{{ item.end_time }}</block>
  29. </text>
  30. </view>
  31. </view>
  32. <view v-if="item.describe" class="coupon-expand" @click="handleDescribe(index)">
  33. <text>使用说明</text>
  34. <text class="coupon-expand-arrow iconfont icon-arrow-down" :class="[item.expand ? 'expand' : '']" />
  35. </view>
  36. </view>
  37. <view class="coupon-right">
  38. <view v-if="$checkModule('market-coupon') && item.state.value" class="btn-receive" @click="handleReceive(item.coupon_id)">
  39. <text>领取</text>
  40. </view>
  41. <view v-if="!item.state.value" class="state-text">
  42. <text>{{ item.state.text }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 优惠券描述 -->
  47. <view :class="[item.expand ? 'expand' : '']" class="coupon-expand-rules">
  48. <view class="coupon-expand-rules-content">
  49. <view class="pre">{{ item.describe }}</view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <empty v-if="!list.length" :isLoading="isLoading" />
  55. </view>
  56. </template>
  57. <script>
  58. import * as CouponApi from '@/api/coupon'
  59. import * as MyCouponApi from '@/api/myCoupon'
  60. import { CouponTypeEnum } from '@/common/enum/coupon'
  61. import Empty from '@/components/empty'
  62. export default {
  63. components: {
  64. Empty
  65. },
  66. data() {
  67. return {
  68. // 枚举类
  69. CouponTypeEnum,
  70. // 优惠券列表
  71. list: [],
  72. // 正在加载中
  73. isLoading: true
  74. }
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad(options) {
  80. // 获取优惠券列表
  81. this.getCouponList()
  82. },
  83. methods: {
  84. /**
  85. * 获取优惠券列表
  86. * @param {bool} load 是否显示loading弹窗
  87. */
  88. getCouponList(load = true) {
  89. const app = this
  90. app.isLoading = true
  91. CouponApi.list({}, { load })
  92. .then(result => app.list = result.data.list)
  93. .finally(() => app.isLoading = false)
  94. },
  95. // 立即领取
  96. handleReceive(couponId) {
  97. const app = this
  98. MyCouponApi.receive(couponId)
  99. .then(result => {
  100. // 显示领取成功提示
  101. app.$success(result.message)
  102. // 刷新优惠券列表
  103. app.getCouponList(false)
  104. })
  105. },
  106. // 展开优惠券描述
  107. handleDescribe(index) {
  108. this.list[index].expand = !this.list[index].expand
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss" scoped>
  114. .coupon-list {
  115. padding: 20rpx;
  116. }
  117. .coupon-item {
  118. margin-bottom: 22rpx;
  119. font-size: 24rpx;
  120. background: #fff;
  121. // min-height: 178rpx;
  122. border-radius: 12rpx;
  123. overflow: hidden;
  124. box-shadow: 0 16rpx 80rpx 0 rgba(0, 0, 0, .04);
  125. position: relative;
  126. }
  127. .item-wrapper {
  128. display: flex;
  129. align-items: center;
  130. &.disable {
  131. .coupon-tag {
  132. background: linear-gradient(-113deg, #bdbdbd, #a2a1a2);
  133. }
  134. .coupon-reduce {
  135. color: #757575;
  136. }
  137. .state-text {
  138. color: #757575;
  139. }
  140. }
  141. }
  142. .coupon-tag {
  143. position: absolute;
  144. left: 0;
  145. top: 0;
  146. color: #fff;
  147. width: 96rpx;
  148. text-align: center;
  149. font-size: 22rpx;
  150. border-radius: 12rpx 0 12rpx 0;
  151. font-weight: 500;
  152. height: 34rpx;
  153. display: flex;
  154. align-items: center;
  155. justify-content: center;
  156. background: linear-gradient(to right, $main-bg, $main-bg2);
  157. color: $main-text;
  158. }
  159. .coupon-left {
  160. width: 242rpx;
  161. text-align: center;
  162. display: flex;
  163. flex-flow: column;
  164. justify-content: center;
  165. position: relative;
  166. .coupon-reduce {
  167. color: $main-bg;
  168. &-unit {
  169. display: inline-block;
  170. margin-right: -4rpx;
  171. font-size: 32rpx;
  172. font-weight: 600;
  173. }
  174. &-amount {
  175. display: inline-block;
  176. .value {
  177. font-size: 48rpx;
  178. }
  179. }
  180. }
  181. .coupon-hint {
  182. margin-top: 16rpx;
  183. color: #757575;
  184. font-size: 24rpx;
  185. white-space: nowrap;
  186. text-overflow: ellipsis;
  187. overflow: hidden;
  188. }
  189. }
  190. .coupon-content {
  191. flex: 1;
  192. padding: 32rpx 0;
  193. position: relative;
  194. display: flex;
  195. flex-direction: column;
  196. flex-wrap: nowrap;
  197. align-items: flex-start;
  198. justify-content: space-between;
  199. .coupon-name {
  200. color: #212121;
  201. font-size: 28rpx;
  202. font-weight: 500;
  203. }
  204. .coupon-middle {
  205. flex: 1;
  206. padding-top: 12rpx;
  207. margin-bottom: 26rpx;
  208. .coupon-expire {
  209. color: #757575;
  210. font-size: 24rpx;
  211. }
  212. }
  213. .coupon-expand {
  214. display: flex;
  215. align-items: center;
  216. color: #9e9e9e;
  217. font-size: 24rpx;
  218. &-arrow {
  219. margin-top: 4rpx;
  220. font-size: 24rpx;
  221. display: inline-block;
  222. vertical-align: initial;
  223. transform: rotate(0);
  224. margin-left: 8rpx;
  225. transition: all .15s ease-in-out;
  226. &.expand {
  227. transform: rotate(180deg);
  228. }
  229. }
  230. }
  231. }
  232. .coupon-right {
  233. padding-right: 38rpx;
  234. .btn-receive,
  235. .state-text {
  236. text-align: center;
  237. width: 100rpx;
  238. padding: 15rpx 0;
  239. }
  240. .btn-receive {
  241. font-size: 23rpx;
  242. line-height: 1;
  243. font-weight: 500;
  244. border-radius: 8rpx;
  245. cursor: pointer;
  246. background: linear-gradient(to right, $main-bg, $main-bg2);
  247. color: $main-text;
  248. }
  249. .state-text {}
  250. }
  251. .coupon-expand-rules {
  252. display: none;
  253. position: relative;
  254. &.expand {
  255. top: -30rpx;
  256. display: block;
  257. }
  258. &-content {
  259. padding: 8rpx 30rpx 8rpx 242rpx;
  260. font-weight: 400;
  261. color: #9e9e9e;
  262. line-height: 36rpx;
  263. .pre {
  264. font-family: auto;
  265. white-space: pre-wrap;
  266. word-wrap: break-word;
  267. word-break: break-all;
  268. }
  269. }
  270. }
  271. </style>