2023-06-24 01:48:07 +08:00
|
|
|
|
<template>
|
2023-06-25 16:43:49 +08:00
|
|
|
|
<el-table :data="spuData" :default-expand-all="true">
|
2023-06-24 01:48:07 +08:00
|
|
|
|
<el-table-column type="expand" width="30">
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
<SkuList
|
|
|
|
|
ref="skuListRef"
|
|
|
|
|
:is-activity-component="true"
|
|
|
|
|
:prop-form-data="spuPropertyList.find((item) => item.spuId === row.id)?.spuDetail"
|
|
|
|
|
:property-list="spuPropertyList.find((item) => item.spuId === row.id)?.propertyList"
|
|
|
|
|
:rule-config="ruleConfig"
|
|
|
|
|
>
|
|
|
|
|
<template #extension>
|
|
|
|
|
<el-table-column align="center" label="秒杀库存" min-width="168">
|
|
|
|
|
<template #default="{ row: sku }">
|
|
|
|
|
<el-input-number v-model="sku.productConfig.stock" :min="0" class="w-100%" />
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column align="center" label="秒杀价格(元)" min-width="168">
|
|
|
|
|
<template #default="{ row: sku }">
|
|
|
|
|
<el-input-number
|
|
|
|
|
v-model="sku.productConfig.seckillPrice"
|
|
|
|
|
:min="0"
|
|
|
|
|
:precision="2"
|
|
|
|
|
:step="0.1"
|
|
|
|
|
class="w-100%"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</template>
|
|
|
|
|
</SkuList>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column key="id" align="center" label="商品编号" prop="id" />
|
|
|
|
|
<el-table-column label="商品图" min-width="80">
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
<el-image :src="row.picUrl" class="w-30px h-30px" @click="imagePreview(row.picUrl)" />
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column :show-overflow-tooltip="true" label="商品名称" min-width="300" prop="name" />
|
|
|
|
|
<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="stock" />
|
|
|
|
|
</el-table>
|
|
|
|
|
</template>
|
2023-06-25 16:43:49 +08:00
|
|
|
|
<script generic="T extends Spu" lang="ts" setup>
|
2023-06-24 01:48:07 +08:00
|
|
|
|
import { formatToFraction } from '@/utils'
|
|
|
|
|
import { createImageViewer } from '@/components/ImageViewer'
|
2023-06-25 16:43:49 +08:00
|
|
|
|
import { Spu } from '@/api/mall/product/spu'
|
|
|
|
|
import { RuleConfig, SkuList } from '@/views/mall/product/spu/components'
|
|
|
|
|
import { SpuProperty } from '@/views/mall/promotion/components/index'
|
2023-06-25 09:35:20 +08:00
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'PromotionSpuAndSkuList' })
|
|
|
|
|
|
2023-06-25 16:43:49 +08:00
|
|
|
|
const props = defineProps<{
|
|
|
|
|
spuList: T[]
|
|
|
|
|
ruleConfig: RuleConfig[]
|
|
|
|
|
spuPropertyListP: SpuProperty<T>[]
|
|
|
|
|
}>()
|
2023-06-24 01:48:07 +08:00
|
|
|
|
|
2023-06-25 16:43:49 +08:00
|
|
|
|
const spuData = ref<Spu[]>([]) // spu 详情数据列表
|
2023-06-24 01:48:07 +08:00
|
|
|
|
const skuListRef = ref() // 商品属性列表Ref
|
|
|
|
|
|
2023-06-25 16:43:49 +08:00
|
|
|
|
const spuPropertyList = ref<SpuProperty<T>[]>([]) // spuId 对应的 sku 的属性列表
|
|
|
|
|
|
2023-06-24 01:48:07 +08:00
|
|
|
|
/**
|
2023-07-03 12:07:19 +08:00
|
|
|
|
* 获取所有 sku 活动配置
|
2023-06-25 16:43:49 +08:00
|
|
|
|
* @param extendedAttribute 在 sku 上扩展的属性,例:秒杀活动 sku 扩展属性 productConfig 请参考 seckillActivity.ts
|
2023-06-24 01:48:07 +08:00
|
|
|
|
*/
|
2023-07-03 12:07:19 +08:00
|
|
|
|
const getSkuConfigs = (extendedAttribute: string) => {
|
2023-06-25 16:43:49 +08:00
|
|
|
|
skuListRef.value.validateSku()
|
2023-07-03 12:07:19 +08:00
|
|
|
|
const seckillProducts = []
|
2023-06-24 01:48:07 +08:00
|
|
|
|
spuPropertyList.value.forEach((item) => {
|
|
|
|
|
item.spuDetail.skus.forEach((sku) => {
|
2023-06-25 16:43:49 +08:00
|
|
|
|
seckillProducts.push(sku[extendedAttribute])
|
2023-06-24 01:48:07 +08:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
return seckillProducts
|
|
|
|
|
}
|
|
|
|
|
// 暴露出给表单提交时使用
|
|
|
|
|
defineExpose({ getSkuConfigs })
|
2023-06-24 18:53:57 +08:00
|
|
|
|
|
2023-06-24 01:48:07 +08:00
|
|
|
|
/** 商品图预览 */
|
|
|
|
|
const imagePreview = (imgUrl: string) => {
|
|
|
|
|
createImageViewer({
|
|
|
|
|
zIndex: 99999999,
|
|
|
|
|
urlList: [imgUrl]
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-06-24 18:53:57 +08:00
|
|
|
|
|
2023-06-24 01:48:07 +08:00
|
|
|
|
/**
|
|
|
|
|
* 将传进来的值赋值给 skuList
|
|
|
|
|
*/
|
|
|
|
|
watch(
|
|
|
|
|
() => props.spuList,
|
|
|
|
|
(data) => {
|
|
|
|
|
if (!data) return
|
2023-06-25 16:43:49 +08:00
|
|
|
|
spuData.value = data as Spu[]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
deep: true,
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
/**
|
|
|
|
|
* 将传进来的值赋值给 skuList
|
|
|
|
|
*/
|
|
|
|
|
watch(
|
|
|
|
|
() => props.spuPropertyListP,
|
|
|
|
|
(data) => {
|
|
|
|
|
if (!data) return
|
|
|
|
|
spuPropertyList.value = data as SpuProperty<T>[]
|
2023-06-24 01:48:07 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
deep: true,
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
</script>
|