123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <template>
- <view class="">
- <u-navbar
- :title="title"
- :autoBack="true"
- :safeAreaInsetTop="true"
- >
- </u-navbar>
- <!-- <view class="sort u-flex">
- <view class="sort-item"
- :class="{active:index==activeIndex}"
- @click="sortClick(index)"
- v-for="(item,index) in sortArr" :key="index">
- {{item.name}}
- </view>
- </view> -->
- <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
- <view class="page-wrap" >
- <view class="comment" v-for="item in dataList" :key="item.id">
- <view class="top u-flex u-row-between">
- <view class="left u-flex">
- <u-avatar :src="item.avatar"></u-avatar>
- <view class="name">{{item.createBy}}</view>
- </view>
- <view class="time">{{item.createTime}}</view>
- </view>
- <u-rate count="5" active-color="#FFB600" v-model="item.star"></u-rate>
- <view class="text">{{item.contentText}}</view>
- <view class="imgs" v-if="item.contentImgList">
- <u-album :urls="item.contentImgList"></u-album>
- </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
- components: {
-
- },
- data() {
- return {
- staticUrl:this.$commonConfig.staticUrl,
- downOption: {},
- // 上拉加载的配置(可选, 绝大部分情况无需配置)
- upOption: {
- page: {
- size: 10 // 每页数据的数量,默认10
- },
- noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
- empty: {
- tip: '暂无相关数据'
- }
- },
- title:'商品评价',
- params:{
- id:'',
- },
- activeIndex:0,
- sortArr:[{name:'综合'},{name:'有图'},{name:'最新'},{name:'好评'}],
- // 列表数据
- dataList: []
- }
- },
- onLoad(page) {
- // console.log('page',page);
- this.params.id = page.id;
- },
- methods: {
- /*下拉刷新的回调, 重置列表为第一页 (此处可删,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:升序 (默认星级降序排序)
- if('最新'){
- this.params.isAsc = 0
- }
- this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
- this.$u.api.commentList(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();
- },
- sortClick(index){
- this.activeIndex = index;
- this.params.name = this.sortArr[index].name;
- this.reloadList();
- },
- search(e){
- this.reloadList();
- console.log('search',e)
- }
- }
- }
- </script>
- <style>
- page{
- background-color: #F5F5F5;
- }
- </style>
- <style lang="scss" scoped>
- .sort{
- background-color: #fff;
- padding: 40rpx 20rpx 20rpx;
- margin-bottom: 20rpx;
- .sort-item{
- background-color: #F5F5F5;
- border-radius: 2px;
- font-size: 26rpx;
- padding: 6rpx 18rpx;
- border: 1px solid #F5F5F5;
- &.active{
- background-color: #E5F5EC;
- border-color: #00A447;
- color: #00A447;
- }
- &:not(:first-child){
- margin-left: 20rpx;
- }
- }
- }
- .comment{
- background-color: #fff;
- padding: 20rpx;
- margin-bottom: 70rpx;
- font-size: 26rpx;
- .top{
- margin-bottom: 30rpx;
- font-weight: 400;
- color: #999999;
- .name{
- margin-left: 10rpx;
- font-weight: 600;
- color: #333333;
- }
- }
- .text{
- margin:20rpx 0;
- font-weight: 400;
- color: #333333;
- line-height: 37rpx;
- }
- }
- </style>
|