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

This commit is contained in:
YunaiV 2023-12-06 12:32:51 +08:00
parent ee9667504f
commit b3d66cd0aa
5 changed files with 92 additions and 97 deletions

View File

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

View File

@ -204,5 +204,6 @@ export enum DICT_TYPE {
CRM_CUSTOMER_LEVEL = 'crm_customer_level', CRM_CUSTOMER_LEVEL = 'crm_customer_level',
CRM_CUSTOMER_SOURCE = 'crm_customer_source', CRM_CUSTOMER_SOURCE = 'crm_customer_source',
CRM_PRODUCT_STATUS = 'crm_product_status', 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> </Dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
// TODO tab
import { DICT_TYPE } from '@/utils/dict' import { DICT_TYPE } from '@/utils/dict'
import * as ProductCategoryApi from '@/api/crm/product/productCategory' import * as ProductCategoryApi from '@/api/crm/product/productCategory'
import * as ProductApi from '@/api/crm/product' import * as ProductApi from '@/api/crm/product'

View File

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

View File

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