商城:
1. 修复秒杀活动,修改商品的秒杀价格,会存在 *100 的问题
(cherry picked from commit ff8bde207d
)
This commit is contained in:
parent
3b21e610af
commit
ffc797ae31
@ -9,6 +9,7 @@ import { TableColumn } from '@/types/table'
|
||||
import { DescriptionsSchema } from '@/types/descriptions'
|
||||
import { ComponentOptions, ComponentProps } from '@/types/components'
|
||||
import { DictTag } from '@/components/DictTag'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
|
||||
export type CrudSchema = Omit<TableColumn, 'children'> & {
|
||||
isSearch?: boolean // 是否在查询显示
|
||||
@ -306,3 +307,12 @@ const filterOptions = (options: Recordable, labelField?: string) => {
|
||||
return v
|
||||
})
|
||||
}
|
||||
|
||||
// 将 tableColumns 指定 fields 放到最前面
|
||||
export const sortTableColumns = (tableColumns: TableColumn[], field: string) => {
|
||||
const fieldIndex = tableColumns.findIndex((item) => item.field === field)
|
||||
const fieldColumn = cloneDeep(tableColumns[fieldIndex])
|
||||
tableColumns.splice(fieldIndex, 1)
|
||||
// 添加到开头
|
||||
tableColumns.unshift(fieldColumn)
|
||||
}
|
||||
|
@ -98,7 +98,6 @@ const handleDelete = (id: number) => {
|
||||
tableMethods.delList(id, false)
|
||||
}
|
||||
|
||||
// TODO @puhui999:要不还是使用原生的 element plus 做。感觉 crud schema 复杂界面,做起来麻烦
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
/**
|
||||
|
@ -45,6 +45,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { SpuAndSkuList, SpuProperty, SpuSelect } from '../../components'
|
||||
import { allSchemas, rules } from './seckillActivity.data'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
|
||||
import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
|
||||
import { SeckillProductVO } from '@/api/mall/promotion/seckill/seckillActivity'
|
||||
@ -70,13 +71,13 @@ const spuAndSkuListRef = ref() // sku 秒杀配置组件Ref
|
||||
const ruleConfig: RuleConfig[] = [
|
||||
{
|
||||
name: 'productConfig.stock',
|
||||
rule: (arg) => arg > 1,
|
||||
message: '商品秒杀库存必须大于 1 !!!'
|
||||
rule: (arg) => arg >= 1,
|
||||
message: '商品秒杀库存必须大于等于 1 !!!'
|
||||
},
|
||||
{
|
||||
name: 'productConfig.seckillPrice',
|
||||
rule: (arg) => arg > 0.01,
|
||||
message: '商品秒杀价格必须大于 0.01 !!!'
|
||||
rule: (arg) => arg >= 0.01,
|
||||
message: '商品秒杀价格必须大于等于 0.01 !!!'
|
||||
}
|
||||
]
|
||||
const spuList = ref<SeckillActivityApi.SpuExtension[]>([]) // 选择的 spu
|
||||
@ -112,7 +113,6 @@ const getSpuDetails = async (
|
||||
if (typeof products !== 'undefined') {
|
||||
const product = products.find((item) => item.skuId === sku.id)
|
||||
if (product) {
|
||||
// 分转元
|
||||
product.seckillPrice = formatToFraction(product.seckillPrice)
|
||||
}
|
||||
config = product || config
|
||||
@ -153,13 +153,6 @@ const open = async (type: string, id?: number) => {
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = async () => {
|
||||
spuList.value = []
|
||||
spuPropertyList.value = []
|
||||
await nextTick()
|
||||
formRef.value.getElFormRef().resetFields()
|
||||
}
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
@ -170,14 +163,14 @@ const submitForm = async () => {
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formRef.value.formModel as SeckillActivityApi.SeckillActivityVO
|
||||
const products = spuAndSkuListRef.value.getSkuConfigs('productConfig')
|
||||
// 获取秒杀商品配置
|
||||
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
|
||||
products.forEach((item: SeckillProductVO) => {
|
||||
// 秒杀价格元转分
|
||||
item.seckillPrice = convertToInteger(item.seckillPrice)
|
||||
})
|
||||
// 获取秒杀商品配置
|
||||
const data = formRef.value.formModel as SeckillActivityApi.SeckillActivityVO
|
||||
data.products = products
|
||||
// 真正提交
|
||||
if (formType.value === 'create') {
|
||||
await SeckillActivityApi.createSeckillActivity(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
@ -192,6 +185,15 @@ const submitForm = async () => {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = async () => {
|
||||
spuList.value = []
|
||||
spuPropertyList.value = []
|
||||
await nextTick()
|
||||
formRef.value.getElFormRef().resetFields()
|
||||
}
|
||||
// TODO @puhui999:下面的 css 名字,是不是可以改下;demo-table-expand
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.demo-table-expand {
|
||||
|
@ -10,8 +10,7 @@
|
||||
type="primary"
|
||||
@click="openForm('create')"
|
||||
>
|
||||
<Icon class="mr-5px" icon="ep:plus" />
|
||||
新增
|
||||
<Icon class="mr-5px" icon="ep:plus" /> 新增
|
||||
</el-button>
|
||||
</template>
|
||||
</Search>
|
||||
@ -74,8 +73,8 @@ import { allSchemas } from './seckillActivity.data'
|
||||
import { getSimpleSeckillConfigList } from '@/api/mall/promotion/seckill/seckillConfig'
|
||||
import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
|
||||
import SeckillActivityForm from './SeckillActivityForm.vue'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
import { createImageViewer } from '@/components/ImageViewer'
|
||||
import { sortTableColumns } from '@/hooks/web/useCrudSchemas'
|
||||
|
||||
defineOptions({ name: 'PromotionSeckillActivity' })
|
||||
|
||||
@ -99,12 +98,14 @@ const openForm = (type: string, id?: number) => {
|
||||
const handleDelete = (id: number) => {
|
||||
tableMethods.delList(id, false)
|
||||
}
|
||||
|
||||
/** 商品图预览 */
|
||||
const imagePreview = (imgUrl: string) => {
|
||||
createImageViewer({
|
||||
urlList: [imgUrl]
|
||||
})
|
||||
}
|
||||
|
||||
const configList = ref([]) // 时段配置精简列表
|
||||
const convertSeckillConfigNames = computed(
|
||||
() => (row) =>
|
||||
@ -120,18 +121,10 @@ const expandChange = (row, expandedRows) => {
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(async () => {
|
||||
/*
|
||||
TODO
|
||||
后面准备封装成一个函数来操作 tableColumns 重新排列:比如说需求是表单上商品选择是在后面的而列表展示的时候需要调到位置。
|
||||
封装效果支持批量操作,给出 field 和需要插入的位置,例:[{field:'spuId',index: 1}] 效果为把 field 为 spuId 的 column 移动到第一个位置
|
||||
*/
|
||||
// 处理一下表格列让商品往前
|
||||
const index = allSchemas.tableColumns.findIndex((item) => item.field === 'spuId')
|
||||
const column = cloneDeep(allSchemas.tableColumns[index])
|
||||
allSchemas.tableColumns.splice(index, 1)
|
||||
// 添加到开头
|
||||
allSchemas.tableColumns.unshift(column)
|
||||
// 获得活动列表
|
||||
sortTableColumns(allSchemas.tableColumns, 'spuId')
|
||||
await getList()
|
||||
// 获得秒杀时间段
|
||||
configList.value = await getSimpleSeckillConfigList()
|
||||
})
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user