couponCenter.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <!-- 领券中心 -->
  2. <template>
  3. <view class="my_coupon">
  4. <!-- 随机优惠券 start -->
  5. <view :class="{'hide':!rondomMod,'random_coupon':true}" style="position: fixed;width: 750rpx;height:100vh;background:rgba(0,0,0,0.6);z-index: 10;">
  6. <view class="random_coupon_bg" :style="{backgroundImage:'url(' + imgUrl + 'coupon/random_bg.png)'}" @click="goMyCoupon()">
  7. <view class="random_coupon_price">¥{{rondomDes.publishValue}}</view>
  8. <view class="random_coupon_des">{{rondomDes.couponContent}}</view>
  9. <view class="close_btn" :style="{backgroundImage:'url(' + imgUrl + 'coupon/close.png)'}" @click.stop="close"></view>
  10. </view>
  11. </view>
  12. <!-- 随机优惠券 end -->
  13. <view class="coupon_center_bg">
  14. <image :src="imgUrl + 'coupon/coupon_bg.png'" mode=""></image>
  15. </view>
  16. <view class="my_coupon_nav">
  17. <view class="my_coupon_nav_pre_wrap">
  18. <view class="my_coupon_nav_pre" :class="{active:categoryId == '-1'}" @click="handleNav('-1')" >{{$L('精选')}}</view>
  19. <view class="my_coupon_nav_pre" :class="{active:categoryId == '-2'}" @click="handleNav('-2')" >{{$L('全部')}}</view>
  20. <view class="my_coupon_nav_pre" :class="{active:categoryId == item.categoryId}" @click="handleNav(item.categoryId)" v-for="(item,index) in categoryList" :key="index">{{item.categoryName}}</view>
  21. </view>
  22. </view>
  23. <view class="my_coupon_list" v-if="couponList && !noData">
  24. <view class="my_coupon_pre" v-for="(item,index) in couponList" :key="index">
  25. <view class="coupon_pre_top" :style="{backgroundImage:'url(' + item.couponBg + ')'}">
  26. <view class="coupon_pre_left">
  27. <view class="coupon_pre_price" v-if="item.couponType != 2">
  28. <text class="unit">¥ </text>
  29. <text class="price_int">{{$getPartNumber(item.publishValue,'int')}}</text>
  30. </view>
  31. <view class="coupon_pre_price" v-if="item.couponType == 2">
  32. <view class=""></view>
  33. <text class="price_int">{{filters.toSplit(filters.toFixNum(item.publishValue,1))[0]}}</text>.
  34. <text class="price_decimal">{{filters.toSplit(filters.toFixNum(item.publishValue,1))[1]}}</text>
  35. <text class="price_decimal">{{$L('折')}}</text>
  36. </view>
  37. <view class="coupon_pre_active">{{item.couponContent}}</view>
  38. </view>
  39. <view class="coupon_pre_cen">
  40. <view class="coupon_pre_title">{{item.useTypeValue}}</view>
  41. <view class="coupon_pre_time">{{item.publishStartTime}}~{{item.publishEndTime}}</view>
  42. <view class="coupon_pre_rules" @click="descriptionOpen(item.couponId)">
  43. <text>使用规则</text>
  44. <image :src="item.isOpen ? imgUrl + 'coupon/up.png' : imgUrl + 'coupon/down.png'" mode=""></image>
  45. </view>
  46. </view>
  47. <view class="coupon_pre_right coupon_state_no" v-if="item.receivedState == 3">{{$L('已抢完')}}</view>
  48. <view class="coupon_pre_right" v-if="item.receivedState == 2" @click="goGoodsList(item)">{{$L('已领')}}</view>
  49. <view class="coupon_pre_right" v-if="item.receivedState == 1" @click="goReceive(item)">{{$L('立即领取')}}</view>
  50. </view>
  51. <view class="coupon_rules" v-if="item.isOpen == true">
  52. <view class="coupon_rules_title">{{$L('使用规则')}}:{{item.description}}</view>
  53. </view>
  54. <view class="coupon_type">{{item.couponTypeValue}}</view>
  55. <view class="coupon_progress" v-if="item.receivedState != 3">
  56. {{$L('已抢')}}{{item.robbedRate}}%
  57. <view class="progress_con">
  58. <progress :percent="item.robbedRate" stroke-width="3" activeColor="#FFFFFF" backgroundColor="#FF1919" border-radius='2px' />
  59. </view>
  60. </view>
  61. </view>
  62. <loadingState v-if="loadingState == 'first_loading'||couponList.length > 0" :state='loadingState' />
  63. </view>
  64. <view class="no_data" v-if="noData">
  65. <image :src="imgUrl + 'no_coupon.png'" mode=""></image>
  66. <text>{{$L('暂无优惠券')}}~</text>
  67. </view>
  68. </view>
  69. </template>
  70. <script module="filters" lang="wxs" src="../../utils/filter.wxs"></script>
  71. <script>
  72. import loadingState from "@/components/loading-state.vue";
  73. import notOpen from '@/components/not_open.vue'
  74. import {
  75. mapState
  76. } from 'vuex';
  77. export default {
  78. components: {
  79. loadingState,
  80. notOpen
  81. },
  82. data() {
  83. return {
  84. imgUrl: getApp().globalData.imgUrl,
  85. loadingState: 'first_loading',
  86. pageSize: 10,
  87. current: 1,
  88. couponList:[], //优惠券列表
  89. categoryList:[], //分类列表
  90. categoryId:'-1', //当前点击的nav,默认第一项
  91. noData:false, //无数据
  92. loading: false, //是否加载数据
  93. hasMore: true, //是否还有数据
  94. goReceiveBg:getApp().globalData.imgUrl + 'coupon/coupon_pre_bg.png', //立即领取背景
  95. finishReceiveBg:getApp().globalData.imgUrl + 'coupon/finishReceiveBg.png', //已抢完背景
  96. hasReceiveBg:getApp().globalData.imgUrl + 'coupon/hasReceiveBg.png', //已领取背景
  97. rondomMod:false, //随机弹框
  98. activity_open:false,
  99. rondomDes:{}
  100. };
  101. },
  102. computed: {
  103. ...mapState(['hasLogin', 'userInfo'])
  104. },
  105. async onLoad(options) {
  106. this.getCouponList();
  107. },
  108. onReachBottom(){
  109. if(this.hasMore){
  110. this.getMoreData()
  111. }
  112. },
  113. methods: {
  114. // 判断活动是否开启
  115. ifOpen(){
  116. let param = {}
  117. param.data={}
  118. param.data.names='coupon_is_enable'
  119. param.url = 'v3/system/front/setting/getSettings'
  120. param.method = 'GET'
  121. this.$request(param).then(res => {
  122. if (res.state == 200) {
  123. if(res.data[0]=='1'){
  124. this.activity_open=true
  125. }else{
  126. this.activity_open=false
  127. }
  128. }
  129. })
  130. },
  131. //获取领券中心数据
  132. getCouponList(categoryId) {
  133. this.categoryId = categoryId ? categoryId : this.categoryId;
  134. let param = {};
  135. param.url = 'v3/promotion/front/coupon/couponCenter';
  136. param.method = 'GET';
  137. param.data = {};
  138. param.data.current = this.current;
  139. param.data.pageSize = this.pageSize;
  140. if(this.categoryId == '-1'){
  141. param.data.isSelected = true;
  142. }else if(this.categoryId == '-2'){
  143. param.data.isSelected = false;
  144. }else{
  145. param.data.isSelected = false;
  146. param.data.categoryId = this.categoryId; //分类id
  147. }
  148. this.$request(param).then(res => {
  149. if (res.state == 200) {
  150. let result = res.data;
  151. this.categoryList = result.categoryList;
  152. if(result.couponList.length == 0){
  153. this.noData = true;
  154. this.couponList = result.couponList;
  155. }else{
  156. if(this.current == 1){
  157. this.couponList = result.couponList;
  158. }else{
  159. this.couponList = this.couponList.concat(result.couponList);
  160. }
  161. this.noData = false;
  162. }
  163. this.couponList.forEach((item,index)=>{
  164. item.isOpen = false;
  165. if(item.receivedState == 3){
  166. item.couponBg = this.finishReceiveBg;
  167. }
  168. if(item.receivedState == 2){
  169. item.couponBg = this.hasReceiveBg;
  170. }
  171. if(item.receivedState == 1){
  172. item.couponBg = this.goReceiveBg;
  173. }
  174. })
  175. this.hasMore = this.$checkPaginationHasMore(res.data.pagination); //是否还有数据
  176. if (this.hasMore) {
  177. this.current++;
  178. this.loadingState = 'allow_loading_more';
  179. } else {
  180. this.loadingState = 'no_more_data';
  181. }
  182. } else {
  183. this.$api.msg(res.msg);
  184. }
  185. }).catch((e) => {
  186. //异常处理
  187. })
  188. },
  189. handleNav(categoryId){
  190. this.categoryId = categoryId;
  191. this.current = 1;
  192. this.getCouponList(categoryId);
  193. },
  194. //规则展开
  195. descriptionOpen(couponId){
  196. this.couponList.map(item=>{
  197. if(item.couponId == couponId){
  198. if(item.description != ''){
  199. item.isOpen = !item.isOpen
  200. this.$forceUpdate()
  201. }
  202. }
  203. })
  204. },
  205. //加载更多事件
  206. getMoreData() {
  207. if (this.hasMore) {
  208. this.getCouponList();
  209. }
  210. },
  211. //立即领取
  212. goReceive(item){
  213. let couponId = item.couponId
  214. let param = {};
  215. param.url = 'v3/promotion/front/coupon/receiveCoupon';
  216. param.method = 'GET';
  217. param.data = {};
  218. param.data.couponId = couponId;
  219. this.$request(param).then(res => {
  220. if (res.state == 200) {
  221. let result = res.data;
  222. this.current = 1;
  223. this.getCouponList();
  224. if(item.couponType == 3){ //随机优惠券
  225. this.rondomMod = true;
  226. this.rondomDes = result;
  227. }
  228. const pages = getCurrentPages(); //当前页面栈
  229. if (pages.length > 1) {
  230. const beforePage = pages[pages.length - 2]; //获取上一个页面实例对象
  231. beforePage.$vm.getCouponList(); //触发上个面中的方法 获取优惠券列表*getCouponList为上个页面的方法*
  232. }
  233. this.$api.msg('领取成功!');
  234. } else {
  235. this.$api.msg(res.msg);
  236. this.getCouponList();
  237. }
  238. }).catch((e) => {
  239. //异常处理
  240. })
  241. },
  242. //去优惠券对应的商品列表
  243. goGoodsList(item){
  244. if(item.useState == '2'){
  245. uni.navigateTo({
  246. url:'/pages/product/list?couponId=' + item.couponId
  247. })
  248. }
  249. },
  250. //关闭领取随机优惠券弹框
  251. close(){
  252. this.rondomMod = false;
  253. },
  254. //去我的优惠券列表页面
  255. goMyCoupon(){
  256. uni.navigateTo({
  257. url:'/pages/coupon/myCoupon'
  258. })
  259. }
  260. },
  261. }
  262. </script>
  263. <style lang="scss">
  264. page{
  265. background: $bg-color-split;
  266. }
  267. .my_coupon{
  268. width: 750rpx;
  269. margin: 0 auto;
  270. overflow-x: hidden;
  271. .random_coupon.hide{
  272. display: none;
  273. }
  274. .random_coupon{
  275. display: flex;
  276. justify-content: center;
  277. padding-top: 250rpx;
  278. .random_coupon_bg{
  279. width: 598rpx;
  280. height: 804rpx;
  281. background-size: 100% 100%;
  282. padding-top: 330rpx;
  283. display: flex;
  284. flex-direction: column;
  285. align-items: center;
  286. position: relative;
  287. .random_coupon_price{
  288. font-size: 68rpx;
  289. font-family: PangMenZhengDao;
  290. font-weight: 400;
  291. color: #D41E04;
  292. }
  293. .random_coupon_des{
  294. font-size: 30rpx;
  295. font-family: Source Han Sans CN;
  296. font-weight: 400;
  297. color: #E52308;
  298. line-height: 34rpx;
  299. }
  300. .close_btn{
  301. position: absolute;
  302. right: 10rpx;
  303. top: 22rpx;
  304. z-index: 20;
  305. width: 57rpx;
  306. height: 57rpx;
  307. background-size: 100% 100%;
  308. }
  309. }
  310. }
  311. .coupon_center_bg{
  312. width: 750rpx;
  313. height: 589rpx;
  314. image{
  315. width: 750rpx;
  316. height: 589rpx;
  317. }
  318. }
  319. .my_coupon_nav{
  320. display: flex;
  321. flex-wrap: nowrap;
  322. align-items: center;
  323. background: #FFFFFF;
  324. height: 78rpx;
  325. padding:0 20rpx;
  326. margin-bottom: 22rpx;
  327. .my_coupon_nav_pre_wrap{
  328. width: 715rpx;
  329. display: flex;
  330. flex-wrap: nowrap;
  331. align-items: center;
  332. overflow-x: auto;
  333. .my_coupon_nav_pre{
  334. font-size: 28rpx;
  335. font-family: PingFang SC;
  336. font-weight: 500;
  337. color: #333333;
  338. height: 78rpx;
  339. line-height: 78rpx;
  340. margin-right: 77rpx;
  341. min-width: max-content;
  342. &:last-child{
  343. margin-right: 20rpx;
  344. }
  345. }
  346. }
  347. .active{
  348. font-size: 32rpx;
  349. font-family: PingFang SC;
  350. font-weight: bold;
  351. color: #FC1C1C;
  352. position: relative;
  353. border-bottom: 8rpx solid #FC1C1C;
  354. }
  355. }
  356. .my_coupon_list{
  357. margin: 0 20rpx;
  358. width: 710rpx;
  359. height: 100%;
  360. .my_coupon_pre{
  361. margin-bottom: 20rpx;
  362. position: relative;
  363. .coupon_pre_top{
  364. width: 710rpx;
  365. height: 190rpx;
  366. background-size: 100% 100%;
  367. display: flex;
  368. align-items: center;
  369. .coupon_pre_left{
  370. display: flex;
  371. flex-direction: column;
  372. width: 203rpx;
  373. align-items: center;
  374. .coupon_pre_price{
  375. font-size: 20rpx;
  376. font-family: Source Han Sans CN;
  377. font-weight: bold;
  378. color: #F20C06;
  379. line-height: 31rpx;
  380. text:nth-child(2){
  381. font-size: 48rpx;
  382. font-family: Source Han Sans CN;
  383. font-weight: bold;
  384. color: #F30801;
  385. line-height: 31rpx;
  386. }
  387. }
  388. .coupon_pre_active{
  389. font-size: 24rpx;
  390. font-family: Source Han Sans CN;
  391. font-weight: 400;
  392. color: #F6130E;
  393. line-height: 31rpx;
  394. margin-top: 20rpx;
  395. }
  396. }
  397. .coupon_pre_cen{
  398. display: felx;
  399. flex-direction: column;
  400. flex:1;
  401. padding-left: 44rpx;
  402. .coupon_pre_title{
  403. font-size: 30rpx;
  404. font-family: PingFang SC;
  405. font-weight: bold;
  406. color: #111111;
  407. line-height: 31rpx;
  408. }
  409. .coupon_pre_time{
  410. font-size: 24rpx;
  411. font-family: PingFang SC;
  412. font-weight: 500;
  413. color: #333333;
  414. line-height: 31rpx;
  415. margin: 21rpx 0 17rpx;
  416. }
  417. .coupon_pre_rules{
  418. display: flex;
  419. align-items: center;
  420. text{
  421. font-size: 24rpx;
  422. font-family: PingFang SC;
  423. font-weight: 500;
  424. color: #999999;
  425. line-height: 31rpx;
  426. }
  427. image{
  428. width: 12rpx;
  429. height: 7rpx;
  430. margin-left: 20rpx;
  431. }
  432. }
  433. }
  434. .coupon_pre_right{
  435. width: 130rpx;
  436. box-sizing: border-box;
  437. font-size: 24rpx;
  438. font-family: Source Han Sans CN;
  439. font-weight: 400;
  440. color: #FFFFFF;
  441. text-align: center;
  442. }
  443. .coupon_state_no{
  444. padding: 0;
  445. text-align: center;
  446. }
  447. }
  448. .coupon_rules{
  449. width: 710rpx;
  450. padding: 20rpx 0 20rpx 43rpx;
  451. box-sizing: border-box;
  452. font-size: 22rpx;
  453. font-family: PingFang SC;
  454. font-weight: 500;
  455. color: #666666;
  456. line-height: 30rpx;
  457. background: #FFFFFF;
  458. border-top: 1rpx solid #f2f2f2;
  459. border-radius: 0 0 15rpx 15rpx;
  460. .coupon_rules_title{
  461. margin-bottom: 10rpx;
  462. }
  463. }
  464. .coupon_type{
  465. position: absolute;
  466. top: 0;
  467. left: 0;
  468. padding: 0 5rpx;
  469. height: 30rpx;
  470. background: linear-gradient(0deg, #FF3000 0%, #FB3E31 0%, #FF3728 0%, #FF142F 100%);
  471. font-size: 20rpx;
  472. font-family: Source Han Sans CN;
  473. font-weight: 400;
  474. color: #FFFFFF;
  475. line-height: 30rpx;
  476. text-align: center;
  477. border-radius: 15rpx 0 15rpx 0;
  478. }
  479. .coupon_progress{
  480. position: absolute;
  481. width: 130rpx;
  482. top: 10rpx;
  483. right: 0rpx;
  484. display: flex;
  485. flex-direction: column;
  486. align-items: center;
  487. font-size: 18rpx;
  488. font-family: Source Han Sans CN;
  489. font-weight: 400;
  490. color: #FFFFFF;
  491. line-height: 31rpx;
  492. .progress_con{
  493. width: 84rpx;
  494. margin-top: 5rpx;
  495. border-radius: 5rpx;
  496. progress{
  497. border: 1rpx solid #FFFFFF;
  498. border-radius: 5rpx;
  499. }
  500. }
  501. }
  502. }
  503. }
  504. .no_data{
  505. display: flex;
  506. flex-direction: column;
  507. align-items: center;
  508. padding-top: 180rpx;
  509. image{
  510. width: 187rpx;
  511. height: 187rpx;
  512. }
  513. text{
  514. font-size: 26rpx;
  515. font-family: Source Han Sans CN;
  516. font-weight: 400;
  517. color: #999999;
  518. margin: 30rpx 0;
  519. }
  520. .go_coupon_center{
  521. width: 160rpx;
  522. height: 54rpx;
  523. background: #F5EAEA;
  524. border-radius: 27rpx;
  525. font-size: 28rpx;
  526. font-family: PingFang SC;
  527. font-weight: 500;
  528. color: #EF242F;
  529. text-align: center;
  530. line-height: 54rpx;
  531. }
  532. }
  533. }
  534. </style>