Files
SupplierSystem/miniprogram/components/order-manage-panel/index.js
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

286 lines
8.8 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.
const {
fetchOrdersManagement,
advanceOrderManage,
} = require('../../utils/request');
const { ensureMobileRole } = require('../../utils/roleGuard');
const { beginPanelShow, endPanelShow } = require('../../utils/panelShowGate');
const { ORDER_STATUS_LABELS } = require('../../utils/constants');
const { chinaTodayYmd, shiftChinaYmd } = require('../../utils/chinaDate');
const ADMIN_ROLES = ['admin', 'operator'];
function presetBounds(preset) {
const today = chinaTodayYmd();
if (preset === 'today') return { from: today, to: today };
if (preset === 'month') {
return { from: `${today.slice(0, 7)}-01`, to: today };
}
const weekday = new Date(`${today}T12:00:00+08:00`).getUTCDay();
const diffToMonday = weekday === 0 ? 6 : weekday - 1;
const weekStart = shiftChinaYmd(today, -diffToMonday);
return { from: weekStart, to: shiftChinaYmd(weekStart, 6) };
}
function formatRangeChip(from, to) {
if (!from || !to) return '选择起止日期';
return `${from.slice(5)} ~ ${to.slice(5)}`;
}
Component({
options: { addGlobalClass: true },
properties: {
embedded: { type: Boolean, value: false },
homeStatusGroup: { type: String, value: '' },
},
data: {
loading: true,
error: '',
rows: [],
total: 0,
totalAmountText: '0.00',
statusGroup: '',
dateField: 'delivery_date',
dateRange: 'today',
dateFrom: '',
dateTo: '',
customRangeLabel: '选择起止日期',
search: '',
stats: { pending: 0, processing: 0, completed: 0 },
statusGroups: [
{ value: '', label: '全部', count: -1 },
{ value: 'pending', label: '待处理', count: 0 },
{ value: 'processing', label: '履约中', count: 0 },
{ value: 'completed', label: '已完成', count: 0 },
],
dateRanges: [
{ value: 'today', label: '今天' },
{ value: 'week', label: '本周' },
{ value: 'month', label: '本月' },
],
advancingOrderCode: '',
},
observers: {
homeStatusGroup(next) {
if (!this.properties.embedded) return;
const value = String(next || 'pending');
if (value === this.data.statusGroup) return;
this.setData({ statusGroup: value }, () => {
if (this._panelReady) this.loadRows();
});
},
},
lifetimes: {
attached() {
this.onPanelShow();
},
},
pageLifetimes: {
show() {
this.onPanelShow();
},
},
methods: {
async onPanelShow() {
if (!beginPanelShow(this)) return;
try {
const ok = await ensureMobileRole(ADMIN_ROLES);
if (!ok) return;
if (this.properties.embedded) {
const fromHome = String(this.properties.homeStatusGroup || 'pending');
if (fromHome !== this.data.statusGroup) {
this.setData({ statusGroup: fromHome });
}
}
await this.loadRows();
this._panelReady = true;
} finally {
endPanelShow(this);
}
},
onStatusGroup(e) {
this.setData({ statusGroup: e.currentTarget.dataset.value || '' }, () => this.loadRows());
},
setDateField(e) {
const field = e.currentTarget.dataset.field;
if (!field || field === this.data.dateField) return;
this.setData({ dateField: field }, () => this.loadRows());
},
onDateRange(e) {
const value = e.currentTarget.dataset.value || 'today';
this.setData(
{
dateRange: value,
dateFrom: '',
dateTo: '',
customRangeLabel: '选择起止日期',
},
() => this.loadRows()
);
},
onOpenCustomRange() {
const seeded =
this.data.dateRange === 'custom' && this.data.dateFrom && this.data.dateTo
? { from: this.data.dateFrom, to: this.data.dateTo }
: presetBounds(this.data.dateRange === 'custom' ? 'week' : this.data.dateRange);
this.setData(
{
dateRange: 'custom',
dateFrom: seeded.from,
dateTo: seeded.to,
customRangeLabel: formatRangeChip(seeded.from, seeded.to),
},
() => this.loadRows()
);
},
onCustomFromChange(e) {
const dateFrom = String(e.detail.value || '').slice(0, 10);
let dateTo = this.data.dateTo || dateFrom;
if (dateFrom && dateTo && dateFrom > dateTo) dateTo = dateFrom;
this.setData(
{
dateRange: 'custom',
dateFrom,
dateTo,
customRangeLabel: formatRangeChip(dateFrom, dateTo),
},
() => this.loadRows()
);
},
onCustomToChange(e) {
const dateTo = String(e.detail.value || '').slice(0, 10);
let dateFrom = this.data.dateFrom || dateTo;
if (dateFrom && dateTo && dateFrom > dateTo) dateFrom = dateTo;
this.setData(
{
dateRange: 'custom',
dateFrom,
dateTo,
customRangeLabel: formatRangeChip(dateFrom, dateTo),
},
() => this.loadRows()
);
},
onSearchInput(e) {
this.setData({ search: e.detail.value || '' });
},
onSearch() {
this.loadRows();
},
async loadRows() {
this.setData({ loading: true, error: '' });
try {
const query = {
page: 1,
page_size: 50,
status_group: this.data.statusGroup || undefined,
search: this.data.search || undefined,
date_field: this.data.dateField || 'delivery_date',
};
if (this.data.dateRange === 'custom' && this.data.dateFrom && this.data.dateTo) {
query.date_range = 'custom';
query.date_from = this.data.dateFrom;
query.date_to = this.data.dateTo;
} else {
query.date_range = this.data.dateRange || 'today';
}
const result = await fetchOrdersManagement(query);
const stats = result.stats || { pending: 0, processing: 0, completed: 0 };
const rows = (result.data || []).map((row) => ({
...row,
statusLabel: ORDER_STATUS_LABELS[row.order_status] || String(row.order_status),
amountText: Number(row.total_amount || 0).toFixed(2),
}));
this.setData({
rows,
total: Number(result.total) || 0,
totalAmountText: Number(result.total_amount || 0).toFixed(2),
stats,
statusGroups: [
{ value: '', label: '全部', count: -1 },
{ value: 'pending', label: '待处理', count: Number(stats.pending) || 0 },
{ value: 'processing', label: '履约中', count: Number(stats.processing) || 0 },
{ value: 'completed', label: '已完成', count: Number(stats.completed) || 0 },
],
});
this.triggerEvent('progresschange', {
pendingCount: Number(stats.pending) || 0,
processingCount: Number(stats.processing) || 0,
completedCount: Number(stats.completed) || 0,
});
this.triggerEvent('badgechange');
} catch (error) {
this.setData({
rows: [],
total: 0,
totalAmountText: '0.00',
error: error.message || '加载失败',
});
wx.showToast({ title: error.message || '加载失败', icon: 'none' });
} finally {
this.setData({ loading: false });
}
},
openDetail(e) {
const code = String(e.currentTarget.dataset.code || '').trim();
if (!code) {
wx.showToast({ title: '订单号缺失', icon: 'none' });
return;
}
const q = String(this.data.search || '').trim();
const qPart = q ? `&q=${encodeURIComponent(q)}` : '';
wx.navigateTo({
url: `/pages/order-manage-detail/order-manage-detail?orderCode=${encodeURIComponent(code)}${qPart}`,
fail: (err) => {
wx.showToast({
title: (err && err.errMsg) || '打开详情失败,请重新上传小程序',
icon: 'none',
});
},
});
},
onAdvance(e) {
const code = String(e.currentTarget.dataset.code || '').trim();
const status = Number(e.currentTarget.dataset.status);
const label = e.currentTarget.dataset.label || '推进';
if (!code || !status || this.data.advancingOrderCode) return;
wx.showModal({
title: label,
content: `确认将订单 ${code} ${label}?`,
success: async (res) => {
if (!res.confirm) return;
this.setData({ advancingOrderCode: code });
wx.showLoading({ title: '处理中', mask: true });
try {
await advanceOrderManage(code, status);
wx.hideLoading();
wx.showToast({ title: '已推进', icon: 'success' });
await this.loadRows();
} catch (error) {
wx.hideLoading();
wx.showToast({ title: error.message || '推进失败', icon: 'none', duration: 2500 });
} finally {
this.setData({ advancingOrderCode: '' });
}
},
});
},
},
});