Skip to content

Commit ff8bde2

Browse files
committed
商城:
1. 修复秒杀活动,修改商品的秒杀价格,会存在 *100 的问题
1 parent 9984de0 commit ff8bde2

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

src/hooks/web/useCrudSchemas.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { TableColumn } from '@/types/table'
99
import { DescriptionsSchema } from '@/types/descriptions'
1010
import { ComponentOptions, ComponentProps } from '@/types/components'
1111
import { DictTag } from '@/components/DictTag'
12+
import { cloneDeep } from 'lodash-es'
1213

1314
export type CrudSchema = Omit<TableColumn, 'children'> & {
1415
isSearch?: boolean // 是否在查询显示
@@ -306,3 +307,12 @@ const filterOptions = (options: Recordable, labelField?: string) => {
306307
return v
307308
})
308309
}
310+
311+
// 将 tableColumns 指定 fields 放到最前面
312+
export const sortTableColumns = (tableColumns: TableColumn[], field: string) => {
313+
const fieldIndex = tableColumns.findIndex((item) => item.field === field)
314+
const fieldColumn = cloneDeep(tableColumns[fieldIndex])
315+
tableColumns.splice(fieldIndex, 1)
316+
// 添加到开头
317+
tableColumns.unshift(fieldColumn)
318+
}

src/views/mall/promotion/combination/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const handleDelete = (id: number) => {
9898
tableMethods.delList(id, false)
9999
}
100100
101-
// TODO @puhui999:要不还是使用原生的 element plus 做。感觉 crud schema 复杂界面,做起来麻烦
102101
/** 初始化 **/
103102
onMounted(() => {
104103
/**

src/views/mall/promotion/seckill/activity/SeckillActivityForm.vue

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<script lang="ts" setup>
4646
import { SpuAndSkuList, SpuProperty, SpuSelect } from '../../components'
4747
import { allSchemas, rules } from './seckillActivity.data'
48+
import { cloneDeep } from 'lodash-es'
4849
4950
import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
5051
import { SeckillProductVO } from '@/api/mall/promotion/seckill/seckillActivity'
@@ -70,13 +71,13 @@ const spuAndSkuListRef = ref() // sku 秒杀配置组件Ref
7071
const ruleConfig: RuleConfig[] = [
7172
{
7273
name: 'productConfig.stock',
73-
rule: (arg) => arg > 1,
74-
message: '商品秒杀库存必须大于 1 !!!'
74+
rule: (arg) => arg >= 1,
75+
message: '商品秒杀库存必须大于等于 1 !!!'
7576
},
7677
{
7778
name: 'productConfig.seckillPrice',
78-
rule: (arg) => arg > 0.01,
79-
message: '商品秒杀价格必须大于 0.01 !!!'
79+
rule: (arg) => arg >= 0.01,
80+
message: '商品秒杀价格必须大于等于 0.01 !!!'
8081
}
8182
]
8283
const spuList = ref<SeckillActivityApi.SpuExtension[]>([]) // 选择的 spu
@@ -112,7 +113,6 @@ const getSpuDetails = async (
112113
if (typeof products !== 'undefined') {
113114
const product = products.find((item) => item.skuId === sku.id)
114115
if (product) {
115-
// 分转元
116116
product.seckillPrice = formatToFraction(product.seckillPrice)
117117
}
118118
config = product || config
@@ -153,13 +153,6 @@ const open = async (type: string, id?: number) => {
153153
}
154154
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
155155
156-
/** 重置表单 */
157-
const resetForm = async () => {
158-
spuList.value = []
159-
spuPropertyList.value = []
160-
await nextTick()
161-
formRef.value.getElFormRef().resetFields()
162-
}
163156
/** 提交表单 */
164157
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
165158
const submitForm = async () => {
@@ -170,14 +163,14 @@ const submitForm = async () => {
170163
// 提交请求
171164
formLoading.value = true
172165
try {
173-
const data = formRef.value.formModel as SeckillActivityApi.SeckillActivityVO
174-
const products = spuAndSkuListRef.value.getSkuConfigs('productConfig')
166+
// 获取秒杀商品配置
167+
const products = cloneDeep(spuAndSkuListRef.value.getSkuConfigs('productConfig'))
175168
products.forEach((item: SeckillProductVO) => {
176-
// 秒杀价格元转分
177169
item.seckillPrice = convertToInteger(item.seckillPrice)
178170
})
179-
// 获取秒杀商品配置
171+
const data = formRef.value.formModel as SeckillActivityApi.SeckillActivityVO
180172
data.products = products
173+
// 真正提交
181174
if (formType.value === 'create') {
182175
await SeckillActivityApi.createSeckillActivity(data)
183176
message.success(t('common.createSuccess'))
@@ -192,6 +185,15 @@ const submitForm = async () => {
192185
formLoading.value = false
193186
}
194187
}
188+
189+
/** 重置表单 */
190+
const resetForm = async () => {
191+
spuList.value = []
192+
spuPropertyList.value = []
193+
await nextTick()
194+
formRef.value.getElFormRef().resetFields()
195+
}
196+
// TODO @puhui999:下面的 css 名字,是不是可以改下;demo-table-expand
195197
</script>
196198
<style lang="scss" scoped>
197199
.demo-table-expand {

src/views/mall/promotion/seckill/activity/index.vue

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
type="primary"
1111
@click="openForm('create')"
1212
>
13-
<Icon class="mr-5px" icon="ep:plus" />
14-
新增
13+
<Icon class="mr-5px" icon="ep:plus" /> 新增
1514
</el-button>
1615
</template>
1716
</Search>
@@ -74,8 +73,8 @@ import { allSchemas } from './seckillActivity.data'
7473
import { getSimpleSeckillConfigList } from '@/api/mall/promotion/seckill/seckillConfig'
7574
import * as SeckillActivityApi from '@/api/mall/promotion/seckill/seckillActivity'
7675
import SeckillActivityForm from './SeckillActivityForm.vue'
77-
import { cloneDeep } from 'lodash-es'
7876
import { createImageViewer } from '@/components/ImageViewer'
77+
import { sortTableColumns } from '@/hooks/web/useCrudSchemas'
7978
8079
defineOptions({ name: 'PromotionSeckillActivity' })
8180
@@ -99,12 +98,14 @@ const openForm = (type: string, id?: number) => {
9998
const handleDelete = (id: number) => {
10099
tableMethods.delList(id, false)
101100
}
101+
102102
/** 商品图预览 */
103103
const imagePreview = (imgUrl: string) => {
104104
createImageViewer({
105105
urlList: [imgUrl]
106106
})
107107
}
108+
108109
const configList = ref([]) // 时段配置精简列表
109110
const convertSeckillConfigNames = computed(
110111
() => (row) =>
@@ -120,18 +121,10 @@ const expandChange = (row, expandedRows) => {
120121
121122
/** 初始化 **/
122123
onMounted(async () => {
123-
/*
124-
TODO
125-
后面准备封装成一个函数来操作 tableColumns 重新排列:比如说需求是表单上商品选择是在后面的而列表展示的时候需要调到位置。
126-
封装效果支持批量操作,给出 field 和需要插入的位置,例:[{field:'spuId',index: 1}] 效果为把 field 为 spuId 的 column 移动到第一个位置
127-
*/
128-
// 处理一下表格列让商品往前
129-
const index = allSchemas.tableColumns.findIndex((item) => item.field === 'spuId')
130-
const column = cloneDeep(allSchemas.tableColumns[index])
131-
allSchemas.tableColumns.splice(index, 1)
132-
// 添加到开头
133-
allSchemas.tableColumns.unshift(column)
124+
// 获得活动列表
125+
sortTableColumns(allSchemas.tableColumns, 'spuId')
134126
await getList()
127+
// 获得秒杀时间段
135128
configList.value = await getSimpleSeckillConfigList()
136129
})
137130
</script>

0 commit comments

Comments
 (0)