来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
230 lines
6.4 KiB
JavaScript
230 lines
6.4 KiB
JavaScript
const { ensureMobileRole } = require('../../utils/roleGuard');
|
||
const { beginPanelShow, endPanelShow } = require('../../utils/panelShowGate');
|
||
const { prepareOrderImageBase64 } = require('../../utils/orderImage');
|
||
const {
|
||
fetchSupplierQualityReports,
|
||
fetchSupplierQualityReportTypes,
|
||
uploadSupplierQualityReport,
|
||
} = require('../../utils/request');
|
||
|
||
function validityClass(status) {
|
||
if (status === 'in_range') return 'status-ok';
|
||
if (status === 'expired' || status === 'not_yet') return 'status-bad';
|
||
return 'status-warn';
|
||
}
|
||
|
||
function mapUploaded(row) {
|
||
const related = Array.isArray(row.related_batch_nos)
|
||
? row.related_batch_nos.filter(Boolean)
|
||
: [];
|
||
const batches = related.length ? related : row.batch_no ? [row.batch_no] : [];
|
||
return {
|
||
...row,
|
||
validityClass: validityClass(row.validity_status),
|
||
batchText: batches.length ? batches.join('、') : '尚未入库',
|
||
batchWarn: !batches.length,
|
||
firstBatch: batches[0] || '',
|
||
};
|
||
}
|
||
|
||
Component({
|
||
options: { addGlobalClass: true },
|
||
|
||
properties: {
|
||
embedded: { type: Boolean, value: false },
|
||
},
|
||
|
||
data: {
|
||
tab: 'pending',
|
||
loading: false,
|
||
error: '',
|
||
pending: [],
|
||
uploaded: [],
|
||
typeOptions: [],
|
||
typeLabels: [],
|
||
uploadTypeIndex: 0,
|
||
uploadTypeCode: 'other',
|
||
},
|
||
|
||
lifetimes: {
|
||
attached() {
|
||
this.onPanelShow();
|
||
},
|
||
},
|
||
|
||
pageLifetimes: {
|
||
show() {
|
||
this.onPanelShow();
|
||
},
|
||
},
|
||
|
||
methods: {
|
||
async onPanelShow() {
|
||
if (!beginPanelShow(this)) return;
|
||
try {
|
||
const ok = await ensureMobileRole('supplier', {
|
||
message: '请切换到供应商工作台后再上传报告',
|
||
});
|
||
if (!ok) return;
|
||
this.load();
|
||
} finally {
|
||
endPanelShow(this);
|
||
}
|
||
},
|
||
|
||
onTab(e) {
|
||
const tab = e.currentTarget.dataset.tab;
|
||
if (!tab || tab === this.data.tab) return;
|
||
this.setData({ tab });
|
||
},
|
||
|
||
onTypePick(e) {
|
||
const idx = Number(e.detail.value);
|
||
const opt = (this.data.typeOptions || [])[idx];
|
||
if (!opt) return;
|
||
this.setData({
|
||
uploadTypeIndex: idx,
|
||
uploadTypeCode: opt.code,
|
||
});
|
||
},
|
||
|
||
async load() {
|
||
this.setData({ loading: true, error: '' });
|
||
try {
|
||
const [result, typesRes] = await Promise.all([
|
||
fetchSupplierQualityReports({ days: 14 }),
|
||
fetchSupplierQualityReportTypes().catch(() => null),
|
||
]);
|
||
const data = result.data || result || {};
|
||
const pending = (data.pending || []).map((item) => ({
|
||
...item,
|
||
item_names_text: (item.item_names || []).join('、'),
|
||
}));
|
||
const uploaded = (data.uploaded || []).map(mapUploaded);
|
||
const types = (typesRes && typesRes.data && typesRes.data.types) || [];
|
||
const typeOptions = types.length
|
||
? types
|
||
: [
|
||
{ code: 'quarantine', label: '检疫报告' },
|
||
{ code: 'inspection', label: '检验报告' },
|
||
{ code: 'pesticide', label: '农残报告' },
|
||
{ code: 'batch', label: '批次报告' },
|
||
{ code: 'other', label: '其他报告' },
|
||
];
|
||
const typeLabels = typeOptions.map((t) => t.label);
|
||
const first = typeOptions[0] || { code: 'other', label: '其他报告' };
|
||
this.setData(
|
||
{
|
||
pending,
|
||
uploaded,
|
||
typeOptions,
|
||
typeLabels,
|
||
uploadTypeIndex: 0,
|
||
uploadTypeCode: first.code,
|
||
loading: false,
|
||
},
|
||
() => {
|
||
this.triggerEvent('badgechange', { count: pending.length });
|
||
}
|
||
);
|
||
} catch (err) {
|
||
this.setData({
|
||
loading: false,
|
||
error: (err && err.message) || '加载失败',
|
||
pending: [],
|
||
uploaded: [],
|
||
});
|
||
}
|
||
},
|
||
|
||
uploadReport(e) {
|
||
const id = e.currentTarget.dataset.id;
|
||
const requiredType = e.currentTarget.dataset.type || '';
|
||
if (!id) return;
|
||
const typeOptions = this.data.typeOptions || [];
|
||
let reportType = this.data.uploadTypeCode || 'other';
|
||
if (requiredType) {
|
||
const hit = typeOptions.findIndex((t) => t.code === requiredType);
|
||
if (hit >= 0) {
|
||
reportType = requiredType;
|
||
this.setData({ uploadTypeIndex: hit, uploadTypeCode: requiredType });
|
||
} else {
|
||
reportType = requiredType;
|
||
}
|
||
}
|
||
wx.chooseMedia({
|
||
count: 3,
|
||
mediaType: ['image'],
|
||
sourceType: ['album', 'camera'],
|
||
success: (res) => {
|
||
const files = res.tempFiles || [];
|
||
if (!files.length) return;
|
||
wx.showLoading({ title: '上传中', mask: true });
|
||
Promise.all(
|
||
files.map((file) =>
|
||
prepareOrderImageBase64(file.tempFilePath).then(
|
||
(content) => `data:image/jpeg;base64,${content}`
|
||
)
|
||
)
|
||
)
|
||
.then((payloads) =>
|
||
uploadSupplierQualityReport({
|
||
preparation_id: id,
|
||
files: payloads,
|
||
report_type: reportType,
|
||
})
|
||
)
|
||
.then((result) => {
|
||
const label =
|
||
(result && result.data && result.data.validity_label) || '已上传';
|
||
wx.showToast({ title: `报告${label}`, icon: 'none' });
|
||
this.setData({ tab: 'uploaded' });
|
||
this.load();
|
||
})
|
||
.catch((err) => {
|
||
wx.showToast({ title: (err && err.message) || '上传失败', icon: 'none' });
|
||
})
|
||
.finally(() => wx.hideLoading());
|
||
},
|
||
});
|
||
},
|
||
|
||
preview(e) {
|
||
const urls = e.currentTarget.dataset.urls || [];
|
||
const current = e.currentTarget.dataset.url;
|
||
if (!urls.length) return;
|
||
wx.previewImage({ urls, current });
|
||
},
|
||
|
||
goTrace(e) {
|
||
const batch = e.currentTarget.dataset.batch;
|
||
if (!batch) return;
|
||
// 供应商无内部溯源权限:走公开 H5 /t/:code(设计 20260720)
|
||
const config = require('../../config');
|
||
const webBase = String(config.webBase || '').replace(/\/$/, '');
|
||
if (!webBase) {
|
||
wx.showToast({ title: '未配置公开溯源地址', icon: 'none' });
|
||
return;
|
||
}
|
||
const url = `${webBase}/t/${encodeURIComponent(batch)}`;
|
||
wx.setClipboardData({
|
||
data: url,
|
||
success: () => {
|
||
wx.showModal({
|
||
title: '公开溯源',
|
||
content: `链接已复制,可在浏览器打开:\n${url}`,
|
||
showCancel: false,
|
||
});
|
||
},
|
||
fail: () => {
|
||
wx.showModal({
|
||
title: '公开溯源',
|
||
content: url,
|
||
showCancel: false,
|
||
});
|
||
},
|
||
});
|
||
},
|
||
},
|
||
});
|