112 lines
4.0 KiB
JavaScript
112 lines
4.0 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const api_appUser = require("../../api/appUser.js");
|
|
const _sfc_main = {
|
|
__name: "index",
|
|
setup(__props) {
|
|
const records = common_vendor.ref([]);
|
|
const loading = common_vendor.ref(false);
|
|
const loadingMore = common_vendor.ref(false);
|
|
const error = common_vendor.ref("");
|
|
const page = common_vendor.ref(1);
|
|
const pageSize = common_vendor.ref(20);
|
|
const hasMore = common_vendor.ref(true);
|
|
function formatTime(t) {
|
|
if (!t)
|
|
return "";
|
|
const d = typeof t === "string" ? new Date(t) : new Date(t);
|
|
const y = d.getFullYear();
|
|
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
const day = String(d.getDate()).padStart(2, "0");
|
|
const hh = String(d.getHours()).padStart(2, "0");
|
|
const mm = String(d.getMinutes()).padStart(2, "0");
|
|
return `${y}-${m}-${day} ${hh}:${mm}`;
|
|
}
|
|
async function fetchRecords(append = false) {
|
|
const user_id = common_vendor.index.getStorageSync("user_id");
|
|
const token = common_vendor.index.getStorageSync("token");
|
|
const phoneBound = !!common_vendor.index.getStorageSync("phone_bound");
|
|
if (!user_id || !token || !phoneBound) {
|
|
common_vendor.index.showModal({
|
|
title: "提示",
|
|
content: "请先登录并绑定手机号",
|
|
confirmText: "去登录",
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
common_vendor.index.navigateTo({ url: "/pages/login/index" });
|
|
}
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
if (append) {
|
|
if (!hasMore.value || loadingMore.value)
|
|
return;
|
|
loadingMore.value = true;
|
|
page.value = page.value + 1;
|
|
} else {
|
|
loading.value = true;
|
|
page.value = 1;
|
|
hasMore.value = true;
|
|
}
|
|
error.value = "";
|
|
try {
|
|
const list = await api_appUser.getPointsRecords(user_id, page.value, pageSize.value);
|
|
const items = Array.isArray(list) ? list : list && list.items || [];
|
|
const total = list && list.total || 0;
|
|
if (append) {
|
|
records.value = records.value.concat(items);
|
|
} else {
|
|
records.value = items;
|
|
}
|
|
if (total) {
|
|
hasMore.value = records.value.length < total;
|
|
} else {
|
|
hasMore.value = items.length === pageSize.value;
|
|
}
|
|
} catch (e) {
|
|
error.value = e && (e.message || e.errMsg) || "获取积分记录失败";
|
|
} finally {
|
|
if (append) {
|
|
loadingMore.value = false;
|
|
} else {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
}
|
|
common_vendor.onLoad(() => {
|
|
fetchRecords(false);
|
|
});
|
|
common_vendor.onReachBottom(() => {
|
|
fetchRecords(true);
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: error.value
|
|
}, error.value ? {
|
|
b: common_vendor.t(error.value)
|
|
} : {}, {
|
|
c: records.value.length === 0 && !loading.value
|
|
}, records.value.length === 0 && !loading.value ? {} : {}, {
|
|
d: common_vendor.f(records.value, (item, k0, i0) => {
|
|
return {
|
|
a: common_vendor.t(item.title || item.reason || "变更"),
|
|
b: common_vendor.t(formatTime(item.time || item.created_at)),
|
|
c: common_vendor.t((item.change ?? item.amount ?? 0) > 0 ? "+" : ""),
|
|
d: common_vendor.t(item.change ?? item.amount ?? 0),
|
|
e: (item.change || item.amount || 0) > 0 ? 1 : "",
|
|
f: (item.change || item.amount || 0) < 0 ? 1 : "",
|
|
g: item.id || item.time || item.created_at
|
|
};
|
|
}),
|
|
e: loadingMore.value
|
|
}, loadingMore.value ? {} : !hasMore.value && records.value.length > 0 ? {} : {}, {
|
|
f: !hasMore.value && records.value.length > 0
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-dd6e20da"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/points/index.js.map
|