index.vue 7.3 KB

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