This commit is contained in:
YunaiV
2024-08-26 21:58:12 +08:00
35 changed files with 807 additions and 144 deletions

View File

@@ -29,6 +29,17 @@
</el-table-column>
<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 v-if="spuData.length > 1 && isDelete" align="center" label="操作" min-width="90" >
<template #default="scope">
<el-button
type="primary"
link
@click="deleteSpu(scope.row.id)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</template>
<script generic="T extends Spu" lang="ts" setup>
@@ -40,10 +51,13 @@ import { SpuProperty } from '@/views/mall/promotion/components/index'
defineOptions({ name: 'PromotionSpuAndSkuList' })
const message = useMessage() // 消息弹窗
const props = defineProps<{
spuList: T[]
ruleConfig: RuleConfig[]
spuPropertyListP: SpuProperty<T>[]
isDelete?: boolean //spu是否可以多选
}>()
const spuData = ref<Spu[]>([]) // spu 详情数据列表
@@ -77,6 +91,19 @@ const imagePreview = (imgUrl: string) => {
})
}
// 删除时的触发事件
const emits = defineEmits<{
(e: 'delete', spuId: number): void
}>()
/** 多选时可以删除spu **/
const deleteSpu = async (spuId: number) => {
await message.confirm('是否删除商品编号为' + spuId + '的数据?')
let index = spuData.value.findIndex((item) => item.id == spuId)
spuData.value.splice(index,1);
emits('delete',spuId)
}
/**
* 将传进来的值赋值给 skuList
*/

View File

@@ -19,6 +19,8 @@
:rule-config="ruleConfig"
:spu-list="spuList"
:spu-property-list-p="spuPropertyList"
:isDelete="true"
@delete="deleteSpu"
>
<el-table-column align="center" label="优惠金额" min-width="168">
<template #default="{ row: sku }">
@@ -47,6 +49,7 @@ import { cloneDeep } from 'lodash-es'
import * as DiscountActivityApi from '@/api/mall/promotion/discount/discountActivity'
import * as ProductSpuApi from '@/api/mall/product/spu'
import { getPropertyList, RuleConfig } from '@/views/mall/product/spu/components'
import {formatToFraction} from "@/utils";
defineOptions({ name: 'PromotionDiscountActivityForm' })
@@ -65,8 +68,8 @@ const spuAndSkuListRef = ref() // sku 限时折扣 配置组件Ref
const ruleConfig: RuleConfig[] = []
const spuList = ref<DiscountActivityApi.SpuExtension[]>([]) // 选择的 spu
const spuPropertyList = ref<SpuProperty<DiscountActivityApi.SpuExtension>[]>([])
const spuIds = ref<number[]>([]);
const selectSpu = (spuId: number, skuIds: number[]) => {
formRef.value.setValues({ spuId })
getSpuDetails(spuId, skuIds)
}
/**
@@ -75,14 +78,22 @@ const selectSpu = (spuId: number, skuIds: number[]) => {
const getSpuDetails = async (
spuId: number,
skuIds: number[] | undefined,
products?: DiscountActivityApi.DiscountProductVO[]
products?: DiscountActivityApi.DiscountProductVO[],
type?: string
) => {
const spuProperties: SpuProperty<DiscountActivityApi.SpuExtension>[] = []
//如果已经包含spu则跳过
if(spuIds.value.includes(spuId)){
if(type !== "load"){
message.error("数据重复选择!")
}
return;
}
spuIds.value.push(spuId)
const res = (await ProductSpuApi.getSpuDetailList([spuId])) as DiscountActivityApi.SpuExtension[]
if (res.length == 0) {
return
}
spuList.value = []
//spuList.value = []
// 因为只能选择一个
const spu = res[0]
const selectSkus =
@@ -100,15 +111,19 @@ const getSpuDetails = async (
config = product || config
}
sku.productConfig = config
sku.price = formatToFraction(sku.price)
sku.marketPrice = formatToFraction(sku.marketPrice)
sku.costPrice = formatToFraction(sku.costPrice)
sku.firstBrokeragePrice = formatToFraction(sku.firstBrokeragePrice)
sku.secondBrokeragePrice = formatToFraction(sku.secondBrokeragePrice)
})
spu.skus = selectSkus as DiscountActivityApi.SkuExtension[]
spuProperties.push({
spuPropertyList.value.push({
spuId: spu.id!,
spuDetail: spu,
propertyList: getPropertyList(spu)
})
spuList.value.push(spu)
spuPropertyList.value = spuProperties
}
// ================= end =================
@@ -126,8 +141,10 @@ const open = async (type: string, id?: number) => {
const data = (await DiscountActivityApi.getDiscountActivity(
id
)) as DiscountActivityApi.DiscountActivityVO
const supId = data.products[0].spuId
await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products)
for (let productsKey in data.products) {
const supId = data.products[productsKey].spuId
await getSpuDetails(supId!, data.products?.map((sku) => sku.skuId), data.products,"load")
}
formRef.value.setValues(data)
} finally {
formLoading.value = false
@@ -149,9 +166,20 @@ const submitForm = async () => {
const data = formRef.value.formModel as DiscountActivityApi.DiscountActivityVO
// 获取 折扣商品配置
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
let timp = false;
products.forEach((item: DiscountActivityApi.DiscountProductVO) => {
item.discountType = data['discountType']
if(item.discountPrice != null && item.discountPrice > 0){
item.discountType = 1
}else if(item.discountPercent != null && item.discountPercent > 0){
item.discountType = 2
}else{
timp = true
}
})
if(timp){
message.error("优惠金额和折扣百分比需要填写一个");
return;
}
data.products = products
// 真正提交
if (formType.value === 'create') {
@@ -173,7 +201,16 @@ const submitForm = async () => {
const resetForm = async () => {
spuList.value = []
spuPropertyList.value = []
spuIds.value = []
await nextTick()
formRef.value.getElFormRef().resetFields()
}
/**
* 删除spu
*/
const deleteSpu = (spuId: number) => {
spuIds.value.splice(spuIds.value.findIndex((item) => item == spuId), 1)
spuPropertyList.value.splice(spuPropertyList.value.findIndex((item) => item.spuId == spuId), 1)
}
</script>

View File

@@ -72,17 +72,6 @@ const crudSchemas = reactive<CrudSchema[]>([
width: 120
}
},
{
label: '优惠类型',
field: 'discountType',
dictType: DICT_TYPE.PROMOTION_DISCOUNT_TYPE,
dictClass: 'number',
isSearch: true,
form: {
component: 'Radio',
value: 1
}
},
{
label: '活动商品',
field: 'spuId',

View File

@@ -70,17 +70,17 @@
~ {{ formatDate(scope.row.endTime, 'YYYY-MM-DD') }}
</template>
</el-table-column>
<el-table-column label="商品图片" prop="spuName" min-width="80">
<template #default="scope">
<el-image
:src="scope.row.picUrl"
class="h-40px w-40px"
:preview-src-list="[scope.row.picUrl]"
preview-teleported
/>
</template>
</el-table-column>
<el-table-column label="商品标题" prop="spuName" min-width="300" />
<!-- <el-table-column label="商品图片" prop="spuName" min-width="80">-->
<!-- <template #default="scope">-->
<!-- <el-image-->
<!-- :src="scope.row.picUrl"-->
<!-- class="h-40px w-40px"-->
<!-- :preview-src-list="[scope.row.picUrl]"-->
<!-- preview-teleported-->
<!-- />-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column label="商品标题" prop="spuName" min-width="300" />-->
<el-table-column label="活动状态" align="center" prop="status" min-width="100">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />

View File

@@ -71,6 +71,7 @@
<MessageItem :message="item">
<ProductItem
v-if="KeFuMessageContentTypeEnum.PRODUCT === item.contentType"
:spuId="getMessageContent(item).spuId"
:picUrl="getMessageContent(item).picUrl"
:price="getMessageContent(item).price"
:skuText="getMessageContent(item).introduction"
@@ -393,7 +394,7 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
border-left: 5px solid transparent;
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
border-right: 5px solid #ffffff;
border-right: 5px solid var(--app-content-bg-color);
}
}
}
@@ -412,7 +413,7 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
right: -19px;
top: calc(50% - 10px);
position: absolute;
border-left: 5px solid #ffffff;
border-left: 5px solid var(--app-content-bg-color);
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
border-right: 5px solid transparent;
@@ -422,9 +423,9 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
// 消息气泡
.kefu-message {
color: #333;
color: #A9A9A9;
border-radius: 5px;
box-shadow: 3px 5px 15px rgba(0, 0, 0, 0.2);
box-shadow: 3px 3px 5px rgba(220,220,220, 0.1);
padding: 5px 10px;
width: auto;
max-width: 50%;
@@ -432,7 +433,7 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
display: inline-block !important;
position: relative;
word-break: break-all;
background-color: #ffffff;
background-color: var(--app-content-bg-color);
transition: all 0.2s;
&:hover {
@@ -454,7 +455,7 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
.chat-tools {
width: 100%;
border: #e4e0e0 solid 1px;
border: var(--el-border-color) solid 1px;
border-radius: 10px;
height: 44px;
}

View File

@@ -1,6 +1,7 @@
<template>
<ProductItem
v-for="item in list"
:spu-id="item.spuId"
:key="item.id"
:picUrl="item.picUrl"
:price="item.price"

View File

@@ -1,5 +1,5 @@
<template>
<div v-if="isObject(getMessageContent)">
<div v-if="isObject(getMessageContent)" @click="openDetail(getMessageContent.id)" style="cursor: pointer;">
<div :key="getMessageContent.id" class="order-list-card-box mt-14px">
<div class="order-card-header flex items-center justify-between p-x-5px">
<div class="order-no">订单号{{ getMessageContent.no }}</div>
@@ -9,6 +9,7 @@
</div>
<div v-for="item in getMessageContent.items" :key="item.id" class="border-bottom">
<ProductItem
:spu-id="item.spuId"
:num="item.count"
:picUrl="item.picUrl"
:price="item.price"
@@ -36,6 +37,8 @@ import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
import { isObject } from '@/utils/is'
import ProductItem from '@/views/mall/promotion/kefu/components/message/ProductItem.vue'
const { push } = useRouter()
defineOptions({ name: 'OrderItem' })
const props = defineProps<{
message?: KeFuMessageRespVO
@@ -46,6 +49,12 @@ const getMessageContent = computed(() =>
typeof props.message !== 'undefined' ? jsonParse(props!.message!.content) : props.order
)
/** 查看订单详情 */
const openDetail = (id: number) => {
console.log(getMessageContent)
push({ name: 'TradeOrderDetail', params: { id } })
}
/**
* 格式化订单状态的颜色
*
@@ -97,7 +106,7 @@ function formatOrderStatus(order: any) {
.order-list-card-box {
border-radius: 10px;
padding: 10px;
border: 1px #6a6a6a solid;
border: 1px var(--el-border-color) solid;
background-color: var(--app-content-bg-color);
.order-card-header {

View File

@@ -1,5 +1,5 @@
<template>
<div>
<div @click.stop="openDetail(props.spuId)" style="cursor: pointer;">
<div>
<slot name="top"></slot>
</div>
@@ -15,6 +15,7 @@
class="order-img"
fit="contain"
preview-teleported
@click.stop
/>
</div>
<div
@@ -53,8 +54,14 @@
<script lang="ts" setup>
import { fenToYuan } from '@/utils'
const { push } = useRouter()
defineOptions({ name: 'ProductItem' })
const props = defineProps({
spuId: {
type: Number,
default: 0
},
picUrl: {
type: String,
default: 'https://img1.baidu.com/it/u=1601695551,235775011&fm=26&fmt=auto'
@@ -107,13 +114,19 @@ const skuString = computed(() => {
}
return props.skuText
})
/** 查看商品详情 */
const openDetail = (spuId: number) => {
console.log(props.spuId)
push({ name: 'ProductSpuDetail', params: { id: spuId } })
}
</script>
<style lang="scss" scoped>
.ss-order-card-warp {
padding: 20px;
border-radius: 10px;
border: 1px #6a6a6a solid;
border: 1px var(--el-border-color) solid;
background-color: var(--app-content-bg-color);
.img-box {
@@ -134,7 +147,7 @@ const skuString = computed(() => {
.tool-box {
position: absolute;
right: 0px;
right: 0;
bottom: -10px;
}
}