index.vue 7.6 KB

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