REVIEW 商品属性

This commit is contained in:
YunaiV 2023-04-02 09:46:45 +08:00
parent 5a5202d483
commit b18bf8a95f
2 changed files with 53 additions and 54 deletions

View File

@ -7,7 +7,7 @@
label-width="80px"
v-loading="formLoading"
>
<el-form-item label="属性id" prop="category">
<el-form-item label="属性编号" prop="category">
<el-input v-model="formData.propertyId" disabled="" />
</el-form-item>
<el-form-item label="名称" prop="name">
@ -18,16 +18,13 @@
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="modelVisible = false"> </el-button>
</div>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="modelVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import * as PropertyApi from '@/api/mall/product/property'
const { t } = useI18n() //
const message = useMessage() //
@ -35,13 +32,12 @@ const modelVisible = ref(false) // 弹窗的是否展示
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const defaultFormData: PropertyApi.PropertyValueVO = {
const formData = ref({
id: undefined,
propertyId: undefined,
name: '',
remark: ''
}
const formData = ref({ ...defaultFormData })
})
const formRules = reactive({
propertyId: [{ required: true, message: '属性不能为空', trigger: 'blur' }],
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
@ -49,12 +45,12 @@ const formRules = reactive({
const formRef = ref() // Ref
/** 打开弹窗 */
const openModal = async (type: string, propertyId: number, id?: number) => {
const open = async (type: string, propertyId: number, id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.' + type)
formType.value = type
defaultFormData.propertyId = propertyId
resetForm()
formData.value.propertyId = propertyId
//
if (id) {
formLoading.value = true
@ -65,7 +61,7 @@ const openModal = async (type: string, propertyId: number, id?: number) => {
}
}
}
defineExpose({ openModal }) // openModal
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
@ -95,7 +91,12 @@ const submitForm = async () => {
/** 重置表单 */
const resetForm = () => {
formData.value = { ...defaultFormData }
formData.value = {
id: undefined,
propertyId: undefined,
name: '',
remark: ''
}
formRef.value?.resetFields()
}
</script>

View File

@ -1,9 +1,15 @@
<template>
<content-wrap>
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
<!-- 搜索工作栏 -->
<ContentWrap>
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="属性项" prop="propertyId">
<el-select v-model="queryParams.propertyId">
<el-select v-model="queryParams.propertyId" class="!w-240px">
<el-option
v-for="item in propertyOptions"
:key="item.id"
@ -18,19 +24,27 @@
placeholder="请输入名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button type="primary" @click="openModal('create')" v-hasPermi="['infra:config:create']">
<el-button
plain
type="primary"
@click="openForm('create')"
v-hasPermi="['product:property:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<el-table v-loading="loading" :data="list" align="center">
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list">
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="名称" align="center" prop="name" :show-overflow-tooltip="true" />
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
@ -46,8 +60,8 @@
<el-button
link
type="primary"
@click="openModal('update', scope.row.id)"
v-hasPermi="['infra:config:update']"
@click="openForm('update', scope.row.id)"
v-hasPermi="['product:property:update']"
>
编辑
</el-button>
@ -55,7 +69,7 @@
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['infra:config:delete']"
v-hasPermi="['product:property:delete']"
>
删除
</el-button>
@ -69,30 +83,30 @@
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</content-wrap>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<value-form ref="modalRef" @success="getList" />
<ValueForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts" name="Config">
import { dateFormatter } from '@/utils/formatTime'
import * as PropertyApi from '@/api/mall/product/property'
import ValueForm from './form.vue'
import ValueForm from './ValueForm.vue'
const message = useMessage() //
const { t } = useI18n() //
const { params } = useRoute() //
const loading = ref(true) //
const total = ref(0) //
const list = ref([]) //
const propertyOptions = ref<any[]>([])
const defaultPropertyId = ref()
const queryParams = reactive<any>({
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: undefined,
propertyId: undefined
propertyId: Number(params.propertyId),
name: undefined
})
const queryFormRef = ref() //
const propertyOptions = ref([]) //
/** 查询参数列表 */
const getList = async () => {
@ -106,20 +120,6 @@ const getList = async () => {
}
}
/** 属性项下拉框数据 */
const getPropertyList = async () => {
const data = await PropertyApi.getPropertyList({})
propertyOptions.value = data
}
/** 查询字典类型详细 */
const getProperty = async (propertyId: number) => {
const data = await PropertyApi.getProperty(propertyId)
queryParams.propertyId = data.id
defaultPropertyId.value = data.id
await getList()
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
@ -133,9 +133,9 @@ const resetQuery = () => {
}
/** 添加/修改操作 */
const modalRef = ref()
const openModal = (type: string, id?: number) => {
modalRef.value.openModal(type, defaultPropertyId, id)
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, queryParams.propertyId, id)
}
/** 删除按钮操作 */
@ -152,11 +152,9 @@ const handleDelete = async (id: number) => {
}
/** 初始化 **/
const router = useRouter()
onMounted(() => {
const propertyId: number =
router.currentRoute.value.params && (router.currentRoute.value.params.propertyId as any)
getProperty(propertyId)
getPropertyList()
onMounted(async () => {
await getList()
//
propertyOptions.value = await PropertyApi.getPropertyList({})
})
</script>