Files
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

208 lines
5.8 KiB
JavaScript
Raw Permalink 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 { ensureMobileRole } = require('../../utils/roleGuard');
const { beginPanelShow, endPanelShow } = require('../../utils/panelShowGate');
const {
fetchSupplierBids,
fetchSupplierBidDetail,
submitSupplierBidQuotes,
} = require('../../utils/request');
function statusMeta(row) {
const inv = row.status;
const round = row.round_status;
if (inv === 'expired') return { statusText: '已出局', statusClass: 'expired' };
if (inv === 'quoted') {
if (round === 'awarded') return { statusText: '已中标/已开标', statusClass: 'done' };
return { statusText: '已报价', statusClass: 'quoted' };
}
if (round === 'open') return { statusText: '待报价', statusClass: 'open' };
return { statusText: round || inv, statusClass: 'done' };
}
function formatDeadline(v) {
if (!v) return '—';
const d = new Date(v);
if (Number.isNaN(d.getTime())) return String(v);
const pad = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
}
Component({
options: { addGlobalClass: true },
properties: {
embedded: { type: Boolean, value: false },
},
data: {
tab: 'open',
loading: false,
error: '',
enabled: true,
allRows: [],
list: [],
detail: null,
priceMap: {},
submitting: false,
},
lifetimes: {
attached() {
// 首页 wx:if 切模块时页面已 show,pageLifetimes.show 不会再触发
this.onPanelShow();
},
detached() {
this.setData({ detail: null, priceMap: {} });
},
},
pageLifetimes: {
show() {
this.onPanelShow();
},
hide() {
this.setData({ detail: null, priceMap: {} });
},
},
methods: {
async onPanelShow() {
if (!beginPanelShow(this)) return;
try {
const ok = await ensureMobileRole('supplier', {
message: '请切换到供应商工作台后再查看竞价',
});
if (!ok) return;
await this.load();
} finally {
endPanelShow(this);
}
},
onTab(e) {
const tab = e.currentTarget.dataset.tab;
if (!tab || tab === this.data.tab) return;
this.setData({ tab }, () => this.applyFilter());
},
applyFilter() {
const { tab, allRows } = this.data;
const list =
tab === 'open'
? allRows.filter((r) => r.status === 'pending' && r.round_status === 'open')
: allRows.filter((r) => !(r.status === 'pending' && r.round_status === 'open'));
this.setData({ list });
},
async load() {
this.setData({ loading: true, error: '' });
try {
const result = await fetchSupplierBids();
const settings = result.settings || {};
const rows = (result.data || []).map((row) => {
const meta = statusMeta(row);
return {
...row,
...meta,
deadlineText: formatDeadline(row.respond_deadline || row.round_respond_deadline),
};
});
this.setData(
{
loading: false,
enabled: settings.enabled !== false,
allRows: rows,
},
() => {
this.applyFilter();
const count = rows.filter((row) => row.status === 'pending' && row.round_status === 'open').length;
this.triggerEvent('badgechange', { count });
}
);
} catch (err) {
this.setData({
loading: false,
error: (err && err.message) || '加载失败',
allRows: [],
list: [],
});
}
},
async openDetail(e) {
const id = e.currentTarget.dataset.id;
if (!id) return;
wx.showLoading({ title: '加载中' });
try {
const result = await fetchSupplierBidDetail(id);
const data = result.data || {};
const invitation = data.invitation || {};
const invStatus = invitation.status;
const canQuote = data.round && data.round.status === 'open' && invStatus !== 'expired';
const priceMap = {};
(data.my_quotes || []).forEach((q) => {
priceMap[q.sku_code] = String(q.unit_price);
});
(data.items || []).forEach((item) => {
if (priceMap[item.sku_code] == null) priceMap[item.sku_code] = '';
});
this.setData({
detail: {
...data,
invitation: {
...invitation,
statusText: statusMeta({
status: invStatus,
round_status: data.round && data.round.status,
}).statusText,
deadlineText: formatDeadline(invitation.respond_deadline),
},
canQuote,
awards: data.awards || [],
},
priceMap,
});
} catch (err) {
wx.showToast({ title: (err && err.message) || '加载失败', icon: 'none' });
} finally {
wx.hideLoading();
}
},
closeDetail() {
this.setData({ detail: null, priceMap: {} });
},
onPriceInput(e) {
const sku = e.currentTarget.dataset.sku;
const value = e.detail.value;
this.setData({ [`priceMap.${sku}`]: value });
},
async submitQuotes() {
const detail = this.data.detail;
if (!detail || !detail.canQuote) return;
const quotes = Object.keys(this.data.priceMap)
.map((sku_code) => ({
sku_code,
unit_price: Number(this.data.priceMap[sku_code]),
}))
.filter((q) => Number.isFinite(q.unit_price) && q.unit_price > 0);
if (!quotes.length) {
wx.showToast({ title: '请至少填写一条报价', icon: 'none' });
return;
}
this.setData({ submitting: true });
try {
await submitSupplierBidQuotes(detail.round.id, { quotes });
wx.showToast({ title: '报价已提交', icon: 'success' });
this.setData({ detail: null });
await this.load();
} catch (err) {
wx.showToast({ title: (err && err.message) || '提交失败', icon: 'none' });
} finally {
this.setData({ submitting: false });
}
},
},
});