Prechádzať zdrojové kódy

fix: 拓客排行榜下拉刷新

xuyunhui 1 rok pred
rodič
commit
f266d5aa4d

+ 158 - 155
pages/spreadRankingList/module/mescrollUni-item.vue

@@ -1,174 +1,177 @@
 <template>
-    <!--
-    swiper中的transfrom会使fixed失效,此时用height固定高度;
-    swiper中无法触发mescroll-mixins.js的onPageScroll和onReachBottom方法,只能用mescroll-uni,不能用mescroll-body
-    -->
-    <!-- ref动态生成: 字节跳动小程序编辑器不支持一个页面存在相同的ref (如不考虑字节跳动小程序可固定值为 ref="mescrollRef") -->
-    <!-- top的高度等于悬浮菜单tabs的高度 -->
-    <mescroll-uni :ref="'mescrollRef' + i" @init="mescrollInit" :height="height" :down="downOption" @down="downCallback"
-                  :up="upOption" @up="upCallback" @emptyclick="emptyClick">
+  <!--
+  swiper中的transfrom会使fixed失效,此时用height固定高度;
+  swiper中无法触发mescroll-mixins.js的onPageScroll和onReachBottom方法,只能用mescroll-uni,不能用mescroll-body
+  -->
+  <!-- ref动态生成: 字节跳动小程序编辑器不支持一个页面存在相同的ref (如不考虑字节跳动小程序可固定值为 ref="mescrollRef") -->
+  <!-- top的高度等于悬浮菜单tabs的高度 -->
+  <mescroll-uni :ref="'mescrollRef' + i" @init="mescrollInit" :height="height" :down="downOption" @down="downCallback"
+                :up="upOption" @up="upCallback" @emptyclick="emptyClick">
 
-        <view class="flex-col list" v-for="(item,index) in rankDate">
+    <view class="flex-col list" v-for="(item,index) in rankDate">
 
 
-<!--            <view class="flex-row justify-center" v-if="index === 0">-->
-<!--                <view class="flex-col justify-evenly medal">-->
-<!--                    <text>第一名:对对对</text>-->
-<!--                    <text>3000</text>-->
-<!--                </view>-->
-<!--            </view>-->
+      <!--            <view class="flex-row justify-center" v-if="index === 0">-->
+      <!--                <view class="flex-col justify-evenly medal">-->
+      <!--                    <text>第一名:对对对</text>-->
+      <!--                    <text>3000</text>-->
+      <!--                </view>-->
+      <!--            </view>-->
 
-<!--            <view class="flex-col justify-evenly medal medal2" v-if="index === 1">-->
-<!--                <text>第二名:滴滴滴</text>-->
-<!--                <text>2000</text>-->
-<!--            </view>-->
+      <!--            <view class="flex-col justify-evenly medal medal2" v-if="index === 1">-->
+      <!--                <text>第二名:滴滴滴</text>-->
+      <!--                <text>2000</text>-->
+      <!--            </view>-->
 
-<!--            <view class="flex-col justify-evenly medal medal3" v-if="index === 2">-->
-<!--                <text>第三名:龙傲天</text>-->
-<!--                <text>1000</text>-->
-<!--            </view>-->
+      <!--            <view class="flex-col justify-evenly medal medal3" v-if="index === 2">-->
+      <!--                <text>第三名:龙傲天</text>-->
+      <!--                <text>1000</text>-->
+      <!--            </view>-->
 
 
-            <view class="flex-row justify-between listItem" :class="{listItemFirst:index === 3}" >
-                <text>{{index + 1}}.</text>
-                <text>{{ item.expandUserName }}</text>
-                <text>{{ item.total }}</text>
-            </view>
+      <view class="flex-row justify-between listItem" :class="{listItemFirst:index === 3}">
+        <text>{{ index + 1 }}.</text>
+        <text>{{ item.expandUserName }}</text>
+        <text>{{ item.total }}</text>
+      </view>
 
-        </view>
+    </view>
 
-    </mescroll-uni>
+  </mescroll-uni>
 </template>
 
 <script>
-    import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
-    import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js"
-    import NextSwipeAction from "../../../components/next-swipe-action/next-swipe-action";
-    import {object} from "../../../uni_modules/uv-ui-tools/libs/function/test";
-
-    export default {
-        mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
-        components: {
-            NextSwipeAction
+import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
+import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js"
+import NextSwipeAction from "../../../components/next-swipe-action/next-swipe-action";
+import {object} from "../../../uni_modules/uv-ui-tools/libs/function/test";
+
+export default {
+  mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
+  components: {
+    NextSwipeAction
+  },
+
+  data() {
+    return {
+      downOption: {
+        auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
+      },
+      upOption: {
+        auto: false, // 不自动加载
+        // page: {
+        // 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
+        // 	size: 10 // 每页数据的数量
+        // },
+        noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
+        empty: {
+          icon: '/static/dataNull.png',
+          tip: '暂无内容', // 提示
+          // btnText: '去看看'
         },
-
-        data() {
-            return {
-                downOption: {
-                    auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
-                },
-                upOption: {
-                    auto: false, // 不自动加载
-                    // page: {
-                    // 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
-                    // 	size: 10 // 每页数据的数量
-                    // },
-                    noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
-                    empty: {
-                        icon: '/static/dataNull.png',
-                        tip: '暂无内容', // 提示
-                        // btnText: '去看看'
-                    },
-                    textNoMore: '没有更多了'
-                },
-                list: [],
-            }
-        },
-        props: {
-            i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
-            index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
-                type: Number,
-                default() {
-                    return 0
-                }
-            },
-            rankDate: [],
-            height: [Number, String], // mescroll的高度
-
-        },
-        watch: {},
-
-        created() {
-
-
-        },
-
-        methods: {
-
-            openAddRemarkPopup(e) {
-                console.log(e)
-                this.$emit('openAddRemarkPopup', e)
-            },
-
-            navigateToPage(url) {
-                uni.navigateTo({
-                    url: url
-                })
-            },
-
-            /*下拉刷新的回调 */
-            downCallback() {
-                // 这里加载你想下拉刷新的数据, 比如刷新轮播数据
-                // loadSwiper();
-                // 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
-                this.mescroll.resetUpScroll()
-            },
-            /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
-            upCallback(page) {
-
-                //联网加载数据
-                let httpData = {
-                    pageNum: page.num,
-                    pageSize: 10
-                }
-
-                this.$api.service.getMyExpandAttacheList(httpData).then((res) => {
-                    //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
-                    this.mescroll.endSuccess(res.data.data.length, res.data.data.length === 10);
-                    //设置列表数据
-                    if (page.num === 1) this.list = []; //如果是第一页需手动制空列表
-                    this.list = this.list.concat(res.data.data); //追加新数据
-                    this.getImgUrlByOssId(this.list)
-                    console.log(this.list)
-                }).catch((err) => {
-                    //联网失败, 结束加载
-                    this.mescroll.endErr();
-                })
-
-
-            },
-
-            //点击空布局按钮的回调
-            emptyClick() {
-                uni.showToast({
-                    title: '点击了按钮,具体逻辑自行实现'
-                })
-            },
-            // 搜索
-            doSearch() {
-                this.list = []; // 先清空列表,显示加载进度
-                this.mescroll.resetUpScroll();
-            },
-
-            getImgUrlByOssId(list) {
-                if (list) {
-                    list.forEach((item, index) => {
-                        if (item.img && !item.selfPhotoUrl) {
-                            this.$api.service.getImage(item.img).then(res => {
-                                item.selfPhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
-                                this.$set(this.list, index, item)
-                                console.log('+++++++++++++++++', item)
-                            });
-                        }
-                    })
-                }
-            },
-        },
-
+        textNoMore: '没有更多了'
+      },
+      list: [],
+    }
+  },
+  props: {
+    i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
+    index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
+      type: Number,
+      default() {
+        return 0
+      }
+    },
+    rankDate: {
+      type: Array,
+      default: []
+    },
+    height: [Number, String], // mescroll的高度v
+    maskClick: {
+      type: Function,
+      require: true,
+      default: null
     }
+  },
+  watch: {},
+
+  created() {
+
+
+  },
+
+  methods: {
+    openAddRemarkPopup(e) {
+      this.$emit('openAddRemarkPopup', e)
+    },
+
+    navigateToPage(url) {
+      uni.navigateTo({
+        url: url
+      })
+    },
+
+    /*下拉刷新的回调 */
+    downCallback() {
+      // 这里加载你想下拉刷新的数据, 比如刷新轮播数据
+      // loadSwiper();
+      // 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
+      this.mescroll.resetUpScroll()
+      this.$emit("call-father");
+    },
+    /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
+    upCallback(page) {
+      //联网加载数据
+      let httpData = {
+        pageNum: page.num,
+        pageSize: 10
+      }
+
+      this.$api.service.getMyExpandAttacheList(httpData).then((res) => {
+        //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
+        this.mescroll.endSuccess(res.data.data.length, res.data.data.length === 10);
+        //设置列表数据
+        if (page.num === 1) this.list = []; //如果是第一页需手动制空列表
+        this.list = this.list.concat(res.data.data); //追加新数据
+        this.getImgUrlByOssId(this.list)
+      }).catch((err) => {
+        //联网失败, 结束加载
+        this.mescroll.endErr();
+      })
+
+
+    },
+
+    //点击空布局按钮的回调
+    emptyClick() {
+      uni.showToast({
+        title: '点击了按钮,具体逻辑自行实现'
+      })
+    },
+    // 搜索
+    doSearch() {
+      this.list = []; // 先清空列表,显示加载进度
+      this.mescroll.resetUpScroll();
+    },
+
+    getImgUrlByOssId(list) {
+      if (list) {
+        list.forEach((item, index) => {
+          if (item.img && !item.selfPhotoUrl) {
+            this.$api.service.getImage(item.img).then(res => {
+              item.selfPhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
+              this.$set(this.list, index, item)
+            });
+          }
+        })
+      }
+    },
+  },
+
+}
 </script>
 <style>
-    @import '/common/css/common.css';
-    @import './index.rpx.css';
+@import '/common/css/common.css';
+@import './index.rpx.css';
 
 </style>

+ 69 - 63
pages/spreadRankingList/spreadRankingList.vue

@@ -1,78 +1,84 @@
 <template>
-	<view class="page">
-		<!-- #ifdef H5-->
-		<uni-nav-bar v-if="!$isWxBrowser()" :fixed="true" background-color="#FFE05C" :border="false" :statusBar="false"
-					 left-icon="left" title="拓客排行榜" @clickLeft="back"/>
-		<!-- #endif -->
+  <view class="page">
+    <!-- #ifdef H5-->
+    <uni-nav-bar v-if="!$isWxBrowser()" :fixed="true" background-color="#FFE05C" :border="false" :statusBar="false"
+                 left-icon="left" title="拓客排行榜" @clickLeft="back"/>
+    <!-- #endif -->
 
     <view class="example-body">
-      <uni-datetime-picker v-model="range" type="daterange"  @change="maskClick"/>
+      <uni-datetime-picker v-model="range" type="daterange" @change="maskClick"/>
 
     </view>
-		<view :style="{height:height}">
-			<mescroll-item ref="MescrollItem" :i="0"  :index="0" :rankDate='rankDate' :height="height">
-			</mescroll-item>
-		</view>
+    <view :style="{height:height}">
+      <mescroll-item ref="MescrollItem" @call-father="maskClick(range)" :i="0" :index="0" :rankDate='rankDate' :height="height">
+      </mescroll-item>
+    </view>
 
 
-		<!--#ifdef H5-->
-		<liu-drag-button v-if="$isWxBrowser()" @clickBtn="back">返回</liu-drag-button>
-		<!--#endif-->
-	</view>
+    <!--#ifdef H5-->
+    <liu-drag-button v-if="$isWxBrowser()" @clickBtn="back">返回</liu-drag-button>
+    <!--#endif-->
+  </view>
 </template>
 
 <script>
-	import MescrollItem from "./module/mescrollUni-item.vue";
-	export default {
-		components: {
-			MescrollItem
-		},
-		data() {
-			return {
-				height:'',
-        rankDate:null,
-        range:null,
-			}
-		},
-		onLoad(e) {
-      this.getRanking()
-			let sysInfo = uni.getSystemInfoSync()
-			this.height = sysInfo.windowHeight  - 50 + 'px' //除标题栏栏外的屏幕可用高度
-		},
-		methods: {
-      getRanking(date){
-        this.$api.service.getRank(date).then((res)=>{
-          console.log(res)
-          this.rankDate = res.data.data
-        })
-      },
-      maskClick(e){
-        console.log('maskClick事件:', e,this.range);
-        const date = {
-          startDate:this.range[0],
-          endDate:this.range[1],
-        }
+import MescrollItem from "./module/mescrollUni-item.vue";
 
-        this.getRanking(date)
-      },
-			back() {
-				let pages = getCurrentPages()
-				if (pages.length > 1){
-					uni.navigateBack({
-						delta: 1,
-						fail:err=>{
-							console.log(err)
-						}
-					})
-				}else {
-					uni.switchTab({
-						url: '/pages/my/my'
-					});
-				}
-			},
+export default {
+  components: {
+    MescrollItem
+  },
+  data() {
+    return {
+      height: '',
+      rankDate: null,
+      range: null,
+    }
+  },
+  onLoad(e) {
+    this.getRanking()
+    let sysInfo = uni.getSystemInfoSync()
+    this.height = sysInfo.windowHeight - 50 + 'px' //除标题栏栏外的屏幕可用高度
+  },
+  methods: {
+    getRanking(date) {
+      this.$api.service.getRank(date).then((res) => {
+        this.rankDate = res.data.data
+      })
+    },
+    maskClick(e) {
+      let date = null
+      if (e) {
+        this.range = e
+      }
+      if(this.range &&this.range.length > 0){
+        date = {
+          startDate: this.range[0],
+              endDate: this.range[1],
+        }
+      }else {
+        date = null
+      }
+      this.getRanking(date)
+    },
+    back() {
+      let pages = getCurrentPages()
+      if (pages.length > 1) {
+        uni.navigateBack({
+          delta: 1,
+          fail: err => {
+            console.log(err)
+          }
+        })
+      } else {
+        uni.switchTab({
+          url: '/pages/my/my'
+        });
+      }
+    },
 
-		}
-	}
+  }
+}
 </script>
 
 <style>