1386 lines
42 KiB
JavaScript
1386 lines
42 KiB
JavaScript
const config = require('../config');
|
|
const { getSession, clearSession } = require('./auth');
|
|
const { goLogin } = require('./nav');
|
|
|
|
let redirectingToLogin = false;
|
|
|
|
function redirectToLoginOnUnauthorized() {
|
|
if (redirectingToLogin) return;
|
|
redirectingToLogin = true;
|
|
try {
|
|
clearSession();
|
|
} catch (_) {
|
|
/* ignore */
|
|
}
|
|
try {
|
|
goLogin();
|
|
} catch (_) {
|
|
wx.reLaunch({ url: '/pages/login/login' });
|
|
}
|
|
setTimeout(() => {
|
|
redirectingToLogin = false;
|
|
}, 1500);
|
|
}
|
|
|
|
function readErrorMessage(body, statusCode) {
|
|
if (!body || typeof body !== 'object') return `请求失败(${statusCode})`;
|
|
if (body.error_description) return body.error_description;
|
|
if (typeof body.message === 'string' && body.message) return body.message;
|
|
if (typeof body.error === 'string' && body.error) return body.error;
|
|
if (body.error && typeof body.error === 'object' && body.error.message) {
|
|
return body.error.message;
|
|
}
|
|
return `请求失败(${statusCode})`;
|
|
}
|
|
|
|
function isSessionRevokedError(code) {
|
|
const key = String(code || '').trim();
|
|
return key === 'invalid_token' || key === 'pwdv_mismatch' || key === 'token_missing_pwdv';
|
|
}
|
|
|
|
function maybeRedirectOnUnauthorized(auth, skipAuthRedirect, errorCode) {
|
|
if (auth && !skipAuthRedirect && isSessionRevokedError(errorCode)) {
|
|
redirectToLoginOnUnauthorized();
|
|
}
|
|
}
|
|
|
|
function readErrorCode(body) {
|
|
if (!body || typeof body !== 'object') return '';
|
|
if (typeof body.error === 'string') return body.error;
|
|
if (body.error && typeof body.error === 'object' && body.error.code) {
|
|
return String(body.error.code);
|
|
}
|
|
return '';
|
|
}
|
|
|
|
function request(path, options = {}) {
|
|
const { method = 'GET', data = {}, auth = true, skipAuthRedirect = false, timeout } = options;
|
|
const session = getSession();
|
|
const header = {
|
|
'Content-Type': 'application/json',
|
|
};
|
|
if (auth && session?.access_token) {
|
|
header.Authorization = `Bearer ${session.access_token}`;
|
|
}
|
|
|
|
const upperMethod = String(method).toUpperCase();
|
|
const requestData =
|
|
upperMethod === 'GET' ? data : typeof data === 'string' ? data : JSON.stringify(data);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const reqOpts = {
|
|
url: `${config.apiBase}${path}`,
|
|
method: upperMethod,
|
|
data: requestData,
|
|
header,
|
|
success(res) {
|
|
const body = res.data || {};
|
|
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
resolve(body);
|
|
return;
|
|
}
|
|
if (res.statusCode === 401) {
|
|
const code = readErrorCode(body) || 'invalid_token';
|
|
const message =
|
|
body.error_description ||
|
|
body.message ||
|
|
'登录无效,请稍后重新登录';
|
|
maybeRedirectOnUnauthorized(auth, skipAuthRedirect, code);
|
|
reject(
|
|
Object.assign(new Error(message), {
|
|
statusCode: res.statusCode,
|
|
code,
|
|
body,
|
|
})
|
|
);
|
|
return;
|
|
}
|
|
reject(
|
|
Object.assign(new Error(readErrorMessage(body, res.statusCode)), {
|
|
statusCode: res.statusCode,
|
|
code: readErrorCode(body),
|
|
body,
|
|
})
|
|
);
|
|
},
|
|
fail(err) {
|
|
reject(new Error(err.errMsg || '网络错误,请检查 API 地址与后端服务'));
|
|
},
|
|
};
|
|
if (Number(timeout) > 0) reqOpts.timeout = Number(timeout);
|
|
wx.request(reqOpts);
|
|
});
|
|
}
|
|
|
|
function login(username, password, roleType) {
|
|
const data = { username, password };
|
|
if (roleType) data.role_type = roleType;
|
|
return request('/mobile/login', {
|
|
method: 'POST',
|
|
data,
|
|
auth: false,
|
|
skipAuthRedirect: true,
|
|
});
|
|
}
|
|
|
|
/** 微信小程序 getPhoneNumber 快速登录 */
|
|
function loginByPhone(phoneCode, roleType) {
|
|
const data = { phone_code: phoneCode };
|
|
if (roleType) data.role_type = roleType;
|
|
return request('/mobile/login/phone', {
|
|
method: 'POST',
|
|
data,
|
|
auth: false,
|
|
skipAuthRedirect: true,
|
|
});
|
|
}
|
|
|
|
function loginChooseBranch(ticket, branchCode, roleType) {
|
|
const data = { ticket, branch_code: branchCode };
|
|
if (roleType) data.role_type = roleType;
|
|
return request('/mobile/login/choose-branch', {
|
|
method: 'POST',
|
|
data,
|
|
auth: false,
|
|
skipAuthRedirect: true,
|
|
});
|
|
}
|
|
|
|
function fetchMe() {
|
|
return request('/mobile/me');
|
|
}
|
|
|
|
function fetchMobileRoles() {
|
|
return request('/mobile/roles');
|
|
}
|
|
|
|
/** 首页模块角标聚合:modules 传模块 id,后端按账号能力重算后返回各 badgeKey 数量 */
|
|
function fetchMobileBadges(modules = []) {
|
|
const list = Array.isArray(modules) ? modules : [modules];
|
|
const ids = list.map((item) => String(item || '').trim()).filter(Boolean);
|
|
const qs = ids.length ? `?modules=${encodeURIComponent(ids.join(','))}` : '';
|
|
return request(`/mobile/badges${qs}`);
|
|
}
|
|
|
|
function switchMobileRole(roleType) {
|
|
return request('/mobile/switch-role', {
|
|
method: 'POST',
|
|
data: { role_type: roleType },
|
|
});
|
|
}
|
|
|
|
function fetchDeliveryTasks(params = {}) {
|
|
const parts = [];
|
|
if (params.delivery_date) parts.push(`delivery_date=${encodeURIComponent(params.delivery_date)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/delivery/tasks${qs}`);
|
|
}
|
|
|
|
function fetchDeliveryLoading(taskCode) {
|
|
return request(`/mobile/delivery/loading/${encodeURIComponent(taskCode)}`);
|
|
}
|
|
|
|
function uploadDeliveryLoadingPhoto(payload) {
|
|
return request('/mobile/delivery/loading/photo', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function confirmDeliveryLoadingItem(payload) {
|
|
return request('/mobile/delivery/loading/confirm-item', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function unconfirmDeliveryLoadingItem(payload) {
|
|
return request('/mobile/delivery/loading/unconfirm-item', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function scanDeliveryLoading(payload) {
|
|
return request('/mobile/delivery/loading/scan', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function startDelivery(payload) {
|
|
return request('/mobile/delivery/start', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function startDeliveryBatch(taskCodes, extra) {
|
|
const data =
|
|
Array.isArray(taskCodes) && taskCodes.length ? { task_codes: taskCodes } : {};
|
|
if (extra && extra.lat != null && extra.lng != null) {
|
|
data.lat = extra.lat;
|
|
data.lng = extra.lng;
|
|
}
|
|
return request('/mobile/delivery/start-batch', {
|
|
method: 'POST',
|
|
data,
|
|
});
|
|
}
|
|
|
|
function fetchDeliveryPresence() {
|
|
return request('/mobile/delivery/presence', { method: 'GET' });
|
|
}
|
|
|
|
function setDeliveryOnline() {
|
|
return request('/mobile/delivery/online', { method: 'POST', data: {} });
|
|
}
|
|
|
|
function setDeliveryOffline() {
|
|
return request('/mobile/delivery/offline', { method: 'POST', data: {} });
|
|
}
|
|
|
|
/**
|
|
* 结束配送。
|
|
* position:可选的最后一次已知定位({lat,lng,accuracy}),随请求带上,
|
|
* 服务端据此补一次进圈判定 —— 避免途中上报断档时进圈时刻永远为空。
|
|
* 见 docs/design/20260918-delivery-geofence-report-gap.md。
|
|
*/
|
|
function stopDelivery(taskCode, position) {
|
|
const data = { task_code: taskCode || '' };
|
|
if (position && Number.isFinite(Number(position.lat)) && Number.isFinite(Number(position.lng))) {
|
|
data.lat = Number(position.lat);
|
|
data.lng = Number(position.lng);
|
|
if (position.accuracy != null) data.accuracy = Number(position.accuracy);
|
|
}
|
|
return request('/mobile/delivery/stop', {
|
|
method: 'POST',
|
|
data,
|
|
});
|
|
}
|
|
|
|
function reportDeliveryLocation(payload) {
|
|
return request('/mobile/delivery/location', {
|
|
method: 'POST',
|
|
data: payload || {},
|
|
});
|
|
}
|
|
|
|
function uploadDeliverySignPhoto(payload) {
|
|
return request('/mobile/delivery/sign-photo', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchSupplierPreparations(params = {}) {
|
|
const parts = [];
|
|
if (params.view) parts.push(`view=${encodeURIComponent(params.view)}`);
|
|
if (params.date) parts.push(`date=${encodeURIComponent(params.date)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
if (params.delivery_date) parts.push(`delivery_date=${encodeURIComponent(params.delivery_date)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/supplier/preparations${qs}`);
|
|
}
|
|
|
|
function fetchSupplierBids() {
|
|
return request('/mobile/supplier/bids');
|
|
}
|
|
|
|
function fetchSupplierBidDetail(id) {
|
|
return request(`/mobile/supplier/bids/${encodeURIComponent(id)}`);
|
|
}
|
|
|
|
function submitSupplierBidQuotes(id, payload) {
|
|
return request(`/mobile/supplier/bids/${encodeURIComponent(id)}/quotes`, {
|
|
method: 'POST',
|
|
data: payload || {},
|
|
});
|
|
}
|
|
|
|
function fetchAdminPreparations(params = {}) {
|
|
const parts = [];
|
|
if (params.delivery_date) parts.push(`delivery_date=${encodeURIComponent(params.delivery_date)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
if (params.date_field) parts.push(`date_field=${encodeURIComponent(params.date_field)}`);
|
|
if (params.status != null && params.status !== '') parts.push(`status=${encodeURIComponent(params.status)}`);
|
|
if (params.stockout) parts.push(`stockout=${encodeURIComponent(params.stockout)}`);
|
|
if (params.q) parts.push(`q=${encodeURIComponent(params.q)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/admin/preparations${qs}`);
|
|
}
|
|
|
|
function updateAdminPreparationStatus(payload) {
|
|
return request('/mobile/admin/preparations/status', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function updateAdminPreparationPurchasePrice(payload) {
|
|
return request('/mobile/admin/preparations/purchase-price', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function transferAdminPreparationStockout(payload) {
|
|
return request('/mobile/admin/preparations/stockout-transfer', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function updateSupplierPreparationStatus(payload) {
|
|
return request('/mobile/supplier/preparations/status', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function amendSupplierPreparationPrice(payload) {
|
|
return request('/mobile/supplier/preparations/amend-price', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function uploadSupplierQualityReport(payload) {
|
|
return request('/mobile/supplier/quality-reports', {
|
|
method: 'POST',
|
|
data: payload,
|
|
timeout: 120000,
|
|
});
|
|
}
|
|
|
|
function confirmSupplierQualityReportHits(id, prepIds) {
|
|
return request(`/mobile/supplier/quality-reports/${encodeURIComponent(id)}/confirm-hits`, {
|
|
method: 'POST',
|
|
data: { prep_ids: prepIds || [] },
|
|
});
|
|
}
|
|
|
|
function discardSupplierQualityReport(id) {
|
|
return request(`/mobile/supplier/quality-reports/${encodeURIComponent(id)}/discard`, {
|
|
method: 'POST',
|
|
data: {},
|
|
});
|
|
}
|
|
|
|
/** 检验报告文件:multer 通道(单文件 10MB),返回 quality-reports 桶内对象路径。不要带 application/json。 */
|
|
function uploadQualityReportStorageFile(filePath, fileName) {
|
|
const session = getSession();
|
|
const rawName = String(fileName || '').trim() || String(filePath || '').split('/').pop() || 'quality-report.jpg';
|
|
const name = /\.(pdf|jpe?g|png|webp)$/i.test(rawName) ? rawName : `${rawName}.jpg`;
|
|
const pathQ = encodeURIComponent(name);
|
|
return new Promise((resolve, reject) => {
|
|
wx.uploadFile({
|
|
url: `${config.apiBase}/storage/quality-reports/upload?path=${pathQ}`,
|
|
filePath,
|
|
name: 'file',
|
|
formData: { path: name },
|
|
timeout: 120000,
|
|
header: session?.access_token ? { Authorization: `Bearer ${session.access_token}` } : {},
|
|
success(res) {
|
|
let body = {};
|
|
try {
|
|
body = typeof res.data === 'string' ? JSON.parse(res.data) : res.data || {};
|
|
} catch (_) {
|
|
body = {};
|
|
}
|
|
if (res.statusCode >= 200 && res.statusCode < 300 && body.path) {
|
|
resolve(String(body.path));
|
|
return;
|
|
}
|
|
if (res.statusCode === 401) {
|
|
const code = readErrorCode(body) || 'invalid_token';
|
|
maybeRedirectOnUnauthorized(true, false, code);
|
|
}
|
|
reject(new Error(body.error_description || body.error || `上传失败(${res.statusCode})`));
|
|
},
|
|
fail(err) {
|
|
reject(new Error(err.errMsg || '上传失败'));
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
function fetchSupplierQualityReportTypes() {
|
|
return request('/mobile/supplier/quality-report-types');
|
|
}
|
|
|
|
function fetchSupplierQualityReports(params = {}) {
|
|
const qs = [];
|
|
if (params.days != null) qs.push(`days=${encodeURIComponent(params.days)}`);
|
|
const suffix = qs.length ? `?${qs.join('&')}` : '';
|
|
return request(`/mobile/supplier/quality-reports${suffix}`);
|
|
}
|
|
|
|
function uploadPurchaseQualityReport(payload) {
|
|
return request('/mobile/purchase/quality-reports', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchPrepAmendPending() {
|
|
return request('/mobile/prep-amend/pending');
|
|
}
|
|
|
|
function fetchPrepAmendReviewed() {
|
|
return request('/mobile/prep-amend/reviewed');
|
|
}
|
|
|
|
function fetchPrepAmendPendingCount() {
|
|
return request('/mobile/prep-amend/pending-count');
|
|
}
|
|
|
|
function fetchPrepAmendDetail(id) {
|
|
return request(`/mobile/prep-amend/${encodeURIComponent(id || '')}`);
|
|
}
|
|
|
|
function confirmPrepAmend(id, payload) {
|
|
return request(`/mobile/prep-amend/${encodeURIComponent(id || '')}/confirm`, {
|
|
method: 'POST',
|
|
data: payload || {},
|
|
});
|
|
}
|
|
|
|
function rejectPrepAmend(id, payload) {
|
|
return request(`/mobile/prep-amend/${encodeURIComponent(id || '')}/reject`, {
|
|
method: 'POST',
|
|
data: payload || {},
|
|
});
|
|
}
|
|
|
|
function searchPurchaserOrderCustomers(params = {}) {
|
|
const parts = [];
|
|
if (params.q) parts.push(`q=${encodeURIComponent(params.q)}`);
|
|
if (params.date_range) parts.push(`date_range=${encodeURIComponent(params.date_range)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/purchaser/order-items/customers${qs}`);
|
|
}
|
|
|
|
function fetchPurchaserOrderList(params = {}) {
|
|
const parts = [];
|
|
if (params.customer_code) parts.push(`customer_code=${encodeURIComponent(params.customer_code)}`);
|
|
if (params.all_pending) parts.push('all_pending=1');
|
|
if (params.date_range) parts.push(`date_range=${encodeURIComponent(params.date_range)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/purchaser/order-items/orders${qs}`);
|
|
}
|
|
|
|
function fetchPurchaserOrderDetail(orderCode) {
|
|
return request(`/mobile/purchaser/order-items/orders/${encodeURIComponent(orderCode || '')}`);
|
|
}
|
|
|
|
function searchPurchaserOrderSkus(params = {}) {
|
|
const parts = [`customer_code=${encodeURIComponent(params.customer_code || '')}`];
|
|
if (params.q) parts.push(`q=${encodeURIComponent(params.q)}`);
|
|
return request(`/mobile/purchaser/order-items/skus?${parts.join('&')}`);
|
|
}
|
|
|
|
function savePurchaserOrderItems(orderCode, payload) {
|
|
return request(`/mobile/purchaser/order-items/orders/${encodeURIComponent(orderCode || '')}/items`, {
|
|
method: 'POST',
|
|
data: payload || {},
|
|
});
|
|
}
|
|
|
|
function updatePurchaserOrder(orderCode, payload) {
|
|
return request(`/mobile/purchaser/order-items/orders/${encodeURIComponent(orderCode || '')}`, {
|
|
method: 'PATCH',
|
|
data: payload || {},
|
|
});
|
|
}
|
|
|
|
function fetchSubstitutionCandidates(originalSkuCode, maxPrice = 0) {
|
|
return request(
|
|
`/mobile/supplier/substitution/candidates?original_sku_code=${encodeURIComponent(originalSkuCode)}&max_price=${maxPrice}`
|
|
);
|
|
}
|
|
|
|
function submitSupplierSubstitution(payload) {
|
|
return request('/mobile/supplier/substitution', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchInspectionTasks(params = {}) {
|
|
const parts = [];
|
|
if (params.source_type) parts.push(`source_type=${encodeURIComponent(params.source_type)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
if (params.date_field) parts.push(`date_field=${encodeURIComponent(params.date_field)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/inspection/tasks${qs}`);
|
|
}
|
|
|
|
function completeInspection(payload) {
|
|
return request('/mobile/inspection/complete', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function uploadInspectionPhoto(payload) {
|
|
return request('/mobile/inspection/photo', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function deleteInspectionPhoto(payload) {
|
|
const id = encodeURIComponent(payload.id || '');
|
|
const index = Number(payload.index);
|
|
return request(`/mobile/inspection/photo?id=${id}&index=${index}`, {
|
|
method: 'DELETE',
|
|
});
|
|
}
|
|
|
|
function analyzeInspectionQuality(payload) {
|
|
return request('/functions/ai-quality-analysis', {
|
|
method: 'POST',
|
|
data: {
|
|
image: payload.image,
|
|
imageBase64: payload.image,
|
|
product_name: payload.product_name,
|
|
expected_qty: payload.expected_qty,
|
|
actual_qty: payload.actual_qty,
|
|
loss_qty: payload.loss_qty || 0,
|
|
},
|
|
timeout: 120000,
|
|
}).then((result) => {
|
|
const data = result && result.data;
|
|
if (!data) {
|
|
const err = result && result.error;
|
|
const message =
|
|
(err && typeof err === 'object' && err.message) ||
|
|
(typeof err === 'string' && err) ||
|
|
'AI 分析失败';
|
|
throw new Error(message);
|
|
}
|
|
return data;
|
|
});
|
|
}
|
|
|
|
function fetchStockInboundCategories() {
|
|
return request('/mobile/inventory/categories');
|
|
}
|
|
|
|
function fetchStockInboundStorageZones() {
|
|
return request('/mobile/inventory/storage-zones');
|
|
}
|
|
|
|
function createStockInboundCategory(name) {
|
|
return request('/mobile/inventory/categories', {
|
|
method: 'POST',
|
|
data: { name },
|
|
});
|
|
}
|
|
|
|
function recognizeStockInboundCatalog(payload) {
|
|
return request('/mobile/inventory/recognize-catalog', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchStockInboundSkuSimilar(params = {}) {
|
|
const parts = [];
|
|
if (params.name) parts.push(`name=${encodeURIComponent(params.name)}`);
|
|
if (params.spec) parts.push(`spec=${encodeURIComponent(params.spec)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/inventory/sku-similar${qs}`);
|
|
}
|
|
|
|
function createStockInboundProduct(payload) {
|
|
return request('/mobile/catalog/products', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function submitStockInbound(payload) {
|
|
return request('/mobile/inventory/stock-in', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
/** 多商品识别(送货单/实物堆):单张图 → 多行 + 逐行匹配 */
|
|
function recognizeStockInboundLines(payload) {
|
|
return request('/mobile/inventory/recognize-lines', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
/** 多商品审核后批量入库 */
|
|
function submitStockInboundBatch(payload) {
|
|
return request('/mobile/inventory/stock-in-batch', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchPickingTasks(params = {}) {
|
|
const parts = [];
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
if (params.date_field) parts.push(`date_field=${encodeURIComponent(params.date_field)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/picking/tasks${qs}`);
|
|
}
|
|
|
|
function fetchPickingWeighDevices(opts = {}) {
|
|
const mine = opts === true || opts.mine === true;
|
|
const online = opts && typeof opts === 'object' && opts.online === true;
|
|
const parts = [];
|
|
if (mine) parts.push('mine=1');
|
|
if (online) parts.push('online=1');
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/picking/weigh-devices${qs}`);
|
|
}
|
|
|
|
function createPickingPrintJobs(payload) {
|
|
return request('/mobile/picking/print-jobs', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function savePickingProgress(payload) {
|
|
return request('/mobile/picking/progress', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function confirmPickingComplete(payload) {
|
|
return request('/mobile/picking/complete', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function scanPickingBarcode(payload) {
|
|
return request('/mobile/picking/scan', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function searchPurchaseSkus(q) {
|
|
const query = String(q || '').trim();
|
|
const qs = query ? `?q=${encodeURIComponent(query)}` : '';
|
|
return request(`/mobile/purchase/skus${qs}`);
|
|
}
|
|
|
|
function createSelfPurchaseStockInbound(payload) {
|
|
return request('/mobile/purchase/self-purchase-stock-inbound', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchPurchaseOrders(params = {}) {
|
|
const parts = [];
|
|
if (params.all_pending) parts.push('all_pending=1');
|
|
if (params.delivery_date) parts.push(`delivery_date=${encodeURIComponent(params.delivery_date)}`);
|
|
if (params.category_code) parts.push(`category_code=${encodeURIComponent(params.category_code)}`);
|
|
if (params.view) parts.push(`view=${encodeURIComponent(params.view)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
if (params.date_field) parts.push(`date_field=${encodeURIComponent(params.date_field)}`);
|
|
if (params.scope) parts.push(`scope=${encodeURIComponent(params.scope)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/purchase/orders${qs}`);
|
|
}
|
|
|
|
function fetchAdminPurchaseOrders(params = {}) {
|
|
const parts = [];
|
|
if (params.view) parts.push(`view=${encodeURIComponent(params.view)}`);
|
|
if (params.status_group) parts.push(`status_group=${encodeURIComponent(params.status_group)}`);
|
|
if (params.category_code) parts.push(`category_code=${encodeURIComponent(params.category_code)}`);
|
|
if (params.category) parts.push(`category=${encodeURIComponent(params.category)}`);
|
|
if (params.search) parts.push(`search=${encodeURIComponent(params.search)}`);
|
|
if (params.source_type) parts.push(`source_type=${encodeURIComponent(params.source_type)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
if (params.date_field) parts.push(`date_field=${encodeURIComponent(params.date_field)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/admin/purchase/orders${qs}`);
|
|
}
|
|
|
|
function completeAdminPurchase(payload) {
|
|
return request('/workflow/purchase/complete', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function setAdminPurchaseSelfProcessed(purchaseCode, selfProcessed) {
|
|
return request('/workflow/purchase/self-process', {
|
|
method: 'POST',
|
|
data: { purchase_code: purchaseCode, self_processed: selfProcessed },
|
|
});
|
|
}
|
|
|
|
function fetchAdminPurchaseAssignSuppliers(purchaseCode) {
|
|
return request(
|
|
`/workflow/purchase/assign-suppliers?purchase_code=${encodeURIComponent(purchaseCode)}`
|
|
);
|
|
}
|
|
|
|
function assignAdminPurchaseToSupplier(payload) {
|
|
return request('/workflow/purchase/assign-supplier', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function amendAdminPurchaseActual(purchaseCode, payload) {
|
|
return request(`/workflow/purchase/${encodeURIComponent(purchaseCode)}/amend-actual`, {
|
|
method: 'PATCH',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function updateAdminPurchaseSalePrice(purchaseCode, salePrice) {
|
|
return request(`/workflow/purchase/${encodeURIComponent(purchaseCode)}/linked-sale-price`, {
|
|
method: 'PATCH',
|
|
data: { sale_price: salePrice },
|
|
});
|
|
}
|
|
|
|
function fetchAdminPurchasePurchasers() {
|
|
return request('/workflow/purchase/purchasers');
|
|
}
|
|
|
|
function patchAdminPurchasePurchaser(purchaseCode, purchaserCode) {
|
|
return request(`/workflow/purchase/${encodeURIComponent(purchaseCode)}/purchaser`, {
|
|
method: 'PATCH',
|
|
data: { purchaser_code: purchaserCode },
|
|
});
|
|
}
|
|
|
|
function assignAdminPurchasePurchasers(payload) {
|
|
return request('/workflow/purchase/assign-purchasers', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchPurchaseCategories() {
|
|
return request('/mobile/purchase/categories');
|
|
}
|
|
|
|
function createPurchaseCategory(name) {
|
|
return request('/mobile/purchase/categories', {
|
|
method: 'POST',
|
|
data: { name },
|
|
});
|
|
}
|
|
|
|
function fetchPurchaseAssignSuppliers(purchaseCode) {
|
|
return request(`/workflow/purchase/assign-suppliers?purchase_code=${encodeURIComponent(purchaseCode)}`);
|
|
}
|
|
|
|
function assignPurchaseToSupplier(payload) {
|
|
return request('/workflow/purchase/assign-supplier', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchUiPreference(key) {
|
|
return request(`/mobile/ui-preferences/${encodeURIComponent(key)}`);
|
|
}
|
|
|
|
function setUiPreference(key, value) {
|
|
return request(`/mobile/ui-preferences/${encodeURIComponent(key)}`, {
|
|
method: 'PUT',
|
|
data: { value },
|
|
});
|
|
}
|
|
|
|
function fetchPurchaserSupplierStatus(params = {}) {
|
|
const parts = [];
|
|
if (params.all_pending) parts.push('all_pending=1');
|
|
if (params.delivery_date) parts.push(`delivery_date=${encodeURIComponent(params.delivery_date)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
const qs = parts.length ? `?${parts.join('&')}` : '';
|
|
return request(`/mobile/purchase/supplier-status${qs}`);
|
|
}
|
|
|
|
function completePurchaserSupplierInspectionBatch(payload) {
|
|
return request('/mobile/purchase/supplier-inspection/complete-batch', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function updatePurchaseOrderStatus(payload) {
|
|
return request('/mobile/purchase/orders/status', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function uploadPurchaseDirectDeliveryPhoto(payload) {
|
|
return request('/mobile/purchase/direct-delivery-photo', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchOrderEntryCustomers() {
|
|
return request('/mobile/order-entry/customers');
|
|
}
|
|
|
|
/** 录单员:客户生效报价单价目(成本/售价) */
|
|
function fetchOrderEntryQuotePrices(customerCode) {
|
|
return request(`/mobile/order-entry/quote-prices/${encodeURIComponent(customerCode)}`);
|
|
}
|
|
|
|
function searchOrderEntrySkus(params = {}) {
|
|
const parts = [];
|
|
if (params.customer_code) parts.push(`customer_code=${encodeURIComponent(params.customer_code)}`);
|
|
if (params.q) parts.push(`q=${encodeURIComponent(params.q)}`);
|
|
return request(`/mobile/order-entry/skus?${parts.join('&')}`);
|
|
}
|
|
|
|
/** 录单员:写回生效报价单成本价 */
|
|
function upsertOrderEntryQuoteCosts(payload) {
|
|
return request('/mobile/order-entry/quote-costs', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function submitOrderEntryOrder(payload) {
|
|
return request('/mobile/order-entry/orders', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
/** 提交订单;若需新建基础商品则弹窗确认后带 confirm_new_products 重试 */
|
|
function submitOrderWithCatalogConfirm(submitFn, payload) {
|
|
return submitFn({ ...payload, confirm_new_products: false }).catch((err) => {
|
|
const code = err?.body?.error;
|
|
if (code !== 'needs_confirm_new_products') {
|
|
throw err;
|
|
}
|
|
const names = (err.body?.new_products || [])
|
|
.map((row) => row.name)
|
|
.filter(Boolean);
|
|
const unique = [...new Set(names)];
|
|
const preview = unique.slice(0, 8).join('、');
|
|
const more = unique.length > 8 ? `等共 ${unique.length} 个` : '';
|
|
const content =
|
|
err.message ||
|
|
`有 ${unique.length || names.length} 个商品不在基础商品库,确认后将自动创建:${preview}${more}`;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
wx.showModal({
|
|
title: '自动创建基础商品',
|
|
content,
|
|
confirmText: '确认创建',
|
|
cancelText: '取消',
|
|
success(res) {
|
|
if (!res.confirm) {
|
|
reject(Object.assign(new Error('已取消提交'), { cancelled: true }));
|
|
return;
|
|
}
|
|
submitFn({ ...payload, confirm_new_products: true }).then(resolve).catch(reject);
|
|
},
|
|
fail: () => reject(new Error('确认失败')),
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function fetchOrderEntryDetail(orderCode) {
|
|
return request(`/mobile/order-entry/orders/${encodeURIComponent(orderCode)}`);
|
|
}
|
|
|
|
function updateOrderEntryOrder(orderCode, payload) {
|
|
return request(`/mobile/order-entry/orders/${encodeURIComponent(orderCode)}`, {
|
|
method: 'PATCH',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchCustomerOrderPrefill(customerCode) {
|
|
return request(`/mobile/customer-order/prefill/${encodeURIComponent(customerCode)}`);
|
|
}
|
|
|
|
function fetchCustomerOrderBudget(customerCode, orderAmount = 0) {
|
|
return request(
|
|
`/mobile/customer-order/budget/${encodeURIComponent(customerCode)}?order_amount=${Number(orderAmount) || 0}`
|
|
);
|
|
}
|
|
|
|
function submitOrderEntryOrderWithConfirm(payload) {
|
|
return submitOrderWithCatalogConfirm(submitOrderEntryOrder, payload);
|
|
}
|
|
|
|
function parseCustomerOrder(payload) {
|
|
return request('/mobile/customer-order/parse', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchOrderCategories() {
|
|
return request('/mobile/customer-order/categories');
|
|
}
|
|
|
|
function fetchCustomerMappingSkus(customerCode) {
|
|
const qs = customerCode ? `?customer_code=${encodeURIComponent(customerCode)}` : '';
|
|
return request(`/mobile/customer-order/customer-skus${qs}`);
|
|
}
|
|
|
|
function createOrderCategory(name) {
|
|
return request('/mobile/customer-order/categories', {
|
|
method: 'POST',
|
|
data: { name },
|
|
});
|
|
}
|
|
|
|
function fetchProcessingTasks(params = {}) {
|
|
const tab = params.tab || 'work';
|
|
const parts = [`tab=${encodeURIComponent(tab)}`];
|
|
if (params.delivery_date) parts.push(`delivery_date=${encodeURIComponent(params.delivery_date)}`);
|
|
if (params.date_from) parts.push(`date_from=${encodeURIComponent(params.date_from)}`);
|
|
if (params.date_to) parts.push(`date_to=${encodeURIComponent(params.date_to)}`);
|
|
if (params.date_field) parts.push(`date_field=${encodeURIComponent(params.date_field)}`);
|
|
return request(`/mobile/processing/tasks?${parts.join('&')}`);
|
|
}
|
|
|
|
function fetchStandaloneProcessingSkuOptions(search = '', limit = 20) {
|
|
const parts = [];
|
|
if (search) parts.push(`search=${encodeURIComponent(search)}`);
|
|
if (limit) parts.push(`limit=${encodeURIComponent(limit)}`);
|
|
return request(`/mobile/processing/standalone/sku-options?${parts.join('&')}`);
|
|
}
|
|
|
|
function createStandaloneProcessingTask(payload) {
|
|
return request('/mobile/processing/standalone/create', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function pickDemandSheetMaterial(taskId, payload) {
|
|
return request(`/mobile/processing/demand/${encodeURIComponent(taskId)}/pick`, {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function skipWarehouseDemandPurchase(purchaseCode) {
|
|
return request('/workflow/purchase/skip-warehouse-demand', {
|
|
method: 'POST',
|
|
data: { purchase_code: purchaseCode },
|
|
});
|
|
}
|
|
|
|
function startProcessingTask(taskId) {
|
|
return request('/mobile/processing/start', {
|
|
method: 'POST',
|
|
data: { task_id: taskId },
|
|
});
|
|
}
|
|
|
|
function completeProcessingWork(payload) {
|
|
return request('/mobile/processing/complete', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function uploadProcessingInspectPhoto(payload) {
|
|
return request('/mobile/processing/inspect/photo', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function submitProcessingInspection(payload) {
|
|
return request('/mobile/processing/inspect/complete', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function fetchNotifications(limit) {
|
|
const params = {};
|
|
const max = Number(limit);
|
|
if (max > 0) params.limit = max;
|
|
return request('/mobile/notifications', { data: params });
|
|
}
|
|
|
|
function markAllNotificationsRead() {
|
|
return request('/mobile/notifications/mark-all-read', { method: 'POST' });
|
|
}
|
|
|
|
function fetchOrdersManagement(params = {}) {
|
|
const data = {};
|
|
Object.keys(params || {}).forEach((key) => {
|
|
const value = params[key];
|
|
if (value === undefined || value === null || value === '') return;
|
|
data[key] = value;
|
|
});
|
|
return request('/mobile/orders/management-list', { data });
|
|
}
|
|
|
|
function fetchOrderManageDetail(orderCode) {
|
|
const code = String(orderCode || '').trim();
|
|
return request(`/mobile/orders/${encodeURIComponent(code)}`);
|
|
}
|
|
|
|
function searchOrderManageSkus(params = {}) {
|
|
const parts = [];
|
|
if (params.q) parts.push(`q=${encodeURIComponent(params.q)}`);
|
|
if (params.customer_code) parts.push(`customer_code=${encodeURIComponent(params.customer_code)}`);
|
|
if (params.branch_code) parts.push(`branch_code=${encodeURIComponent(params.branch_code)}`);
|
|
return request(`/mobile/admin/skus?${parts.join('&')}`);
|
|
}
|
|
|
|
function resolveOrderManageCatalogProduct(payload) {
|
|
return request('/mobile/admin/catalog-products/resolve', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function updateOrderManage(orderCode, payload) {
|
|
return request(`/mobile/orders/${encodeURIComponent(orderCode)}`, {
|
|
method: 'PATCH',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function advanceOrderManage(orderCode, targetStatus) {
|
|
return request('/mobile/orders/advance', {
|
|
method: 'POST',
|
|
data: { order_code: orderCode, target_status: targetStatus },
|
|
});
|
|
}
|
|
|
|
function deleteOrderManage(orderCode) {
|
|
return request('/mobile/orders/delete', {
|
|
method: 'POST',
|
|
data: { order_code: orderCode },
|
|
});
|
|
}
|
|
|
|
function searchProductTrace(params = {}) {
|
|
const q = typeof params === 'string' ? params : String(params.q || '');
|
|
const input = typeof params === 'string' ? { q } : params || {};
|
|
const qs = [];
|
|
if (q) qs.push(`q=${encodeURIComponent(q)}`);
|
|
if (input.date_from) qs.push(`date_from=${encodeURIComponent(input.date_from)}`);
|
|
if (input.date_to) qs.push(`date_to=${encodeURIComponent(input.date_to)}`);
|
|
if (input.date_field) qs.push(`date_field=${encodeURIComponent(input.date_field)}`);
|
|
if (input.limit) qs.push(`limit=${encodeURIComponent(input.limit)}`);
|
|
if (input.offset != null && input.offset !== '') qs.push(`offset=${encodeURIComponent(input.offset)}`);
|
|
const suffix = qs.length ? `?${qs.join('&')}` : '';
|
|
return request(`/mobile/trace/search${suffix}`, { method: 'GET' });
|
|
}
|
|
|
|
function fetchProductTrace(batchNo) {
|
|
return request(`/mobile/trace/batch/${encodeURIComponent(batchNo || '')}`, { method: 'GET' });
|
|
}
|
|
|
|
function fetchUnits() {
|
|
return request('/mobile/units', { method: 'GET' });
|
|
}
|
|
|
|
function fetchFreeCostTypes() {
|
|
return request('/workflow/cost/free-cost/types', { method: 'GET' });
|
|
}
|
|
|
|
function fetchFreeCostSettings() {
|
|
return request('/workflow/cost/free-cost/settings', { method: 'GET' });
|
|
}
|
|
|
|
function addFreeCostType(label) {
|
|
return request('/workflow/cost/free-cost/types', {
|
|
method: 'POST',
|
|
data: { label },
|
|
});
|
|
}
|
|
|
|
function fetchFreeCostEntries(params = {}) {
|
|
const qs = [];
|
|
if (params.cycle_code) qs.push(`cycle_code=${encodeURIComponent(params.cycle_code)}`);
|
|
if (params.page) qs.push(`page=${encodeURIComponent(params.page)}`);
|
|
if (params.page_size) qs.push(`page_size=${encodeURIComponent(params.page_size)}`);
|
|
qs.push('mine=1');
|
|
return request(`/workflow/cost/free-cost/entries?${qs.join('&')}`, { method: 'GET' });
|
|
}
|
|
|
|
function createFreeCostEntry(payload) {
|
|
return request('/workflow/cost/free-cost', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 凭证识图。优先 voucher_path(服务端读已上传文件,避免真机大图 base64 超 JSON 限制)。
|
|
* @param {{ voucher_path?: string, image_base64?: string }|string} payload
|
|
*/
|
|
function extractFreeCostVoucherAmount(payload) {
|
|
const data =
|
|
payload && typeof payload === 'object' && !Array.isArray(payload)
|
|
? payload
|
|
: { image_base64: String(payload || '') };
|
|
return request('/workflow/cost/free-cost/voucher-amount', {
|
|
method: 'POST',
|
|
data,
|
|
timeout: 120000,
|
|
});
|
|
}
|
|
|
|
function uploadFreeCostVoucher(filePath) {
|
|
const session = getSession();
|
|
const ext = String(filePath.split('.').pop() || 'jpg').toLowerCase().replace(/[^a-z0-9]/g, '') || 'jpg';
|
|
return new Promise((resolve, reject) => {
|
|
wx.uploadFile({
|
|
url: `${config.apiBase}/storage/invoices/upload`,
|
|
filePath,
|
|
name: 'file',
|
|
formData: { path: `free-cost/voucher.${ext}` },
|
|
header: session?.access_token ? { Authorization: `Bearer ${session.access_token}` } : {},
|
|
success(res) {
|
|
let body = {};
|
|
try {
|
|
body = typeof res.data === 'string' ? JSON.parse(res.data) : res.data || {};
|
|
} catch (_) {
|
|
body = {};
|
|
}
|
|
if (res.statusCode >= 200 && res.statusCode < 300 && body.path) {
|
|
resolve(body);
|
|
return;
|
|
}
|
|
if (res.statusCode === 401) {
|
|
const code = readErrorCode(body) || 'invalid_token';
|
|
maybeRedirectOnUnauthorized(true, false, code);
|
|
}
|
|
reject(new Error(body.error_description || body.error || `上传失败(${res.statusCode})`));
|
|
},
|
|
fail(err) {
|
|
reject(new Error(err.errMsg || '上传失败'));
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
function extractFreeCostInvoice(payload) {
|
|
return request('/workflow/cost/free-cost/extract-invoice', {
|
|
method: 'POST',
|
|
data: payload,
|
|
timeout: 120000,
|
|
});
|
|
}
|
|
|
|
function saveFreeCostInvoice(payload) {
|
|
return request('/workflow/cost/free-cost/invoices', {
|
|
method: 'POST',
|
|
data: payload,
|
|
});
|
|
}
|
|
|
|
function uploadFreeCostInvoice(filePath) {
|
|
const session = getSession();
|
|
const ext = String(filePath.split('.').pop() || 'jpg').toLowerCase().replace(/[^a-z0-9]/g, '') || 'jpg';
|
|
return new Promise((resolve, reject) => {
|
|
wx.uploadFile({
|
|
url: `${config.apiBase}/storage/invoices/upload`,
|
|
filePath,
|
|
name: 'file',
|
|
formData: { path: `free-cost-invoice/invoice.${ext}` },
|
|
header: session?.access_token ? { Authorization: `Bearer ${session.access_token}` } : {},
|
|
success(res) {
|
|
let body = {};
|
|
try {
|
|
body = typeof res.data === 'string' ? JSON.parse(res.data) : res.data || {};
|
|
} catch (_) {
|
|
body = {};
|
|
}
|
|
if (res.statusCode >= 200 && res.statusCode < 300 && body.path) {
|
|
resolve(body);
|
|
return;
|
|
}
|
|
if (res.statusCode === 401) {
|
|
const code = readErrorCode(body) || 'invalid_token';
|
|
maybeRedirectOnUnauthorized(true, false, code);
|
|
}
|
|
reject(new Error(body.error_description || body.error || `上传失败(${res.statusCode})`));
|
|
},
|
|
fail(err) {
|
|
reject(new Error(err.errMsg || '上传失败'));
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
request,
|
|
login,
|
|
loginByPhone,
|
|
loginChooseBranch,
|
|
fetchMe,
|
|
fetchMobileRoles,
|
|
fetchMobileBadges,
|
|
switchMobileRole,
|
|
fetchDeliveryTasks,
|
|
fetchDeliveryLoading,
|
|
uploadDeliveryLoadingPhoto,
|
|
confirmDeliveryLoadingItem,
|
|
unconfirmDeliveryLoadingItem,
|
|
scanDeliveryLoading,
|
|
startDelivery,
|
|
startDeliveryBatch,
|
|
fetchDeliveryPresence,
|
|
setDeliveryOnline,
|
|
setDeliveryOffline,
|
|
stopDelivery,
|
|
reportDeliveryLocation,
|
|
uploadDeliverySignPhoto,
|
|
fetchSupplierPreparations,
|
|
fetchSupplierBids,
|
|
fetchSupplierBidDetail,
|
|
submitSupplierBidQuotes,
|
|
fetchAdminPreparations,
|
|
updateAdminPreparationStatus,
|
|
updateAdminPreparationPurchasePrice,
|
|
transferAdminPreparationStockout,
|
|
updateSupplierPreparationStatus,
|
|
amendSupplierPreparationPrice,
|
|
uploadSupplierQualityReport,
|
|
uploadQualityReportStorageFile,
|
|
confirmSupplierQualityReportHits,
|
|
discardSupplierQualityReport,
|
|
fetchSupplierQualityReports,
|
|
fetchSupplierQualityReportTypes,
|
|
uploadPurchaseQualityReport,
|
|
fetchPrepAmendPending,
|
|
fetchPrepAmendReviewed,
|
|
fetchPrepAmendPendingCount,
|
|
fetchPrepAmendDetail,
|
|
confirmPrepAmend,
|
|
rejectPrepAmend,
|
|
searchPurchaserOrderCustomers,
|
|
fetchPurchaserOrderList,
|
|
fetchPurchaserOrderDetail,
|
|
searchPurchaserOrderSkus,
|
|
savePurchaserOrderItems,
|
|
updatePurchaserOrder,
|
|
fetchSubstitutionCandidates,
|
|
submitSupplierSubstitution,
|
|
fetchInspectionTasks,
|
|
completeInspection,
|
|
uploadInspectionPhoto,
|
|
deleteInspectionPhoto,
|
|
analyzeInspectionQuality,
|
|
fetchStockInboundCategories,
|
|
fetchStockInboundStorageZones,
|
|
createStockInboundCategory,
|
|
recognizeStockInboundCatalog,
|
|
fetchStockInboundSkuSimilar,
|
|
createStockInboundProduct,
|
|
submitStockInbound,
|
|
recognizeStockInboundLines,
|
|
submitStockInboundBatch,
|
|
fetchPickingTasks,
|
|
fetchPickingWeighDevices,
|
|
createPickingPrintJobs,
|
|
savePickingProgress,
|
|
confirmPickingComplete,
|
|
scanPickingBarcode,
|
|
searchPurchaseSkus,
|
|
createSelfPurchaseStockInbound,
|
|
fetchPurchaseOrders,
|
|
fetchAdminPurchaseOrders,
|
|
completeAdminPurchase,
|
|
setAdminPurchaseSelfProcessed,
|
|
fetchAdminPurchaseAssignSuppliers,
|
|
assignAdminPurchaseToSupplier,
|
|
amendAdminPurchaseActual,
|
|
updateAdminPurchaseSalePrice,
|
|
fetchAdminPurchasePurchasers,
|
|
patchAdminPurchasePurchaser,
|
|
assignAdminPurchasePurchasers,
|
|
fetchPurchaseCategories,
|
|
createPurchaseCategory,
|
|
fetchPurchaseAssignSuppliers,
|
|
assignPurchaseToSupplier,
|
|
fetchUiPreference,
|
|
setUiPreference,
|
|
fetchPurchaserSupplierStatus,
|
|
completePurchaserSupplierInspectionBatch,
|
|
updatePurchaseOrderStatus,
|
|
uploadPurchaseDirectDeliveryPhoto,
|
|
fetchOrderEntryCustomers,
|
|
fetchOrderEntryQuotePrices,
|
|
searchOrderEntrySkus,
|
|
upsertOrderEntryQuoteCosts,
|
|
submitOrderEntryOrder,
|
|
submitOrderEntryOrderWithConfirm,
|
|
fetchOrderEntryDetail,
|
|
updateOrderEntryOrder,
|
|
fetchCustomerOrderPrefill,
|
|
fetchCustomerOrderBudget,
|
|
parseCustomerOrder,
|
|
fetchOrderCategories,
|
|
fetchCustomerMappingSkus,
|
|
createOrderCategory,
|
|
fetchProcessingTasks,
|
|
fetchStandaloneProcessingSkuOptions,
|
|
createStandaloneProcessingTask,
|
|
pickDemandSheetMaterial,
|
|
skipWarehouseDemandPurchase,
|
|
startProcessingTask,
|
|
completeProcessingWork,
|
|
uploadProcessingInspectPhoto,
|
|
submitProcessingInspection,
|
|
fetchNotifications,
|
|
markAllNotificationsRead,
|
|
fetchOrdersManagement,
|
|
fetchOrderManageDetail,
|
|
searchOrderManageSkus,
|
|
resolveOrderManageCatalogProduct,
|
|
updateOrderManage,
|
|
advanceOrderManage,
|
|
deleteOrderManage,
|
|
searchProductTrace,
|
|
fetchProductTrace,
|
|
fetchUnits,
|
|
fetchFreeCostTypes,
|
|
fetchFreeCostSettings,
|
|
addFreeCostType,
|
|
fetchFreeCostEntries,
|
|
createFreeCostEntry,
|
|
extractFreeCostVoucherAmount,
|
|
uploadFreeCostVoucher,
|
|
extractFreeCostInvoice,
|
|
saveFreeCostInvoice,
|
|
uploadFreeCostInvoice,
|
|
};
|