289 lines
8.0 KiB
Vue
289 lines
8.0 KiB
Vue
<script setup lang="ts">
|
||
/** 批量编辑分类对话框(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」):
|
||
* 京东数据库页勾选商品(翻页累计,由页面持有勾选集)→ 本对话框选目标分类或移出分类 →
|
||
* 一次批量归类。归属写「本组」的归属行(biz_jd_product_group_assign,V203 一组一商品一行),
|
||
* 归类不置人工编辑锁(采集照常更新价格/库存)。本组无分类时只有提示不给提交
|
||
* (移出对未分类行是无谓操作),引导去工具栏「分类管理」新建(2026-11-17 独立页并回本页)。 */
|
||
import { computed, ref, watch } from 'vue'
|
||
import { batchAssignJdProductGroup, type JdProductGroup } from './jd-product-api.ts'
|
||
import { requestErrorMessage } from '../../api/envelope.ts'
|
||
|
||
const props = defineProps<{
|
||
visible: boolean
|
||
/** 当前数据权限分组(归类的落点组;V203 同一商品在其他组可另归一类)。 */
|
||
ownerGroupId: number
|
||
ownerGroupName: string
|
||
/** 当前分组的分类选项(含商品数徽标;由页面在打开时刷新)。 */
|
||
categories: JdProductGroup[]
|
||
/** 页面持有的勾选集(跨页累计),展开成 id 数组传入。 */
|
||
selectedIds: number[]
|
||
}>()
|
||
|
||
const emit = defineEmits<{ (event: 'close'): void; (event: 'done', updated: number, targetName: string | null): void }>()
|
||
|
||
/** 选中的目标分类 id;0=移出分类(回到未分类)。 */
|
||
const pickedId = ref(0)
|
||
const assigning = ref(false)
|
||
const errorText = ref('')
|
||
|
||
const picked = computed(() => props.categories.find((group) => group.id === pickedId.value) || null)
|
||
const confirmText = computed(() => (picked.value ? `归入「${picked.value.name}」` : '移出分类'))
|
||
/** 提交条件:有勾选、未在提交中,且选了目标分类(pickedId>0)或选了移出(pickedId=0,
|
||
* 但本组得有分类可移——全组无分类时移出是无谓操作,整对话框只留提示)。 */
|
||
const canSubmit = computed(() => props.selectedIds.length > 0 && !assigning.value
|
||
&& (picked.value ? true : props.categories.length > 0))
|
||
|
||
watch(
|
||
() => props.visible,
|
||
(visible) => {
|
||
if (visible) {
|
||
pickedId.value = 0
|
||
errorText.value = ''
|
||
}
|
||
},
|
||
)
|
||
|
||
async function submit(): Promise<void> {
|
||
if (!canSubmit.value) return
|
||
const target = picked.value
|
||
assigning.value = true
|
||
errorText.value = ''
|
||
try {
|
||
// target null=移出分类(groupId 传 null,后端只解挂本组归属行)。
|
||
const updated = await batchAssignJdProductGroup(
|
||
props.selectedIds,
|
||
target ? target.id : null,
|
||
props.ownerGroupId,
|
||
)
|
||
emit('done', updated, target ? target.name : null)
|
||
emit('close')
|
||
} catch (error) {
|
||
errorText.value = requestErrorMessage(error) || '批量归类失败'
|
||
} finally {
|
||
assigning.value = false
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
|
||
<div class="batch-modal">
|
||
<div class="modal-head">
|
||
<h3>批量编辑分类<span v-if="ownerGroupName" class="modal-sub">· {{ ownerGroupName }}</span></h3>
|
||
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
|
||
</div>
|
||
<p class="modal-tip">
|
||
已勾选 {{ selectedIds.length }} 个商品(翻页累计)。选目标分类后确认;
|
||
归类只记在分类归属上,不影响采集对价格/库存的更新。
|
||
</p>
|
||
<p v-if="errorText" class="group-error">{{ errorText }}</p>
|
||
|
||
<div v-if="!categories.length" class="batch-empty">本组暂无分类,先用工具栏「分类管理」新建一个</div>
|
||
<ul v-else class="option-list">
|
||
<li
|
||
v-for="group in categories"
|
||
:key="group.id"
|
||
class="option-row"
|
||
:class="{ active: pickedId === group.id }"
|
||
@click="pickedId = group.id"
|
||
>
|
||
<span class="option-radio" aria-hidden="true"></span>
|
||
<span class="option-name" :title="group.name">{{ group.name }}</span>
|
||
<span class="option-meta">{{ group.productCount }}</span>
|
||
</li>
|
||
<li class="option-row option-detach" :class="{ active: pickedId === 0 }" @click="pickedId = 0">
|
||
<span class="option-radio" aria-hidden="true"></span>
|
||
<span class="option-name">移出分类</span>
|
||
<span class="option-meta">回到未分类</span>
|
||
</li>
|
||
</ul>
|
||
|
||
<div class="modal-foot">
|
||
<button class="btn btn-secondary" type="button" @click="emit('close')">取消</button>
|
||
<button class="btn" type="button" :disabled="!canSubmit" @click="submit">
|
||
{{ assigning ? '提交中...' : confirmText }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.modal-mask {
|
||
position: fixed;
|
||
inset: 0;
|
||
z-index: 2800;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 40px 20px;
|
||
background: rgba(45, 66, 86, 0.36);
|
||
backdrop-filter: blur(6px);
|
||
}
|
||
.batch-modal {
|
||
display: flex;
|
||
flex-direction: column;
|
||
width: min(430px, 100%);
|
||
max-height: 80vh;
|
||
padding: 18px 20px 20px;
|
||
border: 1px solid #c7d7e5;
|
||
border-radius: 14px;
|
||
background: #ffffff;
|
||
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
|
||
}
|
||
.modal-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
.modal-head h3 {
|
||
margin: 0;
|
||
font-size: 15px;
|
||
font-weight: 650;
|
||
color: #24384d;
|
||
}
|
||
.modal-sub {
|
||
margin-left: 6px;
|
||
color: #5b6f83;
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
}
|
||
.modal-close {
|
||
width: 30px;
|
||
height: 30px;
|
||
border: 1px solid transparent;
|
||
border-radius: 9px;
|
||
background: none;
|
||
color: #5b6f83;
|
||
font-size: 20px;
|
||
line-height: 1;
|
||
cursor: pointer;
|
||
}
|
||
.modal-close:hover {
|
||
border-color: #cbd9e6;
|
||
background: #eef4fa;
|
||
color: #24384d;
|
||
}
|
||
.modal-tip {
|
||
margin: 8px 0 10px;
|
||
color: #8293a5;
|
||
font-size: 12.5px;
|
||
line-height: 1.5;
|
||
}
|
||
.group-error {
|
||
margin: 0 0 8px;
|
||
padding: 10px 12px;
|
||
border: 1px solid #f0c9c2;
|
||
border-radius: 10px;
|
||
background: #fdf1ef;
|
||
color: #a04432;
|
||
font-size: 13px;
|
||
}
|
||
.batch-empty {
|
||
padding: 26px 12px;
|
||
border: 1px dashed #cbd9e6;
|
||
border-radius: 10px;
|
||
color: #8293a5;
|
||
font-size: 13px;
|
||
text-align: center;
|
||
}
|
||
.option-list {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow-y: auto;
|
||
margin: 0;
|
||
padding: 0;
|
||
list-style: none;
|
||
border-top: 1px solid #e7eef5;
|
||
}
|
||
.option-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
padding: 10px 8px;
|
||
border-bottom: 1px solid #e7eef5;
|
||
font-size: 13.5px;
|
||
cursor: pointer;
|
||
}
|
||
.option-row:hover {
|
||
background: #f1f7fb;
|
||
}
|
||
/* 点亮=归类目标:与旧弹窗左栏同款左缘蓝条。 */
|
||
.option-row.active {
|
||
background: #e8f1fa;
|
||
box-shadow: inset 3px 0 0 #4f78a5;
|
||
}
|
||
.option-radio {
|
||
flex: none;
|
||
width: 14px;
|
||
height: 14px;
|
||
border: 1.6px solid #9fb7cd;
|
||
border-radius: 50%;
|
||
background: #ffffff;
|
||
}
|
||
.option-row.active .option-radio {
|
||
border-color: #4f78a5;
|
||
background: radial-gradient(circle, #4f78a5 0 4px, #ffffff 4.6px);
|
||
}
|
||
.option-name {
|
||
flex: 1;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
color: #24384d;
|
||
}
|
||
.option-detach .option-name {
|
||
color: #a04432;
|
||
}
|
||
.option-meta {
|
||
flex: none;
|
||
min-width: 22px;
|
||
padding: 1px 7px;
|
||
border-radius: 9px;
|
||
background: #eef4fa;
|
||
color: #4e6479;
|
||
font-size: 12px;
|
||
text-align: center;
|
||
white-space: nowrap;
|
||
}
|
||
.option-detach .option-meta {
|
||
background: transparent;
|
||
color: #8293a5;
|
||
}
|
||
.modal-foot {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
gap: 10px;
|
||
margin-top: 14px;
|
||
}
|
||
.btn {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
min-height: 38px;
|
||
padding: 7px 16px;
|
||
border: 1px solid #4f78a5;
|
||
border-radius: 9px;
|
||
background: linear-gradient(135deg, #5f85ad, #4f78a5);
|
||
color: #ffffff;
|
||
font-family: inherit;
|
||
font-size: 13px;
|
||
cursor: pointer;
|
||
}
|
||
.btn:disabled {
|
||
cursor: not-allowed;
|
||
opacity: 0.6;
|
||
}
|
||
.btn-secondary {
|
||
background: #ffffff;
|
||
color: #5b6f83;
|
||
border-color: #c7d7e5;
|
||
}
|
||
.btn-secondary:hover:not(:disabled) {
|
||
color: #2f5d8b;
|
||
border-color: #95b1cb;
|
||
background: #edf5fb;
|
||
}
|
||
</style>
|