index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="container" :style="appThemeStyle">
  3. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ use: false }" :up="upOption" @up="upCallback">
  4. <!-- tab栏 -->
  5. <u-tabs :list="tabs" :is-scroll="false" v-model="curTab" :active-color="appTheme.mainBg" :duration="0.2" @change="onChangeTab" />
  6. <!-- 优惠券列表 -->
  7. <view class="coupon-list">
  8. <view class="coupon-item" v-for="(item, index) in list.data" :key="index">
  9. <view class="item-wrapper" :class="[ !item.state.value ? 'disable' : '' ]">
  10. <!-- 优惠券类型 (标签) -->
  11. <view class="coupon-tag">
  12. <text>{{ CouponTypeEnum[item.coupon_type].name }}</text>
  13. </view>
  14. <view class="coupon-left">
  15. <!-- 优惠额度/折扣 -->
  16. <view class="coupon-reduce">
  17. <view class="coupon-reduce-unit"><text>¥</text></view>
  18. <view class="coupon-reduce-amount">
  19. <text class="value">{{ item.reduce_price }}</text>
  20. </view>
  21. </view>
  22. <!-- 最低消费金额 -->
  23. <text class="coupon-hint">满{{ item.min_price }}元可用</text>
  24. </view>
  25. <view class="coupon-content">
  26. <view class="coupon-name">{{ item.name }}</view>
  27. <view class="coupon-middle">
  28. <view class="coupon-expire">
  29. <text v-if="item.expire_type == CouponTypeEnum.FULL_DISCOUNT.value">领取后{{ item.expire_day }}天内有效</text>
  30. <text v-if="item.expire_type == CouponTypeEnum.DISCOUNT.value">
  31. <block v-if="item.start_time === item.end_time">{{ item.start_time }} 当天有效</block>
  32. <block v-else>{{ item.start_time }}~{{ item.end_time }}</block>
  33. </text>
  34. </view>
  35. </view>
  36. <view v-if="item.describe" class="coupon-expand" @click="handleDescribe(index)">
  37. <text>使用说明</text>
  38. <text class="coupon-expand-arrow iconfont icon-arrow-down" :class="[item.expand ? 'expand' : '']" />
  39. </view>
  40. </view>
  41. <view class="coupon-right">
  42. <view v-if="!item.state.value" class="state-text">
  43. <text>{{ item.state.text }}</text>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 优惠券描述 -->
  48. <view :class="[item.expand ? 'expand' : '']" class="coupon-expand-rules">
  49. <view class="coupon-expand-rules-content">
  50. <view class="pre">{{ item.describe }}</view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </mescroll-body>
  56. </view>
  57. </template>
  58. <script>
  59. import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins'
  60. import { getEmptyPaginateObj, getMoreListData } from '@/core/app'
  61. import * as MyCouponApi from '@/api/myCoupon'
  62. import { CouponTypeEnum } from '@/common/enum/coupon'
  63. const pageSize = 15
  64. const tabs = [{
  65. name: `未使用`,
  66. value: 'isUnused'
  67. }, {
  68. name: `已使用`,
  69. value: 'isUse'
  70. }, {
  71. name: `已过期`,
  72. value: 'isExpire'
  73. }]
  74. export default {
  75. mixins: [MescrollMixin],
  76. data() {
  77. return {
  78. // 枚举类
  79. CouponTypeEnum,
  80. // 标签栏数据
  81. tabs,
  82. // 当前标签索引
  83. curTab: 0,
  84. // 优惠券列表数据
  85. list: getEmptyPaginateObj(),
  86. // 上拉加载配置
  87. upOption: {
  88. // 首次自动执行
  89. auto: true,
  90. // 每页数据的数量; 默认10
  91. page: { size: pageSize },
  92. // 数量要大于4条才显示无更多数据
  93. noMoreSize: 4,
  94. // 空布局
  95. empty: {
  96. tip: '亲,暂无相关优惠券'
  97. }
  98. }
  99. }
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad(options) {
  105. },
  106. methods: {
  107. /**
  108. * 上拉加载的回调 (页面初始化时也会执行一次)
  109. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  110. * @param {Object} page
  111. */
  112. upCallback(page) {
  113. const app = this
  114. // 设置列表数据
  115. app.getCouponList(page.num)
  116. .then(list => {
  117. const curPageLen = list.data.length
  118. const totalSize = list.data.total
  119. app.mescroll.endBySize(curPageLen, totalSize)
  120. })
  121. .catch(() => app.mescroll.endErr())
  122. },
  123. // 获取优惠券列表
  124. getCouponList(pageNo = 1) {
  125. const app = this
  126. return new Promise((resolve, reject) => {
  127. MyCouponApi.list({ dataType: app.getTabValue(), page: pageNo }, { load: false })
  128. .then(result => {
  129. // 合并新数据
  130. const newList = result.data.list
  131. app.list.data = getMoreListData(newList, app.list, pageNo)
  132. resolve(newList)
  133. })
  134. })
  135. },
  136. // 评分类型
  137. getTabValue() {
  138. return this.tabs[this.curTab].value
  139. },
  140. // 切换标签项
  141. onChangeTab(index) {
  142. const app = this
  143. // 设置当前选中的标签
  144. app.curTab = index
  145. // 刷新优惠券列表
  146. app.onRefreshList()
  147. },
  148. // 刷新优惠券列表
  149. onRefreshList() {
  150. this.list = getEmptyPaginateObj()
  151. setTimeout(() => {
  152. this.mescroll.resetUpScroll()
  153. }, 120)
  154. },
  155. // 展开优惠券描述
  156. handleDescribe(index) {
  157. this.list.data[index].expand = !this.list.data[index].expand
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .coupon-list {
  164. padding: 20rpx;
  165. }
  166. .coupon-item {
  167. margin-bottom: 22rpx;
  168. font-size: 24rpx;
  169. background: #fff;
  170. // min-height: 178rpx;
  171. border-radius: 12rpx;
  172. overflow: hidden;
  173. box-shadow: 0 16rpx 80rpx 0 rgba(0, 0, 0, .04);
  174. position: relative;
  175. }
  176. .item-wrapper {
  177. display: flex;
  178. align-items: center;
  179. &.disable {
  180. .coupon-tag {
  181. background: linear-gradient(-113deg, #bdbdbd, #a2a1a2);
  182. }
  183. .coupon-reduce {
  184. color: #757575;
  185. }
  186. .state-text {
  187. color: #757575;
  188. }
  189. }
  190. }
  191. .coupon-tag {
  192. position: absolute;
  193. left: 0;
  194. top: 0;
  195. color: #fff;
  196. width: 96rpx;
  197. text-align: center;
  198. font-size: 22rpx;
  199. border-radius: 12rpx 0 12rpx 0;
  200. font-weight: 500;
  201. height: 34rpx;
  202. display: flex;
  203. align-items: center;
  204. justify-content: center;
  205. background: linear-gradient(to right, $main-bg, $main-bg2);
  206. color: $main-text;
  207. }
  208. .coupon-left {
  209. width: 242rpx;
  210. text-align: center;
  211. display: flex;
  212. flex-flow: column;
  213. justify-content: center;
  214. position: relative;
  215. .coupon-reduce {
  216. color: $main-bg;
  217. &-unit {
  218. display: inline-block;
  219. margin-right: -4rpx;
  220. font-size: 32rpx;
  221. font-weight: 600;
  222. }
  223. &-amount {
  224. display: inline-block;
  225. .value {
  226. font-size: 48rpx;
  227. }
  228. }
  229. }
  230. .coupon-hint {
  231. margin-top: 12rpx;
  232. color: #757575;
  233. font-size: 24rpx;
  234. white-space: nowrap;
  235. text-overflow: ellipsis;
  236. overflow: hidden;
  237. }
  238. }
  239. .coupon-content {
  240. flex: 1;
  241. padding: 32rpx 0;
  242. position: relative;
  243. display: flex;
  244. flex-direction: column;
  245. flex-wrap: nowrap;
  246. align-items: flex-start;
  247. justify-content: space-between;
  248. .coupon-name {
  249. color: #212121;
  250. font-size: 28rpx;
  251. font-weight: 500;
  252. }
  253. .coupon-middle {
  254. flex: 1;
  255. padding-top: 12rpx;
  256. margin-bottom: 26rpx;
  257. .coupon-expire {
  258. color: #757575;
  259. font-size: 24rpx;
  260. }
  261. }
  262. .coupon-expand {
  263. display: flex;
  264. align-items: center;
  265. color: #9e9e9e;
  266. font-size: 24rpx;
  267. &-arrow {
  268. margin-top: 4rpx;
  269. font-size: 24rpx;
  270. display: inline-block;
  271. vertical-align: initial;
  272. transform: rotate(0);
  273. margin-left: 8rpx;
  274. transition: all .15s ease-in-out;
  275. &.expand {
  276. transform: rotate(180deg);
  277. }
  278. }
  279. }
  280. }
  281. .coupon-right {
  282. padding-right: 38rpx;
  283. .btn-receive,
  284. .state-text {
  285. text-align: center;
  286. width: 100rpx;
  287. padding: 15rpx 0;
  288. }
  289. .btn-receive {
  290. font-size: 23rpx;
  291. line-height: 1;
  292. font-weight: 500;
  293. border-radius: 8rpx;
  294. cursor: pointer;
  295. background: linear-gradient(to right, $main-bg, $main-bg2);
  296. color: $main-text;
  297. }
  298. .state-text {}
  299. }
  300. .coupon-expand-rules {
  301. display: none;
  302. position: relative;
  303. &.expand {
  304. top: -30rpx;
  305. display: block;
  306. }
  307. &-content {
  308. padding: 8rpx 30rpx 8rpx 242rpx;
  309. font-weight: 400;
  310. color: #9e9e9e;
  311. line-height: 36rpx;
  312. .pre {
  313. font-family: auto;
  314. white-space: pre-wrap;
  315. word-wrap: break-word;
  316. word-break: break-all;
  317. }
  318. }
  319. }
  320. </style>