123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <template>
- <view class="single-list">
- <slot name="items" v-bind:list="list"></slot>
- </view>
- </template>
- <script>
- const TAG_NAME = "SINGLE_LIST";
- export default {
- props: {
- //请求数据
- sendData:{
- type:Object,
- default:()=>({})
- },
- //请求地址
- url:{
- type:String,
- default:''
- }
- },
- data() {
- return {
- loadingType:'more',
- pageNum:1,
- pageSize:20,
- list:[],
- }
- },
- watch:{
- /*onLoad内必须在this.$nextTick更改*/
- sendData:{
- handler(v,o){
- // console.log(TAG_NAME,'sendData',v,o);
- this.getList(true);
- },
- immediate:false, //由父组件触发,因为可能onShow刷新
- deep:true,
- }
- },
- methods:{
- //搜索
- async getList(isRefresh=false){
- // console.log('触发函数getList')
- if(isRefresh){
- this.loadingType='more'
- this.pageNum=1
- this.pageSize=20
- this.list=[]
- }
- if (this.loadingType === 'loading' || this.loadingType == 'noMore') {
- //防止重复加载
- return;
- }
- // console.log('触发开始',this.pageNum)
- this.loadingType = 'loading';
- const sendData={
- ...this.sendData,
- page: this.pageNum,
- limit: this.pageSize,
- }
- let res = await this.$request(this.url,sendData);
- uni.stopPullDownRefresh();
- // this.isTriggerRefresh=false;
- // this.isLoaded = true;
- let result = res.data.row || [];
-
- if ( this.pageSize > result.length) {
- this.loadingType = 'noMore';
- } else {
- this.loadingType = 'more';
- }
- // 页数加一
- this.pageNum++;
- if(isRefresh){
- this.pageNum = 2;
- this.list=result;
- this.$emit('reqEnd',{loadingType:this.loadingType,pageOneRes:result}) //主要判断list是否空
- return;
- }
- result.forEach(item => {
- // item = Object.assign(item, this.handleStatus(item.status));
- this.list.push(item);
- });
- this.$emit('reqEnd',{loadingType:this.loadingType,pageOneRes:this.list[0]})
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- // .submit-btn{
- // opacity: 0.6;
- // }
- </style>
|