fix(admin): simplify product forms
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
|||||||
FolderAdd, Aim, ArrowDown,
|
FolderAdd, Aim, ArrowDown,
|
||||||
} from '@element-plus/icons-vue'
|
} from '@element-plus/icons-vue'
|
||||||
import type {
|
import type {
|
||||||
CategoryTree, Country, Tag, TagGroup, Good, GoodDetail, Position,
|
CategoryTree, Country, Tag, TagGroup, Good, GoodDetail,
|
||||||
OriginGoodsTreeResponse,
|
OriginGoodsTreeResponse,
|
||||||
} from '@/types'
|
} from '@/types'
|
||||||
import { goodsApi } from '@/api/goods'
|
import { goodsApi } from '@/api/goods'
|
||||||
@@ -15,7 +15,6 @@ import { countriesApi } from '@/api/countries'
|
|||||||
import { categoriesApi } from '@/api/categories'
|
import { categoriesApi } from '@/api/categories'
|
||||||
import { tagsApi } from '@/api/tags'
|
import { tagsApi } from '@/api/tags'
|
||||||
import { tagGroupsApi } from '@/api/tag-groups'
|
import { tagGroupsApi } from '@/api/tag-groups'
|
||||||
import { positionsApi } from '@/api/positions'
|
|
||||||
import { originGoodsApi } from '@/api/origin-goods'
|
import { originGoodsApi } from '@/api/origin-goods'
|
||||||
import { syncApi } from '@/api/sync'
|
import { syncApi } from '@/api/sync'
|
||||||
|
|
||||||
@@ -365,7 +364,6 @@ const configForm = ref({
|
|||||||
countryId: '', cascaderCategory: [] as string[], categoryId: '',
|
countryId: '', cascaderCategory: [] as string[], categoryId: '',
|
||||||
tagIds: [] as string[], positionId: '', goodImage: '',
|
tagIds: [] as string[], positionId: '', goodImage: '',
|
||||||
})
|
})
|
||||||
const configPositions = ref<Position[]>([])
|
|
||||||
|
|
||||||
function openConfigModal(og: any, dropTarget: any) {
|
function openConfigModal(og: any, dropTarget: any) {
|
||||||
configOG.value = og
|
configOG.value = og
|
||||||
@@ -379,7 +377,6 @@ function openConfigModal(og: any, dropTarget: any) {
|
|||||||
configForm.value.countryId = dropTarget.id
|
configForm.value.countryId = dropTarget.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadConfigPositions()
|
|
||||||
configVisible.value = true
|
configVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,19 +390,8 @@ function openConfigFromRightTree(data: any) {
|
|||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadConfigPositions() {
|
|
||||||
const params: any = { page: 1, pageSize: 200 }
|
|
||||||
if (configForm.value.countryId) params.countryId = configForm.value.countryId
|
|
||||||
if (configForm.value.categoryId) params.categoryId = configForm.value.categoryId
|
|
||||||
try {
|
|
||||||
const res = await positionsApi.getPositionsList(params) as any
|
|
||||||
configPositions.value = Array.isArray(res) ? res : (res.items ?? [])
|
|
||||||
} catch { configPositions.value = [] }
|
|
||||||
}
|
|
||||||
|
|
||||||
function onConfigCascaderChange(val: string[]) {
|
function onConfigCascaderChange(val: string[]) {
|
||||||
configForm.value.categoryId = val.length ? val[val.length - 1] : ''
|
configForm.value.categoryId = val.length ? val[val.length - 1] : ''
|
||||||
loadConfigPositions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleConfigSubmit() {
|
async function handleConfigSubmit() {
|
||||||
@@ -434,36 +420,23 @@ async function handleConfigSubmit() {
|
|||||||
// ─── Custom Good ───
|
// ─── Custom Good ───
|
||||||
const customVisible = ref(false)
|
const customVisible = ref(false)
|
||||||
const customLoading = ref(false)
|
const customLoading = ref(false)
|
||||||
const customPositions = ref<Position[]>([])
|
|
||||||
const customForm = ref({
|
const customForm = ref({
|
||||||
goodName: '', goodImage: '', goodPrice: '', countryId: '',
|
goodName: '', goodImage: '', goodPrice: '', countryId: '',
|
||||||
cascaderCategory: [] as string[], categoryId: '', tagIds: [] as string[],
|
cascaderCategory: [] as string[], categoryId: '', tagIds: [] as string[],
|
||||||
positionId: '', goodPriority: 0,
|
goodPriority: 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
function openCustomCreate() {
|
function openCustomCreate() {
|
||||||
customForm.value = {
|
customForm.value = {
|
||||||
goodName: '', goodImage: '', goodPrice: '', countryId: '',
|
goodName: '', goodImage: '', goodPrice: '', countryId: '',
|
||||||
cascaderCategory: [], categoryId: '', tagIds: [], positionId: '', goodPriority: 0,
|
cascaderCategory: [], categoryId: '', tagIds: [], goodPriority: 0,
|
||||||
}
|
}
|
||||||
customPositions.value = []
|
|
||||||
customVisible.value = true
|
customVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadCustomPositions() {
|
|
||||||
const params: any = { page: 1, pageSize: 200 }
|
|
||||||
if (customForm.value.countryId) params.countryId = customForm.value.countryId
|
|
||||||
if (customForm.value.categoryId) params.categoryId = customForm.value.categoryId
|
|
||||||
try {
|
|
||||||
const res = await positionsApi.getPositionsList(params) as any
|
|
||||||
customPositions.value = Array.isArray(res) ? res : (res.items ?? [])
|
|
||||||
} catch { customPositions.value = [] }
|
|
||||||
}
|
|
||||||
|
|
||||||
function onCustomCascaderChange(val: any) {
|
function onCustomCascaderChange(val: any) {
|
||||||
const path = Array.isArray(val) ? val : []
|
const path = Array.isArray(val) ? val : []
|
||||||
customForm.value.categoryId = path.length ? String(path[path.length - 1]) : ''
|
customForm.value.categoryId = path.length ? String(path[path.length - 1]) : ''
|
||||||
loadCustomPositions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleCustomCreate() {
|
async function handleCustomCreate() {
|
||||||
@@ -479,7 +452,6 @@ async function handleCustomCreate() {
|
|||||||
countryId: Number(customForm.value.countryId),
|
countryId: Number(customForm.value.countryId),
|
||||||
categoryId: Number(customForm.value.categoryId),
|
categoryId: Number(customForm.value.categoryId),
|
||||||
tagIds: customForm.value.tagIds.map(Number),
|
tagIds: customForm.value.tagIds.map(Number),
|
||||||
positionId: customForm.value.positionId ? Number(customForm.value.positionId) : undefined,
|
|
||||||
goodPriority: customForm.value.goodPriority,
|
goodPriority: customForm.value.goodPriority,
|
||||||
detail: {},
|
detail: {},
|
||||||
})
|
})
|
||||||
@@ -599,7 +571,6 @@ async function openEdit(g: Good) {
|
|||||||
positionId: g.positionId || '',
|
positionId: g.positionId || '',
|
||||||
}
|
}
|
||||||
editVisible.value = true
|
editVisible.value = true
|
||||||
loadEditPositions()
|
|
||||||
editDetailLoading.value = true
|
editDetailLoading.value = true
|
||||||
try {
|
try {
|
||||||
const detail = await goodsApi.getGoodById(g.id)
|
const detail = await goodsApi.getGoodById(g.id)
|
||||||
@@ -736,17 +707,6 @@ async function handleEditSubmit() {
|
|||||||
function onEditCascaderChange(val: any) {
|
function onEditCascaderChange(val: any) {
|
||||||
const path = Array.isArray(val) ? val : []
|
const path = Array.isArray(val) ? val : []
|
||||||
editForm.value.categoryId = path.length ? String(path[path.length - 1]) : ''
|
editForm.value.categoryId = path.length ? String(path[path.length - 1]) : ''
|
||||||
loadEditPositions()
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadEditPositions() {
|
|
||||||
const params: any = { page: 1, pageSize: 200 }
|
|
||||||
if (editForm.value.countryId) params.countryId = editForm.value.countryId
|
|
||||||
if (editForm.value.categoryId) params.categoryId = editForm.value.categoryId
|
|
||||||
try {
|
|
||||||
const res = await positionsApi.getPositionsList(params) as any
|
|
||||||
configPositions.value = Array.isArray(res) ? res : (res.items ?? [])
|
|
||||||
} catch { configPositions.value = [] }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleDeleteGood(g: Good) {
|
async function handleDeleteGood(g: Good) {
|
||||||
@@ -1760,7 +1720,7 @@ onMounted(() => loadAll())
|
|||||||
<el-form label-width="80px" style="margin-top: 16px">
|
<el-form label-width="80px" style="margin-top: 16px">
|
||||||
<el-form-item label="国家">
|
<el-form-item label="国家">
|
||||||
<div v-if="mode === 'category' || !configDropTarget" class="select-inline">
|
<div v-if="mode === 'category' || !configDropTarget" class="select-inline">
|
||||||
<el-select v-model="configForm.countryId" placeholder="请选择国家" filterable @change="loadConfigPositions">
|
<el-select v-model="configForm.countryId" placeholder="请选择国家" filterable>
|
||||||
<el-option v-for="c in allCountries" :key="c.id" :label="c.countryName" :value="c.id" />
|
<el-option v-for="c in allCountries" :key="c.id" :label="c.countryName" :value="c.id" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button text :icon="Plus" @click="quickCreateCountry(() => { const latest = allCountries.value[allCountries.value.length - 1]; if (latest) configForm.value.countryId = latest.id })" />
|
<el-button text :icon="Plus" @click="quickCreateCountry(() => { const latest = allCountries.value[allCountries.value.length - 1]; if (latest) configForm.value.countryId = latest.id })" />
|
||||||
@@ -1784,11 +1744,6 @@ onMounted(() => loadAll())
|
|||||||
<el-button text :icon="Plus" @click="quickCreateTag(() => { const latest = allTags.value[allTags.value.length - 1]; if (latest) configForm.value.tagIds.push(latest.id) })" />
|
<el-button text :icon="Plus" @click="quickCreateTag(() => { const latest = allTags.value[allTags.value.length - 1]; if (latest) configForm.value.tagIds.push(latest.id) })" />
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="位置">
|
|
||||||
<el-select v-model="configForm.positionId" clearable placeholder="可选">
|
|
||||||
<el-option v-for="p in configPositions" :key="p.id" :label="`#${p.indexVal}`" :value="p.id" />
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="configVisible = false">取消</el-button>
|
<el-button @click="configVisible = false">取消</el-button>
|
||||||
@@ -1809,25 +1764,20 @@ onMounted(() => loadAll())
|
|||||||
<el-form-item label="商品图片"><ImageUpload v-model="customForm.goodImage" label="上传图片" /></el-form-item>
|
<el-form-item label="商品图片"><ImageUpload v-model="customForm.goodImage" label="上传图片" /></el-form-item>
|
||||||
<el-form-item label="基础价格"><el-input v-model="customForm.goodPrice" placeholder="例如 28.00" /></el-form-item>
|
<el-form-item label="基础价格"><el-input v-model="customForm.goodPrice" placeholder="例如 28.00" /></el-form-item>
|
||||||
<el-form-item label="国家" required>
|
<el-form-item label="国家" required>
|
||||||
<el-select v-model="customForm.countryId" filterable style="width:100%" @change="loadCustomPositions">
|
<el-select v-model="customForm.countryId" filterable placeholder="请选择国家" style="width:100%">
|
||||||
<el-option v-for="c in allCountries" :key="c.id" :label="c.countryName" :value="c.id" />
|
<el-option v-for="c in allCountries" :key="c.id" :label="c.countryName" :value="c.id" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="分类" required>
|
<el-form-item label="分类" required>
|
||||||
<el-cascader v-model="customForm.cascaderCategory" :options="categoryCascader as any" :props="{ checkStrictly: true }" style="width:100%" @change="onCustomCascaderChange" />
|
<el-cascader v-model="customForm.cascaderCategory" :options="categoryCascader as any" :props="{ checkStrictly: true }" placeholder="请选择分类" style="width:100%" @change="onCustomCascaderChange" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="标签">
|
<el-form-item label="标签">
|
||||||
<el-select v-model="customForm.tagIds" multiple filterable style="width:100%">
|
<el-select v-model="customForm.tagIds" multiple filterable placeholder="请选择标签" style="width:100%">
|
||||||
<el-option-group v-for="g in groupedTagOptions" :key="g.id" :label="g.label">
|
<el-option-group v-for="g in groupedTagOptions" :key="g.id" :label="g.label">
|
||||||
<el-option v-for="t in g.tags" :key="t.id" :label="t.tagName" :value="t.id" />
|
<el-option v-for="t in g.tags" :key="t.id" :label="t.tagName" :value="t.id" />
|
||||||
</el-option-group>
|
</el-option-group>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="运营位">
|
|
||||||
<el-select v-model="customForm.positionId" clearable style="width:100%">
|
|
||||||
<el-option v-for="p in customPositions" :key="p.id" :label="`#${p.indexVal}`" :value="p.id" />
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="优先级"><el-input-number v-model="customForm.goodPriority" :min="0" /></el-form-item>
|
<el-form-item label="优先级"><el-input-number v-model="customForm.goodPriority" :min="0" /></el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@@ -1874,14 +1824,14 @@ onMounted(() => loadAll())
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="国家">
|
<el-form-item label="国家">
|
||||||
<div class="select-inline">
|
<div class="select-inline">
|
||||||
<el-select v-model="editForm.countryId" filterable @change="loadEditPositions">
|
<el-select v-model="editForm.countryId" filterable placeholder="请选择国家">
|
||||||
<el-option v-for="c in allCountries" :key="c.id" :label="c.countryName" :value="c.id" />
|
<el-option v-for="c in allCountries" :key="c.id" :label="c.countryName" :value="c.id" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button text :icon="Plus" @click="quickCreateCountry(() => { const latest = allCountries[allCountries.length - 1]; if (latest) editForm.countryId = latest.id })" />
|
<el-button text :icon="Plus" @click="quickCreateCountry(() => { const latest = allCountries[allCountries.length - 1]; if (latest) editForm.countryId = latest.id })" />
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="分类">
|
<el-form-item label="分类">
|
||||||
<el-cascader v-model="editForm.cascaderCategory" :options="categoryCascader as any" :props="{ checkStrictly: true }" @change="onEditCascaderChange" />
|
<el-cascader v-model="editForm.cascaderCategory" :options="categoryCascader as any" :props="{ checkStrictly: true }" placeholder="请选择分类" @change="onEditCascaderChange" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="标签">
|
<el-form-item label="标签">
|
||||||
<div class="select-inline">
|
<div class="select-inline">
|
||||||
@@ -1893,11 +1843,6 @@ onMounted(() => loadAll())
|
|||||||
<el-button text :icon="Plus" @click="quickCreateTag(() => { const latest = allTags[allTags.length - 1]; if (latest) editForm.tagIds.push(latest.id) })" />
|
<el-button text :icon="Plus" @click="quickCreateTag(() => { const latest = allTags[allTags.length - 1]; if (latest) editForm.tagIds.push(latest.id) })" />
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="运营位">
|
|
||||||
<el-select v-model="editForm.positionId" clearable placeholder="可选">
|
|
||||||
<el-option v-for="p in configPositions" :key="p.id" :label="`#${p.indexVal}`" :value="p.id" />
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item v-if="editIsCustom" label="基础价格">
|
<el-form-item v-if="editIsCustom" label="基础价格">
|
||||||
<el-input v-model="customContentForm.goodPrice" placeholder="例如 28.00" />
|
<el-input v-model="customContentForm.goodPrice" placeholder="例如 28.00" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|||||||
Reference in New Issue
Block a user