|
@@ -1,151 +1,158 @@
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
|
|
+import type { OrdersEntity } from '@vben/types';
|
|
|
|
|
+
|
|
|
import { computed, ref } from 'vue';
|
|
import { computed, ref } from 'vue';
|
|
|
|
|
|
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
|
|
|
|
|
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
|
|
+
|
|
|
import { useVbenForm, z } from '#/adapter/form';
|
|
import { useVbenForm, z } from '#/adapter/form';
|
|
|
-import { getCustomerDetailApi } from '#/api/customer-manage';
|
|
|
|
|
|
|
+import { addOrdersApi, editOrdersApi, getOrdersDetailApi } from '#/api/orders';
|
|
|
|
|
|
|
|
|
|
+const emit = defineEmits(['finish']);
|
|
|
const data = ref();
|
|
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({
|
|
const [BaseForm, baseFormApi] = useVbenForm({
|
|
|
showDefaultActions: false,
|
|
showDefaultActions: false,
|
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
|
commonConfig: {
|
|
commonConfig: {
|
|
|
- labelWidth: 120,
|
|
|
|
|
|
|
+ labelWidth: 140,
|
|
|
// 所有表单项
|
|
// 所有表单项
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
class: 'w-full',
|
|
class: 'w-full',
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
|
|
+ wrapperClass: 'grid-cols-1 lg:grid-cols-2',
|
|
|
schema: [
|
|
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: '请输入用户名称' }),
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ // { title: '订单号', field: 'ordersnumber' },
|
|
|
|
|
+ // { title: '订单关联用户id', field: 'ordersuserid' },
|
|
|
|
|
+ // { title: '订单关联产品id', field: 'ordersproductid' },
|
|
|
|
|
+ // { title: '产品名称', field: 'ordersproductname' },
|
|
|
|
|
+ // { title: '产品sn', field: 'ordersproductsn' },
|
|
|
|
|
+ // { title: '订单总金额', field: 'orderstotalprice' },
|
|
|
|
|
+ // { title: '订单优惠后金额', field: 'ordersdiscountprice' },
|
|
|
|
|
+ // { title: '优惠金额', field: 'ordersyhprice' },
|
|
|
|
|
+ // { title: '优惠卷id', field: 'orderscouponid' },
|
|
|
|
|
+ // { title: '订单状态', field: 'ordersorderstatus' },
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'usersnature',
|
|
|
|
|
- label: '用户性质',
|
|
|
|
|
|
|
+ fieldName: 'ordersnumber',
|
|
|
|
|
+ label: '订单号',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户性质',
|
|
|
|
|
|
|
+ placeholder: '请输入订单号',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.number().min(1, { message: '请输入用户性质' }),
|
|
|
|
|
|
|
+ rules: z.string().min(1, { message: '请输入订单号' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'usersidcardnumber',
|
|
|
|
|
- label: '用户证件号码',
|
|
|
|
|
|
|
+ fieldName: 'ordersuserid',
|
|
|
|
|
+ label: '订单关联用户id',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户证件号码',
|
|
|
|
|
|
|
+ placeholder: '请输入订单关联用户id',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户证件号码' }),
|
|
|
|
|
|
|
+ rules: z.string().min(1, { message: '请输入订单关联用户id' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'usersbankname',
|
|
|
|
|
- label: '用户开户银行名称',
|
|
|
|
|
|
|
+ fieldName: 'ordersproductid',
|
|
|
|
|
+ label: '订单关联产品id',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户开户银行名称',
|
|
|
|
|
|
|
+ placeholder: '请输入订单关联产品id',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户开户银行名称' }),
|
|
|
|
|
|
|
+ rules: z.string().min(1, { message: '请输入订单关联产品id' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'usersbanknumber',
|
|
|
|
|
- label: '用户开户银行账号',
|
|
|
|
|
|
|
+ fieldName: 'ordersproductname',
|
|
|
|
|
+ label: '产品名称',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户开户银行账号',
|
|
|
|
|
|
|
+ placeholder: '请输入产品名称',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户开户银行账号' }),
|
|
|
|
|
|
|
+ rules: z.string().min(1, { message: '请输入产品名称' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'usersphone',
|
|
|
|
|
- label: '用户手机号',
|
|
|
|
|
|
|
+ fieldName: 'ordersproductsn',
|
|
|
|
|
+ label: '产品sn',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户手机号',
|
|
|
|
|
|
|
+ placeholder: '请输入产品sn',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户手机号' }),
|
|
|
|
|
|
|
+ rules: z.string().min(1, { message: '请输入产品sn' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'usersemail',
|
|
|
|
|
- label: '用户邮箱',
|
|
|
|
|
|
|
+ fieldName: 'orderstotalprice',
|
|
|
|
|
+ label: '订单总金额',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户邮箱',
|
|
|
|
|
|
|
+ placeholder: '请输入订单总金额',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户邮箱' }),
|
|
|
|
|
|
|
+ rules: z.number().min(0, { message: '请输入有效的订单总金额' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'usersaddress',
|
|
|
|
|
- label: '用户地址',
|
|
|
|
|
|
|
+ fieldName: 'ordersdiscountprice',
|
|
|
|
|
+ label: '订单优惠后金额',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户地址',
|
|
|
|
|
|
|
+ placeholder: '请输入订单优惠后金额',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户地址' }),
|
|
|
|
|
|
|
+ rules: z.number().min(0, { message: '请输入有效的订单优惠后金额' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'userscontactphone',
|
|
|
|
|
- label: '用户联系手机号',
|
|
|
|
|
|
|
+ fieldName: 'ordersyhprice',
|
|
|
|
|
+ label: '优惠金额',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户联系手机号',
|
|
|
|
|
|
|
+ placeholder: '请输入优惠金额',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户联系手机号' }),
|
|
|
|
|
|
|
+ rules: z.number().min(0, { message: '请输入有效的优惠金额' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
- fieldName: 'userscontactemail',
|
|
|
|
|
- label: '用户联系邮箱',
|
|
|
|
|
|
|
+ fieldName: 'orderscouponid',
|
|
|
|
|
+ label: '优惠券id',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户联系邮箱',
|
|
|
|
|
|
|
+ placeholder: '请输入优惠券id',
|
|
|
allowClear: true,
|
|
allowClear: true,
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户联系邮箱' }),
|
|
|
|
|
|
|
+ rules: z.string().min(1, { message: '请输入优惠券id' }),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- component: 'Input',
|
|
|
|
|
- fieldName: 'userscontactaddress',
|
|
|
|
|
- label: '用户联系地址',
|
|
|
|
|
|
|
+ component: 'Select',
|
|
|
|
|
+ fieldName: 'ordersorderstatus',
|
|
|
|
|
+ label: '订单状态',
|
|
|
componentProps: {
|
|
componentProps: {
|
|
|
- placeholder: '请输入用户联系地址',
|
|
|
|
|
- allowClear: true,
|
|
|
|
|
|
|
+ placeholder: '请选择订单状态',
|
|
|
|
|
+ options: [
|
|
|
|
|
+ { label: '待审核', value: 0 },
|
|
|
|
|
+ { label: '已支付', value: 1 },
|
|
|
|
|
+ { label: '已完成', value: 2 },
|
|
|
|
|
+ ],
|
|
|
},
|
|
},
|
|
|
- rules: z.string().min(1, { message: '请输入用户联系地址' }),
|
|
|
|
|
|
|
+ rules: z.number().min(0, { message: '请选择订单状态' }),
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const [Modal, modalApi] = useVbenModal({
|
|
const [Modal, modalApi] = useVbenModal({
|
|
|
|
|
+ class: 'w-7/12',
|
|
|
onCancel() {
|
|
onCancel() {
|
|
|
modalApi.close();
|
|
modalApi.close();
|
|
|
},
|
|
},
|
|
@@ -156,23 +163,47 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- modalApi.close();
|
|
|
|
|
- // const values = await baseFormApi.getValues();
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 调用新增或编辑接口
|
|
|
|
|
+ const apiMap = {
|
|
|
|
|
+ create: () => addOrdersApi(validate.values as OrdersEntity),
|
|
|
|
|
+ edit: () =>
|
|
|
|
|
+ editOrdersApi({
|
|
|
|
|
+ ...validate.values,
|
|
|
|
|
+ 'ordersid.value': data.value.row.ordersid,
|
|
|
|
|
+ } as any),
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- // console.log(Object.keys(values));
|
|
|
|
|
|
|
+ if (formType.value === 'detail') {
|
|
|
|
|
+ modalApi.close();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ await apiMap[formType.value]();
|
|
|
|
|
+ ElMessage.success('操作成功');
|
|
|
|
|
+
|
|
|
|
|
+ emit('finish');
|
|
|
|
|
+ modalApi.close();
|
|
|
|
|
+ } catch {}
|
|
|
},
|
|
},
|
|
|
async onOpenChange(isOpen) {
|
|
async onOpenChange(isOpen) {
|
|
|
if (isOpen) {
|
|
if (isOpen) {
|
|
|
data.value = modalApi.getData();
|
|
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;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
modalApi.setState({ loading: true });
|
|
modalApi.setState({ loading: true });
|
|
|
- const detailData = await getCustomerDetailApi({
|
|
|
|
|
- usersid: data.value.row.usersid,
|
|
|
|
|
|
|
+ const detailData = await getOrdersDetailApi({
|
|
|
|
|
+ ordersid: data.value.row.ordersid,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
baseFormApi.setValues(detailData);
|
|
baseFormApi.setValues(detailData);
|