|
|
@@ -1,151 +1,194 @@
|
|
|
<script lang="ts" setup>
|
|
|
+import type { ProductEntity } from '@vben/types';
|
|
|
+
|
|
|
import { computed, ref } from 'vue';
|
|
|
|
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
|
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
+
|
|
|
import { useVbenForm, z } from '#/adapter/form';
|
|
|
-import { getCustomerDetailApi } from '#/api/customer-manage';
|
|
|
+import {
|
|
|
+ addProductApi,
|
|
|
+ editProductApi,
|
|
|
+ getProductDetailApi,
|
|
|
+} from '#/api/product-manage';
|
|
|
|
|
|
+const emit = defineEmits(['finish']);
|
|
|
const data = ref();
|
|
|
+const formType = ref<'create' | 'detail' | 'edit'>('create');
|
|
|
+
|
|
|
+const titleMap = {
|
|
|
+ create: '新增产品',
|
|
|
+ detail: '产品详情',
|
|
|
+ edit: '编辑产品',
|
|
|
+} as const;
|
|
|
|
|
|
-const getTitle = computed(() => (data.value?.create ? '新增客户' : '编辑客户'));
|
|
|
+const getTitle = computed(() => titleMap[formType.value]);
|
|
|
|
|
|
const [BaseForm, baseFormApi] = useVbenForm({
|
|
|
showDefaultActions: false,
|
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
|
commonConfig: {
|
|
|
- labelWidth: 120,
|
|
|
+ labelWidth: 140,
|
|
|
// 所有表单项
|
|
|
componentProps: {
|
|
|
class: 'w-full',
|
|
|
},
|
|
|
},
|
|
|
+ wrapperClass: 'grid-cols-1 lg:grid-cols-2',
|
|
|
schema: [
|
|
|
- // { title: '用户名称', field: 'usersname' },
|
|
|
- // { title: '用户性质', field: 'usersnature' },
|
|
|
- // { title: '用户证件号码', field: 'usersidcardnumber' },
|
|
|
- // { title: '用户开户银行名称', field: 'usersbankname' },
|
|
|
- // { title: '用户开户银行账号', field: 'usersbanknumber' },
|
|
|
- // { title: '用户手机号', field: 'usersphone' },
|
|
|
- // { title: '用户邮箱', field: 'usersemail' },
|
|
|
- // { title: '用户地址', field: 'usersaddress' },
|
|
|
- // { title: '用户联系手机号', field: 'userscontactphone' },
|
|
|
- // { title: '用户联系邮箱', field: 'userscontactemail' },
|
|
|
- // { title: '用户联系地址', field: 'userscontactaddress' },
|
|
|
+ // { title: '产品名称', field: 'productsname' },
|
|
|
+ // { title: '产品类别', field: 'productscategory' },
|
|
|
+ // { title: '产品原价', field: 'productsprice' },
|
|
|
+ // { title: '产品型号', field: 'productsmodel' },
|
|
|
+ // { title: '产品sn号', field: 'productssn' },
|
|
|
+ // { title: '品目', field: 'productspm' },
|
|
|
+ // { title: '一级分类', field: 'productsfl1' },
|
|
|
+ // { title: '二级分类', field: 'productsfl2' },
|
|
|
+ // { title: '分档名称', field: 'productsfdmc' },
|
|
|
+ // { title: '分档编号', field: 'productsfdbh' },
|
|
|
+ // { title: '中央补贴金额', field: 'productszybt' },
|
|
|
+ // { title: '特殊县中央补贴金额', field: 'productstsxzybt' },
|
|
|
+ // { title: '机具类型', field: 'productsjjlx' },
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersname',
|
|
|
- label: '用户名称',
|
|
|
+ fieldName: 'productsname',
|
|
|
+ label: '产品名称',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户名称',
|
|
|
+ placeholder: '请输入产品名称',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户名称' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入产品名称' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersnature',
|
|
|
- label: '用户性质',
|
|
|
+ fieldName: 'productscategory',
|
|
|
+ label: '产品类别',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户性质',
|
|
|
+ placeholder: '请输入产品类别',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.number().min(1, { message: '请输入用户性质' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入产品类别' }),
|
|
|
},
|
|
|
{
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'usersidcardnumber',
|
|
|
- label: '用户证件号码',
|
|
|
+ component: 'InputNumber',
|
|
|
+ fieldName: 'productsprice',
|
|
|
+ label: '产品原价',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户证件号码',
|
|
|
- allowClear: true,
|
|
|
+ placeholder: '请输入产品原价',
|
|
|
+ min: 0,
|
|
|
+ precision: 2,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户证件号码' }),
|
|
|
+ rules: z.number().min(0, { message: '请输入正确的产品原价' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersbankname',
|
|
|
- label: '用户开户银行名称',
|
|
|
+ fieldName: 'productsmodel',
|
|
|
+ label: '产品型号',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户开户银行名称',
|
|
|
+ placeholder: '请输入产品型号',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户开户银行名称' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入产品型号' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersbanknumber',
|
|
|
- label: '用户开户银行账号',
|
|
|
+ fieldName: 'productssn',
|
|
|
+ label: '产品SN号',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户开户银行账号',
|
|
|
+ placeholder: '请输入产品SN号',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户开户银行账号' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入产品SN号' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersphone',
|
|
|
- label: '用户手机号',
|
|
|
+ fieldName: 'productspm',
|
|
|
+ label: '品目',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户手机号',
|
|
|
+ placeholder: '请输入品目',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户手机号' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入品目' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersemail',
|
|
|
- label: '用户邮箱',
|
|
|
+ fieldName: 'productsfl1',
|
|
|
+ label: '一级分类',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户邮箱',
|
|
|
+ placeholder: '请输入一级分类',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户邮箱' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入一级分类' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersaddress',
|
|
|
- label: '用户地址',
|
|
|
+ fieldName: 'productsfl2',
|
|
|
+ label: '二级分类',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户地址',
|
|
|
+ placeholder: '请输入二级分类',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户地址' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入二级分类' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'userscontactphone',
|
|
|
- label: '用户联系手机号',
|
|
|
+ fieldName: 'productsfdmc',
|
|
|
+ label: '分档名称',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户联系手机号',
|
|
|
+ placeholder: '请输入分档名称',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户联系手机号' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入分档名称' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'userscontactemail',
|
|
|
- label: '用户联系邮箱',
|
|
|
+ fieldName: 'productsfdbh',
|
|
|
+ label: '分档编号',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户联系邮箱',
|
|
|
+ placeholder: '请输入分档编号',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户联系邮箱' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入分档编号' }),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ component: 'InputNumber',
|
|
|
+ fieldName: 'productszybt',
|
|
|
+ label: '中央补贴金额',
|
|
|
+ componentProps: {
|
|
|
+ placeholder: '请输入中央补贴金额',
|
|
|
+ min: 0,
|
|
|
+ precision: 2,
|
|
|
+ },
|
|
|
+ rules: z.number().min(0, { message: '请输入正确的中央补贴金额' }),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ component: 'InputNumber',
|
|
|
+ fieldName: 'productstsxzybt',
|
|
|
+ label: '特殊县中央补贴金额',
|
|
|
+ componentProps: {
|
|
|
+ placeholder: '请输入特殊县中央补贴金额',
|
|
|
+ min: 0,
|
|
|
+ precision: 2,
|
|
|
+ },
|
|
|
+ rules: z.number().min(0, { message: '请输入正确的特殊县中央补贴金额' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'userscontactaddress',
|
|
|
- label: '用户联系地址',
|
|
|
+ fieldName: 'productsjjlx',
|
|
|
+ label: '机具类型',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户联系地址',
|
|
|
+ placeholder: '请输入机具类型',
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户联系地址' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入机具类型' }),
|
|
|
},
|
|
|
],
|
|
|
});
|
|
|
|
|
|
const [Modal, modalApi] = useVbenModal({
|
|
|
+ class: 'w-7/12',
|
|
|
onCancel() {
|
|
|
modalApi.close();
|
|
|
},
|
|
|
@@ -156,23 +199,47 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- modalApi.close();
|
|
|
- // const values = await baseFormApi.getValues();
|
|
|
+ try {
|
|
|
+ // 调用新增或编辑接口
|
|
|
+ const apiMap = {
|
|
|
+ create: () => addProductApi(validate.values as ProductEntity),
|
|
|
+ edit: () =>
|
|
|
+ editProductApi({
|
|
|
+ ...validate.values,
|
|
|
+ 'productsid.value': data.value.row.productsid,
|
|
|
+ } as any),
|
|
|
+ };
|
|
|
+
|
|
|
+ if (formType.value === 'detail') {
|
|
|
+ modalApi.close();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ await apiMap[formType.value]();
|
|
|
+ ElMessage.success('操作成功');
|
|
|
|
|
|
- // console.log(Object.keys(values));
|
|
|
+ emit('finish');
|
|
|
+ modalApi.close();
|
|
|
+ } catch {}
|
|
|
},
|
|
|
async onOpenChange(isOpen) {
|
|
|
if (isOpen) {
|
|
|
data.value = modalApi.getData();
|
|
|
|
|
|
- if (data.value.create) {
|
|
|
+ formType.value = data.value.formType;
|
|
|
+
|
|
|
+ baseFormApi.setState({
|
|
|
+ commonConfig: { disabled: formType.value === 'detail' },
|
|
|
+ });
|
|
|
+
|
|
|
+ if (data.value.formType === 'create') {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
modalApi.setState({ loading: true });
|
|
|
- const detailData = await getCustomerDetailApi({
|
|
|
- usersid: data.value.row.usersid,
|
|
|
+ const detailData = await getProductDetailApi({
|
|
|
+ productsid: data.value.row.productsid,
|
|
|
});
|
|
|
|
|
|
baseFormApi.setValues(detailData);
|