index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="container">
  3. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ use: true }" @down="downCallback" :up="upOption"
  4. @up="upCallback">
  5. <!-- tab栏 -->
  6. <u-tabs :list="tabs" :is-scroll="false" :current="curTab" active-color="#FA2209" :duration="0.2" @change="onChangeTab" />
  7. <!-- 卡券列表 -->
  8. <view class="goods-list">
  9. <view class="goods-item" v-for="(item, index) in list.content" :key="index">
  10. <!-- 单列卡券 -->
  11. <view class="dis-flex" @click="onDetail(item.id, item.type)">
  12. <!-- 卡券图片 -->
  13. <view class="goods-item_left">
  14. <image class="image" :src="item.image"></image>
  15. </view>
  16. <view class="goods-item_right">
  17. <!-- 卡券名称 -->
  18. <view class="goods-name twolist-hidden">
  19. <text>{{ item.name }}</text>
  20. </view>
  21. <view class="goods-item_desc">
  22. <!-- 卡券卖点 -->
  23. <view class="desc-selling_point dis-flex">
  24. <text class="onelist-hidden">{{ item.tips }}</text>
  25. </view>
  26. <view class="coupon-attr">
  27. <view class="attr-l">
  28. <view class="desc-goods_sales dis-flex">
  29. <text>{{ item.effectiveDate }}</text>
  30. </view>
  31. <view v-if="item.amount > 0" class="desc_footer">
  32. <text class="price_x">¥{{ item.amount }}</text>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </mescroll-body>
  42. </view>
  43. </template>
  44. <script>
  45. import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  46. import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  47. import { getEmptyPaginateObj, getMoreListData } from '@/utils/app'
  48. import * as MyCouponApi from '@/api/myCoupon'
  49. import { CouponTypeEnum } from '@/common/enum/coupon'
  50. import Empty from '@/components/empty'
  51. const color = ['red', 'blue', 'violet', 'yellow']
  52. const pageSize = 15
  53. const tabs = [{
  54. name: `未使用`,
  55. value: 'A'
  56. }, {
  57. name: `已使用`,
  58. value: 'B'
  59. }, {
  60. name: `已过期`,
  61. value: 'C'
  62. }]
  63. export default {
  64. components: {
  65. MescrollBody,
  66. Empty
  67. },
  68. mixins: [MescrollMixin],
  69. data() {
  70. return {
  71. // 枚举类
  72. CouponTypeEnum,
  73. // 颜色组
  74. color,
  75. // 标签栏数据
  76. tabs,
  77. // 当前标签索引
  78. curTab: 0,
  79. // 卡券类型
  80. type: "",
  81. // 优惠券列表数据
  82. list: getEmptyPaginateObj(),
  83. // 正在加载
  84. isLoading: false,
  85. // 上拉加载配置
  86. upOption: {
  87. // 首次自动执行
  88. auto: true,
  89. // 每页数据的数量; 默认10
  90. page: { size: pageSize },
  91. // 数量要大于4条才显示无更多数据
  92. noMoreSize: 4,
  93. // 空布局
  94. empty: {
  95. tip: '亲,暂无卡券'
  96. }
  97. }
  98. }
  99. },
  100. /**
  101. * 生命周期函数--监听页面加载
  102. */
  103. onLoad(options) {
  104. let type = options.type !== undefined ? options.type : '';
  105. this.type = type;
  106. uni.setNavigationBarTitle({
  107. title: "我的" + CouponTypeEnum[type].name
  108. })
  109. },
  110. onShow() {
  111. // 获取页面数据
  112. this.getCouponList(1);
  113. },
  114. methods: {
  115. upCallback(page) {
  116. const app = this
  117. // 设置列表数据
  118. app.getCouponList(page.num)
  119. .then(list => {
  120. const curPageLen = list.content.length
  121. const totalSize = list.totalElements
  122. app.mescroll.endBySize(curPageLen, totalSize)
  123. })
  124. .catch(() => app.mescroll.endErr())
  125. },
  126. // 卡券详情
  127. onDetail(userCouponId, type) {
  128. if (type === 'C') {
  129. this.$navTo(`pages/coupon/detail`, { userCouponId });
  130. } else if(type === 'T') {
  131. this.$navTo(`pages/timer/detail`, { userCouponId });
  132. } else if(type === 'P') {
  133. this.$navTo(`pages/prestore/detail`, { userCouponId });
  134. }
  135. },
  136. /**
  137. * 获取卡券列表
  138. */
  139. getCouponList(pageNo = 1) {
  140. const app = this;
  141. return new Promise((resolve, reject) => {
  142. MyCouponApi.list({ type: app.type, status: app.getTabValue(), page: pageNo }, { load: false })
  143. .then(result => {
  144. // 合并新数据
  145. const newList = result.data;
  146. app.list.content = getMoreListData(newList, app.list, pageNo);
  147. resolve(newList);
  148. })
  149. })
  150. },
  151. // 类型
  152. getTabValue() {
  153. return this.tabs[this.curTab].value;
  154. },
  155. // 切换标签项
  156. onChangeTab(index) {
  157. const app = this;
  158. // 设置当前选中的标签
  159. app.curTab = index;
  160. // 刷新优惠券列表
  161. app.onRefreshList();
  162. },
  163. // 刷新优惠券列表
  164. onRefreshList() {
  165. this.list = getEmptyPaginateObj();
  166. setTimeout(() => {
  167. this.mescroll.resetUpScroll();
  168. }, 120)
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .goods-list {
  175. padding: 4rpx;
  176. box-sizing: border-box;
  177. .goods-item {
  178. box-sizing: border-box;
  179. padding: 10rpx;
  180. height: 260rpx;
  181. .goods-item_left {
  182. display: flex;
  183. width: 35%;
  184. align-items: center;
  185. background: #fff;
  186. padding: 20rpx;
  187. height: 244rpx;
  188. .image {
  189. display: block;
  190. border-radius: 5rpx;
  191. width: 200rpx;
  192. height: 158rpx;
  193. border: solid 1rpx #cccccc;
  194. }
  195. }
  196. .goods-item_right {
  197. position: relative;
  198. width: 65%;
  199. background: #fff;
  200. .goods-name {
  201. margin-top: 45rpx;
  202. height: 45rpx;
  203. white-space: normal;
  204. color: #484848;
  205. font-weight: bold;
  206. font-size: 30rpx;
  207. }
  208. }
  209. .goods-item_desc {
  210. margin-top: 0rpx;
  211. .coupon-attr {
  212. .attr-l {
  213. float: left;
  214. width: 100%;
  215. }
  216. .attr-r {
  217. margin-top: 5rpx;
  218. float:left;
  219. }
  220. }
  221. }
  222. .desc-selling_point {
  223. width: 400rpx;
  224. font-size: 24rpx;
  225. color: #e49a3d;
  226. }
  227. .desc-goods_sales {
  228. color: #999;
  229. font-size: 24rpx;
  230. }
  231. .desc_footer {
  232. font-size: 24rpx;
  233. .price_x {
  234. margin-right: 16rpx;
  235. color: #f03c3c;
  236. font-size: 30rpx;
  237. }
  238. .price_y {
  239. text-decoration: line-through;
  240. }
  241. }
  242. }
  243. // 空数据按钮
  244. .empty-ipt {
  245. width: 220rpx;
  246. margin: 10rpx auto;
  247. font-size: 28rpx;
  248. height: 64rpx;
  249. line-height: 64rpx;
  250. text-align: center;
  251. color: #fff;
  252. border-radius: 5rpx;
  253. background: linear-gradient(to right, $fuint-theme, $fuint-theme);
  254. }
  255. }
  256. </style>