coupon.vue 13 KB

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