Skip to content

Commit b18bf8a

Browse files
committed
REVIEW 商品属性
1 parent 5a5202d commit b18bf8a

File tree

2 files changed

+53
-54
lines changed

2 files changed

+53
-54
lines changed

src/views/mall/product/property/value/form.vue renamed to src/views/mall/product/property/value/ValueForm.vue

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
label-width="80px"
88
v-loading="formLoading"
99
>
10-
<el-form-item label="属性id" prop="category">
10+
<el-form-item label="属性编号" prop="category">
1111
<el-input v-model="formData.propertyId" disabled="" />
1212
</el-form-item>
1313
<el-form-item label="名称" prop="name">
@@ -18,43 +18,39 @@
1818
</el-form-item>
1919
</el-form>
2020
<template #footer>
21-
<div class="dialog-footer">
22-
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
23-
<el-button @click="modelVisible = false">取 消</el-button>
24-
</div>
21+
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
22+
<el-button @click="modelVisible = false">取 消</el-button>
2523
</template>
2624
</Dialog>
2725
</template>
2826
<script setup lang="ts">
2927
import * as PropertyApi from '@/api/mall/product/property'
30-
3128
const { t } = useI18n() // 国际化
3229
const message = useMessage() // 消息弹窗
3330
3431
const modelVisible = ref(false) // 弹窗的是否展示
3532
const modelTitle = ref('') // 弹窗的标题
3633
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
3734
const formType = ref('') // 表单的类型:create - 新增;update - 修改
38-
const defaultFormData: PropertyApi.PropertyValueVO = {
35+
const formData = ref({
3936
id: undefined,
4037
propertyId: undefined,
4138
name: '',
4239
remark: ''
43-
}
44-
const formData = ref({ ...defaultFormData })
40+
})
4541
const formRules = reactive({
4642
propertyId: [{ required: true, message: '属性不能为空', trigger: 'blur' }],
4743
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
4844
})
4945
const formRef = ref() // 表单 Ref
5046
5147
/** 打开弹窗 */
52-
const openModal = async (type: string, propertyId: number, id?: number) => {
48+
const open = async (type: string, propertyId: number, id?: number) => {
5349
modelVisible.value = true
5450
modelTitle.value = t('action.' + type)
5551
formType.value = type
56-
defaultFormData.propertyId = propertyId
5752
resetForm()
53+
formData.value.propertyId = propertyId
5854
// 修改时,设置数据
5955
if (id) {
6056
formLoading.value = true
@@ -65,7 +61,7 @@ const openModal = async (type: string, propertyId: number, id?: number) => {
6561
}
6662
}
6763
}
68-
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
64+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
6965
7066
/** 提交表单 */
7167
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
@@ -95,7 +91,12 @@ const submitForm = async () => {
9591
9692
/** 重置表单 */
9793
const resetForm = () => {
98-
formData.value = { ...defaultFormData }
94+
formData.value = {
95+
id: undefined,
96+
propertyId: undefined,
97+
name: '',
98+
remark: ''
99+
}
99100
formRef.value?.resetFields()
100101
}
101102
</script>

src/views/mall/product/property/value/index.vue

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<template>
2-
<content-wrap>
3-
<!-- 搜索工作栏 -->
4-
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
2+
<!-- 搜索工作栏 -->
3+
<ContentWrap>
4+
<el-form
5+
class="-mb-15px"
6+
:model="queryParams"
7+
ref="queryFormRef"
8+
:inline="true"
9+
label-width="68px"
10+
>
511
<el-form-item label="属性项" prop="propertyId">
6-
<el-select v-model="queryParams.propertyId">
12+
<el-select v-model="queryParams.propertyId" class="!w-240px">
713
<el-option
814
v-for="item in propertyOptions"
915
:key="item.id"
@@ -18,19 +24,27 @@
1824
placeholder="请输入名称"
1925
clearable
2026
@keyup.enter="handleQuery"
27+
class="!w-240px"
2128
/>
2229
</el-form-item>
2330
<el-form-item>
2431
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
2532
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
26-
<el-button type="primary" @click="openModal('create')" v-hasPermi="['infra:config:create']">
33+
<el-button
34+
plain
35+
type="primary"
36+
@click="openForm('create')"
37+
v-hasPermi="['product:property:create']"
38+
>
2739
<Icon icon="ep:plus" class="mr-5px" /> 新增
2840
</el-button>
2941
</el-form-item>
3042
</el-form>
43+
</ContentWrap>
3144

32-
<!-- 列表 -->
33-
<el-table v-loading="loading" :data="list" align="center">
45+
<!-- 列表 -->
46+
<ContentWrap>
47+
<el-table v-loading="loading" :data="list">
3448
<el-table-column label="编号" align="center" prop="id" />
3549
<el-table-column label="名称" align="center" prop="name" :show-overflow-tooltip="true" />
3650
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
@@ -46,16 +60,16 @@
4660
<el-button
4761
link
4862
type="primary"
49-
@click="openModal('update', scope.row.id)"
50-
v-hasPermi="['infra:config:update']"
63+
@click="openForm('update', scope.row.id)"
64+
v-hasPermi="['product:property:update']"
5165
>
5266
编辑
5367
</el-button>
5468
<el-button
5569
link
5670
type="danger"
5771
@click="handleDelete(scope.row.id)"
58-
v-hasPermi="['infra:config:delete']"
72+
v-hasPermi="['product:property:delete']"
5973
>
6074
删除
6175
</el-button>
@@ -69,30 +83,30 @@
6983
v-model:limit="queryParams.pageSize"
7084
@pagination="getList"
7185
/>
72-
</content-wrap>
86+
</ContentWrap>
7387

7488
<!-- 表单弹窗:添加/修改 -->
75-
<value-form ref="modalRef" @success="getList" />
89+
<ValueForm ref="formRef" @success="getList" />
7690
</template>
7791
<script setup lang="ts" name="Config">
7892
import { dateFormatter } from '@/utils/formatTime'
7993
import * as PropertyApi from '@/api/mall/product/property'
80-
import ValueForm from './form.vue'
94+
import ValueForm from './ValueForm.vue'
8195
const message = useMessage() // 消息弹窗
8296
const { t } = useI18n() // 国际化
97+
const { params } = useRoute() // 查询参数
8398
8499
const loading = ref(true) // 列表的加载中
85100
const total = ref(0) // 列表的总页数
86101
const list = ref([]) // 列表的数据
87-
const propertyOptions = ref<any[]>([])
88-
const defaultPropertyId = ref()
89-
const queryParams = reactive<any>({
102+
const queryParams = reactive({
90103
pageNo: 1,
91104
pageSize: 10,
92-
name: undefined,
93-
propertyId: undefined
105+
propertyId: Number(params.propertyId),
106+
name: undefined
94107
})
95108
const queryFormRef = ref() // 搜索的表单
109+
const propertyOptions = ref([]) // 属性项的列表
96110
97111
/** 查询参数列表 */
98112
const getList = async () => {
@@ -106,20 +120,6 @@ const getList = async () => {
106120
}
107121
}
108122
109-
/** 属性项下拉框数据 */
110-
const getPropertyList = async () => {
111-
const data = await PropertyApi.getPropertyList({})
112-
propertyOptions.value = data
113-
}
114-
115-
/** 查询字典类型详细 */
116-
const getProperty = async (propertyId: number) => {
117-
const data = await PropertyApi.getProperty(propertyId)
118-
queryParams.propertyId = data.id
119-
defaultPropertyId.value = data.id
120-
await getList()
121-
}
122-
123123
/** 搜索按钮操作 */
124124
const handleQuery = () => {
125125
queryParams.pageNo = 1
@@ -133,9 +133,9 @@ const resetQuery = () => {
133133
}
134134
135135
/** 添加/修改操作 */
136-
const modalRef = ref()
137-
const openModal = (type: string, id?: number) => {
138-
modalRef.value.openModal(type, defaultPropertyId, id)
136+
const formRef = ref()
137+
const openForm = (type: string, id?: number) => {
138+
formRef.value.open(type, queryParams.propertyId, id)
139139
}
140140
141141
/** 删除按钮操作 */
@@ -152,11 +152,9 @@ const handleDelete = async (id: number) => {
152152
}
153153
154154
/** 初始化 **/
155-
const router = useRouter()
156-
onMounted(() => {
157-
const propertyId: number =
158-
router.currentRoute.value.params && (router.currentRoute.value.params.propertyId as any)
159-
getProperty(propertyId)
160-
getPropertyList()
155+
onMounted(async () => {
156+
await getList()
157+
// 属性项下拉框数据
158+
propertyOptions.value = await PropertyApi.getPropertyList({})
161159
})
162160
</script>

0 commit comments

Comments
 (0)