fix(admin): simplify product forms
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
FolderAdd, Aim, ArrowDown,
|
||||
} from '@element-plus/icons-vue'
|
||||
import type {
|
||||
CategoryTree, Country, Tag, TagGroup, Good, GoodDetail, Position,
|
||||
CategoryTree, Country, Tag, TagGroup, Good, GoodDetail,
|
||||
OriginGoodsTreeResponse,
|
||||
} from '@/types'
|
||||
import { goodsApi } from '@/api/goods'
|
||||
@@ -15,7 +15,6 @@ import { countriesApi } from '@/api/countries'
|
||||
import { categoriesApi } from '@/api/categories'
|
||||
import { tagsApi } from '@/api/tags'
|
||||
import { tagGroupsApi } from '@/api/tag-groups'
|
||||
import { positionsApi } from '@/api/positions'
|
||||
import { originGoodsApi } from '@/api/origin-goods'
|
||||
import { syncApi } from '@/api/sync'
|
||||
|
||||
@@ -365,7 +364,6 @@ const configForm = ref({
|
||||
countryId: '', cascaderCategory: [] as string[], categoryId: '',
|
||||
tagIds: [] as string[], positionId: '', goodImage: '',
|
||||
})
|
||||
const configPositions = ref<Position[]>([])
|
||||
|
||||
function openConfigModal(og: any, dropTarget: any) {
|
||||
configOG.value = og
|
||||
@@ -379,7 +377,6 @@ function openConfigModal(og: any, dropTarget: any) {
|
||||
configForm.value.countryId = dropTarget.id
|
||||
}
|
||||
}
|
||||
loadConfigPositions()
|
||||
configVisible.value = true
|
||||
}
|
||||
|
||||
@@ -393,19 +390,8 @@ function openConfigFromRightTree(data: any) {
|
||||
}, 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[]) {
|
||||
configForm.value.categoryId = val.length ? val[val.length - 1] : ''
|
||||
loadConfigPositions()
|
||||
}
|
||||
|
||||
async function handleConfigSubmit() {
|
||||
@@ -434,36 +420,23 @@ async function handleConfigSubmit() {
|
||||
// ─── Custom Good ───
|
||||
const customVisible = ref(false)
|
||||
const customLoading = ref(false)
|
||||
const customPositions = ref<Position[]>([])
|
||||
const customForm = ref({
|
||||
goodName: '', goodImage: '', goodPrice: '', countryId: '',
|
||||
cascaderCategory: [] as string[], categoryId: '', tagIds: [] as string[],
|
||||
positionId: '', goodPriority: 0,
|
||||
goodPriority: 0,
|
||||
})
|
||||
|
||||
function openCustomCreate() {
|
||||
customForm.value = {
|
||||
goodName: '', goodImage: '', goodPrice: '', countryId: '',
|
||||
cascaderCategory: [], categoryId: '', tagIds: [], positionId: '', goodPriority: 0,
|
||||
cascaderCategory: [], categoryId: '', tagIds: [], goodPriority: 0,
|
||||
}
|
||||
customPositions.value = []
|
||||
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) {
|
||||
const path = Array.isArray(val) ? val : []
|
||||
customForm.value.categoryId = path.length ? String(path[path.length - 1]) : ''
|
||||
loadCustomPositions()
|
||||
}
|
||||
|
||||
async function handleCustomCreate() {
|
||||
@@ -479,7 +452,6 @@ async function handleCustomCreate() {
|
||||
countryId: Number(customForm.value.countryId),
|
||||
categoryId: Number(customForm.value.categoryId),
|
||||
tagIds: customForm.value.tagIds.map(Number),
|
||||
positionId: customForm.value.positionId ? Number(customForm.value.positionId) : undefined,
|
||||
goodPriority: customForm.value.goodPriority,
|
||||
detail: {},
|
||||
})
|
||||
@@ -599,7 +571,6 @@ async function openEdit(g: Good) {
|
||||
positionId: g.positionId || '',
|
||||
}
|
||||
editVisible.value = true
|
||||
loadEditPositions()
|
||||
editDetailLoading.value = true
|
||||
try {
|
||||
const detail = await goodsApi.getGoodById(g.id)
|
||||
@@ -736,17 +707,6 @@ async function handleEditSubmit() {
|
||||
function onEditCascaderChange(val: any) {
|
||||
const path = Array.isArray(val) ? val : []
|
||||
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) {
|
||||
@@ -1760,7 +1720,7 @@ onMounted(() => loadAll())
|
||||
<el-form label-width="80px" style="margin-top: 16px">
|
||||
<el-form-item label="国家">
|
||||
<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-select>
|
||||
<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) })" />
|
||||
</div>
|
||||
</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>
|
||||
<template #footer>
|
||||
<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="基础价格"><el-input v-model="customForm.goodPrice" placeholder="例如 28.00" /></el-form-item>
|
||||
<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-select>
|
||||
</el-form-item>
|
||||
<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 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 v-for="t in g.tags" :key="t.id" :label="t.tagName" :value="t.id" />
|
||||
</el-option-group>
|
||||
</el-select>
|
||||
</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>
|
||||
<template #footer>
|
||||
@@ -1874,14 +1824,14 @@ onMounted(() => loadAll())
|
||||
</el-form-item>
|
||||
<el-form-item label="国家">
|
||||
<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-select>
|
||||
<el-button text :icon="Plus" @click="quickCreateCountry(() => { const latest = allCountries[allCountries.length - 1]; if (latest) editForm.countryId = latest.id })" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<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 label="标签">
|
||||
<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) })" />
|
||||
</div>
|
||||
</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-input v-model="customContentForm.goodPrice" placeholder="例如 28.00" />
|
||||
</el-form-item>
|
||||
|
||||
Reference in New Issue
Block a user