商城:

1. 修复秒杀活动,修改商品的秒杀价格,会存在 *100 的问题
This commit is contained in:
YunaiV 2023-08-12 16:25:05 +08:00
parent 9984de0dc7
commit ff8bde207d
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 { DescriptionsSchema } from '@/types/descriptions'
import { ComponentOptions, ComponentProps } from '@/types/components' import { ComponentOptions, ComponentProps } from '@/types/components'
import { DictTag } from '@/components/DictTag' import { DictTag } from '@/components/DictTag'
import { cloneDeep } from 'lodash-es'
export type CrudSchema = Omit<TableColumn, 'children'> & { export type CrudSchema = Omit<TableColumn, 'children'> & {
isSearch?: boolean // 是否在查询显示 isSearch?: boolean // 是否在查询显示
@ -306,3 +307,12 @@ const filterOptions = (options: Recordable, labelField?: string) => {
return v 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) tableMethods.delList(id, false)
} }
// TODO @puhui999使 element plus crud schema
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onMounted(() => {
/** /**

View File

@ -45,6 +45,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { SpuAndSkuList, SpuProperty, SpuSelect } from '../../components' import { SpuAndSkuList, SpuProperty, SpuSelect } from '../../components'
import { allSchemas, rules } from './seckillActivity.data' import { allSchemas, rules } from './seckillActivity.data'
import { cloneDeep } from 'lodash-es'
import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity' import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
import { SeckillProductVO } 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[] = [ const ruleConfig: RuleConfig[] = [
{ {
name: 'productConfig.stock', name: 'productConfig.stock',
rule: (arg) => arg > 1, rule: (arg) => arg >= 1,
message: '商品秒杀库存必须大于 1 ' message: '商品秒杀库存必须大于等于 1 '
}, },
{ {
name: 'productConfig.seckillPrice', name: 'productConfig.seckillPrice',
rule: (arg) => arg > 0.01, rule: (arg) => arg >= 0.01,
message: '商品秒杀价格必须大于 0.01 ' message: '商品秒杀价格必须大于等于 0.01 '
} }
] ]
const spuList = ref<SeckillActivityApi.SpuExtension[]>([]) // spu const spuList = ref<SeckillActivityApi.SpuExtension[]>([]) // spu
@ -112,7 +113,6 @@ const getSpuDetails = async (
if (typeof products !== 'undefined') { if (typeof products !== 'undefined') {
const product = products.find((item) => item.skuId === sku.id) const product = products.find((item) => item.skuId === sku.id)
if (product) { if (product) {
//
product.seckillPrice = formatToFraction(product.seckillPrice) product.seckillPrice = formatToFraction(product.seckillPrice)
} }
config = product || config config = product || config
@ -153,13 +153,6 @@ const open = async (type: string, id?: number) => {
} }
defineExpose({ open }) // open defineExpose({ open }) // open
/** 重置表单 */
const resetForm = async () => {
spuList.value = []
spuPropertyList.value = []
await nextTick()
formRef.value.getElFormRef().resetFields()
}
/** 提交表单 */ /** 提交表单 */
const emit = defineEmits(['success']) // success const emit = defineEmits(['success']) // success
const submitForm = async () => { const submitForm = async () => {
@ -170,14 +163,14 @@ const submitForm = async () => {
// //
formLoading.value = true formLoading.value = true
try { 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) => { products.forEach((item: SeckillProductVO) => {
//
item.seckillPrice = convertToInteger(item.seckillPrice) item.seckillPrice = convertToInteger(item.seckillPrice)
}) })
// const data = formRef.value.formModel as SeckillActivityApi.SeckillActivityVO
data.products = products data.products = products
//
if (formType.value === 'create') { if (formType.value === 'create') {
await SeckillActivityApi.createSeckillActivity(data) await SeckillActivityApi.createSeckillActivity(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
@ -192,6 +185,15 @@ const submitForm = async () => {
formLoading.value = false formLoading.value = false
} }
} }
/** 重置表单 */
const resetForm = async () => {
spuList.value = []
spuPropertyList.value = []
await nextTick()
formRef.value.getElFormRef().resetFields()
}
// TODO @puhui999 css demo-table-expand
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.demo-table-expand { .demo-table-expand {

View File

@ -10,8 +10,7 @@
type="primary" type="primary"
@click="openForm('create')" @click="openForm('create')"
> >
<Icon class="mr-5px" icon="ep:plus" /> <Icon class="mr-5px" icon="ep:plus" /> 新增
新增
</el-button> </el-button>
</template> </template>
</Search> </Search>
@ -74,8 +73,8 @@ import { allSchemas } from './seckillActivity.data'
import { getSimpleSeckillConfigList } from '@/api/mall/promotion/seckill/seckillConfig' import { getSimpleSeckillConfigList } from '@/api/mall/promotion/seckill/seckillConfig'
import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity' import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
import SeckillActivityForm from './SeckillActivityForm.vue' import SeckillActivityForm from './SeckillActivityForm.vue'
import { cloneDeep } from 'lodash-es'
import { createImageViewer } from '@/components/ImageViewer' import { createImageViewer } from '@/components/ImageViewer'
import { sortTableColumns } from '@/hooks/web/useCrudSchemas'
defineOptions({ name: 'PromotionSeckillActivity' }) defineOptions({ name: 'PromotionSeckillActivity' })
@ -99,12 +98,14 @@ const openForm = (type: string, id?: number) => {
const handleDelete = (id: number) => { const handleDelete = (id: number) => {
tableMethods.delList(id, false) tableMethods.delList(id, false)
} }
/** 商品图预览 */ /** 商品图预览 */
const imagePreview = (imgUrl: string) => { const imagePreview = (imgUrl: string) => {
createImageViewer({ createImageViewer({
urlList: [imgUrl] urlList: [imgUrl]
}) })
} }
const configList = ref([]) // const configList = ref([]) //
const convertSeckillConfigNames = computed( const convertSeckillConfigNames = computed(
() => (row) => () => (row) =>
@ -120,18 +121,10 @@ const expandChange = (row, expandedRows) => {
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
/* //
TODO sortTableColumns(allSchemas.tableColumns, 'spuId')
后面准备封装成一个函数来操作 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)
await getList() await getList()
//
configList.value = await getSimpleSeckillConfigList() configList.value = await getSimpleSeckillConfigList()
}) })
</script> </script>