coupon.vue 14 KB

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