diff --git a/deploy.sh b/deploy.sh index 52bd99e7..5225d5a3 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,40 +1,94 @@ #!/bin/bash +set -eu # --- 配置 --- USER="webdev" IP="112.124.21.102" # 服务器 IP -BASE_PATH="/www/wwwroot/web" # 请修改为您的项目在服务器上的存放路径 -RELEASE_NAME="v$(date +'%Y%m%d_%H%M%S')" # 生成版本号:如 v20260328_1445 +BASE_PATH="/www/wwwroot/web" # 项目在服务器上的存放路径 +RELEASE_NAME="v$(date +'%Y%m%d_%H%M%S')_$$" # 版本号(带 PID,避免并发/重复发布冲突) LOCAL_DIST="./dist" +KEEP_RELEASES=5 # 服务器上保留的最近版本数 +SITE_HOST="wms.wms.gztbyc.com" # 发版后健康检查域名 # SSH 密钥提示:请确保本地已将 id_ed25519.pub 添加到服务器的 ~/.ssh/authorized_keys # 密钥内容:ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICJtwa+MFLQEgkEbcGQ6dkQOiFydRvjVeidJ/7uBsF2e 3313488199@qq.com - SSH_KEY="$HOME/.ssh/id_ed25519_admin" SSH_OPTS="-i $SSH_KEY -o StrictHostKeyChecking=no" +REMOTE_RELEASE="$BASE_PATH/releases/$RELEASE_NAME" + +# 无论成功失败都清理本地临时压缩包 +trap 'rm -f dist.tar.gz' EXIT + echo "🚀 开始发布版本: $RELEASE_NAME" -# 1. 本地打包 +# 1. 本地打包(失败立即中止,防止把坏产物发到线上) npm run build -# 2. 压缩并上传 -tar -czf dist.tar.gz -C $LOCAL_DIST . -ssh $SSH_OPTS $USER@$IP "mkdir -p $BASE_PATH/releases/$RELEASE_NAME" -scp $SSH_OPTS dist.tar.gz $USER@$IP:$BASE_PATH/releases/$RELEASE_NAME +# 2. 校验本地产物完整性 +if [ ! -f "$LOCAL_DIST/index.html" ] || [ ! -d "$LOCAL_DIST/assets" ]; then + echo "❌ 本地构建产物不完整(缺少 index.html 或 assets),中止发布" + exit 1 +fi -# 3. 远程解压、更新软链接、清理旧版本 -ssh $SSH_OPTS $USER@$IP << EOF - cd $BASE_PATH/releases/$RELEASE_NAME - tar -xzf dist.tar.gz - rm dist.tar.gz - - # 原子化更新软链接:先创建临时链接再重命名(防止切换瞬间服务中断) - ln -sfn $BASE_PATH/releases/$RELEASE_NAME $BASE_PATH/current_new - mv -Tf $BASE_PATH/current_new $BASE_PATH/current +# 3. 压缩并上传到独立的新版本目录(全程不触碰当前运行目录) +tar -czf dist.tar.gz -C "$LOCAL_DIST" . +ssh $SSH_OPTS $USER@$IP "mkdir -p '$REMOTE_RELEASE'" +scp $SSH_OPTS dist.tar.gz $USER@$IP:"$REMOTE_RELEASE/dist.tar.gz" - # 只保留最近 5 个版本,删除更旧的 - cd $BASE_PATH/releases && ls -t | tail -n +6 | xargs rm -rf -EOF +# 4. 远程:解压 → 校验 → 补齐旧资源 → 原子切换 → 健康检查 → 清理 +ssh $SSH_OPTS $USER@$IP "RELEASE='$REMOTE_RELEASE' BASE='$BASE_PATH' KEEP=$KEEP_RELEASES HOST='$SITE_HOST' bash -s" << 'REMOTE_EOF' +set -euo pipefail -echo "✨ 发布成功!当前版本: $RELEASE_NAME" \ No newline at end of file +cd "$RELEASE" + +# 4.1 解压 +tar -xzf dist.tar.gz +rm -f dist.tar.gz + +# 4.2 完整性校验:新版本必须完整,残缺则取消切换(当前线上版本不受影响) +if [ ! -s index.html ]; then + echo "❌ 新版本 index.html 缺失或为空,取消切换" + exit 1 +fi +missing="" +for ref in $(grep -oE '/assets/[A-Za-z0-9._-]+\.(js|css)' index.html | sort -u || true); do + [ -f ".$ref" ] || missing="$missing $ref" +done +if [ -n "$missing" ]; then + echo "❌ 新版本缺少以下资源,取消切换:$missing" + exit 1 +fi + +# 4.3 补齐旧版本静态资源(无感切换的关键) +# 把最近几个历史版本中、本版本缺失的文件(旧 chunk、hikvision、logo 等)合并进新版本, +# 保证切换后正在使用旧版本页面的用户,动态 import 旧资源依然能找到,不会 404。 +for src in $(ls -td "$BASE"/releases/*/ 2>/dev/null | head -n "$((KEEP + 1))" || true); do + [ -d "$src" ] || continue + [ "$(readlink -f "$src" 2>/dev/null)" = "$(pwd)" ] && continue + cp -rn "$src/." "$RELEASE/" 2>/dev/null || true +done + +# 4.4 原子切换软链接(先建临时链接再改名,切换瞬间服务不中断) +ln -sfn "$RELEASE" "$BASE/current_new" +mv -Tf "$BASE/current_new" "$BASE/current" + +# 4.5 健康检查(仅提示,不阻断发布) +if command -v curl >/dev/null 2>&1; then + code="$(curl -skL -o /dev/null -w '%{http_code}' -H "Host: $HOST" "https://127.0.0.1/" 2>/dev/null || true)" + echo "ℹ️ 新版本首页 HTTP 状态码: ${code:-未知}" +fi + +# 4.6 清理旧版本:只保留最近 KEEP 个,且绝不删除 current 指向的版本 +CURRENT_TARGET="$(readlink -f "$BASE/current" 2>/dev/null || true)" +count=0 +for d in $(ls -t "$BASE/releases" 2>/dev/null || true); do + count=$((count+1)) + [ "$count" -le "$KEEP" ] && continue + target="$(readlink -f "$BASE/releases/$d" 2>/dev/null || echo "$BASE/releases/$d")" + [ "$target" = "$CURRENT_TARGET" ] && continue + rm -rf "$BASE/releases/$d" +done +REMOTE_EOF + +echo "✨ 发布成功!当前版本: $RELEASE_NAME" diff --git a/req.txt b/req.txt deleted file mode 100644 index ef572e83..00000000 --- a/req.txt +++ /dev/null @@ -1,36 +0,0 @@ -stock.warehouse.search自动匹配商品,返回数据: -{ - "flag": "success", - "code": 200, - "message": "ok", - "data": [ - { - "id": 150181, - "item_code": null, - "goods_code": "581229", - "item_name": "自然派猪肉脯炭烧100g", - "sku_property": "", - "stock_unit": "个", - "quantity": 0, - "locked_quantity": 0, - "brand_name": null, - "item_type": "ZC", - "inbound_min_days": null, - "outbound_min_days": null, - "shelf_life_days": null, - "remaining_threshold_days": null, - "is_shelf_life_mgmt": false, - "gross_weight": "130.00", - "barcodes": [ - "6945309363606" - ], - "store_stock": { - "store_id": 1000195, - "store_remask": "盛昇" - }, - "is_batch_mgmt_enabled": false - } - ], - "total": 1, - "timestamp": 1781342370 -} \ No newline at end of file diff --git a/rollback.sh b/rollback.sh index cc109dbf..ae0384e9 100644 --- a/rollback.sh +++ b/rollback.sh @@ -1,22 +1,31 @@ #!/bin/bash +set -eu -USER="root" -IP="1.2.3.4" # 请修改为您的服务器实际 IP -BASE_PATH="/www/wwwroot/my-project" # 请修改为您的项目在服务器上的存放路径 +USER="webdev" +IP="112.124.21.102" # 服务器 IP +BASE_PATH="/www/wwwroot/web" # 项目在服务器上的存放路径 -# SSH 密钥提示:ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICJtwa+MFLQEgkEbcGQ6dkQOiFydRvjVeidJ/7uBsF2e 3313488199@qq.com +# SSH 密钥提示:请确保本地已将 id_ed25519.pub 添加到服务器的 ~/.ssh/authorized_keys +# 密钥内容:ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICJtwa+MFLQEgkEbcGQ6dkQOiFydRvjVeidJ/7uBsF2e 3313488199@qq.com +SSH_KEY="$HOME/.ssh/id_ed25519_admin" +SSH_OPTS="-i $SSH_KEY -o StrictHostKeyChecking=no" echo "⏪ 正在回滚到上一个版本..." -ssh $USER@$IP << EOF - # 获取 releases 目录下按时间排序的倒数第二个版本 - PREVIOUS_VERSION=$(ls -dt $BASE_PATH/releases/*/ | sed -n '2p') - - if [ -z "$PREVIOUS_VERSION" ]; then - echo "❌ 找不到可回滚的历史版本" - exit 1 - fi +ssh $SSH_OPTS $USER@$IP "BASE='$BASE_PATH' bash -s" << 'REMOTE_EOF' +set -euo pipefail - ln -sfn $PREVIOUS_VERSION $BASE_PATH/current - echo "✅ 已回滚至: $PREVIOUS_VERSION" -EOF \ No newline at end of file +# 获取 releases 目录下按时间排序的倒数第二个版本(当前版本的上一版) +PREVIOUS_VERSION="$(ls -dt "$BASE"/releases/*/ 2>/dev/null | sed -n '2p' || true)" + +if [ -z "$PREVIOUS_VERSION" ]; then + echo "❌ 找不到可回滚的历史版本" + exit 1 +fi + +# 原子切换软链接(与发版脚本一致,切换瞬间服务不中断) +ln -sfn "$PREVIOUS_VERSION" "$BASE/current_new" +mv -Tf "$BASE/current_new" "$BASE/current" + +echo "✅ 已回滚至: $PREVIOUS_VERSION" +REMOTE_EOF diff --git a/server.txt b/server.txt new file mode 100644 index 00000000..30350c54 --- /dev/null +++ b/server.txt @@ -0,0 +1,84 @@ +server +{ + listen 80; + listen 443 ssl; + listen 443 quic; + http2 on; + server_name wms.wms.gztbyc.com; + index index.html index.htm default.htm default.html; + root /www/wwwroot/web/current; + include /www/server/panel/vhost/nginx/extension/wms.wms.gztbyc.com/*.conf; + #CERT-APPLY-CHECK--START + # 用于SSL证书申请时的文件验证相关配置 -- 请勿删除并保持这段设置在优先级高的位置 + include /www/server/panel/vhost/nginx/well-known/wms.wms.gztbyc.com.conf; + #CERT-APPLY-CHECK--END + + #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则 + #error_page 404/404.html; + #HTTP_TO_HTTPS_START + set $isRedcert 1; + if ($server_port != 443) { + set $isRedcert 2; + } + if ( $uri ~ /\.well-known/ ) { + set $isRedcert 1; + } + if ($isRedcert != 1) { + rewrite ^(/.*)$ https://$host$1 permanent; + } + #HTTP_TO_HTTPS_END + ssl_certificate /www/server/panel/vhost/cert/wms.wms.gztbyc.com/fullchain.pem; + ssl_certificate_key /www/server/panel/vhost/cert/wms.wms.gztbyc.com/privkey.pem; + ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; + ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; + ssl_prefer_server_ciphers on; + ssl_session_tickets on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; + add_header Strict-Transport-Security "max-age=31536000"; + add_header Alt-Svc 'quic=":443"; h3=":443"; h3-29=":443"; h3-27=":443";h3-25=":443"; h3-T050=":443"; h3-Q050=":443";h3-Q049=":443";h3-Q048=":443"; h3-Q046=":443"; h3-Q043=":443"'; + error_page 497 https://$host$request_uri; + + #SSL-END + + #ERROR-PAGE-START 错误页配置,可以注释、删除或修改 + #error_page 404 /404.html; + #error_page 502 /502.html; + #ERROR-PAGE-END + + #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效 + include /www/server/panel/vhost/rewrite/html_wms.wms.gztbyc.com.conf; + #REWRITE-END + + #禁止访问的文件或目录 + location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md) + { + return 404; + } + + #一键申请SSL证书验证目录相关设置 + location ~ \.well-known{ + allow all; + } + + #禁止在证书验证目录放入敏感文件 + if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) { + return 403; + } + + location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$ + { + expires 30d; + error_log /dev/null; + access_log /dev/null; + } + + location ~ .*\\.(js|css)?$ + { + expires 12h; + error_log /dev/null; + access_log /dev/null; + } + access_log /www/wwwlogs/wms.wms.gztbyc.com.log; + error_log /www/wwwlogs/wms.wms.gztbyc.com.error.log; +} \ No newline at end of file diff --git a/src/api/order/order.ts b/src/api/order/order.ts index 583af3a3..6c36dc49 100644 --- a/src/api/order/order.ts +++ b/src/api/order/order.ts @@ -5,6 +5,8 @@ const v = '1.0' /** order.wave.batchList 的 where 白名单(禁止 warehouse_id / warehouseId) */ export type WaveBatchListWhere = { wave_id?: number | string + /** 货主(店铺)ID 筛选 */ + store_id?: number | string wave_no?: string wave_type?: number wave_status?: number diff --git a/src/api/setting.warehouse/settingwarehouse.ts b/src/api/setting.warehouse/settingwarehouse.ts index 0595d7df..77a0346b 100644 --- a/src/api/setting.warehouse/settingwarehouse.ts +++ b/src/api/setting.warehouse/settingwarehouse.ts @@ -74,6 +74,8 @@ export type SettingWarehouseSubjectConfig = SettingWarehouseSenderConfig & { group_wave_prefix?: string /** 自动分配快递排除备注:订单备注命中任一关键字时,跳过自动分配快递 */ auto_allocate_express_exclude_remarks?: string[] + /** 默认库位(库位ID,未配置时为 null) */ + default_location_id?: number | null [key: string]: unknown } @@ -148,6 +150,15 @@ export function normalizeWarehouseSubjectConfig( base.group_order_pack_max_minutes = Number.isFinite(groupPackMax) && groupPackMax > 0 ? Math.trunc(groupPackMax) : 40 + // 默认库位(库位ID,未配置时为 null) + const locIdRaw = base.default_location_id + if (locIdRaw === undefined || locIdRaw === null || locIdRaw === '') { + base.default_location_id = null + } else { + const locId = Number(locIdRaw) + base.default_location_id = Number.isFinite(locId) ? Math.trunc(locId) : null + } + return base as SettingWarehouseSubjectConfig } diff --git a/src/api/storage.stockout/stockout.ts b/src/api/storage.stockout/stockout.ts index 823bea9c..44e00751 100644 --- a/src/api/storage.stockout/stockout.ts +++ b/src/api/storage.stockout/stockout.ts @@ -72,15 +72,32 @@ export const stockoutListItems = (data: StockoutListItemsParams) => { // ── storage.stockout.toOrder ── export type StockoutToOrderReceiverInfo = { + /** 收件人姓名(必填) */ name?: string + /** 收件人移动电话(与 tel 至少一项) */ mobile?: string + /** 收件人固定电话(与 mobile 至少一项) */ tel?: string - province?: string - city?: string - area?: string - town?: string - detailAddress?: string + /** 收件人公司名称 */ + company?: string + /** 收件人电子邮箱 */ + email?: string + /** 国家二字码 */ + countryCode?: string + /** 收件人证件号 */ + receiver_id?: string + /** 邮编 */ zipCode?: string + /** 省份(必填) */ + province?: string + /** 城市(必填) */ + city?: string + /** 区/县(必填) */ + area?: string + /** 镇/街道(必填) */ + town?: string + /** 详细地址(必填) */ + detailAddress?: string } export type StockoutToOrderParams = { @@ -88,7 +105,10 @@ export type StockoutToOrderParams = { id: number /** 新订单号,不传自动生成(SK 前缀) */ delivery_order_code?: string - /** 收件人信息,不传时新订单收货信息为空 */ + /** + * 收件人信息,不传时回填出库单已存的收件人字段。 + * 收货信息必填:name、(tel/mobile) 至少一项、省市区镇详细地址,缺失则报错不能转订单 + */ receiverInfo?: StockoutToOrderReceiverInfo } @@ -235,3 +255,91 @@ export const stockoutListLogs = (data: StockoutListLogsParams) => { data: data }) } + +// ── storage.stockout.updateInfo ── + +export type StockoutUpdateInfoParams = { + /** 出库单ID(必填) */ + id: number + /** 收件人姓名 */ + name?: string + /** 收件人固定电话 */ + tel?: string + /** 收件人移动电话 */ + mobile?: string + /** 收件人公司名称 */ + company?: string + /** 收件人电子邮箱 */ + email?: string + /** 邮编 */ + zipCode?: string + /** 国家二字码 */ + countryCode?: string + /** 省份 */ + province?: string + /** 城市 */ + city?: string + /** 区/县 */ + area?: string + /** 镇/街道 */ + town?: string + /** 详细地址 */ + detailAddress?: string + /** 收件人证件号 */ + receiver_id?: string + /** 快递公司编码,传入后自动解析 express_name */ + express_code?: string + /** 来源平台编码 */ + source_platform_code?: string + /** 来源平台名称 */ + source_platform_name?: string +} + +export type StockoutUpdateInfoResponse = { + /** 更新后的出库单完整记录(wms_order_stockout 表字段,含 receiver_*、express_*、source_platform_* 等) */ + data?: Record +} + +/** 修改出库单信息:收件人(name/tel/mobile/company/email 等)、地址、快递编码、来源平台。未传入的字段不修改;仅 CREATED/PENDING 状态允许修改 */ +export const stockoutUpdateInfo = (data: StockoutUpdateInfoParams) => { + return request({ + url: `/system`, + method: 'post', + params: { + method: 'storage.stockout.updateInfo', + v, + timestamp: new Date().getTime() + }, + data: data + }) +} + +// ── storage.stockout.cancel ── + +export type StockoutCancelParams = { + /** 出库单ID(必填) */ + id: number +} + +export type StockoutCancelResponse = { + /** 出库单ID */ + id: number + /** 出库单号 */ + stockout_order_code: string + /** 取消后状态(CANCELLED) */ + order_status: string +} + +/** 取消出库单:仅 CREATED/PENDING 状态允许取消;事务内释放库存锁定并写操作日志(STOCKOUT_CANCEL);TRANSFERRED/COMPLETED 状态禁止取消 */ +export const stockoutCancel = (data: StockoutCancelParams) => { + return request({ + url: `/system`, + method: 'post', + params: { + method: 'storage.stockout.cancel', + v, + timestamp: new Date().getTime() + }, + data: data + }) +} diff --git a/src/views/express/returnUnpackwork/index.vue b/src/views/express/returnUnpackwork/index.vue index 47e5cc9c..45396bd8 100644 --- a/src/views/express/returnUnpackwork/index.vue +++ b/src/views/express/returnUnpackwork/index.vue @@ -57,6 +57,7 @@ class="barcode-qty-input" :disabled="!createResult?.id" title="本次扫码录入数量(一次性使用,扫描后自动重置为1)" + @keyup.enter="handleScanQtyEnter" /> @@ -266,7 +267,7 @@ @@ -295,6 +296,7 @@ × @@ -495,7 +497,7 @@ maxlength="500" show-word-limit placeholder="输入新的备注内容,保存后进入下拉选项并应用到当前商品行" - @keyup.enter.ctrl="confirmAddRemarkOption" + @keyup.enter="confirmAddRemarkOption" /> + + +
+ + + + 收件人信息 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 地址信息 + + + + + + + + + + + + + + + + + + + + + + + + + 快递与平台(可选) + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + + + + + + + + +
+ + +
@@ -241,7 +444,7 @@ import { safeInvoke } from '@/utils/safe-invoke' import * as XLSX from 'xlsx' import * as indexApi from '@/api/index/index' import * as stockoutApi from '@/api/storage.stockout/stockout' //现有的对应API -import type { StockoutToOrderParams } from '@/api/storage.stockout/stockout' +import type { StockoutToOrderParams, StockoutUpdateInfoParams } from '@/api/storage.stockout/stockout' import { availableFields, entryColums, @@ -354,6 +557,16 @@ function resetToOrderForm() { function openToOrderDialog(row: any) { toOrderTargetRow.value = row resetToOrderForm() + // 回填当前行已有收货信息(storage.stockout.list 的 receiver_* → receiverInfo) + toOrderForm.receiverInfo.name = String(row?.receiver_name ?? '') + toOrderForm.receiverInfo.mobile = String(row?.receiver_mobile ?? '') + toOrderForm.receiverInfo.tel = String(row?.receiver_tel ?? '') + toOrderForm.receiverInfo.zipCode = String(row?.receiver_zip_code ?? '') + toOrderForm.receiverInfo.province = String(row?.receiver_province ?? '') + toOrderForm.receiverInfo.city = String(row?.receiver_city ?? '') + toOrderForm.receiverInfo.area = String(row?.receiver_area ?? '') + toOrderForm.receiverInfo.town = String(row?.receiver_town ?? '') + toOrderForm.receiverInfo.detailAddress = String(row?.receiver_detail_address ?? '') toOrderDialogVisible.value = true } @@ -394,6 +607,229 @@ async function handleToOrderSubmit() { } } +// ── 修改出库单信息(storage.stockout.updateInfo)── +const updateInfoDialogVisible = ref(false) +const updateInfoLoading = ref(false) +const updateInfoTargetRow = ref(null) +const updateInfoForm = reactive({ + name: '', + tel: '', + mobile: '', + company: '', + email: '', + zipCode: '', + countryCode: '', + province: '', + city: '', + area: '', + town: '', + detailAddress: '', + receiver_id: '', + express_code: '', + source_platform_code: '', + source_platform_name: '' +}) + +function resetUpdateInfoForm() { + updateInfoForm.name = '' + updateInfoForm.tel = '' + updateInfoForm.mobile = '' + updateInfoForm.company = '' + updateInfoForm.email = '' + updateInfoForm.zipCode = '' + updateInfoForm.countryCode = '' + updateInfoForm.province = '' + updateInfoForm.city = '' + updateInfoForm.area = '' + updateInfoForm.town = '' + updateInfoForm.detailAddress = '' + updateInfoForm.receiver_id = '' + updateInfoForm.express_code = '' + updateInfoForm.source_platform_code = '' + updateInfoForm.source_platform_name = '' +} + +function openUpdateInfoDialog(row: any) { + updateInfoTargetRow.value = row + resetUpdateInfoForm() + // 回填当前行已有数据(列表字段 receiver_* → 表单字段) + updateInfoForm.name = String(row?.receiver_name ?? '') + updateInfoForm.tel = String(row?.receiver_tel ?? '') + updateInfoForm.mobile = String(row?.receiver_mobile ?? '') + updateInfoForm.company = String(row?.receiver_company ?? '') + updateInfoForm.email = String(row?.receiver_email ?? '') + updateInfoForm.zipCode = String(row?.receiver_zip_code ?? '') + updateInfoForm.countryCode = String(row?.receiver_country_code ?? '') + updateInfoForm.province = String(row?.receiver_province ?? '') + updateInfoForm.city = String(row?.receiver_city ?? '') + updateInfoForm.area = String(row?.receiver_area ?? '') + updateInfoForm.town = String(row?.receiver_town ?? '') + updateInfoForm.detailAddress = String(row?.receiver_detail_address ?? '') + updateInfoForm.receiver_id = String(row?.receiver_id ?? '') + updateInfoForm.express_code = String(row?.express_code ?? '') + updateInfoForm.source_platform_code = String(row?.source_platform_code ?? '') + updateInfoForm.source_platform_name = String(row?.source_platform_name ?? '') + // 加载快递/平台下拉选项(后端编码列表),回填值自动选中对应编码选项 + void loadUpdateInfoSelectOptions() + updateInfoDialogVisible.value = true +} + +// ── 修改出库单信息下拉选项(快递 / 来源平台)── +const updateInfoExpressOptions = ref>([]) +const updateInfoPlatformOptions = ref>([]) + +async function loadUpdateInfoSelectOptions() { + try { + const [expressRes, platformRes]: any = await Promise.all([ + indexApi.getExpressList({ systemOnly: 'true' }), + indexApi.getPlatformList({ systemOnly: 'true' }) + ]) + const expressRaw = expressRes?.data?.list || expressRes?.data || [] + updateInfoExpressOptions.value = (Array.isArray(expressRaw) ? expressRaw : []) + .map((item: any) => { + const code = String(item?.express_code || item?.code || item?.express?.code || '').trim() + const name = String(item?.name || item?.express_name || item?.express?.name || '').trim() + return { value: code, label: name ? `${code} - ${name}` : code } + }) + .filter((o) => !!o.value) + const platformRaw = platformRes?.data?.list || platformRes?.data || [] + updateInfoPlatformOptions.value = (Array.isArray(platformRaw) ? platformRaw : []) + .map((item: any) => { + const code = String(item?.code || item?.platform_code || '').trim() + const name = String(item?.name || item?.platform_name || '').trim() + return { value: code, label: name ? `${code} - ${name}` : code } + }) + .filter((o) => !!o.value) + } catch { + updateInfoExpressOptions.value = [] + updateInfoPlatformOptions.value = [] + } +} + +/** 选中来源平台编码时自动带出平台名称 */ +function handleSourcePlatformChange(val: string) { + if (!val) return + const opt = updateInfoPlatformOptions.value.find((o) => o.value === val) + if (opt) { + const sep = opt.label.indexOf(' - ') + updateInfoForm.source_platform_name = sep > -1 ? opt.label.slice(sep + 3) : opt.label + } +} + +async function handleUpdateInfoSubmit() { + const row = updateInfoTargetRow.value + if (!row) return + + // 只提交非空字段(未传入的字段后端不修改) + const payload: StockoutUpdateInfoParams = { id: row.id } + for (const [k, v] of Object.entries(updateInfoForm)) { + if (String(v || '').trim() !== '') { + ;(payload as Record)[k] = v + } + } + + updateInfoLoading.value = true + try { + const res: any = await stockoutApi.stockoutUpdateInfo(payload) + if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) { + ElMessage.success('出库单信息修改成功') + updateInfoDialogVisible.value = false + loadData() + } else { + ElMessage.error(res?.message || '修改失败') + } + } catch (e: any) { + ElMessage.error(e?.message || '修改失败') + } finally { + updateInfoLoading.value = false + } +} + +/** 单行取消出库单(storage.stockout.cancel) */ +async function handleSingleRowCancel(row: any) { + try { + await ElMessageBox.confirm( + `确定要取消出库单「${row.stockout_order_code || row.id}」吗?取消后将释放库存锁定。`, + '取消出库单', + { type: 'warning', confirmButtonText: '确认取消', cancelButtonText: '返回' } + ) + } catch { + return + } + + row._cancelLoading = true + try { + const res: any = await stockoutApi.stockoutCancel({ id: row.id }) + if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) { + ElMessage.success('出库单已取消') + loadData() + } else { + ElMessage.error(res?.message || '取消失败') + } + } catch (e: any) { + ElMessage.error(e?.message || '取消失败') + } finally { + row._cancelLoading = false + } +} + +// ── 更新运单号(storage.stockout.updateExpress)── +const updateExpressDialogVisible = ref(false) +const updateExpressLoading = ref(false) +const updateExpressTargetRow = ref(null) +const updateExpressForm = reactive({ + express_code: '', + express_codes: '' +}) + +function openUpdateExpressDialog() { + const rows = selectionRows.value + if (!rows.length) { + ElMessage.warning('请先选择要更新运单号的出库单') + return + } + if (rows.length > 1) { + ElMessage.warning('请选择单个出库单更新运单号') + return + } + const row = rows[0] + updateExpressTargetRow.value = row + updateExpressForm.express_code = String(row?.express_code ?? '') + updateExpressForm.express_codes = Array.isArray(row?.express_codes) + ? row.express_codes.join('\n') + : String(row?.express_codes ?? '') + updateExpressDialogVisible.value = true +} + +async function handleUpdateExpressSubmit() { + const row = updateExpressTargetRow.value + if (!row) return + const payload: any = { id: row.id } + const code = updateExpressForm.express_code.trim() + if (code) payload.express_code = code + const codes = updateExpressForm.express_codes + .split(/[,;\n]+/) + .map((s: string) => s.trim()) + .filter(Boolean) + if (codes.length) payload.express_codes = codes + + updateExpressLoading.value = true + try { + const res: any = await stockoutApi.stockoutUpdateExpress(payload) + if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) { + ElMessage.success('运单号更新成功') + updateExpressDialogVisible.value = false + loadData() + } else { + ElMessage.error(res?.message || '更新失败') + } + } catch (e: any) { + ElMessage.error(e?.message || '更新失败') + } finally { + updateExpressLoading.value = false + } +} + // ── 工具栏状态 ── const buttonLoadingMap = computed(() => ({ loading: loading.value, @@ -439,6 +875,7 @@ const toolbarActionMap: Record void> = { toggleDetailVisible: () => toggleDetailVisible(), handleCreateStockout: () => handleCreateStockout(), handleImport: () => handleImport(), + handleUpdateExpress: () => openUpdateExpressDialog(), handleOpenPrintDialog: () => { void handleOpenPrintDialog() }, confirmBatchCancel: () => { void confirmBatchCancel() } } @@ -786,8 +1223,21 @@ async function confirmBatchCancel() { } try { await ElMessageBox.confirm(`确定要批量作废 ${selectionRows.value.length} 个出库单吗?`, '确认', { type: 'warning' }) - // 调用 API - ElMessage.success('批量作废成功') + let successCount = 0 + let failCount = 0 + for (const row of selectionRows.value) { + try { + const res: any = await stockoutApi.stockoutCancel({ id: row.id }) + if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) { + successCount += 1 + } else { + failCount += 1 + } + } catch { + failCount += 1 + } + } + ElMessage.success(`批量作废完成:成功 ${successCount} 条${failCount ? `,失败 ${failCount} 条` : ''}`) loadData() } catch (e) {} } diff --git a/src/views/storage/stockout/stockout-config.ts b/src/views/storage/stockout/stockout-config.ts index 5ab73a4a..98fb9493 100644 --- a/src/views/storage/stockout/stockout-config.ts +++ b/src/views/storage/stockout/stockout-config.ts @@ -35,12 +35,20 @@ export const stockoutToolbarButtons: ToolbarButtonConfig[] = [ // size: 'small', // action: 'handleCreateStockout' // }, + // { + // key: 'import', + // label: '导入', + // category: 'action', + // size: 'small', + // action: 'handleImport' + // }, { - key: 'import', - label: '导入', + key: 'updateExpress', + label: '更新运单号', category: 'action', size: 'small', - action: 'handleImport' + disabledKey: 'hasNoSelection', + action: 'handleUpdateExpress' }, { key: 'print', @@ -111,12 +119,14 @@ export const statusConfig: Record = { PROCESSING: { text: '出库中', tagType: 'primary' }, COMPLETED: { text: '已完成', tagType: 'success' }, CANCELLED: { text: '已作废', tagType: 'danger' }, + TRANSFERRED: { text: '已转订单', tagType: 'warning' }, // 兼容旧小写 created: { text: '已创建', tagType: '' }, pending: { text: '待出库', tagType: 'warning' }, processing: { text: '出库中', tagType: 'primary' }, completed: { text: '已完成', tagType: 'success' }, - cancelled: { text: '已作废', tagType: 'danger' } + cancelled: { text: '已作废', tagType: 'danger' }, + transferred: { text: '已转订单', tagType: 'warning' } } // sync_status 实际值(接口返回大写;兼容旧小写与拼写) @@ -169,6 +179,20 @@ export function formatExpressCodes(row: any): string { return unique.map(escapeHtml).join('
') } +// 转单订单号列:从 extend_props.transferred_order_code 提取(转销售订单后的新订单号) +export function formatTransferredOrderCode(row: any): string { + const code = row?.extend_props?.transferred_order_code + return String(code ?? '').trim() || '--' +} + +// 省市区列:拼接 省/市/区县/乡镇,空则 -- +export function formatReceiverRegion(row: any): string { + const parts = [row?.receiver_province, row?.receiver_city, row?.receiver_area, row?.receiver_town] + .map((v) => String(v ?? '').trim()) + .filter(Boolean) + return parts.join(' ') || '--' +} + export const entryColums = [ { prop: 'stockout_order_code', label: '出库单号', width: '220', fixed: 'left', copyAction: 'copy' as const }, { prop: 'order_status', label: '出库状态', width: '100' }, @@ -176,12 +200,18 @@ export const entryColums = [ { prop: 'sync_message', label: '同步消息', minWidth: '140', showOverflowTooltip: true }, { prop: 'order_type', label: '单据类型', width: '100' }, { prop: 'source_type', label: '来源类型', width: '100' }, + { prop: 'store_name', label: '货主', minWidth: '140', formatter: (row: any) => String(row?.store_name || '').trim() || '--' }, + { prop: 'source_platform_name', label: '来源平台', width: '130', formatter: (row: any) => String(row?.source_platform_name || '').trim() || '--' }, + { prop: 'extend_props', label: '转单订单号', width: '180', formatter: (row: any) => formatTransferredOrderCode(row) }, { prop: 'qimen_owner_code', label: '奇门货主编码', width: '140' }, { prop: 'qimen_warehouse_code', label: '奇门仓库编码', width: '140' }, { prop: 'express_codes', label: '运单号', width: '140', formatter: (row: any) => formatExpressCodes(row) }, { prop: 'express_code', label: '快递编码', width: '110' }, { prop: 'express_name', label: '快递名称', width: '110' }, { prop: 'total_order_lines', label: '订单行数', width: '90' }, + { prop: 'receiver_name', label: '收件人', width: '110', formatter: (row: any) => String(row?.receiver_name || '').trim() || '--' }, + { prop: 'receiver_mobile', label: '手机号', width: '120', formatter: (row: any) => String(row?.receiver_mobile || '').trim() || '--' }, + { prop: 'receiver_province', label: '省市区', minWidth: '180', formatter: (row: any) => formatReceiverRegion(row) }, { prop: 'remark', label: '备注', minWidth: '150' }, { prop: 'order_create_time', label: '下单时间', width: '160', sortable: true, formatter: (row: any) => formatDateTime(row.order_create_time) }, { prop: 'created_at', label: '创建时间', width: '160', sortable: true, formatter: (row: any) => formatDateTime(row.created_at) }, @@ -230,7 +260,8 @@ export const availableFields: StockoutScanFieldConfig[] = [ { value: 'PENDING', label: '待出库' }, { value: 'PROCESSING', label: '出库中' }, { value: 'COMPLETED', label: '已完成' }, - { value: 'CANCELLED', label: '已作废' } + { value: 'CANCELLED', label: '已作废' }, + { value: 'TRANSFERRED', label: '已转订单' } ] }), stockoutScanWorkflowField({ @@ -254,15 +285,26 @@ export const availableFields: StockoutScanFieldConfig[] = [ }), ] -// 详情面板表单配置 +// 详情面板表单配置(修改出库单信息:storage.stockout.updateInfo 字段) export const detailpanel = [ { prop: 'stockout_order_code', label: '出库单号', type: 'input', disabled: true }, { prop: 'order_status', label: '出库状态', type: 'select', disabled: true }, - { prop: 'express_code', label: '运单号', type: 'input', disabled: false }, - { prop: 'express_codes', label: '运单号列表', type: 'textarea', disabled: false }, - { prop: 'qimen_owner_code', label: '奇门货主编码', type: 'input', disabled: true }, - { prop: 'qimen_warehouse_code', label: '奇门仓库编码', type: 'input', disabled: true }, - { prop: 'remark', label: '备注', type: 'textarea' }, + { prop: 'name', label: '收件人姓名', type: 'input', disabled: false }, + { prop: 'mobile', label: '手机号', type: 'input', disabled: false }, + { prop: 'tel', label: '电话', type: 'input', disabled: false }, + { prop: 'company', label: '公司', type: 'input', disabled: false }, + { prop: 'email', label: '邮箱', type: 'input', disabled: false }, + { prop: 'zipCode', label: '邮编', type: 'input', disabled: false }, + { prop: 'countryCode', label: '国家', type: 'input', disabled: false }, + { prop: 'receiver_id', label: '证件号', type: 'input', disabled: false }, + { prop: 'province', label: '省份', type: 'input', disabled: false }, + { prop: 'city', label: '城市', type: 'input', disabled: false }, + { prop: 'area', label: '区县', type: 'input', disabled: false }, + { prop: 'town', label: '乡镇', type: 'input', disabled: false }, + { prop: 'detailAddress', label: '详细地址', type: 'textarea', disabled: false }, + { prop: 'express_code', label: '快递编码', type: 'input', disabled: false }, + { prop: 'source_platform_code', label: '来源平台编码', type: 'input', disabled: false }, + { prop: 'source_platform_name', label: '来源平台名称', type: 'input', disabled: false }, ] export const productColumns = [ diff --git a/src/views/system/setting/basicManagement/index.vue b/src/views/system/setting/basicManagement/index.vue index 5e4899b3..bf551d42 100644 --- a/src/views/system/setting/basicManagement/index.vue +++ b/src/views/system/setting/basicManagement/index.vue @@ -417,6 +417,14 @@ const FALLBACK_FIELDS: NormalizedField[] = [ default: [], required: false, description: '订单备注命中任一关键字时,跳过自动分配快递,默认 [](不排除任何订单)' + }, + { + key: 'default_location_id', + label: '默认库位ID', + type: 'number', + min: 0, + precision: 0, + description: '默认库位(库位ID,未配置时为 null;须属于当前仓库且未删除、已启用)' } ]