list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ native: true }" @down="downCallback"
  3. :up="upOption" @up="upCallback">
  4. <!-- 页面头部 -->
  5. <view class="header">
  6. <search class="search" :tips="options.search ? options.search : '搜索卡券'" @event="handleSearch" />
  7. </view>
  8. <!-- 排序标签 -->
  9. <view class="store-sort">
  10. <view class="sort-item" :class="{ active: sortType === 'all' }" @click="handleSortType('all')">
  11. <text>综合</text>
  12. </view>
  13. <view class="sort-item" :class="{ active: sortType === 'sales' }" @click="handleSortType('sales')">
  14. <text>领取数</text>
  15. </view>
  16. <view class="sort-item sort-item-price" :class="{ active: sortType === 'price' }" @click="handleSortType('price')">
  17. <text>面额</text>
  18. <view class="price-arrow">
  19. <view class="icon up" :class="{ active: sortType === 'price' && !sortPrice }">
  20. <text class="iconfont icon-arrow-up"></text>
  21. </view>
  22. <view class="icon down" :class="{ active: sortType === 'price' && sortPrice }">
  23. <text class="iconfont icon-arrow-down"></text> </view>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 卡券列表 -->
  28. <view class="goods-list clearfix" :class="['column-1']">
  29. <view class="goods-item" v-for="(item, index) in list.content" :key="index" @click="onTargetDetail(item.id, item.type, item.userCouponId)">
  30. <view class="dis-flex">
  31. <!-- 卡券图片 -->
  32. <view class="goods-item_left">
  33. <image class="image" :src="item.image"></image>
  34. </view>
  35. <view class="goods-item_right">
  36. <!-- 卡券名称 -->
  37. <view class="goods-name twolist-hidden">
  38. <text>{{ item.name }}</text>
  39. </view>
  40. <view class="goods-item_desc">
  41. <!-- 卡券卖点 -->
  42. <view class="desc-selling_point dis-flex">
  43. <text class="onelist-hidden">{{ item.sellingPoint }}</text>
  44. </view>
  45. <view class="coupon-attr">
  46. <view class="attr-l">
  47. <!-- 卡券销量 -->
  48. <view class="desc-goods_sales dis-flex">
  49. <text v-if="item.type === 'C'">已领取{{ item.gotNum }},剩余{{ item.leftNum }}</text>
  50. <text v-if="item.type === 'P'">已有{{ item.gotNum }}人预存</text>
  51. <text v-if="item.type === 'T'">已领取{{ item.gotNum }},剩余{{ item.leftNum }}</text>
  52. </view>
  53. <!-- 面额 -->
  54. <view v-if="item.amount > 0 && item.type === 'C'" class="desc_footer">
  55. <text class="price_x">¥{{ item.amount }}</text>
  56. </view>
  57. </view>
  58. <view class="attr-r">
  59. <!--领券按钮-->
  60. <view class="receive" v-if="item.type === 'C' && item.isReceive === false">
  61. <text v-if="!item.point || item.point < 1">立即领取</text>
  62. <text v-if="item.point && item.point > 0">立即兑换</text>
  63. </view>
  64. <view class="receive state" v-if="item.type === 'C' && item.isReceive === true">
  65. <text>已领取</text>
  66. </view>
  67. <view class="receive" v-if="item.type === 'P' && item.isReceive === false">
  68. <text>立即预存</text>
  69. </view>
  70. <view v-if="item.type === 'T' && item.isReceive === false" class="receive">
  71. <text>领取次卡</text>
  72. </view>
  73. <view v-if="item.type === 'T' && item.isReceive === true" class="receive state">
  74. <text>已领取</text>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </mescroll-body>
  84. </template>
  85. <script>
  86. import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  87. import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  88. import * as couponApi from '@/api/coupon'
  89. import { getEmptyPaginateObj, getMoreListData } from '@/utils/app'
  90. import Search from '@/components/search'
  91. import { CouponTypeEnum } from '@/common/enum/coupon'
  92. const pageSize = 15
  93. const showViewKey = 'CouponList-ShowView';
  94. export default {
  95. components: {
  96. MescrollBody,
  97. Search
  98. },
  99. mixins: [MescrollMixin],
  100. data() {
  101. return {
  102. // 枚举类
  103. CouponTypeEnum,
  104. sortType: 'all', // 排序类型
  105. sortPrice: false, // 价格排序 (true高到低 false低到高)
  106. options: {}, // 当前页面参数
  107. list: getEmptyPaginateObj(), // 卡券列表数据
  108. // 正在加载
  109. isLoading: false,
  110. // 上拉加载配置
  111. upOption: {
  112. // 首次自动执行
  113. auto: true,
  114. // 每页数据的数量; 默认10
  115. page: { size: pageSize },
  116. // 数量要大于4条才显示无更多数据
  117. noMoreSize: 4,
  118. }
  119. }
  120. },
  121. onShow() {
  122. this.getCouponList(1)
  123. },
  124. /**
  125. * 生命周期函数--监听页面加载
  126. */
  127. onLoad(options) {
  128. // 记录options
  129. this.options = options
  130. // 设置默认列表显示方式
  131. this.setShowView()
  132. // 设置标题
  133. let type = options.type
  134. uni.setNavigationBarTitle({
  135. title: CouponTypeEnum[type].name + "中心"
  136. })
  137. },
  138. methods: {
  139. /**
  140. * 上拉加载的回调 (页面初始化时也会执行一次)
  141. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  142. * @param {Object} page
  143. */
  144. upCallback(page) {
  145. const app = this
  146. // 设置列表数据
  147. app.getCouponList(page.num)
  148. .then(list => {
  149. const curPageLen = list.content.length
  150. const totalSize = list.totalElements
  151. app.mescroll.endBySize(curPageLen, totalSize)
  152. })
  153. .catch(() => app.mescroll.endErr())
  154. },
  155. // 设置默认列表显示方式
  156. setShowView() {
  157. this.showView = uni.getStorageSync(showViewKey) || true
  158. },
  159. // 点击跳转到首页
  160. onTargetIndex() {
  161. this.$navTo('pages/index/index')
  162. },
  163. /**
  164. * 获取卡券列表
  165. * @param {number} pageNo 页码
  166. */
  167. getCouponList(pageNo = 1) {
  168. const app = this
  169. console.log(app.options)
  170. const param = {
  171. sortType: app.sortType,
  172. sortPrice: Number(app.sortPrice),
  173. type: app.options.type || "C",
  174. needPoint: app.options.needPoint || '0',
  175. name: app.options.search || '',
  176. pageNumber: pageNo
  177. }
  178. return new Promise((resolve, reject) => {
  179. couponApi.list(param)
  180. .then(result => {
  181. const newList = result.data.coupon
  182. app.list.content = getMoreListData(newList, app.list, pageNo)
  183. resolve(newList)
  184. })
  185. .catch(reject)
  186. })
  187. },
  188. // 切换排序方式
  189. handleSortType(newSortType) {
  190. const app = this
  191. const newSortPrice = newSortType === 'price' ? !app.sortPrice : true
  192. app.sortType = newSortType
  193. app.sortPrice = newSortPrice
  194. // 刷新列表数据
  195. app.list = getEmptyPaginateObj()
  196. app.mescroll.resetUpScroll()
  197. },
  198. // 切换列表显示方式
  199. handleShowView() {
  200. const app = this
  201. app.showView = !app.showView
  202. uni.setStorageSync(showViewKey, app.showView)
  203. },
  204. // 跳转详情页
  205. onTargetDetail(couponId, type, userCouponId) {
  206. if (type === 'P') {
  207. this.$navTo(`pages/prestore/buy`, { couponId })
  208. } else {
  209. if (type === 'C') {
  210. this.$navTo(`pages/coupon/detail`, { couponId: couponId, userCouponId: userCouponId })
  211. } else if(type === 'T'){
  212. this.$navTo(`pages/timer/detail`, { couponId: couponId, userCouponId: userCouponId })
  213. }
  214. }
  215. },
  216. //卡券搜索
  217. handleSearch() {
  218. const searchPageUrl = 'pages/search/index'
  219. // 判断来源页面
  220. let pages = getCurrentPages()
  221. if (pages.length > 1 &&
  222. pages[pages.length - 2].route === searchPageUrl) {
  223. uni.navigateBack()
  224. return
  225. }
  226. // 跳转到卡券搜索页
  227. this.$navTo(searchPageUrl)
  228. }
  229. },
  230. /**
  231. * 设置分享内容
  232. */
  233. onShareAppMessage() {
  234. // 构建分享参数
  235. return {
  236. title: "全部卡券",
  237. path: "/pages/coupon/list?" + this.$getShareUrlParams()
  238. }
  239. },
  240. /**
  241. * 分享到朋友圈
  242. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  243. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  244. */
  245. onShareTimeline() {
  246. // 构建分享参数
  247. return {
  248. title: "全部卡券",
  249. path: "/pages/coupon/list?" + this.$getShareUrlParams()
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. // 页面头部
  256. .header {
  257. display: block;
  258. align-items: center;
  259. text-align: center;
  260. height: 103rpx;
  261. background: #fff;
  262. // 搜索框
  263. .search {
  264. flex: 1;
  265. }
  266. // 切换显示方式
  267. .show-view {
  268. width: 60rpx;
  269. height: 60rpx;
  270. line-height: 60rpx;
  271. font-size: 36rpx;
  272. color: #505050;
  273. }
  274. }
  275. // 排序组件
  276. .store-sort {
  277. position: sticky;
  278. top: var(--window-top);
  279. display: flex;
  280. padding: 20rpx 0;
  281. font-size: 28rpx;
  282. background: #fff;
  283. color: #000;
  284. z-index: 99;
  285. .sort-item {
  286. flex-basis: 33.3333%;
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. height: 50rpx;
  291. &.active {
  292. color: #e49a3d;
  293. }
  294. }
  295. .sort-item-price .price-arrow {
  296. margin-left: 20rpx;
  297. font-size: 24rpx;
  298. color: #000;
  299. .icon {
  300. &.active {
  301. color: #e49a3d;
  302. }
  303. &.up {
  304. margin-bottom: -16rpx;
  305. }
  306. &.down {
  307. margin-top: -16rpx;
  308. }
  309. }
  310. }
  311. }
  312. // 卡券列表
  313. .goods-list {
  314. padding: 4rpx;
  315. box-sizing: border-box;
  316. }
  317. // 空数据按钮
  318. .empty-ipt {
  319. width: 220rpx;
  320. margin: 10rpx auto;
  321. font-size: 28rpx;
  322. height: 64rpx;
  323. line-height: 64rpx;
  324. text-align: center;
  325. color: #fff;
  326. border-radius: 5rpx;
  327. background: linear-gradient(to right, $fuint-theme, $fuint-theme);
  328. }
  329. // 单列显示
  330. .goods-list.column-1 {
  331. .goods-item {
  332. width: 100%;
  333. height: 260rpx;
  334. margin-bottom: 12rpx;
  335. padding: 20rpx;
  336. box-sizing: border-box;
  337. background: #fff;
  338. line-height: 1.6;
  339. &:last-child {
  340. margin-bottom: 0;
  341. }
  342. }
  343. .goods-item_left {
  344. display: flex;
  345. width: 35%;
  346. background: #fff;
  347. align-items: center;
  348. .image {
  349. display: block;
  350. width: 200rpx;
  351. height: 157rpx;
  352. margin-top: 20rpx;
  353. border-radius: 6rpx;
  354. border: solid 1rpx #cccccc;
  355. }
  356. }
  357. .goods-item_right {
  358. position: relative;
  359. flex: 1;
  360. .goods-name {
  361. margin-top: 30rpx;
  362. height: 44rpx;
  363. line-height: 1.3;
  364. white-space: normal;
  365. color: #484848;
  366. font-size: 30rpx;
  367. }
  368. }
  369. .goods-item_desc {
  370. margin-top: 0rpx;
  371. .coupon-attr {
  372. .attr-l {
  373. float: left;
  374. width: 70%;
  375. }
  376. .attr-r {
  377. margin-top: 0rpx;
  378. float: left;
  379. }
  380. }
  381. }
  382. .desc-selling_point {
  383. width: 400rpx;
  384. font-size: 24rpx;
  385. color: #e49a3d;
  386. }
  387. .receive {
  388. height: 46rpx;
  389. width: 128rpx;
  390. line-height: 46rpx;
  391. text-align: center;
  392. border: 1px solid #f8df00;
  393. border-radius: 5rpx;
  394. color: #f86d48;
  395. background: #f8df98;
  396. font-size: 22rpx;
  397. &.state {
  398. border: none;
  399. color: #cccccc;
  400. background: #F5F5F5;
  401. }
  402. }
  403. .desc-goods_sales {
  404. color: #999;
  405. font-size: 24rpx;
  406. }
  407. .desc_footer {
  408. font-size: 24rpx;
  409. .price_x {
  410. margin-right: 16rpx;
  411. color: #f03c3c;
  412. font-size: 30rpx;
  413. }
  414. .price_y {
  415. text-decoration: line-through;
  416. }
  417. }
  418. }
  419. .goods-item {
  420. float: left;
  421. box-sizing: border-box;
  422. padding: 6rpx;
  423. .goods-image {
  424. position: relative;
  425. width: 100%;
  426. height: 0;
  427. padding-bottom: 100%;
  428. overflow: hidden;
  429. background: #fff;
  430. &:after {
  431. content: '';
  432. display: block;
  433. margin-top: 100%;
  434. }
  435. .image {
  436. position: absolute;
  437. width: 100%;
  438. height: 100%;
  439. top: 0;
  440. left: 0;
  441. -o-object-fit: cover;
  442. object-fit: cover;
  443. }
  444. }
  445. .detail {
  446. padding: 8rpx;
  447. background: #fff;
  448. .goods-name {
  449. height: 64rpx;
  450. line-height: 32rpx;
  451. white-space: normal;
  452. color: #484848;
  453. font-size: 26rpx;
  454. }
  455. .detail-price {
  456. .goods-price {
  457. margin-right: 8rpx;
  458. }
  459. .line-price {
  460. text-decoration: line-through;
  461. }
  462. }
  463. }
  464. }
  465. </style>