Files
gamer/public/js/order-list.js
T
lizhilunandClaude Opus 4.6 4656f3f9ca fix: 移除接单列表页面的自动滚动行为
移除了进入接单列表页面时自动滚动到今天的逻辑,避免界面
在加载后自动往上滚动的问题。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 09:37:49 +08:00

294 lines
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
let orderPage = 1;
let orderHasMore = true;
let orderLoading = false;
async function loadOrders(append) {
if (orderLoading || (!append && !orderHasMore)) return;
orderLoading = true;
document.getElementById('orderLoading').style.display = 'block';
try {
const res = await fetch(API + '/api/records/orders?page=' + orderPage + '&limit=20&year=' + currentYear + '&month=' + currentMonth, { headers: headers() });
if (!res.ok) return;
const data = await res.json();
const container = document.getElementById('orderList');
if (!append) container.innerHTML = '';
if (data.records.length === 0) {
if (orderPage === 1) container.innerHTML = '<div class="ranking-empty">暂无接单记录</div>';
orderHasMore = false;
} else {
const grouped = {};
data.records.forEach(r => {
const date = formatLocalDate(r.created_at);
if (!grouped[date]) grouped[date] = [];
grouped[date].push(r);
});
let html = '';
for (const [date, records] of Object.entries(grouped)) {
html += `<div class="order-date-group" data-date="${date}">
<div class="order-date-label">${date}</div>`;
records.forEach(r => {
const time = formatLocalTime(r.created_at);
html += `<div class="order-item" onclick='openEditModal(${JSON.stringify(r).replace(/'/g, "&#39;")})'>
<div class="order-item-top">
<span class="order-item-boss">${r.boss || '-'}</span>
<span class="order-item-amount">${(r.amount || 0).toFixed(2)}</span>
</div>
<div class="order-item-bottom">
<span>${r.quantity || 0}× ${(r.unit_price || 0).toFixed(2)}</span>
<span>${time}${r.partner ? ' · ' + r.partner : ''}</span>
</div>
</div>`;
});
html += '</div>';
}
container.insertAdjacentHTML('beforeend', html);
orderHasMore = data.records.length >= 20;
orderPage++;
}
} catch (e) { console.error(e); }
orderLoading = false;
document.getElementById('orderLoading').style.display = 'none';
}
// 滚动加载
window.addEventListener('scroll', () => {
if (document.getElementById('orderListPage').classList.contains('active')) {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 100) {
if (orderHasMore && !orderLoading) loadOrders(true);
}
}
if (document.getElementById('dispatchListPage').classList.contains('active')) {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 100) {
if (dispatchHasMore && !dispatchLoading) loadDispatches(true);
}
}
if (document.getElementById('otherIncomeListPage').classList.contains('active')) {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 100) {
if (otherIncomeHasMore && !otherIncomeLoading) loadOtherIncome(true);
}
}
if (document.getElementById('redEnvelopeListPage').classList.contains('active')) {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 100) {
if (redEnvelopeHasMore && !redEnvelopeLoading) loadRedEnvelope(true);
}
}
if (document.getElementById('milkTeaListPage').classList.contains('active')) {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 100) {
if (milkTeaHasMore && !milkTeaLoading) loadMilkTea(true);
}
}
});
// 红包及其他收入列表
let otherIncomePage = 1;
let otherIncomeHasMore = true;
let otherIncomeLoading = false;
async function loadOtherIncome(append) {
if (otherIncomeLoading || (!append && !otherIncomeHasMore)) return;
otherIncomeLoading = true;
document.getElementById('otherIncomeLoading').style.display = 'block';
try {
const res = await fetch(API + '/api/records/other-income?page=' + otherIncomePage + '&limit=20&year=' + currentYear + '&month=' + currentMonth, { headers: headers() });
if (!res.ok) return;
const data = await res.json();
const container = document.getElementById('otherIncomeList');
if (!append) container.innerHTML = '';
if (data.records.length === 0) {
if (otherIncomePage === 1) container.innerHTML = '<div class="ranking-empty">暂无红包及其他收入记录</div>';
otherIncomeHasMore = false;
} else {
const grouped = {};
data.records.forEach(r => {
const date = formatLocalDate(r.created_at);
if (!grouped[date]) grouped[date] = [];
grouped[date].push(r);
});
let html = '';
for (const [date, records] of Object.entries(grouped)) {
html += `<div class="order-date-group" data-date="${date}">
<div class="order-date-label">${date}</div>`;
records.forEach(r => {
const time = formatLocalTime(r.created_at);
const displayCategory = r.category === '红包收入' ? '红包' : (r.category || '-');
html += `<div class="order-item" onclick='openEditModal(${JSON.stringify(r).replace(/'/g, "&#39;")})'>
<div class="order-item-top">
<span class="order-item-boss">${displayCategory}${r.boss ? ' · ' + r.boss : ''}</span>
<span class="order-item-amount">${(r.amount || 0).toFixed(2)}</span>
</div>
<div class="order-item-bottom">
<span>${r.source || ''}</span>
<span>${time}</span>
</div>
</div>`;
});
html += '</div>';
}
container.insertAdjacentHTML('beforeend', html);
otherIncomeHasMore = data.records.length >= 20;
otherIncomePage++;
}
} catch (e) { console.error(e); }
otherIncomeLoading = false;
document.getElementById('otherIncomeLoading').style.display = 'none';
}
// 派单列表
let dispatchPage = 1;
let dispatchHasMore = true;
let dispatchLoading = false;
async function loadDispatches(append) {
if (dispatchLoading || (!append && !dispatchHasMore)) return;
dispatchLoading = true;
document.getElementById('dispatchLoading').style.display = 'block';
try {
const res = await fetch(API + '/api/records/dispatches?page=' + dispatchPage + '&limit=20&year=' + currentYear + '&month=' + currentMonth, { headers: headers() });
if (!res.ok) return;
const data = await res.json();
const container = document.getElementById('dispatchList');
if (!append) container.innerHTML = '';
if (data.records.length === 0) {
if (dispatchPage === 1) container.innerHTML = '<div class="ranking-empty">暂无派单记录</div>';
dispatchHasMore = false;
} else {
const grouped = {};
data.records.forEach(r => {
const date = formatLocalDate(r.created_at);
if (!grouped[date]) grouped[date] = [];
grouped[date].push(r);
});
let html = '';
for (const [date, records] of Object.entries(grouped)) {
html += `<div class="order-date-group" data-date="${date}">
<div class="order-date-label">${date}</div>`;
records.forEach(r => {
const time = formatLocalTime(r.created_at);
html += `<div class="order-item" onclick='openEditModal(${JSON.stringify(r).replace(/'/g, "&#39;")})'>
<div class="order-item-top">
<span class="order-item-boss">${r.boss || '-'}</span>
<span class="order-item-amount">${(r.amount || 0).toFixed(2)}</span>
</div>
<div class="order-item-bottom">
<span>${r.quantity || 0}× ${(r.rebate || r.amount / r.quantity).toFixed(2)}(单价${(r.unit_price || 0).toFixed(2)}</span>
<span>${time}${r.partner ? ' · ' + r.partner : ''}</span>
</div>
</div>`;
});
html += '</div>';
}
container.insertAdjacentHTML('beforeend', html);
dispatchHasMore = data.records.length >= 20;
dispatchPage++;
}
} catch (e) { console.error(e); }
dispatchLoading = false;
document.getElementById('dispatchLoading').style.display = 'none';
}
// 红包收入列表
let redEnvelopePage = 1;
let redEnvelopeHasMore = true;
let redEnvelopeLoading = false;
async function loadRedEnvelope(append) {
if (redEnvelopeLoading || (!append && !redEnvelopeHasMore)) return;
redEnvelopeLoading = true;
document.getElementById('redEnvelopeLoading').style.display = 'block';
try {
const res = await fetch(API + '/api/records/red-envelope?page=' + redEnvelopePage + '&limit=20&year=' + currentYear + '&month=' + currentMonth, { headers: headers() });
if (!res.ok) return;
const data = await res.json();
const container = document.getElementById('redEnvelopeList');
if (!append) container.innerHTML = '';
if (data.records.length === 0) {
if (redEnvelopePage === 1) container.innerHTML = '<div class="ranking-empty">暂无红包收入记录</div>';
redEnvelopeHasMore = false;
} else {
const grouped = {};
data.records.forEach(r => {
const date = formatLocalDate(r.created_at);
if (!grouped[date]) grouped[date] = [];
grouped[date].push(r);
});
let html = '';
for (const [date, records] of Object.entries(grouped)) {
html += `<div class="order-date-group" data-date="${date}">
<div class="order-date-label">${date}</div>`;
records.forEach(r => {
const time = formatLocalTime(r.created_at);
html += `<div class="order-item" onclick='openEditModal(${JSON.stringify(r).replace(/'/g, "&#39;")})'>
<div class="order-item-top">
<span class="order-item-boss">红包</span>
<span class="order-item-amount">${(r.amount || 0).toFixed(2)}</span>
</div>
<div class="order-item-bottom">
<span>${r.source || ''}</span>
<span>${time}</span>
</div>
</div>`;
});
html += '</div>';
}
container.insertAdjacentHTML('beforeend', html);
redEnvelopeHasMore = data.records.length >= 20;
redEnvelopePage++;
}
} catch (e) { console.error(e); }
redEnvelopeLoading = false;
document.getElementById('redEnvelopeLoading').style.display = 'none';
}
// 奶茶收入列表
let milkTeaPage = 1;
let milkTeaHasMore = true;
let milkTeaLoading = false;
async function loadMilkTea(append) {
if (milkTeaLoading || (!append && !milkTeaHasMore)) return;
milkTeaLoading = true;
document.getElementById('milkTeaLoading').style.display = 'block';
try {
const res = await fetch(API + '/api/records/milk-tea?page=' + milkTeaPage + '&limit=20&year=' + currentYear + '&month=' + currentMonth, { headers: headers() });
if (!res.ok) return;
const data = await res.json();
const container = document.getElementById('milkTeaList');
if (!append) container.innerHTML = '';
if (data.records.length === 0) {
if (milkTeaPage === 1) container.innerHTML = '<div class="ranking-empty">暂无奶茶收入记录</div>';
milkTeaHasMore = false;
} else {
const grouped = {};
data.records.forEach(r => {
const date = formatLocalDate(r.created_at);
if (!grouped[date]) grouped[date] = [];
grouped[date].push(r);
});
let html = '';
for (const [date, records] of Object.entries(grouped)) {
html += `<div class="order-date-group" data-date="${date}">
<div class="order-date-label">${date}</div>`;
records.forEach(r => {
const time = formatLocalTime(r.created_at);
html += `<div class="order-item" onclick='openEditModal(${JSON.stringify(r).replace(/'/g, "&#39;")})'>
<div class="order-item-top">
<span class="order-item-boss">奶茶</span>
<span class="order-item-amount">${(r.amount || 0).toFixed(2)}</span>
</div>
<div class="order-item-bottom">
<span>${r.source || ''}</span>
<span>${time}</span>
</div>
</div>`;
});
html += '</div>';
}
container.insertAdjacentHTML('beforeend', html);
milkTeaHasMore = data.records.length >= 20;
milkTeaPage++;
}
} catch (e) { console.error(e); }
milkTeaLoading = false;
document.getElementById('milkTeaLoading').style.display = 'none';
}