coupon.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <view class="container clearfix">
  3. <view class="coupon-tabs">
  4. <coupon-tabs
  5. :tabs="navbar"
  6. :currentTab="currentTab > 2 ? 0 : currentTab"
  7. @change="change"
  8. :itemWidth="100 / navbar.length + '%'"
  9. selectedColor="#FF5B00"
  10. sliderBgColor="#FF5B00"
  11. >
  12. </coupon-tabs>
  13. </view>
  14. <view
  15. class="container-list"
  16. :style="{
  17. overflow: 'auto',
  18. paddingBottom: isIphoneX ? '140rpx' : '0rpx',
  19. height: coupinList.length > 6 ? windowHeight + 'px' : 'auto'
  20. }"
  21. v-show="isRequest"
  22. >
  23. <view class="empty-container" v-if="showEmpty">
  24. <image class="empty-container-image" :src="StaticUrl + '/icon/icon-coupon-empty@2x.png'"></image>
  25. <text class="error-text">暂无优惠券~</text>
  26. </view>
  27. <template v-else>
  28. <view :style="{ height: coupinList.length > 5 ? scrollHeight + 'px' : 'auto' }">
  29. <view
  30. v-for="(coupon, index) in coupinList"
  31. :key="index"
  32. :id="coupon.id"
  33. class="coupon-list"
  34. :class="listClass"
  35. >
  36. <view class="list-cell-le">
  37. <view class="coupon-maxMoney">
  38. <text class="small">¥</text> {{ coupon.couponAmount }}
  39. </view>
  40. <view class="coupon-minMoney"> 满{{ coupon.touchPrice }}可用 </view>
  41. </view>
  42. <view class="list-cell-ri">
  43. <view class="list-cell-top">
  44. <view class="list-cell-type">
  45. <view class="list-cell-tags">
  46. <template v-if="coupon.moneyCouponFlag == 1">
  47. <text
  48. class="tags"
  49. v-if="coupon.moneyCouponType == 1"
  50. :class="coupon.useStatus == 2 || coupon.useStatus == 3 ? 'none' : ''"
  51. >意向{{ coupon.couponType | TypeFormat }}</text
  52. >
  53. <text class="tags" v-else>定向{{ coupon.couponType | TypeFormat }}</text>
  54. </template>
  55. <template v-else>
  56. <text
  57. class="tags"
  58. :class="coupon.useStatus == 2 || coupon.useStatus == 3 ? 'none' : ''"
  59. >{{ coupon.couponType | TypeFormat }}</text
  60. >
  61. </template>
  62. </view>
  63. <view
  64. class="list-cell-texts"
  65. :class="coupon.useStatus == 2 || coupon.useStatus == 3 ? 'none' : ''"
  66. >
  67. <text v-if="coupon.couponType == 0">
  68. {{
  69. coupon.productType && coupon.productType == 1
  70. ? '全商城商品通用'
  71. : '仅可购买指定商品'
  72. }}
  73. </text>
  74. <text v-if="coupon.couponType == 1">
  75. {{ coupon.categoryType == 1 ? '仅限购买产品类商品' : '仅限购买仪器类商品' }}
  76. </text>
  77. <text v-if="coupon.couponType == 3"
  78. >仅限购买店铺【{{ coupon.shopName }}】的商品</text
  79. >
  80. <text v-if="coupon.couponType == 4 || coupon.couponType == 2"
  81. >全商城商品通用</text
  82. >
  83. </view>
  84. </view>
  85. <view class="list-cell-btn">
  86. <view class="icon-used" v-if="coupon.useStatus == 1">
  87. <view class="icon-used-btn" @click="toUseCoupon(coupon)">去使用</view>
  88. </view>
  89. <view class="icon-use" v-if="coupon.useStatus == 2"></view>
  90. <view class="icon-invalid" v-if="coupon.useStatus == 3"></view>
  91. </view>
  92. </view>
  93. <view class="list-cell-time">{{ coupon.startDate }} - {{ coupon.endDate }}</view>
  94. <button open-type="share" class="list-cell-share" :data-coupon="coupon" v-if="coupon.useStatus == 1">
  95. <text class="iconfont icon-fenxiang"></text>
  96. </button>
  97. </view>
  98. </view>
  99. <!--加载loadding-->
  100. <tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
  101. <tui-nomore :visible="!pullUpOn" :backgroundColor="'#F7F7F7'" :text="nomoreText"></tui-nomore>
  102. <!--加载loadding-->
  103. </view>
  104. </template>
  105. </view>
  106. <view class="button-bottom" :style="{ paddingBottom: isIphoneX ? '68rpx' : '20rpx' }">
  107. <view class="button-exchange" @click="navigator('/pages/user/coupon/coupon-exchange')"> 兑换优惠券 </view>
  108. <view class="button-receive" @click="navigator('/pages/user/coupon/coupon-collection')"> 领更多好券 </view>
  109. </view>
  110. </view>
  111. </template>
  112. <script>
  113. import { mapState, mapMutations } from 'vuex'
  114. import couponTabs from '@/components/cm-module/coupon/tui-tabs.vue'
  115. import { COUPON_TEXT_MAP } from '@/utils/coupon.share.js'
  116. export default {
  117. components: {
  118. couponTabs
  119. },
  120. data() {
  121. return {
  122. isRequest: false,
  123. listClass: 'list-used',
  124. StaticUrl: this.$Static,
  125. isIphoneX: this.$store.state.isIphoneX,
  126. currentTab: 0,
  127. listQuery: {
  128. userId: 0,
  129. pageNum: 1,
  130. pageSize: 10,
  131. status: 1
  132. },
  133. navbar: [{ name: '未使用', num: 0 }, { name: '已使用', num: 0 }, { name: '已失效', num: 0 }],
  134. coupinList: [],
  135. windowHeight: '',
  136. scrollHeight: '',
  137. showEmpty: false,
  138. nomoreText: '上拉显示更多',
  139. hasNextPage: false,
  140. loadding: false,
  141. pullUpOn: true,
  142. pullFlag: true
  143. }
  144. },
  145. onLoad() {},
  146. filters: {
  147. TypeFormat(value) {
  148. switch (value) {
  149. case 0:
  150. return '活动券'
  151. break
  152. case 1:
  153. return '品类券'
  154. break
  155. case 2:
  156. return '用户专享券'
  157. break
  158. case 3:
  159. return '店铺券'
  160. break
  161. case 4:
  162. return '新用户券'
  163. break
  164. }
  165. }
  166. },
  167. computed: {
  168. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity'])
  169. },
  170. methods: {
  171. setScrollHeight() {
  172. const { windowHeight, pixelRatio } = wx.getSystemInfoSync()
  173. this.windowHeight = windowHeight - 1
  174. this.scrollHeight = windowHeight - 1
  175. },
  176. QueryCouponList() {
  177. // 获取优惠券列表
  178. this.coupinList = []
  179. this.listQuery.pageNum = 1
  180. this.ProductService.QueryCouponCenter(this.listQuery)
  181. .then(response => {
  182. let data = response.data
  183. if (data.list && data.list.length > 0) {
  184. this.showEmpty = false
  185. this.hasNextPage = data.hasNextPage
  186. this.coupinList = data.list
  187. this.pullFlag = false
  188. setTimeout(() => {
  189. this.pullFlag = true
  190. }, 500)
  191. if (this.hasNextPage) {
  192. this.pullUpOn = false
  193. this.nomoreText = '上拉显示更多'
  194. } else {
  195. if (this.coupinList.length < 8) {
  196. this.pullUpOn = true
  197. } else {
  198. this.pullUpOn = false
  199. this.loadding = false
  200. this.nomoreText = '已至底部'
  201. }
  202. }
  203. } else {
  204. this.showEmpty = true
  205. }
  206. this.isRequest = true
  207. })
  208. .catch(error => {
  209. this.$util.msg(error.msg, 2000)
  210. })
  211. },
  212. getOnReachBottomData() {
  213. // 上滑加载分页
  214. this.listQuery.pageNum += 1
  215. this.ProductService.QueryCouponCenter(this.listQuery)
  216. .then(response => {
  217. let data = response.data
  218. if (data.list && data.list.length > 0) {
  219. this.hasNextPage = data.hasNextPage
  220. this.coupinList = this.coupinList.concat(data.list)
  221. this.pullFlag = false // 防上拉暴滑
  222. setTimeout(() => {
  223. this.pullFlag = true
  224. }, 500)
  225. if (this.hasNextPage) {
  226. this.pullUpOn = false
  227. this.nomoreText = '上拉显示更多'
  228. } else {
  229. this.pullUpOn = false
  230. this.loadding = false
  231. this.nomoreText = '已至底部'
  232. }
  233. }
  234. })
  235. .catch(error => {
  236. this.$util.msg(error.msg, 2000)
  237. })
  238. },
  239. getQueryCouponsCount() {
  240. // 获取优惠券数量
  241. this.ProductService.QueryCouponsCount({
  242. userId: this.listQuery.userId
  243. })
  244. .then(response => {
  245. let data = response.data
  246. this.navbar[0].num = data.unusedNum
  247. this.navbar[1].num = data.usedNum
  248. this.navbar[2].num = data.expiredNum
  249. })
  250. .catch(error => {
  251. this.$util.msg(error.msg, 2000)
  252. })
  253. },
  254. toUseCoupon(coupon) {
  255. // 去使用跳转路径,友盟埋点收集去使用优惠券
  256. if (process.env.NODE_ENV != 'development') {
  257. this.$uma.trackEvent('Um_Event_userCouponToUseCoupon', {
  258. Um_Key_PageName: '机构优惠券列表',
  259. Um_Key_EvenName: '使用优惠券',
  260. Um_Key_CouponId: `${coupon.couponId}`,
  261. })
  262. }
  263. switch (coupon.couponType) {
  264. case 0: // 活动券:跳转到商城首页 / 或者活动页(看是否指定了商品)
  265. if (coupon.productType == 1) {
  266. // 1 全商城通用 2 指定商品
  267. console.log('asdasdasda', coupon.productType)
  268. this.$api.switchTabTo('/pages/tabBar/home/index')
  269. } else {
  270. this.$api.navigateTo('/pages/user/coupon/coupon-product?couponId=' + coupon.couponId)
  271. }
  272. break
  273. case 1: // 品类券:跳转到产品 287 / 仪器页 286
  274. this.$api.navigateTo(`/pages/goods/good-floor?linkId=${coupon.categoryType == 1 ? 287 : 286}`)
  275. break
  276. case 2: // 用户专享券:跳转到商城首页
  277. this.$api.switchTabTo('/pages/tabBar/home/index')
  278. break
  279. case 3: // 店铺券:跳转到店铺首页
  280. this.$api.navigateTo('/pages/supplier/user/my-shop?shopId=' + coupon.shopId)
  281. break
  282. case 4: // 新用户券:跳转到商城首页
  283. this.$api.switchTabTo('/pages/tabBar/home/index')
  284. break
  285. }
  286. },
  287. change(e) {
  288. this.currentTab = e.index
  289. this.isRequest = false
  290. this.listQuery.pageNum = 1
  291. switch (this.currentTab) {
  292. case 0:
  293. this.listClass = 'list-used'
  294. this.listQuery.status = 1
  295. break
  296. case 1:
  297. this.listClass = 'list-none'
  298. this.listQuery.status = 2
  299. break
  300. case 2:
  301. this.listClass = 'list-none'
  302. this.listQuery.status = 3
  303. break
  304. }
  305. this.QueryCouponList()
  306. },
  307. navigator(url) {
  308. this.$api.navigateTo(url)
  309. }
  310. },
  311. onShareAppMessage(res) {
  312. //分享购买优惠券
  313. const coupon = res.target.dataset.coupon
  314. if (res.from === 'button') {
  315. const randomIndex = Math.floor(Math.random() * COUPON_TEXT_MAP.length)
  316. const shareTitle = coupon.moneyCouponFlag === 1 ?
  317. `${coupon.moneyCouponPrice}抵${coupon.couponAmount},限时优惠券等您抢购~` :
  318. COUPON_TEXT_MAP[randomIndex]
  319. return {
  320. title: shareTitle,
  321. path: `pages/user/coupon/coupon-details?couponId=${coupon.couponId}&shareUserId=${this.listQuery.userId}`,
  322. imageUrl: 'https://static.caimei365.com/app/img/icon/icon-shareCoupon@2x.png'
  323. }
  324. }
  325. },
  326. onPullDownRefresh() {
  327. setTimeout(() => {
  328. this.QueryCouponList()
  329. uni.stopPullDownRefresh()
  330. }, 200)
  331. },
  332. onReachBottom() {
  333. if (this.hasNextPage) {
  334. this.loadding = true
  335. this.pullUpOn = true
  336. this.getOnReachBottomData()
  337. }
  338. },
  339. onShow() {
  340. this.setScrollHeight()
  341. this.$api.getComStorage('userInfo').then(resolve => {
  342. this.listQuery.userId = resolve.userId ? resolve.userId : 0
  343. this.getQueryCouponsCount()
  344. this.QueryCouponList()
  345. })
  346. }
  347. }
  348. </script>
  349. <style lang="scss">
  350. page {
  351. background-color: #f7f7f7;
  352. }
  353. .coupon-tabs {
  354. width: 100%;
  355. height: 80rpx;
  356. position: fixed;
  357. top: 0;
  358. left: 0;
  359. z-index: 99;
  360. }
  361. .container {
  362. width: 100%;
  363. height: auto;
  364. padding-top: 80rpx;
  365. }
  366. .container-list {
  367. box-sizing: border-box;
  368. padding: 24rpx;
  369. scroll-view {
  370. height: 100%;
  371. overflow: scroll;
  372. }
  373. .empty-container-image {
  374. width: 260rpx;
  375. height: 260rpx;
  376. margin-top: -300rpx;
  377. }
  378. .toIndexPage {
  379. bottom: 390rpx;
  380. }
  381. .coupon-list {
  382. width: 100%;
  383. height: 200rpx;
  384. margin-bottom: 24rpx;
  385. box-sizing: border-box;
  386. &.list-used {
  387. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  388. background-size: cover;
  389. }
  390. &.list-none {
  391. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-none@2x.png);
  392. background-size: cover;
  393. }
  394. .list-cell-le {
  395. width: 224rpx;
  396. height: 100%;
  397. box-sizing: border-box;
  398. padding: 37rpx 0;
  399. float: left;
  400. .coupon-maxMoney {
  401. width: 100%;
  402. height: 78rpx;
  403. line-height: 78rpx;
  404. font-size: 56rpx;
  405. color: #ffffff;
  406. text-align: center;
  407. .small {
  408. font-size: $font-size-24;
  409. }
  410. }
  411. .coupon-minMoney {
  412. width: 100%;
  413. height: 33rpx;
  414. line-height: 33rpx;
  415. font-size: $font-size-24;
  416. color: #ffffff;
  417. text-align: center;
  418. }
  419. }
  420. .list-cell-ri {
  421. width: 478rpx;
  422. height: 100%;
  423. box-sizing: border-box;
  424. padding: 20rpx 24rpx 0 24rpx;
  425. float: right;
  426. position: relative;
  427. .list-cell-share{
  428. width: 60rpx;
  429. height: 60rpx;
  430. line-height: 60rpx;
  431. text-align: center;
  432. position: absolute;
  433. right: 0;
  434. top: 0;
  435. box-sizing: border-box;
  436. display: block;
  437. background: transparent;
  438. border-radius: 0;
  439. border: 0;
  440. margin: 0;
  441. .iconfont{
  442. font-size: 40rpx;
  443. color: #07c160;
  444. }
  445. }
  446. .list-cell-top {
  447. width: 100%;
  448. height: 121rpx;
  449. float: left;
  450. border-bottom: 1px solid #e1e1e1;
  451. .list-cell-type {
  452. width: 286rpx;
  453. height: 100%;
  454. float: left;
  455. .list-cell-tags {
  456. width: 100%;
  457. height: 32rpx;
  458. margin-bottom: 7rpx;
  459. .tags {
  460. display: inline-block;
  461. padding: 0 10rpx;
  462. height: 32rpx;
  463. line-height: 32rpx;
  464. background-color: #ffdcce;
  465. color: #f94b4b;
  466. font-size: $font-size-20;
  467. border-radius: 8rpx;
  468. text-align: center;
  469. float: left;
  470. &.none {
  471. background-color: #dbdbdb;
  472. color: #ffffff;
  473. }
  474. }
  475. }
  476. .list-cell-texts {
  477. width: 100%;
  478. height: auto;
  479. line-height: 35rpx;
  480. text-overflow: ellipsis;
  481. display: -webkit-box;
  482. word-break: break-all;
  483. -webkit-box-orient: vertical;
  484. -webkit-line-clamp: 2;
  485. overflow: hidden;
  486. font-size: 26rpx;
  487. color: #333333;
  488. &.none {
  489. color: #999999;
  490. }
  491. }
  492. }
  493. .list-cell-btn {
  494. width: 128rpx;
  495. height: 100%;
  496. float: right;
  497. .icon-used {
  498. width: 100%;
  499. height: 100%;
  500. box-sizing: border-box;
  501. padding-top: 57rpx;
  502. .icon-used-btn {
  503. width: 128rpx;
  504. height: 48rpx;
  505. border-radius: 28rpx;
  506. border: solid 1px #f94b4b;
  507. line-height: 48rpx;
  508. font-size: $font-size-26;
  509. color: #f94b4b;
  510. text-align: center;
  511. }
  512. }
  513. .icon-use {
  514. width: 92rpx;
  515. height: 92rpx;
  516. box-sizing: border-box;
  517. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-use@2x.png);
  518. background-size: cover;
  519. float: right;
  520. }
  521. .icon-invalid {
  522. width: 92rpx;
  523. height: 92rpx;
  524. box-sizing: border-box;
  525. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-invalid@2x.png);
  526. background-size: cover;
  527. float: right;
  528. }
  529. }
  530. }
  531. .list-cell-time {
  532. width: 100%;
  533. height: 58rpx;
  534. line-height: 58rpx;
  535. text-align: left;
  536. font-size: $font-size-20;
  537. color: #999999;
  538. }
  539. }
  540. }
  541. }
  542. .button-bottom {
  543. width: 100%;
  544. position: fixed;
  545. background-color: #ffffff;
  546. bottom: 0;
  547. left: 0;
  548. box-sizing: border-box;
  549. padding: 8rpx 24rpx;
  550. z-index: 999;
  551. .button-exchange {
  552. width: 280rpx;
  553. height: 84rpx;
  554. line-height: 84rpx;
  555. background-color: #ffe6dc;
  556. border-radius: 50rpx;
  557. text-align: center;
  558. font-size: $font-size-30;
  559. color: #FF5B00;
  560. float: left;
  561. }
  562. .button-receive {
  563. width: 408rpx;
  564. height: 84rpx;
  565. line-height: 84rpx;
  566. background: $btn-confirm;
  567. border-radius: 50rpx;
  568. text-align: center;
  569. font-size: $font-size-30;
  570. color: #ffffff;
  571. float: right;
  572. }
  573. }
  574. </style>