index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view class="container">
  3. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ use: false }" :up="upOption"
  4. @up="upCallback">
  5. <!-- tab栏 -->
  6. <u-tabs :list="tabs" :is-scroll="false" :current="curTab" active-color="#FA2209" :duration="0.2"
  7. @change="onChangeTab" />
  8. <!-- 优惠券列表 -->
  9. <view class="coupon-list">
  10. <view class="coupon-item" v-for="(item, index) in list.data" :key="index">
  11. <view class="item-wrapper" :class="['color-' + (item.state.value ? color[index % color.length] : 'gray')]">
  12. <view class="coupon-type">{{ CouponTypeEnum[item.coupon_type].name }}</view>
  13. <view class="tip dis-flex flex-dir-column flex-x-center">
  14. <view v-if="item.coupon_type == CouponTypeEnum.FULL_DISCOUNT.value">
  15. <text class="f-30">¥</text>
  16. <text class="money">{{ item.reduce_price }}</text>
  17. </view>
  18. <text class="money" v-if="item.coupon_type == CouponTypeEnum.DISCOUNT.value">{{ item.discount }}折</text>
  19. <text class="pay-line">满{{ item.min_price }}元可用</text>
  20. </view>
  21. <view class="split-line"></view>
  22. <view class="content dis-flex flex-dir-column flex-x-between">
  23. <view class="title">{{ item.name }}</view>
  24. <view class="bottom dis-flex flex-y-center">
  25. <view class="time flex-box">
  26. <text class="f-24">{{ item.start_time }}~{{ item.end_time }}</text>
  27. </view>
  28. <view class="receive state">
  29. <text>{{ item.state.text }}</text>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </mescroll-body>
  37. </view>
  38. </template>
  39. <script>
  40. import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  41. import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  42. import { getEmptyPaginateObj, getMoreListData } from '@/utils/app'
  43. import * as MyCouponApi from '@/api/myCoupon'
  44. import { CouponTypeEnum } from '@/common/enum/coupon'
  45. const color = ['red', 'blue', 'violet', 'yellow']
  46. const pageSize = 15
  47. const tabs = [{
  48. name: `未使用`,
  49. value: 'isUsable'
  50. }, {
  51. name: `已使用`,
  52. value: 'isUse'
  53. }, {
  54. name: `已过期`,
  55. value: 'isExpire'
  56. }]
  57. export default {
  58. components: {
  59. MescrollBody
  60. },
  61. mixins: [MescrollMixin],
  62. data() {
  63. return {
  64. // 枚举类
  65. CouponTypeEnum,
  66. // 颜色组
  67. color,
  68. // 标签栏数据
  69. tabs,
  70. // 当前标签索引
  71. curTab: 0,
  72. // 优惠券列表数据
  73. list: getEmptyPaginateObj(),
  74. // 上拉加载配置
  75. upOption: {
  76. // 首次自动执行
  77. auto: true,
  78. // 每页数据的数量; 默认10
  79. page: { size: pageSize },
  80. // 数量要大于4条才显示无更多数据
  81. noMoreSize: 4,
  82. // 空布局
  83. empty: {
  84. tip: '亲,暂无相关优惠券'
  85. }
  86. }
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面加载
  91. */
  92. onLoad(options) {
  93. },
  94. methods: {
  95. /**
  96. * 上拉加载的回调 (页面初始化时也会执行一次)
  97. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  98. * @param {Object} page
  99. */
  100. upCallback(page) {
  101. const app = this
  102. // 设置列表数据
  103. app.getCouponList(page.num)
  104. .then(list => {
  105. const curPageLen = list.data.length
  106. const totalSize = list.data.total
  107. app.mescroll.endBySize(curPageLen, totalSize)
  108. })
  109. .catch(() => app.mescroll.endErr())
  110. },
  111. /**
  112. * 获取优惠券列表
  113. */
  114. getCouponList(pageNo = 1) {
  115. const app = this
  116. return new Promise((resolve, reject) => {
  117. MyCouponApi.list({ dataType: app.getTabValue(), page: pageNo }, { load: false })
  118. .then(result => {
  119. // 合并新数据
  120. const newList = result.data.list
  121. app.list.data = getMoreListData(newList, app.list, pageNo)
  122. resolve(newList)
  123. })
  124. })
  125. },
  126. // 评分类型
  127. getTabValue() {
  128. return this.tabs[this.curTab].value
  129. },
  130. // 切换标签项
  131. onChangeTab(index) {
  132. const app = this
  133. // 设置当前选中的标签
  134. app.curTab = index
  135. // 刷新优惠券列表
  136. app.onRefreshList()
  137. },
  138. // 刷新优惠券列表
  139. onRefreshList() {
  140. this.list = getEmptyPaginateObj()
  141. setTimeout(() => {
  142. this.mescroll.resetUpScroll()
  143. }, 120)
  144. },
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .coupon-list {
  150. padding: 20rpx;
  151. }
  152. .coupon-item {
  153. position: relative;
  154. overflow: hidden;
  155. margin-bottom: 22rpx;
  156. }
  157. .item-wrapper {
  158. width: 100%;
  159. display: flex;
  160. background: #fff;
  161. border-radius: 8rpx;
  162. color: #fff;
  163. height: 180rpx;
  164. .coupon-type {
  165. position: absolute;
  166. top: 0;
  167. right: 0;
  168. z-index: 10;
  169. width: 128rpx;
  170. padding: 6rpx 0;
  171. background: #a771ff;
  172. font-size: 20rpx;
  173. text-align: center;
  174. color: #ffffff;
  175. transform: rotate(45deg);
  176. transform-origin: 64rpx 64rpx;
  177. }
  178. &.color-blue {
  179. background: linear-gradient(-125deg, #57bdbf, #2f9de2);
  180. }
  181. &.color-red {
  182. background: linear-gradient(-128deg, #ff6d6d, #ff3636);
  183. }
  184. &.color-violet {
  185. background: linear-gradient(-113deg, #ef86ff, #b66ff5);
  186. .coupon-type {
  187. background: #55b5ff;
  188. }
  189. }
  190. &.color-yellow {
  191. background: linear-gradient(-141deg, #f7d059, #fdb054);
  192. }
  193. &.color-gray {
  194. background: linear-gradient(-113deg, #bdbdbd, #a2a1a2);
  195. .coupon-type {
  196. background: #9e9e9e;
  197. }
  198. }
  199. .content {
  200. flex: 1;
  201. padding: 30rpx 20rpx;
  202. border-radius: 16rpx 0 0 16rpx;
  203. .title {
  204. font-size: 32rpx;
  205. }
  206. .bottom {
  207. .time {
  208. font-size: 24rpx;
  209. }
  210. .receive {
  211. height: 46rpx;
  212. width: 122rpx;
  213. line-height: 46rpx;
  214. text-align: center;
  215. border: 1rpx solid #fff;
  216. border-radius: 30rpx;
  217. color: #fff;
  218. font-size: 24rpx;
  219. &.state {
  220. border: none;
  221. }
  222. }
  223. }
  224. }
  225. .tip {
  226. position: relative;
  227. flex: 0 0 32%;
  228. text-align: center;
  229. border-radius: 0 16rpx 16rpx 0;
  230. .money {
  231. font-weight: bold;
  232. font-size: 52rpx;
  233. }
  234. .pay-line {
  235. font-size: 22rpx;
  236. }
  237. }
  238. .split-line {
  239. position: relative;
  240. flex: 0 0 0;
  241. border-left: 4rpx solid #fff;
  242. margin: 0 10rpx 0 6rpx;
  243. background: #fff;
  244. &:before,
  245. {
  246. border-radius: 0 0 16rpx 16rpx;
  247. top: 0;
  248. }
  249. &:after {
  250. border-radius: 16rpx 16rpx 0 0;
  251. bottom: 0;
  252. }
  253. &:before,
  254. &:after {
  255. content: '';
  256. position: absolute;
  257. width: 24rpx;
  258. height: 12rpx;
  259. background: #f7f7f7;
  260. left: -14rpx;
  261. z-index: 1;
  262. }
  263. }
  264. }
  265. </style>