商城:

1. 修复秒杀活动,修改商品的秒杀价格,会存在 *100 的问题

(cherry picked from commit ff8bde207d)
This commit is contained in:
YunaiV 2023-08-12 16:25:05 +08:00 committed by shizhong
parent 3b21e610af
commit ffc797ae31
4 changed files with 35 additions and 31 deletions

View File

@ -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)
}

View File

@ -98,7 +98,6 @@ const handleDelete = (id: number) => {
tableMethods.delList(id, false)
}
// TODO @puhui999使 element plus crud schema
/** 初始化 **/
onMounted(() => {
/**

View File

@ -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 {

View File

@ -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>