coupon.vue 13 KB

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