78 lines
2.7 KiB
JavaScript
78 lines
2.7 KiB
JavaScript
|
import { api } from '@/api/shop';
|
||
|
import { useStore } from 'vuex'
|
||
|
export default {
|
||
|
data() {
|
||
|
const { userinfo } = useStore().state
|
||
|
let uid = userinfo ? {
|
||
|
userId: userinfo.userId
|
||
|
} : {}
|
||
|
return {
|
||
|
userId: uid,
|
||
|
listProperty: {
|
||
|
params: {
|
||
|
// 条数
|
||
|
pageSize: 10,
|
||
|
// 页码
|
||
|
pageNum: 1,
|
||
|
navigation: 1
|
||
|
},
|
||
|
list: [],
|
||
|
// 总数
|
||
|
total: undefined,
|
||
|
status: 'more'
|
||
|
}
|
||
|
};
|
||
|
},
|
||
|
methods: {
|
||
|
// 获取数据 name请求方法名 params额外参数 isInitialLoad是否初始化加载
|
||
|
async getData(name, params, isInitialLoad = false) {
|
||
|
// 显示加载框
|
||
|
uni.showLoading({
|
||
|
title: '加载中'
|
||
|
});
|
||
|
|
||
|
if (this.listProperty.total === this.listProperty.list.length) {
|
||
|
uni.hideLoading();
|
||
|
uni.stopPullDownRefresh();
|
||
|
return uni.showToast({
|
||
|
title: '没有更多数据',
|
||
|
icon: 'none'
|
||
|
});
|
||
|
}
|
||
|
console.log('=== params额外参数=========================');
|
||
|
console.log({
|
||
|
...this.listProperty.params,
|
||
|
...params,
|
||
|
...this.userId
|
||
|
});
|
||
|
console.log('=name====================');
|
||
|
console.log(name);
|
||
|
try {
|
||
|
const res = await api[name.api][name.fn]({
|
||
|
...this.listProperty.params,
|
||
|
...params,
|
||
|
...this.userId
|
||
|
});
|
||
|
console.log('=== async getData=============');
|
||
|
console.log(res);
|
||
|
console.log('====================================');
|
||
|
if (res.data) {
|
||
|
const { rows, total } = res
|
||
|
this.listProperty.list = isInitialLoad ? rows : this.listProperty.list.concat(rows);
|
||
|
this.listProperty.total = total;
|
||
|
this.listProperty.status = this.listProperty.total === this.listProperty.list.length ? 'noMore' : 'more';
|
||
|
}
|
||
|
if (res.rows) {
|
||
|
const { data, total } = res
|
||
|
this.listProperty.list = data
|
||
|
this.listProperty.total = total;
|
||
|
}
|
||
|
} catch (error) {
|
||
|
console.log(error);
|
||
|
} finally {
|
||
|
uni.hideLoading();
|
||
|
uni.stopPullDownRefresh();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|