index.vue 9.3 KB

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