|
|
@@ -1,151 +1,82 @@
|
|
|
<script lang="ts" setup>
|
|
|
+import type { Coupon1Entity } 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 {
|
|
|
+ addCoupon1Api,
|
|
|
+ editCoupon1Api,
|
|
|
+ getCoupon1DetailApi,
|
|
|
+} from '#/api/coupon/coupon1';
|
|
|
+import { $t } from '#/locales';
|
|
|
|
|
|
+const emit = defineEmits(['finish']);
|
|
|
const data = ref();
|
|
|
+const formType = ref<'create' | 'detail' | 'edit'>('create');
|
|
|
|
|
|
-const getTitle = computed(() => (data.value?.create ? '新增客户' : '编辑客户'));
|
|
|
+const titleMap = {
|
|
|
+ create: '新增优惠券',
|
|
|
+ detail: '优惠券详情',
|
|
|
+ edit: '编辑优惠券',
|
|
|
+} as const;
|
|
|
+
|
|
|
+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' },
|
|
|
- {
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'usersname',
|
|
|
- label: '用户名称',
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入用户名称',
|
|
|
- allowClear: true,
|
|
|
- },
|
|
|
- rules: z.string().min(1, { message: '请输入用户名称' }),
|
|
|
- },
|
|
|
- {
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'usersnature',
|
|
|
- label: '用户性质',
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入用户性质',
|
|
|
- allowClear: true,
|
|
|
- },
|
|
|
- rules: z.number().min(1, { message: '请输入用户性质' }),
|
|
|
- },
|
|
|
- {
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'usersidcardnumber',
|
|
|
- label: '用户证件号码',
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入用户证件号码',
|
|
|
- allowClear: true,
|
|
|
- },
|
|
|
- rules: z.string().min(1, { message: '请输入用户证件号码' }),
|
|
|
- },
|
|
|
- {
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'usersbankname',
|
|
|
- label: '用户开户银行名称',
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入用户开户银行名称',
|
|
|
- allowClear: true,
|
|
|
- },
|
|
|
- rules: z.string().min(1, { message: '请输入用户开户银行名称' }),
|
|
|
- },
|
|
|
- {
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'usersbanknumber',
|
|
|
- label: '用户开户银行账号',
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入用户开户银行账号',
|
|
|
- allowClear: true,
|
|
|
- },
|
|
|
- rules: z.string().min(1, { message: '请输入用户开户银行账号' }),
|
|
|
- },
|
|
|
+ // { title: '优惠券名称', field: 'couponmc' },
|
|
|
+ // { title: '优惠券可用产品', field: 'couponproductids' },
|
|
|
+ // { title: '优惠券是否可用', field: 'couponsfky' },
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersphone',
|
|
|
- label: '用户手机号',
|
|
|
+ fieldName: 'couponmc',
|
|
|
+ label: '优惠券名称',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户手机号',
|
|
|
+ placeholder: $t('ui.placeholder.input'),
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户手机号' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入优惠券名称' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersemail',
|
|
|
- label: '用户邮箱',
|
|
|
+ fieldName: 'couponproductids',
|
|
|
+ label: '优惠券可用产品',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户邮箱',
|
|
|
+ placeholder: $t('ui.placeholder.input'),
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户邮箱' }),
|
|
|
+ rules: z.string().min(1, { message: '请输入优惠券可用产品' }),
|
|
|
},
|
|
|
{
|
|
|
component: 'Input',
|
|
|
- fieldName: 'usersaddress',
|
|
|
- label: '用户地址',
|
|
|
+ fieldName: 'couponsfky',
|
|
|
+ label: '优惠券是否可用',
|
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户地址',
|
|
|
+ placeholder: $t('ui.placeholder.input'),
|
|
|
allowClear: true,
|
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户地址' }),
|
|
|
- },
|
|
|
- {
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'userscontactphone',
|
|
|
- label: '用户联系手机号',
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入用户联系手机号',
|
|
|
- allowClear: true,
|
|
|
- },
|
|
|
- rules: z.string().min(1, { message: '请输入用户联系手机号' }),
|
|
|
- },
|
|
|
- {
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'userscontactemail',
|
|
|
- label: '用户联系邮箱',
|
|
|
- componentProps: {
|
|
|
- placeholder: '请输入用户联系邮箱',
|
|
|
- allowClear: true,
|
|
|
- },
|
|
|
- rules: z.string().min(1, { message: '请输入用户联系邮箱' }),
|
|
|
- },
|
|
|
- {
|
|
|
- component: 'Input',
|
|
|
- fieldName: 'userscontactaddress',
|
|
|
- label: '用户联系地址',
|
|
|
- componentProps: {
|
|
|
- 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 +87,47 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- modalApi.close();
|
|
|
- // const values = await baseFormApi.getValues();
|
|
|
+ try {
|
|
|
+ // 调用新增或编辑接口
|
|
|
+ const apiMap = {
|
|
|
+ create: () => addCoupon1Api(validate.values as Coupon1Entity),
|
|
|
+ edit: () =>
|
|
|
+ editCoupon1Api({
|
|
|
+ ...validate.values,
|
|
|
+ 'couponid.value': data.value.row.couponid,
|
|
|
+ } as any),
|
|
|
+ };
|
|
|
+
|
|
|
+ if (formType.value === 'detail') {
|
|
|
+ modalApi.close();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // console.log(Object.keys(values));
|
|
|
+ await apiMap[formType.value]();
|
|
|
+ ElMessage.success('操作成功');
|
|
|
+
|
|
|
+ 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 getCoupon1DetailApi({
|
|
|
+ couponid: data.value.row.couponid,
|
|
|
});
|
|
|
|
|
|
baseFormApi.setValues(detailData);
|