123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <template>
- <view class="">
- <u-navbar
- title="我的优惠券"
- :placeholder="true"
- :autoBack="false"
- @leftClick="leftClick"
- :safeAreaInsetTop="true"
- >
- </u-navbar>
- <view class="tabs-wrap">
- <u-tabs
- :list="tabsList"
- lineColor="#3B49BF"
- :activeStyle="{color:'#333','font-weight': '600','font-size':'30rpx'}"
- :inactiveStyle="{color:'#999'}"
- :itemStyle="{width:'28%','padding-bottom':'20rpx'}"
- @click="tabsClick"></u-tabs>
- </view>
- <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
- <view class="page-wrap">
- <view class="coupon-activity u-flex u-row-right" @click="$u.route('/center/couponlist',{})" :style="{backgroundImage:`url(${staticUrl}/img/coupon-activity.png)`}">
- <view class="u-flex">
- 活动中心
- <u-icon name="arrow-right" color="#fff" size="30rpx"></u-icon>
- </view>
- </view>
- <view class="coupon-list">
- <view class="item"
- :class="{disable:item.status==2}"
- :style="{backgroundImage:`url(${staticUrl}/img/coupon-active-bg.png)`,filter:item.status!=1?'grayscale(100%)':''}" v-for="item in dataList" :key="item.id">
- <view class="content u-flex">
- <view class="left">
- <view class="quota">
- <text v-if="item.type == 1">¥</text>
- <text class="number" :class="{'small': String(item.quota).length>=3}">{{item.quota}}</text>
- <text v-if="item.type == 2">%</text>
- </view>
- <view class="condition" v-if="item.useThresholdType == 2">
- 消费满{{item.useThresholdAmount}}可用
- </view>
- </view>
- <view class="center">
- <view class="name" :class="{'small': String(item.couponName).length>=9}">{{item.couponName}}</view>
- <view class="tip">
- 有效期至 {{item.endTime||''}}
- </view>
- </view>
- <view class="right">
- <text class="btn" @click="couponClick(item)" v-if="item.status == 1">去使用</text>
- <text class="btn" @click="couponClick(item)" v-if="item.status == 2">已使用</text>
- <text class="btn" @click="couponClick(item)" v-if="item.status == 3">已过期</text>
- <text class="btn" @click="couponClick(item)" v-if="item.status == 4">已作废</text>
- <!-- <view class="time">
- <view class="">{{item.startTime}}</view>
- <view class="">{{item.endTime}}</view>
- </view> -->
- </view>
- </view>
- <view class="type" v-if="item.type == 1">满减券</view>
- <view class="type" v-else-if="item.type == 2">折扣卷</view>
- <image class="status-img" :src="staticUrl+'/img/coupon-status-shiyong.png'" v-if="item.status == 2"></image>
- <image class="status-img" :src="staticUrl+'/img/coupon-status-guoqi.png'" v-if="item.status == 3"></image>
- <image class="status-img" :src="staticUrl+'/img/coupon-status-guoqi.png'" v-if="item.status == 4"></image>
- </view>
- </view>
- </view>
- </mescroll-body>
- </view>
- </template>
- <script>
- // 引入mescroll-mixins.js
- import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
- export default {
- mixins: [MescrollMixin], // 使用mixin
- data() {
- return {
- staticUrl:this.$commonConfig.staticUrl,
- downOption: {},
- // 上拉加载的配置(可选, 绝大部分情况无需配置)
- upOption: {
- page: {
- size: 10 // 每页数据的数量,默认10
- },
- noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
- empty: {
- tip: '暂无相关数据'
- }
- },
- tabsList:[{name:'待使用',recordType:1},{name:'已使用',recordType:2},{name:'已过期',recordType:3}],
- params:{
- status:''
- },
- activeIndex:0,
- dataList: []
- }
- },
- onShow() {
-
- },
- onLoad() {
- this.params.status = this.tabsList[this.activeIndex].recordType;
- // console.log('1111', this.tabsList[this.activeIndex]);
- },
- methods: {
- leftClick(e){
- let pages = getCurrentPages();
- if(pages.length==1){
- uni.$u.route('/pages/index/index')
- }else{
- uni.navigateBack()
- };
- },
- /*下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
- downCallback(){
- this.mescroll.resetUpScroll();
- },
- /*上拉加载的回调*/
- upCallback(page) {
- // 此处可以继续请求其他接口
- // if(page.num == 1){
- // // 请求其他接口...
- // }
-
- // 如果希望先请求其他接口,再触发upCallback,可参考以下写法
- // if(!this.params.id){
- // this.mescroll.endErr()
- // return // 此处return,先获取xx
- // }
-
- let pageNum = page.num; // 页码, 默认从1开始
- let pageSize = page.size; // 页长, 默认每页10条isAsc:0//时间排序 0:降序 1:升序 (默认星级降序排序)
- this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
- this.$u.api.myCouponList(this.params).then(data => {
- console.log('data',JSON.parse(JSON.stringify(data)));
- // 接口返回的当前页数据列表 (数组)
- let curPageData = data.data.rows;
- console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
- // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
- let curPageLen = curPageData.length;
- // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
- // let totalPage = data.data.data.totalPage;
- // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
- let totalSize = data.data.total;
- // 接口返回的是否有下一页 (true/false)
- // let hasNext = data.xxx;
- // console.log('totalPage',totalPage,'curPageLen',curPageLen);
- //设置列表数据
- if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
- this.dataList = this.dataList.concat(curPageData); //追加新数据
- // 请求成功,隐藏加载状态
- //方法一(推荐): 后台接口有返回列表的总页数 totalPage
- // this.mescroll.endByPage(curPageLen, totalPage);
- //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
- this.mescroll.endBySize(curPageLen, totalSize);
- }).catch(err => {
- this.mescroll.endErr()
- console.log(err)
- });
-
- },
- /*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
- reloadList() {
- this.mescroll.resetUpScroll();
- },
- tabsClick(item){
- this.params.status = item.recordType;
- this.reloadList()
- // console.log('item',item);
- },
- couponClick(item){
- if(item.status==1){
- uni.$u.route('/pages/index/index');
- }
-
- }
- }
- }
- </script>
- <style>
- page{
- background-color: #f5f5f5;
- }
- </style>
- <style lang="scss" scoped>
- .tabs-wrap{
- background-color: #fff;
- margin-bottom: 10rpx;
- }
- .coupon-activity{
- height: 120rpx;
- background-size: 100%;
- color: #fff;
- font-weight: 500;
- font-size: 24rpx;
- padding-right: 15rpx;
- margin-bottom: 14rpx;
- }
- </style>
|