🔨 CRM:优化产品代码的实现

(cherry picked from commit b3d66cd0aa)
This commit is contained in:
YunaiV 2023-12-06 12:32:51 +08:00 committed by shizhong
parent 72b82625b9
commit 2be6f196e6
5 changed files with 92 additions and 97 deletions

View File

@ -4,7 +4,7 @@ export interface ProductVO {
id: number
name: string
no: string
unit: string
unit: number
price: number
status: number
categoryId: number

View File

@ -204,5 +204,6 @@ export enum DICT_TYPE {
CRM_CUSTOMER_LEVEL = 'crm_customer_level',
CRM_CUSTOMER_SOURCE = 'crm_customer_source',
CRM_PRODUCT_STATUS = 'crm_product_status',
CRM_PERMISSION_LEVEL = 'crm_permission_level' // CRM 数据权限的级别
CRM_PERMISSION_LEVEL = 'crm_permission_level', // CRM 数据权限的级别
CRM_PRODUCT_UNIT = 'crm_product_unit' // 产品单位
}

View File

@ -32,6 +32,7 @@
</Dialog>
</template>
<script setup lang="ts">
// TODO tab
import { DICT_TYPE } from '@/utils/dict'
import * as ProductCategoryApi from '@/api/crm/product/productCategory'
import * as ProductApi from '@/api/crm/product'

View File

@ -1,6 +1,5 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<!-- TODO @zange改成每行两个哈 -->
<el-form
ref="formRef"
:model="formData"
@ -15,14 +14,37 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品编码" prop="no">
<el-input v-model="formData.no" placeholder="请输入产品编码" />
<el-form-item label="负责人" prop="ownerUserId">
<el-select
v-model="formData.ownerUserId"
placeholder="请选择负责人"
:disabled="formData.id"
class="w-1/1"
>
<el-option
v-for="user in userList"
:key="user.id"
:label="user.nickname"
:value="user.id"
/>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="单位" prop="unit">
<el-form-item label="产品类型" prop="categoryId">
<el-cascader
v-model="formData.categoryId"
:options="productCategoryList"
:props="defaultProps"
class="w-1/1"
clearable
placeholder="请选择产品类型"
filterable
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品单位" prop="unit">
<el-select v-model="formData.unit" class="w-1/1" placeholder="请选择单位">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.PRODUCT_UNIT)"
@ -33,57 +55,36 @@
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品编码" prop="no">
<el-input v-model="formData.no" placeholder="请输入产品编码" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="价格" prop="price">
<el-input type="number" v-model="formData.price" placeholder="请输入价格" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="状态" prop="status">
<el-select v-model="formData.status" placeholder="请选择状态">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品分类" prop="categoryId">
<el-cascader
v-model="formData.categoryId"
:options="productCategoryList"
:props="defaultProps"
class="w-1/1"
clearable
placeholder="请选择产品分类"
filterable
<el-input
type="number"
v-model="formData.price"
placeholder="请输入价格"
:min="0"
:precision="2"
:step="0.1"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="产品描述" prop="description">
<el-input v-model="formData.description" placeholder="请输入产品描述" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="负责人" prop="ownerUserId">
<el-select
v-model="formData.ownerUserId"
placeholder="请选择负责人"
:disabled="formData.id"
>
<el-form-item label="上架状态" prop="status">
<el-select v-model="formData.status" placeholder="请选择状态" class="w-1/1">
<el-option
v-for="user in userList"
:key="user.id"
:label="user.nickname"
:value="user.id"
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
@ -103,6 +104,7 @@ import * as ProductCategoryApi from '@/api/crm/product/productCategory'
import { defaultProps, handleTree } from '@/utils/tree'
import { getSimpleUserList, UserVO } from '@/api/system/user'
import { useUserStore } from '@/store/modules/user'
import { fenToYuan, yuanToFen } from '@/utils'
defineOptions({ name: 'CrmProductForm' })
@ -119,11 +121,11 @@ const formData = ref({
name: undefined,
no: undefined,
unit: undefined,
price: undefined,
price: Number(undefined),
status: undefined,
categoryId: undefined,
description: undefined,
ownerUserId: undefined
ownerUserId: -1
})
const formRules = reactive({
name: [{ required: true, message: '产品名称不能为空', trigger: 'blur' }],
@ -131,7 +133,6 @@ const formRules = reactive({
status: [{ required: true, message: '状态不能为空', trigger: 'change' }],
categoryId: [{ required: true, message: '产品分类ID不能为空', trigger: 'blur' }],
ownerUserId: [{ required: true, message: '负责人不能为空', trigger: 'blur' }],
unit: [{ required: true, message: '单位不能为空', trigger: 'blur' }],
price: [{ required: true, message: '价格不能为空', trigger: 'blur' }]
})
@ -143,22 +144,23 @@ const open = async (type: string, id?: number) => {
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
formData.value.ownerUserId = userId
//
if (id) {
formLoading.value = true
try {
formData.value = await ProductApi.getProduct(id)
formData.value.price = fenToYuan(formData.value.price)
} finally {
formLoading.value = false
}
} else {
formData.value.ownerUserId = userId
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
@ -167,7 +169,10 @@ const submitForm = async () => {
//
formLoading.value = true
try {
const data = formData.value as unknown as ProductApi.ProductVO
const data = {
...formData.value,
price: yuanToFen(formData.value.price)
} as unknown as ProductApi.ProductVO
if (formType.value === 'create') {
await ProductApi.createProduct(data)
message.success(t('common.createSuccess'))
@ -190,20 +195,23 @@ const resetForm = () => {
name: undefined,
no: undefined,
unit: undefined,
price: undefined,
price: Number(undefined),
status: undefined,
categoryId: undefined,
description: undefined,
ownerUserId: undefined
ownerUserId: -1
}
formRef.value?.resetFields()
}
/** 初始化 */
const productCategoryList = ref<any[]>([]) //
const userList = ref<UserVO[]>([]) //
onMounted(async () => {
//
const data = await ProductCategoryApi.getProductCategoryList({})
productCategoryList.value = handleTree(data, 'id', 'parentId')
userList.value = await getSimpleUserList()
//
userList.value = await getSimpleUserList() // TODO
})
</script>

View File

@ -20,7 +20,7 @@
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
<el-option
v-for="dict in getBoolDictOptions(DICT_TYPE.CRM_PRODUCT_STATUS)"
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
@ -49,35 +49,35 @@
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<!--<el-table-column label="主键id" align="center" prop="id" />-->
<el-table-column label="产品名称" align="center" prop="name" />
<el-table-column label="产品编码" align="center" prop="no" />
<el-table-column label="单位" align="center" prop="unit">
<el-table-column label="产品类型" align="center" prop="categoryName" />
<el-table-column label="产品单位" align="center" prop="unit">
<template #default="scope">
<dict-tag :type="DICT_TYPE.PRODUCT_UNIT" :value="scope.row.unit" />
</template>
</el-table-column>
<el-table-column label="价格" align="center" prop="price">
<template #default="{ row }">
{{ fenToYuan(row.price) }}
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status">
<el-table-column label="产品编码" align="center" prop="no" />
<el-table-column
label="价格(元)"
align="center"
prop="price"
:formatter="fenToYuanFormat"
/>
<el-table-column label="产品描述" align="center" prop="description" />
<el-table-column label="是否上下架" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.CRM_PRODUCT_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="产品分类" align="center" prop="categoryId">
<template #default="{ row }">
<span>{{ productCategoryList?.find((c) => c.id === row.categoryId)?.name }}</span>
</template>
</el-table-column>
<el-table-column label="产品描述" align="center" prop="description" />
<el-table-column label="负责人" align="center" prop="ownerUserId">
<template #default="{ row }">
<span>{{ userList?.find((c) => c.id === row.ownerUserId)?.nickname }}</span>
</template>
</el-table-column>
<el-table-column label="负责人" align="center" prop="ownerUserName" />
<el-table-column
label="更新时间"
align="center"
prop="updateTime"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column label="创建" align="center" prop="creatorName" />
<el-table-column
label="创建时间"
align="center"
@ -125,21 +125,18 @@
<!-- 表单弹窗添加/修改 -->
<ProductForm ref="formRef" @success="getList" />
<!-- 表单弹窗详情 -->
<ProductDetail ref="detailRef" @success="getList" />
</template>
<script setup lang="ts">
import { DICT_TYPE, getBoolDictOptions } from '@/utils/dict'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import * as ProductApi from '@/api/crm/product'
import ProductForm from './ProductForm.vue'
import ProductDetail from './ProductDetail.vue'
import { fenToYuan } from '@/utils'
import * as ProductCategoryApi from '@/api/crm/product/productCategory'
import { getSimpleUserList, UserVO } from '@/api/system/user'
import { fenToYuanFormat } from '@/utils/formatter'
defineOptions({ name: 'CrmProduct' })
@ -152,15 +149,8 @@ const list = ref([]) // 列表的数据
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
name: null,
no: null,
unit: null,
price: null,
status: null,
categoryId: null,
description: null,
ownerUserId: null,
createTime: []
name: undefined,
status: undefined
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
@ -228,13 +218,8 @@ const handleExport = async () => {
}
}
const productCategoryList = ref([]) //
const userList = ref<UserVO[]>([]) //
/** 初始化 **/
onMounted(async () => {
await getList()
productCategoryList.value = await ProductCategoryApi.getProductCategoryList({})
userList.value = await getSimpleUserList()
})
</script>