index.vue 7.3 KB

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