小如重构
This commit is contained in:
1 parent
54bee11cd4
commit
c52c092d85
7 files changed
+111
-8
No files matched your search
@@ -64,6 +64,8 @@ export interface Spu {
|
||||
status?: number // 商品状态
|
||||
types?: number // 商品类型
|
||||
deviceId?: number // 设备号
|
||||
purchaseLimitType?: number // 限购类型:0-不限购,1-每天限购,2-每周限购,3-终身限购
|
||||
purchaseLimitCount?: number // 限购数量
|
||||
}
|
||||
|
||||
// 获得 Spu 列表
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface DeviceVO {
|
||||
adType: string // 广告类型
|
||||
adUrl: string // 广告链接
|
||||
adImage: string // 广告图片
|
||||
showInApp?: boolean // 是否在 APP 中显示
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,35 @@
|
||||
class="w-80!"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-divider content-position="left">限购配置</el-divider>
|
||||
<el-form-item label="限购类型" prop="purchaseLimitType">
|
||||
<el-select
|
||||
v-model="formData.purchaseLimitType"
|
||||
placeholder="请选择限购类型"
|
||||
class="w-80!"
|
||||
@change="handleLimitTypeChange"
|
||||
>
|
||||
<el-option label="不限购" :value="0" />
|
||||
<el-option label="每天限购" :value="1" />
|
||||
<el-option label="每周限购" :value="2" />
|
||||
<el-option label="终身限购" :value="3" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="formData.purchaseLimitType !== 0"
|
||||
label="限购数量"
|
||||
prop="purchaseLimitCount"
|
||||
>
|
||||
<el-input-number
|
||||
v-model="formData.purchaseLimitCount"
|
||||
:min="1"
|
||||
placeholder="请输入限购数量"
|
||||
class="w-80!"
|
||||
/>
|
||||
<div class="text-gray-400 text-xs mt-1">
|
||||
配合限购类型使用,例如:每天限购 2 件
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
@@ -85,7 +114,9 @@ const formData = reactive<Spu>({
|
||||
deviceId: undefined, // 设备号
|
||||
sort: 0, // 商品排序
|
||||
giveIntegral: 0, // 赠送积分
|
||||
virtualSalesCount: 0 // 虚拟销量
|
||||
virtualSalesCount: 0, // 虚拟销量
|
||||
purchaseLimitType: 0, // 限购类型,默认不限购
|
||||
purchaseLimitCount: undefined // 限购数量
|
||||
})
|
||||
const rules = reactive({
|
||||
name: [required],
|
||||
@@ -94,9 +125,36 @@ const rules = reactive({
|
||||
sliderPicUrls: [required],
|
||||
sort: [required],
|
||||
giveIntegral: [required],
|
||||
virtualSalesCount: [required]
|
||||
virtualSalesCount: [required],
|
||||
purchaseLimitCount: [
|
||||
{
|
||||
validator: (rule: any, value: any, callback: any) => {
|
||||
if (formData.purchaseLimitType !== 0) {
|
||||
if (!value || value <= 0) {
|
||||
callback(new Error('限购数量必须大于 0'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
/** 限购类型变化处理 */
|
||||
const handleLimitTypeChange = (value: number) => {
|
||||
if (value === 0) {
|
||||
// 不限购时清空限购数量
|
||||
formData.purchaseLimitCount = undefined
|
||||
} else if (!formData.purchaseLimitCount) {
|
||||
// 切换到限购时,如果没有数量则设置默认值
|
||||
formData.purchaseLimitCount = 1
|
||||
}
|
||||
}
|
||||
|
||||
/** 将传进来的值赋值给 formData */
|
||||
watch(
|
||||
() => props.propFormData,
|
||||
|
||||
@@ -81,7 +81,9 @@ const formData = ref<Spu>({
|
||||
sort: 0, // 商品排序
|
||||
giveIntegral: 0, // 赠送积分
|
||||
virtualSalesCount: 0, // 虚拟销量
|
||||
deviceId: undefined // 设备号
|
||||
deviceId: undefined, // 设备号
|
||||
purchaseLimitType: 0, // 限购类型,默认不限购
|
||||
purchaseLimitCount: undefined // 限购数量
|
||||
})
|
||||
|
||||
/** 获得详情 */
|
||||
|
||||
@@ -233,6 +233,11 @@
|
||||
<el-table-column label="创建人" min-width="100" prop="creatorName" />
|
||||
<el-table-column label="商品编号" min-width="100" prop="id" />
|
||||
<el-table-column label="销量" min-width="80" prop="salesCount" />
|
||||
<el-table-column align="center" label="限购信息" min-width="120">
|
||||
<template #default="{ row }">
|
||||
{{ formatPurchaseLimit(row) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
:formatter="dateFormatter"
|
||||
align="center"
|
||||
@@ -318,6 +323,7 @@ import { fenToYuan } from '@/utils'
|
||||
import download from '@/utils/download'
|
||||
import { DeviceSpuApi, type Spu } from '@/api/mall/product/device-spu'
|
||||
import * as ProductCategoryApi from '@/api/mall/product/category'
|
||||
import * as ProductSpuApi from '@/api/mall/product/spu'
|
||||
import { DeviceApi, type DeviceVO } from '@/api/product/device'
|
||||
|
||||
defineOptions({ name: 'ProductPickup' })
|
||||
@@ -464,11 +470,10 @@ const handleTabClick = (tab: TabsPaneContext) => {
|
||||
|
||||
/** 获得每个 Tab 的数量 */
|
||||
const getTabsCount = async () => {
|
||||
// TODO: 新 API 中暂无此接口,暂时注释
|
||||
// const res = await DeviceSpuApi.getTabsCount(1);
|
||||
// for (let objName in res) {
|
||||
// tabsData.value[Number(objName)].count = res[objName]
|
||||
// }
|
||||
const res = await ProductSpuApi.getTabsCount(1) // 1 表示容器商品
|
||||
for (let objName in res) {
|
||||
tabsData.value[Number(objName)].count = res[objName]
|
||||
}
|
||||
}
|
||||
|
||||
/** 添加到仓库 / 回收站的状态 */
|
||||
@@ -707,6 +712,25 @@ const formatCategoryName = (categoryId: number) => {
|
||||
return treeToString(categoryList.value, categoryId)
|
||||
}
|
||||
|
||||
/** 格式化限购信息 */
|
||||
const formatPurchaseLimit = (row: Spu) => {
|
||||
const limitTypeMap = {
|
||||
0: '',
|
||||
1: '每天',
|
||||
2: '每周',
|
||||
3: '终身'
|
||||
}
|
||||
|
||||
if (!row.purchaseLimitType || row.purchaseLimitType === 0) {
|
||||
return '-'
|
||||
}
|
||||
|
||||
const typeText = limitTypeMap[row.purchaseLimitType] || ''
|
||||
const count = row.purchaseLimitCount || 0
|
||||
|
||||
return `${typeText}限购 ${count} 件`
|
||||
}
|
||||
|
||||
/** 激活时 */
|
||||
onActivated(() => {
|
||||
getList()
|
||||
|
||||
@@ -13,6 +13,14 @@
|
||||
<el-form-item label="设备IMEI" prop="deviceId">
|
||||
<el-input v-model="formData.deviceId" placeholder="请输入设备IMEI" />
|
||||
</el-form-item>
|
||||
<el-form-item label="APP显示" prop="showInApp">
|
||||
<el-switch
|
||||
v-model="formData.showInApp"
|
||||
active-text="显示"
|
||||
inactive-text="不显示"
|
||||
inline-prompt
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="广告图设置">
|
||||
<el-radio-group v-model="formData.adType" @change="handleAdTypeChange">
|
||||
<el-radio label="upload">上传广告图</el-radio>
|
||||
@@ -64,6 +72,7 @@ const formData = ref({
|
||||
adType: 'upload', // 广告图类型:upload-上传图片,link-链接
|
||||
adImage: undefined, // 广告图文件(使用 /infra/file/upload 接口)
|
||||
adUrl: undefined, // 广告图链接
|
||||
showInApp: true, // 是否在 APP 中显示,默认显示
|
||||
})
|
||||
const formRules = reactive({
|
||||
deviceId: [{ required: true, message: '设备IMEI不能为空', trigger: 'blur' }],
|
||||
@@ -159,6 +168,7 @@ const resetForm = () => {
|
||||
adType: 'upload',
|
||||
adImage: undefined,
|
||||
adUrl: undefined,
|
||||
showInApp: true,
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
@@ -64,6 +64,12 @@ type="success" plain @click="handleExport" :loading="exportLoading"
|
||||
<el-image :src="row.productUrl" class="mr-10px h-30px w-30px" @click="imagePreview(row.productUrl)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="APP显示" align="center" prop="showInApp" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.showInApp" type="success">显示</el-tag>
|
||||
<el-tag v-else type="info">不显示</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" :formatter="dateFormatter" width="180px" />
|
||||
<el-table-column label="操作" align="center" min-width="200px">
|
||||
<template #default="{ row }">
|
||||
|
||||
Reference in new issue
Block a user