coupon.vue 16 KB

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