!157 合并商城部分功能

Merge pull request !157 from 芋道源码/dev
This commit is contained in:
芋道源码 2023-05-29 15:03:34 +00:00 committed by Gitee
commit fa6bcacaef
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
27 changed files with 1743 additions and 699 deletions

View File

@ -102,7 +102,8 @@ const include = [
'element-plus/es/components/timeline-item/style/css', 'element-plus/es/components/timeline-item/style/css',
'element-plus/es/components/collapse/style/css', 'element-plus/es/components/collapse/style/css',
'element-plus/es/components/collapse-item/style/css', 'element-plus/es/components/collapse-item/style/css',
'element-plus/es/components/button-group/style/css' 'element-plus/es/components/button-group/style/css',
'element-plus/es/components/text/style/css'
] ]
const exclude = ['@iconify/json'] const exclude = ['@iconify/json']

View File

@ -54,3 +54,8 @@ export const getBrand = (id: number) => {
export const getBrandParam = (params: PageParam) => { export const getBrandParam = (params: PageParam) => {
return request.get({ url: '/product/brand/page', params }) return request.get({ url: '/product/brand/page', params })
} }
// 获得商品品牌精简信息列表
export const getSimpleBrandList = () => {
return request.get({ url: '/product/brand/list-all-simple' })
}

View File

@ -1,39 +0,0 @@
import request from '@/config/axios'
import type { SpuType } from './type/spuType' // TODO @puhui999: type 和 api 一起放,简单一点哈~
// TODO @puhui999中英文之间有空格
// 获得spu列表 TODO @puhui999这个是 getSpuPage 哈
export const getSpuList = (params: PageParam) => {
return request.get({ url: '/product/spu/page', params })
}
// 获得spu列表tabsCount
export const getTabsCount = () => {
return request.get({ url: '/product/spu/tabsCount' })
}
// 创建商品spu
export const createSpu = (data: SpuType) => {
return request.post({ url: '/product/spu/create', data })
}
// 更新商品spu
export const updateSpu = (data: SpuType) => {
return request.put({ url: '/product/spu/update', data })
}
// 更新商品spu status
export const updateStatus = (data: { id: number; status: number }) => {
return request.put({ url: '/product/spu/updateStatus', data })
}
// 获得商品 spu
export const getSpu = (id: number) => {
return request.get({ url: `/product/spu/get-detail?id=${id}` })
}
// 删除商品Spu
export const deleteSpu = (id: number) => {
return request.delete({ url: `/product/spu/delete?id=${id}` })
}

View File

@ -1,79 +0,0 @@
export interface Property {
/**
*
*
* {@link ProductPropertyDO#getId()}
*/
propertyId?: number
/**
*
*
* {@link ProductPropertyValueDO#getId()}
*/
valueId?: number
/**
*
*/
valueName?: string
}
export interface SkuType {
/**
* SKU
*/
id?: number
/**
* SPU
*/
spuId?: number
/**
* JSON
*/
properties?: Property[]
/**
*
*/
price?: number
/**
*
*/
marketPrice?: number
/**
*
*/
costPrice?: number
/**
*
*/
barCode?: string
/**
*
*/
picUrl?: string
/**
*
*/
stock?: number
/**
* kg
*/
weight?: number
/**
* m^3
*/
volume?: number
/**
*
*/
subCommissionFirstPrice?: number
/**
*
*/
subCommissionSecondPrice?: number
/**
*
*/
salesCount?: number
}

View File

@ -1,25 +0,0 @@
import { SkuType } from './skuType'
export interface SpuType {
id?: number
name?: string // 商品名称
categoryId?: number | null // 商品分类
keyword?: string // 关键字
unit?: number | null // 单位
picUrl?: string // 商品封面图
sliderPicUrls?: string[] // 商品轮播图
introduction?: string // 商品简介
deliveryTemplateId?: number // 运费模版
specType?: boolean // 商品规格
subCommissionType?: boolean // 分销类型
skus: SkuType[] // sku数组
description?: string // 商品详情
sort?: string // 商品排序
giveIntegral?: number // 赠送积分
virtualSalesCount?: number // 虚拟销量
recommendHot?: boolean // 是否热卖
recommendBenefit?: boolean // 是否优惠
recommendBest?: boolean // 是否精品
recommendNew?: boolean // 是否新品
recommendGood?: boolean // 是否优品
}

View File

@ -0,0 +1,92 @@
import request from '@/config/axios'
export interface Property {
propertyId?: number // 属性编号
propertyName?: string // 属性名称
valueId?: number // 属性值编号
valueName?: string // 属性值名称
}
// TODO puhui999是不是直接叫 Sku 更简洁一点哈。type 待后面,总感觉有个类型?
export interface SkuType {
id?: number // 商品 SKU 编号
spuId?: number // SPU 编号
properties?: Property[] // 属性数组
price?: number // 商品价格
marketPrice?: number // 市场价
costPrice?: number // 成本价
barCode?: string // 商品条码
picUrl?: string // 图片地址
stock?: number // 库存
weight?: number // 商品重量单位kg 千克
volume?: number // 商品体积单位m^3 平米
subCommissionFirstPrice?: number // 一级分销的佣金
subCommissionSecondPrice?: number // 二级分销的佣金
salesCount?: number // 商品销量
}
// TODO puhui999是不是直接叫 Spu 更简洁一点哈。type 待后面,总感觉有个类型?
export interface SpuType {
id?: number
name?: string // 商品名称
categoryId?: number | null // 商品分类
keyword?: string // 关键字
unit?: number | null // 单位
picUrl?: string // 商品封面图
sliderPicUrls?: string[] // 商品轮播图
introduction?: string // 商品简介
deliveryTemplateId?: number | null // 运费模版
brandId?: number | null // 商品品牌编号
specType?: boolean // 商品规格
subCommissionType?: boolean // 分销类型
skus: SkuType[] // sku数组
description?: string // 商品详情
sort?: string // 商品排序
giveIntegral?: number // 赠送积分
virtualSalesCount?: number // 虚拟销量
recommendHot?: boolean // 是否热卖
recommendBenefit?: boolean // 是否优惠
recommendBest?: boolean // 是否精品
recommendNew?: boolean // 是否新品
recommendGood?: boolean // 是否优品
}
// 获得 Spu 列表
export const getSpuPage = (params: PageParam) => {
return request.get({ url: '/product/spu/page', params })
}
// 获得 Spu 列表 tabsCount
export const getTabsCount = () => {
return request.get({ url: '/product/spu/get-count' })
}
// 创建商品 Spu
export const createSpu = (data: SpuType) => {
return request.post({ url: '/product/spu/create', data })
}
// 更新商品 Spu
export const updateSpu = (data: SpuType) => {
return request.put({ url: '/product/spu/update', data })
}
// 更新商品 Spu status
export const updateStatus = (data: { id: number; status: number }) => {
return request.put({ url: '/product/spu/update-status', data })
}
// 获得商品 Spu
export const getSpu = (id: number) => {
return request.get({ url: `/product/spu/get-detail?id=${id}` })
}
// 删除商品 Spu
export const deleteSpu = (id: number) => {
return request.delete({ url: `/product/spu/delete?id=${id}` })
}
// 导出商品 Spu Excel
export const exportSpu = async (params) => {
return await request.download({ url: '/product/spu/export', params })
}

View File

@ -0,0 +1,40 @@
import request from '@/config/axios'
export interface DeliveryExpressVO {
id: number
code: string
name: string
logo: string
sort: number
status: number
}
// 查询快递公司列表
export const getDeliveryExpressPage = async (params: PageParam) => {
return await request.get({ url: '/trade/delivery/express/page', params })
}
// 查询快递公司详情
export const getDeliveryExpress = async (id: number) => {
return await request.get({ url: '/trade/delivery/express/get?id=' + id })
}
// 新增快递公司
export const createDeliveryExpress = async (data: DeliveryExpressVO) => {
return await request.post({ url: '/trade/delivery/express/create', data })
}
// 修改快递公司
export const updateDeliveryExpress = async (data: DeliveryExpressVO) => {
return await request.put({ url: '/trade/delivery/express/update', data })
}
// 删除快递公司
export const deleteDeliveryExpress = async (id: number) => {
return await request.delete({ url: '/trade/delivery/express/delete?id=' + id })
}
// 导出快递公司 Excel
export const exportDeliveryExpressApi = async (params) => {
return await request.download({ url: '/trade/delivery/express/export-excel', params })
}

View File

@ -0,0 +1,54 @@
import request from '@/config/axios'
export interface DeliveryExpressTemplateVO {
id: number
name: string
chargeMode: number
sort: number
templateCharge: ExpressTemplateChargeVO[]
templateFree: ExpressTemplateFreeVO[]
}
export declare type ExpressTemplateChargeVO = {
areaIds: number[]
startCount: number
startPrice: number
extraCount: number
extraPrice: number
}
export declare type ExpressTemplateFreeVO = {
areaIds: number[]
freeCount: number
freePrice: number
}
// 查询快递运费模板列表
export const getDeliveryExpressTemplatePage = async (params: PageParam) => {
return await request.get({ url: '/trade/delivery/express-template/page', params })
}
// 查询快递运费模板详情
export const getDeliveryExpressTemplate = async (id: number) => {
return await request.get({ url: '/trade/delivery/express-template/get?id=' + id })
}
// 新增快递运费模板
export const createDeliveryExpressTemplate = async (data: DeliveryExpressTemplateVO) => {
return await request.post({ url: '/trade/delivery/express-template/create', data })
}
// 修改快递运费模板
export const updateDeliveryExpressTemplate = async (data: DeliveryExpressTemplateVO) => {
return await request.put({ url: '/trade/delivery/express-template/update', data })
}
// 删除快递运费模板
export const deleteDeliveryExpressTemplate = async (id: number) => {
return await request.delete({ url: '/trade/delivery/express-template/delete?id=' + id })
}
// 导出快递运费模板 Excel
export const exportDeliveryExpressTemplateApi = async (params) => {
return await request.download({ url: '/trade/delivery/express-template/export-excel', params })
}

View File

@ -5,6 +5,14 @@ export const getAreaTree = async () => {
return await request.get({ url: '/system/area/tree' }) return await request.get({ url: '/system/area/tree' })
} }
export const getChildrenArea = async (id: number) => {
return await request.get({ url: '/system/area/get-children?id=' + id })
}
export const getAreaListByIds = async (ids) => {
return await request.get({ url: '/system/area/get-by-ids?ids=' + ids })
}
// 获得 IP 对应的地区名 // 获得 IP 对应的地区名
export const getAreaByIp = async (ip: string) => { export const getAreaByIp = async (ip: string) => {
return await request.get({ url: '/system/area/get-by-ip?ip=' + ip }) return await request.get({ url: '/system/area/get-by-ip?ip=' + ip })

View File

@ -1,19 +1,19 @@
<template> <template>
<div class="upload-box"> <div class="upload-box">
<el-upload <el-upload
:action="updateUrl"
list-type="picture-card"
:class="['upload', drag ? 'no-border' : '']"
v-model:file-list="fileList" v-model:file-list="fileList"
:multiple="true" :accept="fileType.join(',')"
:limit="limit" :action="updateUrl"
:headers="uploadHeaders"
:before-upload="beforeUpload" :before-upload="beforeUpload"
:class="['upload', drag ? 'no-border' : '']"
:drag="drag"
:headers="uploadHeaders"
:limit="limit"
:multiple="true"
:on-error="uploadError"
:on-exceed="handleExceed" :on-exceed="handleExceed"
:on-success="uploadSuccess" :on-success="uploadSuccess"
:on-error="uploadError" list-type="picture-card"
:drag="drag"
:accept="fileType.join(',')"
> >
<div class="upload-empty"> <div class="upload-empty">
<slot name="empty"> <slot name="empty">
@ -40,15 +40,15 @@
</div> </div>
<el-image-viewer <el-image-viewer
v-if="imgViewVisible" v-if="imgViewVisible"
@close="imgViewVisible = false"
:url-list="[viewImageUrl]" :url-list="[viewImageUrl]"
@close="imgViewVisible = false"
/> />
</div> </div>
</template> </template>
<script setup lang="ts" name="UploadImgs"> <script lang="ts" name="UploadImgs" setup>
import { PropType } from 'vue' import { PropType } from 'vue'
import type { UploadFile, UploadProps, UploadUserFile } from 'element-plus'
import { ElNotification } from 'element-plus' import { ElNotification } from 'element-plus'
import type { UploadProps, UploadFile, UploadUserFile } from 'element-plus'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { getAccessToken, getTenantId } from '@/utils/auth' import { getAccessToken, getTenantId } from '@/utils/auth'
@ -88,8 +88,19 @@ const uploadHeaders = ref({
'tenant-id': getTenantId() 'tenant-id': getTenantId()
}) })
const fileList = ref<UploadUserFile[]>(props.modelValue) const fileList = ref<UploadUserFile[]>()
// fix:
watch(
() => props.modelValue,
(data) => {
if (!data) return
fileList.value = data
},
{
deep: true,
immediate: true
}
)
/** /**
* @description 文件上传之前判断 * @description 文件上传之前判断
* @param rawFile 上传的文件 * @param rawFile 上传的文件
@ -116,9 +127,11 @@ const beforeUpload: UploadProps['beforeUpload'] = (rawFile) => {
interface UploadEmits { interface UploadEmits {
(e: 'update:modelValue', value: UploadUserFile[]): void (e: 'update:modelValue', value: UploadUserFile[]): void
} }
const emit = defineEmits<UploadEmits>() const emit = defineEmits<UploadEmits>()
const uploadSuccess = (response, uploadFile: UploadFile) => { const uploadSuccess = (response, uploadFile: UploadFile) => {
if (!response) return if (!response) return
// TODO urlfileList
uploadFile.url = response.data uploadFile.url = response.data
emit('update:modelValue', fileList.value) emit('update:modelValue', fileList.value)
message.success('上传成功') message.success('上传成功')
@ -159,35 +172,40 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
} }
</script> </script>
<style scoped lang="scss"> <style lang="scss" scoped>
.is-error { .is-error {
.upload { .upload {
:deep(.el-upload--picture-card), :deep(.el-upload--picture-card),
:deep(.el-upload-dragger) { :deep(.el-upload-dragger) {
border: 1px dashed var(--el-color-danger) !important; border: 1px dashed var(--el-color-danger) !important;
&:hover { &:hover {
border-color: var(--el-color-primary) !important; border-color: var(--el-color-primary) !important;
} }
} }
} }
} }
:deep(.disabled) { :deep(.disabled) {
.el-upload--picture-card, .el-upload--picture-card,
.el-upload-dragger { .el-upload-dragger {
cursor: not-allowed; cursor: not-allowed;
background: var(--el-disabled-bg-color) !important; background: var(--el-disabled-bg-color) !important;
border: 1px dashed var(--el-border-color-darker); border: 1px dashed var(--el-border-color-darker);
&:hover { &:hover {
border-color: var(--el-border-color-darker) !important; border-color: var(--el-border-color-darker) !important;
} }
} }
} }
.upload-box { .upload-box {
.no-border { .no-border {
:deep(.el-upload--picture-card) { :deep(.el-upload--picture-card) {
border: none !important; border: none !important;
} }
} }
:deep(.upload) { :deep(.upload) {
.el-upload-dragger { .el-upload-dragger {
display: flex; display: flex;
@ -199,14 +217,17 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
overflow: hidden; overflow: hidden;
border: 1px dashed var(--el-border-color-darker); border: 1px dashed var(--el-border-color-darker);
border-radius: v-bind(borderRadius); border-radius: v-bind(borderRadius);
&:hover { &:hover {
border: 1px dashed var(--el-color-primary); border: 1px dashed var(--el-color-primary);
} }
} }
.el-upload-dragger.is-dragover { .el-upload-dragger.is-dragover {
background-color: var(--el-color-primary-light-9); background-color: var(--el-color-primary-light-9);
border: 2px dashed var(--el-color-primary) !important; border: 2px dashed var(--el-color-primary) !important;
} }
.el-upload-list__item, .el-upload-list__item,
.el-upload--picture-card { .el-upload--picture-card {
width: v-bind(width); width: v-bind(width);
@ -214,11 +235,13 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
background-color: transparent; background-color: transparent;
border-radius: v-bind(borderRadius); border-radius: v-bind(borderRadius);
} }
.upload-image { .upload-image {
width: 100%; width: 100%;
height: 100%; height: 100%;
object-fit: contain; object-fit: contain;
} }
.upload-handle { .upload-handle {
position: absolute; position: absolute;
top: 0; top: 0;
@ -233,6 +256,7 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
background: rgb(0 0 0 / 60%); background: rgb(0 0 0 / 60%);
opacity: 0; opacity: 0;
transition: var(--el-transition-duration-fast); transition: var(--el-transition-duration-fast);
.handle-icon { .handle-icon {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -240,15 +264,18 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
justify-content: center; justify-content: center;
padding: 0 6%; padding: 0 6%;
color: aliceblue; color: aliceblue;
.el-icon { .el-icon {
margin-bottom: 15%; margin-bottom: 15%;
font-size: 140%; font-size: 140%;
} }
span { span {
font-size: 100%; font-size: 100%;
} }
} }
} }
.el-upload-list__item { .el-upload-list__item {
&:hover { &:hover {
.upload-handle { .upload-handle {
@ -256,6 +283,7 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
} }
} }
} }
.upload-empty { .upload-empty {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -263,12 +291,14 @@ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
font-size: 12px; font-size: 12px;
line-height: 30px; line-height: 30px;
color: var(--el-color-info); color: var(--el-color-info);
.el-icon { .el-icon {
font-size: 28px; font-size: 28px;
color: var(--el-text-color-secondary); color: var(--el-text-color-secondary);
} }
} }
} }
.el-upload__tip { .el-upload__tip {
line-height: 15px; line-height: 15px;
text-align: center; text-align: center;

View File

@ -349,22 +349,35 @@ const remainingRouter: AppRouteRecordRaw[] = [
{ {
path: '/product', path: '/product',
component: Layout, component: Layout,
name: 'ProductManagementEdit', name: 'Product',
meta: { meta: {
hidden: true hidden: true
}, },
children: [ children: [
{ {
path: 'productManagementAdd', // TODO @puhui999最好拆成 add 和 edit 两个路由;添加商品;修改商品 path: 'productSpuAdd', // TODO @puhui999最好拆成 add 和 edit 两个路由;添加商品;修改商品 fix
component: () => import('@/views/mall/product/spu/addForm.vue'), component: () => import('@/views/mall/product/spu/addForm.vue'),
name: 'ProductManagementAdd', name: 'ProductSpuAdd',
meta: { meta: {
noCache: true, noCache: true,
hidden: true, hidden: true,
canTo: true, canTo: true,
icon: 'ep:edit', icon: 'ep:edit',
title: '添加商品', title: '添加商品',
activeMenu: '/product/product-management' activeMenu: '/product/product-spu'
}
},
{
path: 'productSpuEdit/:spuId(\\d+)',
component: () => import('@/views/mall/product/spu/addForm.vue'),
name: 'productSpuEdit',
meta: {
noCache: true,
hidden: true,
canTo: true,
icon: 'ep:edit',
title: '编辑商品',
activeMenu: '/product/product-spu'
} }
} }
] ]

View File

@ -148,5 +148,7 @@ export enum DICT_TYPE {
// ========== MALL 模块 ========== // ========== MALL 模块 ==========
PRODUCT_UNIT = 'product_unit', // 商品单位 PRODUCT_UNIT = 'product_unit', // 商品单位
PRODUCT_SPU_STATUS = 'product_spu_status' //商品状态 PRODUCT_SPU_STATUS = 'product_spu_status', //商品状态
// ========== MALL 交易模块 ==========
EXPRESS_CHARGE_MODE = 'trade_delivery_express_charge_mode' //快递的计费方式
} }

View File

@ -155,3 +155,57 @@ export const fileSizeFormatter = (row, column, cellValue) => {
const sizeStr = size.toFixed(2) //保留的小数位数 const sizeStr = size.toFixed(2) //保留的小数位数
return sizeStr + ' ' + unitArr[index] return sizeStr + ' ' + unitArr[index]
} }
/**
* target: {a:1} source:{a:2,b:3} {a:2}
* @param target
* @param source
*/
export const copyValueToTarget = (target, source) => {
const newObj = Object.assign({}, target, source)
// 删除多余属性
Object.keys(newObj).forEach((key) => {
// 如果不是target中的属性则删除
if (Object.keys(target).indexOf(key) === -1) {
delete newObj[key]
}
})
// 更新目标对象值
Object.assign(target, newObj)
}
// TODO @puhui999返回要带上 .00 哈.例如说 1.00
/**
*
* @param num
*/
export const formatToFraction = (num: number | string | undefined): number => {
if (typeof num === 'undefined') return 0
const parsedNumber = typeof num === 'string' ? parseFloat(num) : num
return parseFloat((parsedNumber / 100).toFixed(2))
}
/**
*
* @param num
*/
export const convertToInteger = (num: number | string | undefined): number => {
if (typeof num === 'undefined') return 0
const parsedNumber = typeof num === 'string' ? parseFloat(num) : num
// TODO 分转元后还有小数则四舍五入
return Math.round(parsedNumber * 100)
}
/**
*
*/
export const yuanToFen = (amount: string | number): number => {
return Math.round(Number(amount) * 100)
}
/**
*
*/
export const fenToYuan = (amount: string | number): number => {
return Number((Number(amount) / 100).toFixed(2))
}

View File

@ -1,18 +0,0 @@
// TODO @puhui999这个方法可以考虑放到 index.js
/**
* target: {a:1} source:{a:2,b:3} {a:2}
* @param target
* @param source
*/
export const copyValueToTarget = (target, source) => {
const newObj = Object.assign({}, target, source)
// 删除多余属性
Object.keys(newObj).forEach((key) => {
// 如果不是target中的属性则删除
if (Object.keys(target).indexOf(key) === -1) {
delete newObj[key]
}
})
// 更新目标对象值
Object.assign(target, newObj)
}

View File

@ -11,7 +11,8 @@ const DEFAULT_CONFIG: TreeHelperConfig = {
export const defaultProps = { export const defaultProps = {
children: 'children', children: 'children',
label: 'name', label: 'name',
value: 'id' value: 'id',
isLeaf: 'leaf'
} }
const getConfig = (config: Partial<TreeHelperConfig>) => Object.assign({}, DEFAULT_CONFIG, config) const getConfig = (config: Partial<TreeHelperConfig>) => Object.assign({}, DEFAULT_CONFIG, config)

View File

@ -3,21 +3,21 @@
<el-tabs v-model="activeName"> <el-tabs v-model="activeName">
<el-tab-pane label="商品信息" name="basicInfo"> <el-tab-pane label="商品信息" name="basicInfo">
<BasicInfoForm <BasicInfoForm
ref="BasicInfoRef" ref="basicInfoRef"
v-model:activeName="activeName" v-model:activeName="activeName"
:propFormData="formData" :propFormData="formData"
/> />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="商品详情" name="description"> <el-tab-pane label="商品详情" name="description">
<DescriptionForm <DescriptionForm
ref="DescriptionRef" ref="descriptionRef"
v-model:activeName="activeName" v-model:activeName="activeName"
:propFormData="formData" :propFormData="formData"
/> />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="其他设置" name="otherSettings"> <el-tab-pane label="其他设置" name="otherSettings">
<OtherSettingsForm <OtherSettingsForm
ref="OtherSettingsRef" ref="otherSettingsRef"
v-model:activeName="activeName" v-model:activeName="activeName"
:propFormData="formData" :propFormData="formData"
/> />
@ -31,88 +31,56 @@
</el-form> </el-form>
</ContentWrap> </ContentWrap>
</template> </template>
<script lang="ts" name="ProductManagementForm" setup> <script lang="ts" name="ProductSpuForm" setup>
import { cloneDeep } from 'lodash-es'
import { useTagsViewStore } from '@/store/modules/tagsView' import { useTagsViewStore } from '@/store/modules/tagsView'
import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components' import { BasicInfoForm, DescriptionForm, OtherSettingsForm } from './components'
import type { SpuType } from '@/api/mall/product/management/type/spuType' // api // api
import * as managementApi from '@/api/mall/product/management/spu' import * as ProductSpuApi from '@/api/mall/product/spu'
import * as PropertyApi from '@/api/mall/product/property' import { convertToInteger, formatToFraction } from '@/utils'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const { push, currentRoute } = useRouter() // const { push, currentRoute } = useRouter() //
const { query } = useRoute() // const { params } = useRoute() //
const { delView } = useTagsViewStore() // const { delView } = useTagsViewStore() //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const activeName = ref('basicInfo') // Tag const activeName = ref('basicInfo') // Tag
const BasicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>() // Ref const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>() // Ref
const DescriptionRef = ref<ComponentRef<typeof DescriptionForm>>() // Ref const descriptionRef = ref<ComponentRef<typeof DescriptionForm>>() // Ref
const OtherSettingsRef = ref<ComponentRef<typeof OtherSettingsForm>>() // Ref const otherSettingsRef = ref<ComponentRef<typeof OtherSettingsForm>>() // Ref
const formData = ref<SpuType>({ // spu
name: '213', // const formData = ref<ProductSpuApi.SpuType>({
name: '', //
categoryId: null, // categoryId: null, //
keyword: '213', // keyword: '', //
unit: null, // unit: null, //
picUrl: picUrl: '', //
'http://127.0.0.1:48080/admin-api/infra/file/4/get/6ffdf8f5dfc03f7ceec1ff1ebc138adb8b721a057d505ccfb0e61a8783af1371.png', // sliderPicUrls: [], //
sliderPicUrls: [ introduction: '', //
{ deliveryTemplateId: 1, //
name: 'http://127.0.0.1:48080/admin-api/infra/file/4/get/6ffdf8f5dfc03f7ceec1ff1ebc138adb8b721a057d505ccfb0e61a8783af1371.png', brandId: null, //
url: 'http://127.0.0.1:48080/admin-api/infra/file/4/get/6ffdf8f5dfc03f7ceec1ff1ebc138adb8b721a057d505ccfb0e61a8783af1371.png'
}
], //
introduction: '213', //
deliveryTemplateId: 0, //
specType: false, // specType: false, //
subCommissionType: false, // subCommissionType: false, //
skus: [ skus: [
{ {
/** price: 0, //
* 商品价格单位 TODO @puhui999注释放在尾巴哈简洁一点~ marketPrice: 0, //
*/ costPrice: 0, //
price: 0, barCode: '', //
/** picUrl: '', //
* 市场价单位 stock: 0, //
*/ weight: 0, //
marketPrice: 0, volume: 0, //
/** subCommissionFirstPrice: 0, //
* 成本价单位 subCommissionSecondPrice: 0 //
*/
costPrice: 0,
/**
* 商品条码
*/
barCode: '',
/**
* 图片地址
*/
picUrl: '',
/**
* 库存
*/
stock: 0,
/**
* 商品重量单位kg 千克
*/
weight: 0,
/**
* 商品体积单位m^3 平米
*/
volume: 0,
/**
* 一级分销的佣金单位
*/
subCommissionFirstPrice: 0,
/**
* 二级分销的佣金单位
*/
subCommissionSecondPrice: 0
} }
], ],
description: '5425', // description: '', //
sort: 1, // sort: 0, //
giveIntegral: 1, // giveIntegral: 0, //
virtualSalesCount: 1, // virtualSalesCount: 0, //
recommendHot: false, // recommendHot: false, //
recommendBenefit: false, // recommendBenefit: false, //
recommendBest: false, // recommendBest: false, //
@ -122,19 +90,20 @@ const formData = ref<SpuType>({
/** 获得详情 */ /** 获得详情 */
const getDetail = async () => { const getDetail = async () => {
const id = query.id as unknown as number const id = params.spuId as number
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { try {
const res = (await managementApi.getSpu(id)) as SpuType const res = (await ProductSpuApi.getSpu(id)) as ProductSpuApi.SpuType
res.skus.forEach((item) => {
//
item.price = formatToFraction(item.price)
item.marketPrice = formatToFraction(item.marketPrice)
item.costPrice = formatToFraction(item.costPrice)
item.subCommissionFirstPrice = formatToFraction(item.subCommissionFirstPrice)
item.subCommissionSecondPrice = formatToFraction(item.subCommissionSecondPrice)
})
formData.value = res formData.value = res
// id
// TODO @puhui999 propertyName id + uniapp
const propertyIds = res.skus[0]?.properties.map((item) => item.propertyId)
const PropertyS = await PropertyApi.getPropertyListAndValue({ propertyIds })
await nextTick()
//
BasicInfoRef.value.addAttribute(PropertyS)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -145,96 +114,65 @@ const getDetail = async () => {
const submitForm = async () => { const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
const newSkus = JSON.parse(JSON.stringify(formData.value.skus)) //skus使 //
// TODO
// //
try { try {
await unref(BasicInfoRef)?.validate() await unref(basicInfoRef)?.validate()
await unref(DescriptionRef)?.validate() await unref(descriptionRef)?.validate()
await unref(OtherSettingsRef)?.validate() await unref(otherSettingsRef)?.validate()
// TODO @puhui server const deepCopyFormData = cloneDeep(unref(formData.value)) // fix: server
// // TODO sku
formData.value.skus.forEach((item) => { formData.value.skus.forEach((sku) => {
// sku name //
item.name = formData.value.name if (sku.barCode === '') {
// skusvalue const index = deepCopyFormData.skus.findIndex(
if (formData.value.specType) { (item) => JSON.stringify(item.properties) === JSON.stringify(sku.properties)
item.properties.forEach((item2) => { )
delete item2.valueName // sku
}) deepCopyFormData.skus.splice(index, 1)
} }
}) })
deepCopyFormData.skus.forEach((item) => {
// sku name
item.name = deepCopyFormData.name
// sku
item.price = convertToInteger(item.price)
item.marketPrice = convertToInteger(item.marketPrice)
item.costPrice = convertToInteger(item.costPrice)
item.subCommissionFirstPrice = convertToInteger(item.subCommissionFirstPrice)
item.subCommissionSecondPrice = convertToInteger(item.subCommissionSecondPrice)
})
// //
const newSliderPicUrls = [] const newSliderPicUrls = []
formData.value.sliderPicUrls.forEach((item) => { deepCopyFormData.sliderPicUrls.forEach((item) => {
// //
// TODO @puhui999 object typeof item === 'object' ? newSliderPicUrls.push(item.url) : newSliderPicUrls.push(item)
if (typeof item === 'object') {
newSliderPicUrls.push(item.url)
} else {
newSliderPicUrls.push(item)
}
}) })
formData.value.sliderPicUrls = newSliderPicUrls deepCopyFormData.sliderPicUrls = newSliderPicUrls
// //
const data = formData.value as SpuType const data = deepCopyFormData as ProductSpuApi.SpuType
// skus. const id = params.spuId as number
const id = query.id as unknown as number
if (!id) { if (!id) {
await managementApi.createSpu(data) await ProductSpuApi.createSpu(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await managementApi.updateSpu(data) await ProductSpuApi.updateSpu(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
close() close()
} catch (e) {
// ,skus
if (typeof e === 'string') {
formData.value.skus = newSkus
}
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
} }
/**
* 重置表单
*/
const resetForm = async () => {
formData.value = {
name: '', //
categoryId: 0, //
keyword: '', //
unit: '', //
picUrl: '', //
sliderPicUrls: [], //
introduction: '', //
deliveryTemplateId: 0, //
selectRule: '',
specType: false, //
subCommissionType: false, //
description: '', //
sort: 1, //
giveIntegral: 1, //
virtualSalesCount: 1, //
recommendHot: false, //
recommendBenefit: false, //
recommendBest: false, //
recommendNew: false, //
recommendGood: false //
}
}
/** 关闭按钮 */ /** 关闭按钮 */
const close = () => { const close = () => {
// TODO @puhui999 reset close
resetForm()
delView(unref(currentRoute)) delView(unref(currentRoute))
push('/product/product-management') push('/product/product-spu')
} }
/** 初始化 */ /** 初始化 */
onMounted(() => { onMounted(async () => {
getDetail() await getDetail()
}) })
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<el-form ref="ProductManagementBasicInfoRef" :model="formData" :rules="rules" label-width="120px"> <el-form ref="productSpuBasicInfoRef" :model="formData" :rules="rules" label-width="120px">
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="商品名称" prop="name"> <el-form-item label="商品名称" prop="name">
@ -14,9 +14,9 @@
:data="categoryList" :data="categoryList"
:props="defaultProps" :props="defaultProps"
check-strictly check-strictly
class="w-1/1"
node-key="id" node-key="id"
placeholder="请选择商品分类" placeholder="请选择商品分类"
class="w-1/1"
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -27,7 +27,7 @@
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="单位" prop="unit"> <el-form-item label="单位" prop="unit">
<el-select v-model="formData.unit" placeholder="请选择单位" class="w-1/1"> <el-select v-model="formData.unit" class="w-1/1" placeholder="请选择单位">
<el-option <el-option
v-for="dict in getIntDictOptions(DICT_TYPE.PRODUCT_UNIT)" v-for="dict in getIntDictOptions(DICT_TYPE.PRODUCT_UNIT)"
:key="dict.value" :key="dict.value"
@ -54,18 +54,28 @@
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="商品轮播图" prop="sliderPicUrls"> <el-form-item label="商品轮播图" prop="sliderPicUrls">
<UploadImgs v-model="formData.sliderPicUrls" /> <UploadImgs v-model:modelValue="formData.sliderPicUrls" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="运费模板" prop="deliveryTemplateId"> <el-form-item label="运费模板" prop="deliveryTemplateId">
<el-select v-model="formData.deliveryTemplateId" placeholder="请选择" class="w-1/1"> <el-select v-model="formData.deliveryTemplateId" placeholder="请选择">
<el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.id" /> <el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.id" />
</el-select> </el-select>
<el-button class="ml-20px">运费模板</el-button>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-button class="ml-20px">运费模板</el-button> <el-form-item label="品牌" prop="brandId">
<el-select v-model="formData.brandId" placeholder="请选择">
<el-option
v-for="item in brandList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="商品规格" props="specType"> <el-form-item label="商品规格" props="specType">
@ -86,36 +96,37 @@
<!-- 多规格添加--> <!-- 多规格添加-->
<el-col :span="24"> <el-col :span="24">
<el-form-item v-if="formData.specType" label="商品属性"> <el-form-item v-if="formData.specType" label="商品属性">
<!-- TODO @puhui999参考 https://admin.java.crmeb.net/store/list/creatProduct --> <el-button class="mr-15px mb-10px" @click="attributesAddFormRef.open">添加规格</el-button>
<el-button class="mr-15px mb-10px" @click="AttributesAddFormRef.open">添加规格</el-button> <ProductAttributes :propertyList="propertyList" @success="generateSkus" />
<ProductAttributes :attribute-data="attributeList" />
</el-form-item> </el-form-item>
<template v-if="formData.specType && attributeList.length > 0"> <template v-if="formData.specType && propertyList.length > 0">
<el-form-item label="批量设置"> <el-form-item label="批量设置">
<SkuList :attributeList="attributeList" :is-batch="true" :prop-form-data="formData" /> <SkuList :is-batch="true" :prop-form-data="formData" :propertyList="propertyList" />
</el-form-item> </el-form-item>
<el-form-item label="属性列表"> <el-form-item label="属性列表">
<SkuList :attributeList="attributeList" :prop-form-data="formData" /> <SkuList ref="skuListRef" :prop-form-data="formData" :propertyList="propertyList" />
</el-form-item> </el-form-item>
</template> </template>
<el-form-item v-if="!formData.specType"> <el-form-item v-if="!formData.specType">
<SkuList :attributeList="attributeList" :prop-form-data="formData" /> <SkuList :prop-form-data="formData" :propertyList="propertyList" />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
</el-form> </el-form>
<ProductAttributesAddForm ref="AttributesAddFormRef" @success="addAttribute" /> <ProductAttributesAddForm ref="attributesAddFormRef" :propertyList="propertyList" />
</template> </template>
<script lang="ts" name="ProductManagementBasicInfoForm" setup> <script lang="ts" name="ProductSpuBasicInfoForm" setup>
import { PropType } from 'vue' import { PropType } from 'vue'
import { copyValueToTarget } from '@/utils'
import { propTypes } from '@/utils/propTypes'
import { defaultProps, handleTree } from '@/utils/tree' import { defaultProps, handleTree } from '@/utils/tree'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import type { SpuType } from '@/api/mall/product/management/type/spuType' import type { SpuType } from '@/api/mall/product/spu'
import { UploadImg, UploadImgs } from '@/components/UploadFile' import { UploadImg, UploadImgs } from '@/components/UploadFile'
import { copyValueToTarget } from '@/utils/object'
import { ProductAttributes, ProductAttributesAddForm, SkuList } from './index' import { ProductAttributes, ProductAttributesAddForm, SkuList } from './index'
import * as ProductCategoryApi from '@/api/mall/product/category' import * as ProductCategoryApi from '@/api/mall/product/category'
import { propTypes } from '@/utils/propTypes' import { getSimpleBrandList } from '@/api/mall/product/brand'
const message = useMessage() // const message = useMessage() //
const props = defineProps({ const props = defineProps({
@ -125,27 +136,24 @@ const props = defineProps({
}, },
activeName: propTypes.string.def('') activeName: propTypes.string.def('')
}) })
const AttributesAddFormRef = ref() // TODO @puhui999 const attributesAddFormRef = ref() //
const ProductManagementBasicInfoRef = ref() // Ref TODO @puhui999 const productSpuBasicInfoRef = ref() // Ref
// TODO @puhui999attributeList propertyList const propertyList = ref([]) //
const attributeList = ref([]) // const skuListRef = ref() // Ref
/** 添加商品属性 */ // TODO @puhui999propFormData /** 调用 SkuList generateTableData 方法*/
const addAttribute = (property: any) => { const generateSkus = (propertyList) => {
if (Array.isArray(property)) { skuListRef.value.generateTableData(propertyList)
attributeList.value = property
return
}
attributeList.value.push(property)
} }
const formData = reactive<SpuType>({ const formData = reactive<SpuType>({
name: '', // name: '', //
categoryId: undefined, // categoryId: null, //
keyword: '', // keyword: '', //
unit: '', // unit: '', //
picUrl: '', // picUrl: '', //
sliderPicUrls: [], // sliderPicUrls: [], //
introduction: '', // introduction: '', //
deliveryTemplateId: 1, // deliveryTemplateId: 1, //
brandId: null, //
specType: false, // specType: false, //
subCommissionType: false, // subCommissionType: false, //
skus: [] skus: []
@ -159,6 +167,7 @@ const rules = reactive({
picUrl: [required], picUrl: [required],
sliderPicUrls: [required], sliderPicUrls: [required],
// deliveryTemplateId: [required], // deliveryTemplateId: [required],
brandId: [required],
specType: [required], specType: [required],
subCommissionType: [required] subCommissionType: [required]
}) })
@ -169,11 +178,35 @@ const rules = reactive({
watch( watch(
() => props.propFormData, () => props.propFormData,
(data) => { (data) => {
if (!data) return if (!data) {
return
}
copyValueToTarget(formData, data) copyValueToTarget(formData, data)
formData.sliderPicUrls = data['sliderPicUrls'].map((item) => ({
url: item
}))
// TODO @puhui999if return
//
if (formData.specType) {
// skus propertyList
const properties = []
formData.skus.forEach((sku) => {
sku.properties.forEach(({ propertyId, propertyName, valueId, valueName }) => {
//
if (!properties.some((item) => item.id === propertyId)) {
properties.push({ id: propertyId, name: propertyName, values: [] })
}
//
const index = properties.findIndex((item) => item.id === propertyId)
if (!properties[index].values.some((value) => value.id === valueId)) {
properties[index].values.push({ id: valueId, name: valueName })
}
})
})
propertyList.value = properties
}
}, },
{ {
deep: true,
immediate: true immediate: true
} }
) )
@ -184,8 +217,8 @@ watch(
const emit = defineEmits(['update:activeName']) const emit = defineEmits(['update:activeName'])
const validate = async () => { const validate = async () => {
// //
if (!ProductManagementBasicInfoRef) return if (!productSpuBasicInfoRef) return
return await unref(ProductManagementBasicInfoRef).validate((valid) => { return await unref(productSpuBasicInfoRef).validate((valid) => {
if (!valid) { if (!valid) {
message.warning('商品信息未完善!!') message.warning('商品信息未完善!!')
emit('update:activeName', 'basicInfo') emit('update:activeName', 'basicInfo')
@ -197,7 +230,7 @@ const validate = async () => {
} }
}) })
} }
defineExpose({ validate, addAttribute }) defineExpose({ validate })
/** 分销类型 */ /** 分销类型 */
const changeSubCommissionType = () => { const changeSubCommissionType = () => {
@ -211,7 +244,7 @@ const changeSubCommissionType = () => {
/** 选择规格 */ /** 选择规格 */
const onChangeSpec = () => { const onChangeSpec = () => {
// //
attributeList.value = [] propertyList.value = []
// sku // sku
formData.skus = [ formData.skus = [
{ {
@ -229,10 +262,13 @@ const onChangeSpec = () => {
] ]
} }
const categoryList = ref() // const categoryList = ref([]) //
const brandList = ref([]) //
onMounted(async () => { onMounted(async () => {
// //
const data = await ProductCategoryApi.getCategoryList({}) const data = await ProductCategoryApi.getCategoryList({})
categoryList.value = handleTree(data, 'id', 'parentId') categoryList.value = handleTree(data, 'id', 'parentId')
//
brandList.value = await getSimpleBrandList()
}) })
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<el-form ref="DescriptionFormRef" :model="formData" :rules="rules" label-width="120px"> <el-form ref="descriptionFormRef" :model="formData" :rules="rules" label-width="120px">
<!--富文本编辑器组件--> <!--富文本编辑器组件-->
<el-form-item label="商品详情" prop="description"> <el-form-item label="商品详情" prop="description">
<Editor v-model:modelValue="formData.description" /> <Editor v-model:modelValue="formData.description" />
@ -7,11 +7,11 @@
</el-form> </el-form>
</template> </template>
<script lang="ts" name="DescriptionForm" setup> <script lang="ts" name="DescriptionForm" setup>
import type { SpuType } from '@/api/mall/product/management/type/spuType' import type { SpuType } from '@/api/mall/product/spu'
import { Editor } from '@/components/Editor' import { Editor } from '@/components/Editor'
import { PropType } from 'vue' import { PropType } from 'vue'
import { copyValueToTarget } from '@/utils/object'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { copyValueToTarget } from '@/utils'
const message = useMessage() // const message = useMessage() //
const props = defineProps({ const props = defineProps({
@ -21,7 +21,7 @@ const props = defineProps({
}, },
activeName: propTypes.string.def('') activeName: propTypes.string.def('')
}) })
const DescriptionFormRef = ref() // Ref const descriptionFormRef = ref() // Ref
const formData = ref<SpuType>({ const formData = ref<SpuType>({
description: '' // description: '' //
}) })
@ -29,7 +29,6 @@ const formData = ref<SpuType>({
const rules = reactive({ const rules = reactive({
description: [required] description: [required]
}) })
/** /**
* 富文本编辑器如果输入过再清空会有残留需再重置一次 * 富文本编辑器如果输入过再清空会有残留需再重置一次
*/ */
@ -45,7 +44,6 @@ watch(
immediate: true immediate: true
} }
) )
/** /**
* 将传进来的值赋值给formData * 将传进来的值赋值给formData
*/ */
@ -53,10 +51,11 @@ watch(
() => props.propFormData, () => props.propFormData,
(data) => { (data) => {
if (!data) return if (!data) return
// fix使 copyValueToTarget 使 formData.value = data
copyValueToTarget(formData.value, data) copyValueToTarget(formData.value, data)
}, },
{ {
deep: true, // fix: ,
immediate: true immediate: true
} }
) )
@ -67,8 +66,8 @@ watch(
const emit = defineEmits(['update:activeName']) const emit = defineEmits(['update:activeName'])
const validate = async () => { const validate = async () => {
// //
if (!DescriptionFormRef) return if (!descriptionFormRef) return
return unref(DescriptionFormRef).validate((valid) => { return await unref(descriptionFormRef).validate((valid) => {
if (!valid) { if (!valid) {
message.warning('商品详情为完善!!') message.warning('商品详情为完善!!')
emit('update:activeName', 'description') emit('update:activeName', 'description')

View File

@ -1,39 +1,40 @@
<template> <template>
<el-form ref="OtherSettingsFormRef" :model="formData" :rules="rules" label-width="120px"> <el-form ref="otherSettingsFormRef" :model="formData" :rules="rules" label-width="120px">
<el-row> <el-row>
<!-- TODO @puhui999横着三个哈 -->
<el-col :span="24"> <el-col :span="24">
<el-col :span="8"> <el-row :gutter="20">
<el-form-item label="商品排序" prop="sort"> <el-col :span="8">
<el-input-number v-model="formData.sort" :min="0" /> <el-form-item label="商品排序" prop="sort">
</el-form-item> <el-input-number v-model="formData.sort" :min="0" />
</el-col> </el-form-item>
<el-col :span="8"> </el-col>
<el-form-item label="赠送积分" prop="giveIntegral"> <el-col :span="8">
<el-input-number v-model="formData.giveIntegral" :min="0" /> <el-form-item label="赠送积分" prop="giveIntegral">
</el-form-item> <el-input-number v-model="formData.giveIntegral" :min="0" />
</el-col> </el-form-item>
<el-col :span="8"> </el-col>
<el-form-item label="虚拟销量" prop="virtualSalesCount"> <el-col :span="8">
<el-input-number <el-form-item label="虚拟销量" prop="virtualSalesCount">
v-model="formData.virtualSalesCount" <el-input-number
:min="0" v-model="formData.virtualSalesCount"
placeholder="请输入虚拟销量" :min="0"
/> placeholder="请输入虚拟销量"
</el-form-item> />
</el-col> </el-form-item>
</el-col>
</el-row>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="商品推荐"> <el-form-item label="商品推荐">
<el-checkbox-group v-model="checkboxGroup" @change="onChangeGroup"> <el-checkbox-group v-model="checkboxGroup" @change="onChangeGroup">
<el-checkbox v-for="(item, index) in recommend" :key="index" :label="item.value"> <el-checkbox v-for="(item, index) in recommendOptions" :key="index" :label="item.value">
{{ item.name }} {{ item.name }}
</el-checkbox> </el-checkbox>
</el-checkbox-group> </el-checkbox-group>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<!-- TODO tag展示暂时不考虑排序 --> <!-- TODO tag展示暂时不考虑排序 -->
<el-form-item label="活动优先级"> <el-form-item label="活动优先级">
<el-tag>默认</el-tag> <el-tag>默认</el-tag>
<el-tag class="ml-2" type="success">秒杀</el-tag> <el-tag class="ml-2" type="success">秒杀</el-tag>
@ -51,10 +52,11 @@
</el-form> </el-form>
</template> </template>
<script lang="ts" name="OtherSettingsForm" setup> <script lang="ts" name="OtherSettingsForm" setup>
import type { SpuType } from '@/api/mall/product/management/type/spuType' import type { SpuType } from '@/api/mall/product/spu'
import { PropType } from 'vue' import { PropType } from 'vue'
import { copyValueToTarget } from '@/utils/object'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { copyValueToTarget } from '@/utils'
const message = useMessage() // const message = useMessage() //
const props = defineProps({ const props = defineProps({
@ -64,35 +66,8 @@ const props = defineProps({
}, },
activeName: propTypes.string.def('') activeName: propTypes.string.def('')
}) })
// TODO @puhui999 recommendOptions
const recommend = [ const otherSettingsFormRef = ref() // Ref
{ name: '是否热卖', value: 'recommendHot' },
{ name: '是否优惠', value: 'recommendBenefit' },
{ name: '是否精品', value: 'recommendBest' },
{ name: '是否新品', value: 'recommendNew' },
{ name: '是否优品', value: 'recommendGood' }
]
const checkboxGroup = ref<string[]>(['recommendHot']) //
/** 选择商品后赋值 */
const onChangeGroup = () => {
// TODO @puhui999 recommend
checkboxGroup.value.includes('recommendHot')
? (formData.value.recommendHot = true)
: (formData.value.recommendHot = false)
checkboxGroup.value.includes('recommendBenefit')
? (formData.value.recommendBenefit = true)
: (formData.value.recommendBenefit = false)
checkboxGroup.value.includes('recommendBest')
? (formData.value.recommendBest = true)
: (formData.value.recommendBest = false)
checkboxGroup.value.includes('recommendNew')
? (formData.value.recommendNew = true)
: (formData.value.recommendNew = false)
checkboxGroup.value.includes('recommendGood')
? (formData.value.recommendGood = true)
: (formData.value.recommendGood = false)
}
const OtherSettingsFormRef = ref() // Ref
// //
const formData = ref<SpuType>({ const formData = ref<SpuType>({
sort: 1, // sort: 1, //
@ -110,6 +85,21 @@ const rules = reactive({
giveIntegral: [required], giveIntegral: [required],
virtualSalesCount: [required] virtualSalesCount: [required]
}) })
const recommendOptions = [
{ name: '是否热卖', value: 'recommendHot' },
{ name: '是否优惠', value: 'recommendBenefit' },
{ name: '是否精品', value: 'recommendBest' },
{ name: '是否新品', value: 'recommendNew' },
{ name: '是否优品', value: 'recommendGood' }
] //
const checkboxGroup = ref<string[]>([]) //
/** 选择商品后赋值 */
const onChangeGroup = () => {
recommendOptions.forEach(({ value }) => {
formData.value[value] = checkboxGroup.value.includes(value)
})
}
/** /**
* 将传进来的值赋值给formData * 将传进来的值赋值给formData
@ -117,18 +107,17 @@ const rules = reactive({
watch( watch(
() => props.propFormData, () => props.propFormData,
(data) => { (data) => {
if (!data) return if (!data) {
return
}
copyValueToTarget(formData.value, data) copyValueToTarget(formData.value, data)
// TODO recommendOptions.forEach(({ value }) => {
checkboxGroup.value = [] if (formData.value[value] && !checkboxGroup.value.includes(value)) {
formData.value.recommendHot ? checkboxGroup.value.push('recommendHot') : '' checkboxGroup.value.push(value)
formData.value.recommendBenefit ? checkboxGroup.value.push('recommendBenefit') : '' }
formData.value.recommendBest ? checkboxGroup.value.push('recommendBest') : '' })
formData.value.recommendNew ? checkboxGroup.value.push('recommendNew') : ''
formData.value.recommendGood ? checkboxGroup.value.push('recommendGood') : ''
}, },
{ {
deep: true,
immediate: true immediate: true
} }
) )
@ -139,8 +128,8 @@ watch(
const emit = defineEmits(['update:activeName']) const emit = defineEmits(['update:activeName'])
const validate = async () => { const validate = async () => {
// //
if (!OtherSettingsFormRef) return if (!otherSettingsFormRef) return
return await unref(OtherSettingsFormRef).validate((valid) => { return await unref(otherSettingsFormRef).validate((valid) => {
if (!valid) { if (!valid) {
message.warning('商品其他设置未完善!!') message.warning('商品其他设置未完善!!')
emit('update:activeName', 'otherSettings') emit('update:activeName', 'otherSettings')

View File

@ -2,23 +2,25 @@
<el-col v-for="(item, index) in attributeList" :key="index"> <el-col v-for="(item, index) in attributeList" :key="index">
<div> <div>
<el-text class="mx-1">属性名</el-text> <el-text class="mx-1">属性名</el-text>
<el-text class="mx-1">{{ item.name }}</el-text> <el-tag class="mx-1" closable type="success" @close="handleCloseProperty(index)"
>{{ item.name }}
</el-tag>
</div> </div>
<div> <div>
<el-text class="mx-1">属性值</el-text> <el-text class="mx-1">属性值</el-text>
<el-tag <el-tag
v-for="(value, valueIndex) in item.values" v-for="(value, valueIndex) in item.values"
:key="value.id" :key="value.id"
:disable-transitions="false"
class="mx-1" class="mx-1"
closable closable
@close="handleClose(index, valueIndex)" @close="handleCloseValue(index, valueIndex)"
> >
{{ value.name }} {{ value.name }}
</el-tag> </el-tag>
<el-input <el-input
v-show="inputVisible(index)" v-show="inputVisible(index)"
ref="InputRef" :id="`input${index}`"
:ref="setInputRef"
v-model="inputValue" v-model="inputValue"
class="!w-20" class="!w-20"
size="small" size="small"
@ -51,17 +53,25 @@ const inputVisible = computed(() => (index) => {
if (attributeIndex.value === null) return false if (attributeIndex.value === null) return false
if (attributeIndex.value === index) return true if (attributeIndex.value === index) return true
}) })
const InputRef = ref() //Ref const inputRef = ref([]) //Ref
/** 解决 ref 在 v-for 中的获取问题*/
const setInputRef = (el) => {
if (el === null || typeof el === 'undefined') return
// id
if (!inputRef.value.some((item) => item.input?.attributes.id === el.input?.attributes.id)) {
inputRef.value.push(el)
}
}
const attributeList = ref([]) // const attributeList = ref([]) //
const props = defineProps({ const props = defineProps({
attributeData: { propertyList: {
type: Array, type: Array,
default: () => {} default: () => {}
} }
}) })
watch( watch(
() => props.attributeData, () => props.propertyList,
(data) => { (data) => {
if (!data) return if (!data) return
attributeList.value = data attributeList.value = data
@ -72,18 +82,22 @@ watch(
} }
) )
/** 删除标签 tagValue 标签值*/ /** 删除属性值*/
const handleClose = (index, valueIndex) => { const handleCloseValue = (index, valueIndex) => {
attributeList.value[index].values?.splice(valueIndex, 1) attributeList.value[index].values?.splice(valueIndex, 1)
} }
/** 删除属性*/
const handleCloseProperty = (index) => {
attributeList.value?.splice(index, 1)
}
/** 显示输入框并获取焦点 */ /** 显示输入框并获取焦点 */
const showInput = async (index) => { const showInput = async (index) => {
attributeIndex.value = index attributeIndex.value = index
// refRef inputRef.value[index].focus()
InputRef.value[index]!.input!.focus()
} }
const emit = defineEmits(['success']) // success
/** 输入框失去焦点或点击回车时触发 */ /** 输入框失去焦点或点击回车时触发 */
const handleInputConfirm = async (index, propertyId) => { const handleInputConfirm = async (index, propertyId) => {
if (inputValue.value) { if (inputValue.value) {
@ -92,6 +106,7 @@ const handleInputConfirm = async (index, propertyId) => {
const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value }) const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value })
attributeList.value[index].values.push({ id, name: inputValue.value }) attributeList.value[index].values.push({ id, name: inputValue.value })
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
emit('success', attributeList.value)
} catch { } catch {
message.error('添加失败,请重试') // TODO message.error('添加失败,请重试') // TODO
} }

View File

@ -7,12 +7,9 @@
:rules="formRules" :rules="formRules"
label-width="80px" label-width="80px"
> >
<el-form-item label="名称" prop="name"> <el-form-item label="属性名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入名称" /> <el-input v-model="formData.name" placeholder="请输入名称" />
</el-form-item> </el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="formData.remark" placeholder="请输入内容" type="textarea" />
</el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button> <el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
@ -30,14 +27,31 @@ const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('添加商品属性') // const dialogTitle = ref('添加商品属性') //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formData = ref({ const formData = ref({
name: '', name: ''
remark: ''
}) })
const formRules = reactive({ const formRules = reactive({
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }] name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const attributeList = ref([]) //
const props = defineProps({
propertyList: {
type: Array,
default: () => {}
}
})
watch(
() => props.propertyList,
(data) => {
if (!data) return
attributeList.value = data
},
{
deep: true,
immediate: true
}
)
/** 打开弹窗 */ /** 打开弹窗 */
const open = async () => { const open = async () => {
dialogVisible.value = true dialogVisible.value = true
@ -46,7 +60,6 @@ const open = async () => {
defineExpose({ open }) // open defineExpose({ open }) // open
/** 提交表单 */ /** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => { const submitForm = async () => {
// //
if (!formRef) return if (!formRef) return
@ -60,12 +73,12 @@ const submitForm = async () => {
const res = await PropertyApi.getPropertyListAndValue({ name: data.name }) const res = await PropertyApi.getPropertyListAndValue({ name: data.name })
if (res.length === 0) { if (res.length === 0) {
const propertyId = await PropertyApi.createProperty(data) const propertyId = await PropertyApi.createProperty(data)
emit('success', { id: propertyId, ...formData.value, values: [] }) attributeList.value.push({ id: propertyId, ...formData.value, values: [] })
} else { } else {
if (res[0].values === null) { if (res[0].values === null) {
res[0].values = [] res[0].values = []
} }
emit('success', res[0]) // attributeList.value.push(res[0]) //
} }
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
dialogVisible.value = false dialogVisible.value = false

View File

@ -1,6 +1,6 @@
<template> <template>
<el-table <el-table
:data="isBatch ? SkuData : formData.skus" :data="isBatch ? skuList : formData.skus"
border border
class="tabNumWidth" class="tabNumWidth"
max-height="500" max-height="500"
@ -12,175 +12,155 @@
</template> </template>
</el-table-column> </el-table-column>
<template v-if="formData.specType && !isBatch"> <template v-if="formData.specType && !isBatch">
<!-- 根据商品属性动态添加 --> <!-- 根据商品属性动态添加 -->
<el-table-column <el-table-column
v-for="(item, index) in tableHeaderList" v-for="(item, index) in tableHeaders"
:key="index" :key="index"
:label="item.label" :label="item.label"
align="center" align="center"
min-width="120" min-width="120"
> >
<template #default="{ row }"> <template #default="{ row }">
<!-- TODO puhui999展示成蓝色有点区分度哈 -->
{{ row.properties[index]?.valueName }} {{ row.properties[index]?.valueName }}
</template> </template>
</el-table-column> </el-table-column>
</template> </template>
<!-- TODO @puhui999 controls-position="right" 可以去掉哈不然太长了手动输入更方便 -->
<el-table-column align="center" label="商品条码" min-width="168"> <el-table-column align="center" label="商品条码" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input v-model="row.barCode" class="w-100%" /> <el-input v-model="row.barCode" class="w-100%" />
</template> </template>
</el-table-column> </el-table-column>
<!-- TODO @puhui999用户输入的时候是按照元分主要是我们自己用 --> <el-table-column align="center" label="销售价(元)" min-width="168">
<el-table-column align="center" label="销售价(分)" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number v-model="row.price" :min="0" class="w-100%" controls-position="right" /> <el-input-number v-model="row.price" :min="0" :precision="2" :step="0.1" class="w-100%" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="市场价()" min-width="168"> <el-table-column align="center" label="市场价()" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number <el-input-number
v-model="row.marketPrice" v-model="row.marketPrice"
:min="0" :min="0"
:precision="2"
:step="0.1"
class="w-100%" class="w-100%"
controls-position="right"
/> />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="成本价()" min-width="168"> <el-table-column align="center" label="成本价()" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number <el-input-number
v-model="row.costPrice" v-model="row.costPrice"
:min="0" :min="0"
:precision="2"
:step="0.1"
class="w-100%" class="w-100%"
controls-position="right"
/> />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="库存" min-width="168"> <el-table-column align="center" label="库存" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number v-model="row.stock" :min="0" class="w-100%" controls-position="right" /> <el-input-number v-model="row.stock" :min="0" class="w-100%" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="重量(kg)" min-width="168"> <el-table-column align="center" label="重量(kg)" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number v-model="row.weight" :min="0" class="w-100%" controls-position="right" /> <el-input-number v-model="row.weight" :min="0" :precision="2" :step="0.1" class="w-100%" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="体积(m^3)" min-width="168"> <el-table-column align="center" label="体积(m^3)" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number v-model="row.volume" :min="0" class="w-100%" controls-position="right" /> <el-input-number v-model="row.volume" :min="0" :precision="2" :step="0.1" class="w-100%" />
</template> </template>
</el-table-column> </el-table-column>
<template v-if="formData.subCommissionType"> <template v-if="formData.subCommissionType">
<el-table-column align="center" label="一级返佣()" min-width="168"> <el-table-column align="center" label="一级返佣()" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number <el-input-number
v-model="row.subCommissionFirstPrice" v-model="row.subCommissionFirstPrice"
:min="0" :min="0"
:precision="2"
:step="0.1"
class="w-100%" class="w-100%"
controls-position="right"
/> />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="二级返佣()" min-width="168"> <el-table-column align="center" label="二级返佣()" min-width="168">
<template #default="{ row }"> <template #default="{ row }">
<el-input-number <el-input-number
v-model="row.subCommissionSecondPrice" v-model="row.subCommissionSecondPrice"
:min="0" :min="0"
:precision="2"
:step="0.1"
class="w-100%" class="w-100%"
controls-position="right"
/> />
</template> </template>
</el-table-column> </el-table-column>
</template> </template>
<el-table-column v-if="formData.specType" align="center" fixed="right" label="操作" width="80"> <el-table-column v-if="formData.specType" align="center" fixed="right" label="操作" width="80">
<template #default> <template #default="{ row }">
<el-button v-if="isBatch" link size="small" type="primary" @click="batchAdd"> <el-button v-if="isBatch" link size="small" type="primary" @click="batchAdd">
批量添加 批量添加
</el-button> </el-button>
<el-button v-else link size="small" type="primary">删除</el-button> <el-button v-else link size="small" type="primary" @click="deleteSku(row)">删除</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</template> </template>
<script lang="ts" name="SkuList" setup> <script lang="ts" name="SkuList" setup>
import { UploadImg } from '@/components/UploadFile'
import { PropType } from 'vue' import { PropType } from 'vue'
import { SpuType } from '@/api/mall/product/management/type/spuType' import { copyValueToTarget } from '@/utils'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { SkuType } from '@/api/mall/product/management/type/skuType' import { UploadImg } from '@/components/UploadFile'
import { copyValueToTarget } from '@/utils/object' import type { Property, SkuType, SpuType } from '@/api/mall/product/spu'
const props = defineProps({ const props = defineProps({
propFormData: { propFormData: {
type: Object as PropType<SpuType>, type: Object as PropType<SpuType>,
default: () => {} default: () => {}
}, },
attributeList: { propertyList: {
type: Array, type: Array,
default: () => [] default: () => []
}, },
isBatch: propTypes.bool.def(false) // isBatch: propTypes.bool.def(false) //
}) })
const formData = ref<SpuType>() // const formData = ref<SpuType>() //
// TODO @puhui999 const skuList = ref<SkuType[]>([
const SkuData = ref<SkuType[]>([
{ {
/** price: 0, //
* 商品价格单位 marketPrice: 0, //
*/ costPrice: 0, //
price: 0, barCode: '', //
/** picUrl: '', //
* 市场价单位 stock: 0, //
*/ weight: 0, //
marketPrice: 0, volume: 0, //
/** subCommissionFirstPrice: 0, //
* 成本价单位 subCommissionSecondPrice: 0 //
*/
costPrice: 0,
/**
* 商品条码
*/
barCode: '',
/**
* 图片地址
*/
picUrl: '',
/**
* 库存
*/
stock: 0,
/**
* 商品重量单位kg 千克
*/
weight: 0,
/**
* 商品体积单位m^3 平米
*/
volume: 0,
/**
* 一级分销的佣金单位
*/
subCommissionFirstPrice: 0,
/**
* 二级分销的佣金单位
*/
subCommissionSecondPrice: 0
} }
]) ]) //
// TODO @puhui999 0.01
/** 批量添加 */ /** 批量添加 */
const batchAdd = () => { const batchAdd = () => {
formData.value.skus.forEach((item) => { formData.value.skus.forEach((item) => {
copyValueToTarget(item, SkuData.value[0]) copyValueToTarget(item, skuList.value[0])
}) })
} }
const tableHeaderList = ref<{ prop: string; label: string }[]>([]) /** 删除 sku */
const deleteSku = (row) => {
const index = formData.value.skus.findIndex(
//
(sku) => JSON.stringify(sku.properties) === JSON.stringify(row.properties)
)
formData.value.skus.splice(index, 1)
}
const tableHeaders = ref<{ prop: string; label: string }[]>([]) //
/** /**
* 将传进来的值赋值给SkuData * 将传进来的值赋值给 skuList
*/ */
watch( watch(
() => props.propFormData, () => props.propFormData,
@ -194,35 +174,27 @@ watch(
} }
) )
// TODO @ chatgpt
/** 生成表数据 */ /** 生成表数据 */
const generateTableData = (data: any[]) => { const generateTableData = (propertyList: any[]) => {
// //
const propertiesItemList = [] const propertyValues = propertyList.map((item) =>
for (const item of data) { item.values.map((v) => ({
const objList = [] propertyId: item.id,
for (const v of item.values) { propertyName: item.name,
const obj = { propertyId: 0, valueId: 0, valueName: '' } valueId: v.id,
obj.propertyId = item.id valueName: v.name
obj.valueId = v.id }))
obj.valueName = v.name )
objList.push(obj) // TODO @puhui buildSkuListitem sku
} const buildList = build(propertyValues)
propertiesItemList.push(objList) // sku skus
if (!validateData(propertyList)) {
// sku
formData.value!.skus = []
} }
const buildList = build(propertiesItemList) for (const item of buildList) {
// sku,
if (
buildList.length === formData.value.skus.length ||
data.some((item) => item.values.length === 0)
) {
return
}
//
formData.value!.skus = []
buildList.forEach((item) => {
const row = { const row = {
properties: [], properties: Array.isArray(item) ? item : [item], // property
price: 0, price: 0,
marketPrice: 0, marketPrice: 0,
costPrice: 0, costPrice: 0,
@ -234,32 +206,51 @@ const generateTableData = (data: any[]) => {
subCommissionFirstPrice: 0, subCommissionFirstPrice: 0,
subCommissionSecondPrice: 0 subCommissionSecondPrice: 0
} }
// // sku
if (Array.isArray(item)) { const index = formData.value!.skus.findIndex(
row.properties = item (sku) => JSON.stringify(sku.properties) === JSON.stringify(row.properties)
} else { )
row.properties.push(item) if (index !== -1) {
continue
} }
formData.value.skus.push(row) formData.value.skus.push(row)
}) }
}
/**
* 生成 skus 前置校验
*/
const validateData = (propertyList: any[]) => {
const skuPropertyIds = []
formData.value.skus.forEach((sku) =>
sku.properties
?.map((property) => property.propertyId)
.forEach((propertyId) => {
if (skuPropertyIds.indexOf(propertyId) === -1) {
skuPropertyIds.push(propertyId)
}
})
)
const propertyIds = propertyList.map((item) => item.id)
return skuPropertyIds.length === propertyIds.length
} }
/** 构建所有排列组合 */ /** 构建所有排列组合 */
const build = (list: any[]) => { const build = (propertyValuesList: Property[][]) => {
if (list.length === 0) { if (propertyValuesList.length === 0) {
return [] return []
} else if (list.length === 1) { } else if (propertyValuesList.length === 1) {
return list[0] return propertyValuesList[0]
} else { } else {
const result = [] const result: Property[][] = []
const rest = build(list.slice(1)) const rest = build(propertyValuesList.slice(1))
for (let i = 0; i < list[0].length; i++) { for (let i = 0; i < propertyValuesList[0].length; i++) {
for (let j = 0; j < rest.length; j++) { for (let j = 0; j < rest.length; j++) {
// //
if (Array.isArray(rest[j])) { if (Array.isArray(rest[j])) {
result.push([list[0][i], ...rest[j]]) result.push([propertyValuesList[0][i], ...rest[j]])
} else { } else {
result.push([list[0][i], rest[j]]) result.push([propertyValuesList[0][i], rest[j]])
} }
} }
} }
@ -267,15 +258,17 @@ const build = (list: any[]) => {
} }
} }
/** 监听属性列表生成相关参数和表头 */ /** 监听属性列表生成相关参数和表头 */
watch( watch(
() => props.attributeList, () => props.propertyList,
(data) => { (propertyList) => {
// //
if (!formData.value.specType) return if (!formData.value.specType) {
// 使 return
}
// 使
if (props.isBatch) { if (props.isBatch) {
SkuData.value = [ skuList.value = [
{ {
price: 0, price: 0,
marketPrice: 0, marketPrice: 0,
@ -290,20 +283,35 @@ watch(
} }
] ]
} }
// //
if (JSON.stringify(data) === '[]') return if (JSON.stringify(propertyList) === '[]') {
return
}
// //
tableHeaderList.value = [] tableHeaders.value = []
// //
data.forEach((item, index) => { propertyList.forEach((item, index) => {
// nameindex // nameindex
tableHeaderList.value.push({ prop: `name${index}`, label: item.name }) tableHeaders.value.push({ prop: `name${index}`, label: item.name })
}) })
generateTableData(data)
// sku
if (validateData(propertyList)) {
return
}
//
if (propertyList.some((item) => item.values.length === 0)) {
return
}
// table sku
generateTableData(propertyList)
}, },
{ {
deep: true, deep: true,
immediate: true immediate: true
} }
) )
// sku
defineExpose({ generateTableData })
</script> </script>

View File

@ -8,7 +8,7 @@
class="-mb-15px" class="-mb-15px"
label-width="68px" label-width="68px"
> >
<!-- TODO @puhui999https://admin.java.crmeb.net/store/index使 + --> <!-- TODO @puhui999品牌应该是数据下拉哈 -->
<el-form-item label="品牌名称" prop="name"> <el-form-item label="品牌名称" prop="name">
<el-input <el-input
v-model="queryParams.name" v-model="queryParams.name"
@ -18,15 +18,18 @@
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
/> />
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <!-- TODO 分类只能选择二级分类目前还没做还是先以联调通顺为主 -->
<el-select v-model="queryParams.status" class="!w-240px" clearable placeholder="请选择状态"> <!-- TODO puhui999我们要不改成支持选择一级如果选择一级后端要递归查询下子分类然后去 in -->
<el-option <el-form-item label="商品分类" prop="categoryId">
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" <el-tree-select
:key="dict.value" v-model="queryParams.categoryId"
:label="dict.label" :data="categoryList"
:value="dict.value" :props="defaultProps"
/> check-strictly
</el-select> class="w-1/1"
node-key="id"
placeholder="请选择商品分类"
/>
</el-form-item> </el-form-item>
<el-form-item label="创建时间" prop="createTime"> <el-form-item label="创建时间" prop="createTime">
<el-date-picker <el-date-picker
@ -48,18 +51,27 @@
<Icon class="mr-5px" icon="ep:refresh" /> <Icon class="mr-5px" icon="ep:refresh" />
重置 重置
</el-button> </el-button>
<el-button v-hasPermi="['product:brand:create']" plain type="primary" @click="openForm"> <el-button v-hasPermi="['product:spu:create']" plain type="primary" @click="openForm">
<Icon class="mr-5px" icon="ep:plus" /> <Icon class="mr-5px" icon="ep:plus" />
新增 新增
</el-button> </el-button>
<!-- TODO @puhui999增加一个导出操作 --> <el-button
v-hasPermi="['product:spu:export']"
:loading="exportLoading"
plain
type="success"
@click="handleExport"
>
<Icon class="mr-5px" icon="ep:download" />
导出
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-tabs v-model="queryParams.tabType" @tab-click="handleClick"> <el-tabs v-model="queryParams.tabType" @tab-click="handleTabClick">
<el-tab-pane <el-tab-pane
v-for="item in tabsData" v-for="item in tabsData"
:key="item.type" :key="item.type"
@ -68,35 +80,39 @@
/> />
</el-tabs> </el-tabs>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<!-- TODO puhui999: ID 编号的展示 --> <!-- TODO puhui这几个属性哈一行三个
<!-- TODO 暂时不做折叠数据 --> 商品分类服装鞋包/箱包
<!-- <el-table-column type="expand">--> 商品市场价格100.00
<!-- <template #default="{ row }">--> 成本价0.00
<!-- <el-form inline label-position="left">--> 收藏5
<!-- <el-form-item label="市场价:">--> 虚拟销量999 -->
<!-- <span>{{ row.marketPrice }}</span>--> <el-table-column type="expand" width="30">
<!-- </el-form-item>--> <template #default="{ row }">
<!-- <el-form-item label="成本价:">--> <el-form class="demo-table-expand" inline label-position="left">
<!-- <span>{{ row.costPrice }}</span>--> <el-form-item label="市场价:">
<!-- </el-form-item>--> <span>{{ formatToFraction(row.marketPrice) }}</span>
<!-- <el-form-item label="虚拟销量:">--> </el-form-item>
<!-- <span>{{ row.virtualSalesCount }}</span>--> <el-form-item label="成本价:">
<!-- </el-form-item>--> <span>{{ formatToFraction(row.costPrice) }}</span>
<!-- </el-form>--> </el-form-item>
<!-- </template>--> <el-form-item label="虚拟销量:">
<!-- </el-table-column>--> <span>{{ row.virtualSalesCount }}</span>
</el-form-item>
</el-form>
</template>
</el-table-column>
<el-table-column key="id" align="center" label="商品编号" prop="id" />
<el-table-column label="商品图" min-width="80"> <el-table-column label="商品图" min-width="80">
<template #default="{ row }"> <template #default="{ row }">
<el-image <el-image :src="row.picUrl" @click="imagePreview(row.picUrl)" class="w-30px h-30px" />
:src="row.picUrl"
style="width: 36px; height: 36px"
@click="imagePreview(row.picUrl)"
/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column :show-overflow-tooltip="true" label="商品名称" min-width="300" prop="name" /> <el-table-column :show-overflow-tooltip="true" label="商品名称" min-width="300" prop="name" />
<!-- TODO 价格 / 100.0 --> <el-table-column align="center" label="商品售价" min-width="90" prop="price">
<el-table-column align="center" label="商品售价" min-width="90" prop="price" /> <template #default="{ row }">
{{ formatToFraction(row.price) }}
</template>
</el-table-column>
<el-table-column align="center" label="销量" min-width="90" prop="salesCount" /> <el-table-column align="center" label="销量" min-width="90" prop="salesCount" />
<el-table-column align="center" label="库存" min-width="90" prop="stock" /> <el-table-column align="center" label="库存" min-width="90" prop="stock" />
<el-table-column align="center" label="排序" min-width="70" prop="sort" /> <el-table-column align="center" label="排序" min-width="70" prop="sort" />
@ -107,24 +123,30 @@
prop="createTime" prop="createTime"
width="180" width="180"
/> />
<el-table-column fixed="right" label="状态" min-width="80"> <el-table-column align="center" label="状态" min-width="80">
<template #default="{ row }"> <template #default="{ row }">
<!-- TODO @puhui是不是不用 Number(row.status) 去比较哈直接 row.status < 0 --> <template v-if="row.status >= 0">
<el-switch <el-switch
v-model="row.status" v-model="row.status"
:active-value="1" :active-value="1"
:disabled="Number(row.status) < 0" :inactive-value="0"
:inactive-value="0" active-text="上架"
active-text="上架" inactive-text="下架"
inactive-text="下架" inline-prompt
inline-prompt @change="changeStatus(row)"
@change="changeStatus(row)" />
/> </template>
<template v-else>
<el-tag type="info">回收站</el-tag>
</template>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" fixed="right" label="操作" min-width="150"> <el-table-column align="center" fixed="right" label="操作" min-width="200">
<template #default="{ row }"> <template #default="{ row }">
<!-- TODO @puhui999详情可以后面点做哈 --> <!-- TODO @puhui999详情可以后面点做哈 -->
<el-button v-hasPermi="['product:spu:update']" link type="primary" @click="openDetail">
详情
</el-button>
<template v-if="queryParams.tabType === 4"> <template v-if="queryParams.tabType === 4">
<el-button <el-button
v-hasPermi="['product:spu:delete']" v-hasPermi="['product:spu:delete']"
@ -138,13 +160,15 @@
v-hasPermi="['product:spu:update']" v-hasPermi="['product:spu:update']"
link link
type="primary" type="primary"
@click="addToTrash(row, ProductSpuStatusEnum.DISABLE.status)" @click="changeStatus(row, ProductSpuStatusEnum.DISABLE.status)"
> >
恢复到仓库 恢复到仓库
</el-button> </el-button>
</template> </template>
<template v-else> <template v-else>
<!-- 只有不是上架和回收站的商品可以编辑 -->
<el-button <el-button
v-if="queryParams.tabType !== 0"
v-hasPermi="['product:spu:update']" v-hasPermi="['product:spu:update']"
link link
type="primary" type="primary"
@ -156,7 +180,7 @@
v-hasPermi="['product:spu:update']" v-hasPermi="['product:spu:update']"
link link
type="primary" type="primary"
@click="addToTrash(row, ProductSpuStatusEnum.RECYCLE.status)" @click="changeStatus(row, ProductSpuStatusEnum.RECYCLE.status)"
> >
加入回收站 加入回收站
</el-button> </el-button>
@ -172,26 +196,25 @@
@pagination="getList" @pagination="getList"
/> />
</ContentWrap> </ContentWrap>
<!-- https://kailong110120130.gitee.io/vue-element-plus-admin-doc/components/image-viewer.html -->
<!-- 必须在表格外面展示不然单元格会遮挡图层 -->
<el-image-viewer
v-if="imgViewVisible"
:url-list="imageViewerList"
@close="imgViewVisible = false"
/>
</template> </template>
<script lang="ts" name="ProductList" setup> <script lang="ts" name="ProductSpu" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
// TODO @puhui999managementApi=ProductSpuApi
import * as managementApi from '@/api/mall/product/management/spu'
import { ProductSpuStatusEnum } from '@/utils/constants'
import { TabsPaneContext } from 'element-plus' import { TabsPaneContext } from 'element-plus'
import { cloneDeep } from 'lodash-es'
import { createImageViewer } from '@/components/ImageViewer'
import { dateFormatter } from '@/utils/formatTime'
import { defaultProps, handleTree } from '@/utils/tree'
import { ProductSpuStatusEnum } from '@/utils/constants'
import { formatToFraction } from '@/utils'
import download from '@/utils/download'
import * as ProductSpuApi from '@/api/mall/product/spu'
import * as ProductCategoryApi from '@/api/mall/product/category'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
const { currentRoute, push } = useRouter() // const { currentRoute, push } = useRouter() //
const loading = ref(false) // const loading = ref(false) //
const exportLoading = ref(false) //
const total = ref(0) // const total = ref(0) //
const list = ref<any[]>([]) // const list = ref<any[]>([]) //
// tabs // tabs
@ -225,26 +248,19 @@ const tabsData = ref([
/** 获得每个 Tab 的数量 */ /** 获得每个 Tab 的数量 */
const getTabsCount = async () => { const getTabsCount = async () => {
// TODO @puhui999 try catch const res = await ProductSpuApi.getTabsCount()
try { for (let objName in res) {
const res = await managementApi.getTabsCount() tabsData.value[Number(objName)].count = res[objName]
for (let objName in res) { }
tabsData.value[Number(objName)].count = res[objName]
}
} catch {}
} }
const imgViewVisible = ref(false) //
const imageViewerList = ref<string[]>([]) //
const queryParams = ref({ const queryParams = ref({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
tabType: 0 tabType: 0
}) }) //
const queryFormRef = ref() // const queryFormRef = ref() // Ref
// TODO @puhui999 handleTabClick const handleTabClick = (tab: TabsPaneContext) => {
const handleClick = (tab: TabsPaneContext) => {
queryParams.value.tabType = tab.paneName queryParams.value.tabType = tab.paneName
getList() getList()
} }
@ -253,7 +269,7 @@ const handleClick = (tab: TabsPaneContext) => {
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await managementApi.getSpuList(queryParams.value) const data = await ProductSpuApi.getSpuPage(queryParams.value)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
@ -261,7 +277,6 @@ const getList = async () => {
} }
} }
// TODO @puhui999 changeStatus addToTrash
/** /**
* 更改 SPU 状态 * 更改 SPU 状态
* *
@ -269,10 +284,11 @@ const getList = async () => {
* @param status 更改前的值 * @param status 更改前的值
*/ */
const changeStatus = async (row, status?: number) => { const changeStatus = async (row, status?: number) => {
// TODO const deepCopyValue = cloneDeep(unref(row))
if (typeof status !== 'undefined') deepCopyValue.status = status
try { try {
let text = '' let text = ''
switch (row.status) { switch (deepCopyValue.status) {
case ProductSpuStatusEnum.DISABLE.status: case ProductSpuStatusEnum.DISABLE.status:
text = ProductSpuStatusEnum.DISABLE.name text = ProductSpuStatusEnum.DISABLE.name
break break
@ -284,20 +300,19 @@ const changeStatus = async (row, status?: number) => {
break break
} }
await message.confirm( await message.confirm(
row.status === -1 ? `确认要将[${row.name}]${text}吗?` : `确认要${text}[${row.name}]吗?` deepCopyValue.status === -1
? `确认要将[${row.name}]${text}吗?`
: row.status === -1 // -1: status-1 status0
? `确认要将[${row.name}]恢复到仓库吗?`
: `确认要${text}[${row.name}]吗?`
) )
await managementApi.updateStatus({ id: row.id, status: row.status }) await ProductSpuApi.updateStatus({ id: deepCopyValue.id, status: deepCopyValue.status })
message.success('更新状态成功') message.success('更新状态成功')
// tabs // tabs
await getTabsCount() await getTabsCount()
// //
await getList() await getList()
} catch { } catch {
//
if (typeof status !== 'undefined') {
row.status = status
return
}
// //
row.status = row.status =
row.status === ProductSpuStatusEnum.DISABLE.status row.status === ProductSpuStatusEnum.DISABLE.status
@ -306,26 +321,13 @@ const changeStatus = async (row, status?: number) => {
} }
} }
/**
* 加入回收站
*
* @param row
* @param status
*/
const addToTrash = (row, status) => {
//
const num = Number(`${row.status}`)
row.status = status
changeStatus(row, num)
}
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (id: number) => { const handleDelete = async (id: number) => {
try { try {
// //
await message.delConfirm() await message.delConfirm()
// //
await managementApi.deleteSpu(id) await ProductSpuApi.deleteSpu(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// tabs // tabs
await getTabsCount() await getTabsCount()
@ -334,13 +336,11 @@ const handleDelete = async (id: number) => {
} catch {} } catch {}
} }
/** /** 商品图预览 */
* 商品图预览
* @param imgUrl
*/
const imagePreview = (imgUrl: string) => { const imagePreview = (imgUrl: string) => {
imageViewerList.value = [imgUrl] createImageViewer({
imgViewVisible.value = true urlList: [imgUrl]
})
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
@ -362,27 +362,61 @@ const resetQuery = () => {
const openForm = (id?: number) => { const openForm = (id?: number) => {
// //
if (typeof id === 'number') { if (typeof id === 'number') {
push('/product/productManagementAdd?id=' + id) push('/product/productSpuEdit/' + id)
return return
} }
// //
push('/product/productManagementAdd') push('/product/productSpuAdd')
} }
// TODO @puhui999 /**
* 查看商品详情
*/
const openDetail = () => {
message.alert('查看详情未完善!!!')
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await ProductSpuApi.exportSpu(queryParams)
download.excel(data, '商品列表.xls')
} catch {
} finally {
exportLoading.value = false
}
}
// TODO @puhui999fix:
watch( watch(
() => currentRoute.value, () => currentRoute.value,
() => { () => {
getList() getList()
},
{
immediate: true
} }
) )
const categoryList = ref() //
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onMounted(async () => {
getTabsCount() await getTabsCount()
getList() await getList()
//
const data = await ProductCategoryApi.getCategoryList({})
categoryList.value = handleTree(data, 'id', 'parentId')
}) })
</script> </script>
<style lang="scss" scoped>
.demo-table-expand {
padding-left: 42px;
:deep(.el-form-item__label) {
width: 82px;
font-weight: bold;
color: #99a9bf;
}
}
</style>

View File

@ -0,0 +1,124 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="120px"
v-loading="formLoading"
>
<el-form-item label="快递公司编码" prop="code">
<el-input v-model="formData.code" placeholder="请输入快递编码" />
</el-form-item>
<el-form-item label="快递公司名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入快递名称" />
</el-form-item>
<el-form-item label="快递公司 logo" prop="logo">
<UploadImg v-model="formData.logo" :limit="1" :is-show-tip="false" />
<div style="font-size: 10px" class="pl-10px">推荐 180x180 图片分辨率</div>
</el-form-item>
<el-form-item label="分类排序" prop="sort">
<el-input-number v-model="formData.sort" controls-position="right" :min="0" />
</el-form-item>
<el-form-item label="开启状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts" name="ExpressForm">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { CommonStatusEnum } from '@/utils/constants'
import * as DeliveryExpressApi from '@/api/mall/trade/delivery/express'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
code: '',
name: '',
logo: '',
sort: 0,
status: CommonStatusEnum.ENABLE
})
const formRules = reactive({
code: [{ required: true, message: '快递编码不能为空', trigger: 'blur' }],
name: [{ required: true, message: '分类名称不能为空', trigger: 'blur' }],
logo: [{ required: true, message: '分类图片不能为空', trigger: 'blur' }],
sort: [{ required: true, message: '分类排序不能为空', trigger: 'blur' }],
status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
formLoading.value = true
try {
formData.value = await DeliveryExpressApi.getDeliveryExpress(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as DeliveryExpressApi.DeliveryExpressVO
if (formType.value === 'create') {
await DeliveryExpressApi.createDeliveryExpress(data)
message.success(t('common.createSuccess'))
} else {
await DeliveryExpressApi.updateDeliveryExpress(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
name: '',
picUrl: '',
bigPicUrl: '',
status: CommonStatusEnum.ENABLE
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,184 @@
<template>
<!-- 搜索工作栏 -->
<ContentWrap>
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="100px"
>
<el-form-item label="快递公司编号" prop="code">
<el-input
v-model="queryParams.code"
placeholder="请输快递公司编号"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="快递公司名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输快递公司名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['trade:delivery:express:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['trade:delivery:express:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list">
<el-table-column label="快递公司编号" prop="code" />
<el-table-column label="快递公司名称" prop="name" />
<el-table-column label="快递公司 logo " prop="logo">
<template #default="scope">
<img v-if="scope.row.logo" :src="scope.row.logo" alt="快递公司logo" class="h-100px" />
</template>
</el-table-column>
<el-table-column label="排序" align="center" prop="sort" />
<el-table-column label="开启状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
width="180"
:formatter="dateFormatter"
/>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['trade:delivery:express:update']"
>
编辑
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['trade:delivery:express:delete']"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<ExpressForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts" name="Express">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import * as DeliveryExpressApi from '@/api/mall/trade/delivery/express'
import ExpressForm from './ExpressForm.vue'
const message = useMessage() //
const { t } = useI18n() //
const total = ref(0) //
const loading = ref(true) //
const list = ref<any[]>([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
code: '',
name: ''
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await DeliveryExpressApi.getDeliveryExpressPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await DeliveryExpressApi.deleteDeliveryExpress(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await DeliveryExpressApi.exportDeliveryExpressApi(queryParams)
download.excel(data, '快递公司.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>

View File

@ -0,0 +1,405 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="80%">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="80px"
v-loading="formLoading"
>
<el-form-item label="模板名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入模板名称" />
</el-form-item>
<el-form-item label="计费方式" prop="chargeMode">
<el-radio-group v-model="formData.chargeMode" @change="changeChargeMode">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.EXPRESS_CHARGE_MODE)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="运费" prop="templateCharge">
<el-table border style="width: 100%" :data="formData.templateCharge">
<el-table-column align="center" label="区域" width="180">
<template #default="{ row }">
<!-- 区域数据太多用赖加载方式要不然性能有问题 -->
<el-tree-select
v-model="row.areaIds"
lazy
:load="loadChargeArea"
:props="defaultProps"
multiple
node-key="id"
check-strictly
show-checkbox
check-on-click-node
:render-after-expand="false"
:cache-data="areaCache"
/>
</template>
</el-table-column>
<el-table-column
align="center"
:label="columnTitle.startCountTitle"
width="180"
prop="startCount"
>
<template #default="{ row }">
<el-input-number v-model="row.startCount" :min="1" />
</template>
</el-table-column>
<el-table-column width="180" align="center" label="运费(元)" prop="startPrice">
<template #default="{ row }">
<el-input-number v-model="row.startPrice" :min="1" />
</template>
</el-table-column>
<el-table-column
width="180"
align="center"
:label="columnTitle.extraCountTitle"
prop="extraCount"
>
<template #default="{ row }">
<el-input-number v-model="row.extraCount" :min="1" />
</template>
</el-table-column>
<el-table-column width="180" align="center" label="续费(元)" prop="extraPrice">
<template #default="{ row }">
<el-input-number v-model="row.extraPrice" :min="1" />
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button link type="danger" @click="deleteChargeArea(scope.$index)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
<el-form-item>
<el-button type="primary" plain @click="addChargeArea()">
<Icon icon="ep:plus" class="mr-5px" /> 添加区域
</el-button>
</el-form-item>
<el-form-item label="包邮区域" prop="templateFree">
<el-table border style="width: 100%" :data="formData.templateFree">
<el-table-column align="center" label="区域">
<template #default="{ row }">
<!-- 区域数据太多用赖加载方式要不然性能有问题 -->
<el-tree-select
v-model="row.areaIds"
multiple
lazy
:load="loadFreeArea"
:props="defaultProps"
node-key="id"
check-strictly
show-checkbox
check-on-click-node
:render-after-expand="true"
:cache-data="areaCache"
/>
</template>
</el-table-column>
<el-table-column align="center" :label="columnTitle.freeCountTitle" prop="freeCount">
<template #default="{ row }">
<el-input-number v-model="row.freeCount" :min="1" />
</template>
</el-table-column>
<el-table-column align="center" label="包邮金额(元)" prop="freePrice">
<template #default="{ row }">
<el-input-number v-model="row.freePrice" :min="1" />
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button link type="danger" @click="deleteFreeArea(scope.$index)"> 删除 </el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
<el-form-item>
<el-button type="primary" plain @click="addFreeArea()">
<Icon icon="ep:plus" class="mr-5px" /> 添加区域
</el-button>
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input-number v-model="formData.sort" controls-position="right" :min="0" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as DeliveryExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate'
import { defaultProps } from '@/utils/tree'
import { yuanToFen, fenToYuan } from '@/utils'
import { getChildrenArea, getAreaListByIds } from '@/api/system/area'
import { cloneDeep } from 'lodash-es'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
name: '',
chargeMode: 1,
sort: 0,
templateCharge: [],
templateFree: []
})
const columnTitleMap = new Map()
const columnTitle = ref({
startCountTitle: '首件',
extraCountTitle: '续件',
freeCountTitle: '包邮件数'
})
const formRules = reactive({
name: [{ required: true, message: '模板名称不能为空', trigger: 'blur' }],
chargeMode: [{ required: true, message: '配送计费方式不能为空', trigger: 'blur' }],
sort: [{ required: true, message: '分类排序不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
const areaCache = ref([]) //
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
try {
//
if (id) {
formLoading.value = true
formData.value = await DeliveryExpressTemplateApi.getDeliveryExpressTemplate(id)
columnTitle.value = columnTitleMap.get(formData.value.chargeMode)
const chargeAreaIds = []
const freeAreaIds = []
formData.value.templateCharge.forEach((item) => {
for (let i = 0; i < item.areaIds.length; i++) {
if (!chargeAreaIds.includes(item.areaIds[i])) {
chargeAreaIds.push(item.areaIds[i])
}
}
//
item.startPrice = fenToYuan(item.startPrice)
item.extraPrice = fenToYuan(item.extraPrice)
})
formData.value.templateFree.forEach((item) => {
for (let i = 0; i < item.areaIds.length; i++) {
if (!chargeAreaIds.includes(item.areaIds[i]) && !freeAreaIds.includes(item.areaIds[i])) {
freeAreaIds.push(item.areaIds[i])
}
}
item.freePrice = fenToYuan(item.freePrice)
})
//
const areaIds = chargeAreaIds.concat(freeAreaIds)
//
areaCache.value = await getAreaListByIds(areaIds.join(','))
}
} finally {
formLoading.value = false
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as DeliveryExpressTemplateApi.DeliveryExpressTemplateVO
data.templateCharge.forEach((item) => {
//
item.startPrice = yuanToFen(item.startPrice)
item.extraPrice = yuanToFen(item.extraPrice)
})
data.templateFree.forEach((item) => {
item.freePrice = yuanToFen(item.freePrice)
})
if (formType.value === 'create') {
await DeliveryExpressTemplateApi.createDeliveryExpressTemplate(data)
message.success(t('common.createSuccess'))
} else {
await DeliveryExpressTemplateApi.updateDeliveryExpressTemplate(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
name: '',
chargeMode: 1,
templateCharge: [
{
areaIds: [1],
startCount: 2,
startPrice: 5,
extraCount: 5,
extraPrice: 10
}
],
templateFree: [],
sort: 0
}
columnTitle.value = columnTitleMap.get(1)
formRef.value?.resetFields()
}
/** 配送计费方法改变 */
const changeChargeMode = (chargeMode: number) => {
columnTitle.value = columnTitleMap.get(chargeMode)
}
const defaultArea = [{ id: 1, name: '全国', disabled: false }]
/** 初始化数据 */
const initData = async () => {
// TODO
// formLoading.value = true
// try {
// const data = await getAreaTree()
// areaTree = data
// console.log('areaTree', areaTree)
// } finally {
// formLoading.value = false
// }
//
columnTitleMap.set(1, {
startCountTitle: '首件',
extraCountTitle: '续件',
freeCountTitle: '包邮件数'
})
columnTitleMap.set(2, {
startCountTitle: '首件重量(kg)',
extraCountTitle: '续件重量(kg)',
freeCountTitle: '包邮重量(kg)'
})
columnTitleMap.set(3, {
startCountTitle: '首件体积(m³)',
extraCountTitle: '续件体积(m³)',
freeCountTitle: '包邮体积(m³)'
})
}
/** 懒加载运费区域树 */
const loadChargeArea = async (node, resolve) => {
//
const areaIds = []
formData.value.templateCharge.forEach((item) => {
if (item.areaIds.length > 0) {
item.areaIds.forEach((areaId) => areaIds.push(areaId))
}
})
if (node.isLeaf) return resolve([])
const length = node.data.length
if (length === 0) {
const data = cloneDeep(defaultArea)
const item = data[0]
if (areaIds.includes(item.id)) {
// TODO @
//item.disabled = true
}
resolve(data)
} else {
const id = node.data.id
const data = await getChildrenArea(id)
data.forEach((item) => {
if (areaIds.includes(item.id)) {
//item.disabled = true
}
})
resolve(data)
}
}
/** 懒加载包邮区域树 */
const loadFreeArea = async (node, resolve) => {
if (node.isLeaf) return resolve([])
//
const areaIds = []
formData.value.templateFree.forEach((item) => {
if (item.areaIds.length > 0) {
item.areaIds.forEach((areaId) => areaIds.push(areaId))
}
})
const length = node.data.length
if (length === 0) {
// id == 1
const data = cloneDeep(defaultArea)
const item = data[0]
if (areaIds.includes(item.id)) {
//item.disabled = true
}
resolve(data)
} else {
const id = node.data.id
const data = await getChildrenArea(id)
//
data.forEach((item) => {
if (areaIds.includes(item.id)) {
// TODO @
//item.disabled = true
}
})
resolve(data)
}
}
/** 添加计费区域 */
const addChargeArea = () => {
const data = formData.value
data.templateCharge.push({
areaIds: [],
startCount: 1,
startPrice: 1,
extraCount: 1,
extraPrice: 1
})
}
/** 删除计费区域 */
const deleteChargeArea = (index) => {
const data = formData.value
data.templateCharge.splice(index, 1)
}
/** 添加包邮区域 */
const addFreeArea = () => {
const data = formData.value
data.templateFree.push({
areaIds: [],
freeCount: 1,
freePrice: 1
})
}
/** 删除包邮区域 */
const deleteFreeArea = (index) => {
const data = formData.value
data.templateFree.splice(index, 1)
}
/** 初始化 **/
onMounted(() => {
initData()
})
</script>

View File

@ -0,0 +1,160 @@
<template>
<!-- 搜索工作栏 -->
<ContentWrap>
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="100px"
>
<el-form-item label="模板名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入模板名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="计费方式" prop="chargeMode">
<el-select
v-model="queryParams.chargeMode"
placeholder="计费方式"
clearable
class="!w-240px"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.EXPRESS_CHARGE_MODE)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['trade:delivery:express-template:create']"
>
<Icon icon="ep:plus" class="mr-5px" />
新增
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list">
<el-table-column label="编号" prop="id" />
<el-table-column label="模板名称" prop="name" />
<el-table-column label="计费方式" prop="chargeMode" align="center">
<template #default="scope">
<dict-tag :type="DICT_TYPE.EXPRESS_CHARGE_MODE" :value="scope.row.chargeMode" />
</template>
</el-table-column>
<el-table-column label="排序" prop="sort" />
<el-table-column
label="创建时间"
align="center"
prop="createTime"
width="180"
:formatter="dateFormatter"
/>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['trade:delivery:express-template:update']"
>
编辑
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['trade:delivery:express-template:delete']"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<ExpressTemplateForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts" name="DeliveryExpressTemplate">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import * as DeliveryExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate'
import ExpressTemplateForm from './ExpressTemplateForm.vue'
const message = useMessage() //
const { t } = useI18n() //
const total = ref(0) //
const loading = ref(true) //
const list = ref<any[]>([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: '',
chargeMode: undefined
})
const queryFormRef = ref() //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await DeliveryExpressTemplateApi.getDeliveryExpressTemplatePage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await DeliveryExpressTemplateApi.deleteDeliveryExpressTemplate(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>