coupon.vue 12 KB

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