79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
|
"use strict";
|
||
|
const common_vendor = require("../../common/vendor.js");
|
||
|
const api_shop = require("../../api/shop.js");
|
||
|
const apiMixins = {
|
||
|
data() {
|
||
|
const { userinfo } = common_vendor.useStore().state;
|
||
|
let uid = userinfo ? {
|
||
|
userId: userinfo.userId
|
||
|
} : {};
|
||
|
return {
|
||
|
userId: uid,
|
||
|
listProperty: {
|
||
|
params: {
|
||
|
// 条数
|
||
|
pageSize: 10,
|
||
|
// 页码
|
||
|
pageNum: 1,
|
||
|
navigation: 1
|
||
|
},
|
||
|
list: [],
|
||
|
// 总数
|
||
|
total: void 0,
|
||
|
status: "more"
|
||
|
}
|
||
|
};
|
||
|
},
|
||
|
methods: {
|
||
|
// 获取数据 name请求方法名 params额外参数 isInitialLoad是否初始化加载
|
||
|
async getData(name, params, isInitialLoad = false) {
|
||
|
common_vendor.index.showLoading({
|
||
|
title: "加载中"
|
||
|
});
|
||
|
if (this.listProperty.total === this.listProperty.list.length) {
|
||
|
common_vendor.index.hideLoading();
|
||
|
common_vendor.index.stopPullDownRefresh();
|
||
|
return common_vendor.index.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_shop.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 {
|
||
|
common_vendor.index.hideLoading();
|
||
|
common_vendor.index.stopPullDownRefresh();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
exports.apiMixins = apiMixins;
|