赖奇 пре 1 година
родитељ
комит
71638c2c12

+ 48 - 0
apps/web-ele/src/api/orders/index.ts

@@ -0,0 +1,48 @@
+import type { OrdersEntity, PageConfig } from '@vben/types';
+
+import { adaptBackendRequest } from '@vben/utils';
+
+import { requestClient } from '#/api/request';
+
+interface OrdersPartialEntity
+  extends Partial<Omit<OrdersEntity, 'ordersnumber'>> {
+  ordersnumber?: string;
+}
+
+interface OrdersQueryParams extends OrdersPartialEntity, PageConfig {}
+
+/**
+ * 订单信息_列表
+ */
+export async function getOrdersListApi(params: OrdersQueryParams) {
+  return requestClient.post<any>('/api/query/list?pagevalue=51', {
+    ...params,
+  });
+}
+
+/**
+ * 订单信息_详情
+ */
+export async function getOrdersDetailApi(data: { ordersid: string }) {
+  return requestClient.post<any>(
+    '/api/query/view?pagevalue=52',
+    {
+      ...adaptBackendRequest(data),
+    },
+    { formatData: true }, // 格式化返回数据
+  );
+}
+
+/**
+ * 订单信息_新增
+ */
+export async function addOrdersApi(data: OrdersEntity) {
+  return requestClient.post<any>('/api/add?pagevalue=53', { ...data });
+}
+
+/**
+ * 客户信息_编辑
+ */
+export async function editOrdersApi(data: OrdersEntity) {
+  return requestClient.post<any>('/api/up?pagevalue=54', { ...data });
+}

+ 103 - 72
apps/web-ele/src/views/order-manage/form.vue

@@ -1,151 +1,158 @@
 <script lang="ts" setup>
+import type { OrdersEntity } 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 { addOrdersApi, editOrdersApi, getOrdersDetailApi } from '#/api/orders';
 
+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' },
-    {
-      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',
-      fieldName: 'usersnature',
-      label: '用户性质',
+      fieldName: 'ordersnumber',
+      label: '订单号',
       componentProps: {
-        placeholder: '请输入用户性质',
+        placeholder: '请输入订单号',
         allowClear: true,
       },
-      rules: z.number().min(1, { message: '请输入用户性质' }),
+      rules: z.string().min(1, { message: '请输入订单号' }),
     },
     {
       component: 'Input',
-      fieldName: 'usersidcardnumber',
-      label: '用户证件号码',
+      fieldName: 'ordersuserid',
+      label: '订单关联用户id',
       componentProps: {
-        placeholder: '请输入用户证件号码',
+        placeholder: '请输入订单关联用户id',
         allowClear: true,
       },
-      rules: z.string().min(1, { message: '请输入用户证件号码' }),
+      rules: z.string().min(1, { message: '请输入订单关联用户id' }),
     },
     {
       component: 'Input',
-      fieldName: 'usersbankname',
-      label: '用户开户银行名称',
+      fieldName: 'ordersproductid',
+      label: '订单关联产品id',
       componentProps: {
-        placeholder: '请输入用户开户银行名称',
+        placeholder: '请输入订单关联产品id',
         allowClear: true,
       },
-      rules: z.string().min(1, { message: '请输入用户开户银行名称' }),
+      rules: z.string().min(1, { message: '请输入订单关联产品id' }),
     },
     {
       component: 'Input',
-      fieldName: 'usersbanknumber',
-      label: '用户开户银行账号',
+      fieldName: 'ordersproductname',
+      label: '产品名称',
       componentProps: {
-        placeholder: '请输入用户开户银行账号',
+        placeholder: '请输入产品名称',
         allowClear: true,
       },
-      rules: z.string().min(1, { message: '请输入用户开户银行账号' }),
+      rules: z.string().min(1, { message: '请输入产品名称' }),
     },
     {
       component: 'Input',
-      fieldName: 'usersphone',
-      label: '用户手机号',
+      fieldName: 'ordersproductsn',
+      label: '产品sn',
       componentProps: {
-        placeholder: '请输入用户手机号',
+        placeholder: '请输入产品sn',
         allowClear: true,
       },
-      rules: z.string().min(1, { message: '请输入用户手机号' }),
+      rules: z.string().min(1, { message: '请输入产品sn' }),
     },
     {
       component: 'Input',
-      fieldName: 'usersemail',
-      label: '用户邮箱',
+      fieldName: 'orderstotalprice',
+      label: '订单总金额',
       componentProps: {
-        placeholder: '请输入用户邮箱',
+        placeholder: '请输入订单总金额',
         allowClear: true,
       },
-      rules: z.string().min(1, { message: '请输入用户邮箱' }),
+      rules: z.number().min(0, { message: '请输入有效的订单总金额' }),
     },
     {
       component: 'Input',
-      fieldName: 'usersaddress',
-      label: '用户地址',
+      fieldName: 'ordersdiscountprice',
+      label: '订单优惠后金额',
       componentProps: {
-        placeholder: '请输入用户地址',
+        placeholder: '请输入订单优惠后金额',
         allowClear: true,
       },
-      rules: z.string().min(1, { message: '请输入用户地址' }),
+      rules: z.number().min(0, { message: '请输入有效的订单优惠后金额' }),
     },
     {
       component: 'Input',
-      fieldName: 'userscontactphone',
-      label: '用户联系手机号',
+      fieldName: 'ordersyhprice',
+      label: '优惠金额',
       componentProps: {
-        placeholder: '请输入用户联系手机号',
+        placeholder: '请输入优惠金额',
         allowClear: true,
       },
-      rules: z.string().min(1, { message: '请输入用户联系手机号' }),
+      rules: z.number().min(0, { message: '请输入有效的优惠金额' }),
     },
     {
       component: 'Input',
-      fieldName: 'userscontactemail',
-      label: '用户联系邮箱',
+      fieldName: 'orderscouponid',
+      label: '优惠券id',
       componentProps: {
-        placeholder: '请输入用户联系邮箱',
+        placeholder: '请输入优惠券id',
         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: {
-        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({
+  class: 'w-7/12',
   onCancel() {
     modalApi.close();
   },
@@ -156,23 +163,47 @@ const [Modal, modalApi] = useVbenModal({
       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) {
     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 getOrdersDetailApi({
+          ordersid: data.value.row.ordersid,
         });
 
         baseFormApi.setValues(detailData);

+ 35 - 40
apps/web-ele/src/views/order-manage/index.vue

@@ -7,10 +7,10 @@ import { Page, useVbenModal } from '@vben/common-ui';
 import { MdiDetail, MdiEdit } from '@vben/icons';
 
 import { useVbenVxeGrid } from '#/adapter/vxe-table';
-// import { getCustomerListApi } from '#/api/customer-manage';
+import { getOrdersListApi } from '#/api/orders';
 import { $t } from '#/locales';
 
-import CustomerForm from './form.vue';
+import OrdersForm from './form.vue';
 
 const formOptions: VbenFormProps = {
   // 默认展开
@@ -22,23 +22,15 @@ const formOptions: VbenFormProps = {
   schema: [
     {
       component: 'Input',
-      fieldName: 'usersname',
-      label: '用户名称',
-      componentProps: {
-        placeholder: $t('ui.placeholder.input'),
-        allowClear: true,
-      },
-    },
-    {
-      component: 'Input',
-      fieldName: 'usersphone',
-      label: '用户手机号',
+      fieldName: 'ordersnumber',
+      label: '订单号',
       componentProps: {
         placeholder: $t('ui.placeholder.input'),
         allowClear: true,
       },
     },
   ],
+  wrapperClass: 'grid-cols-1 md:grid-cols-3 lg:grid-cols-5',
 };
 
 const gridOptions: VxeGridProps<any> = {
@@ -62,29 +54,29 @@ const gridOptions: VxeGridProps<any> = {
       result: 'Data',
       total: 'Total',
     },
-    // ajax: {
-    //   query: async ({ page }, formValues) => {
-    //     return await getCustomerListApi({
-    //       pageindex: page.currentPage,
-    //       rows: page.pageSize,
-    //       ...formValues,
-    //     });
-    //   },
-    // },
+    ajax: {
+      query: async ({ page }, formValues) => {
+        return await getOrdersListApi({
+          pageindex: page.currentPage,
+          rows: page.pageSize,
+          ...formValues,
+        });
+      },
+    },
   },
 
   columns: [
-    { 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: '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' },
+    { title: '下单时间', field: 'ordersorderdate' },
     {
       title: '操作',
       field: 'action',
@@ -95,29 +87,32 @@ const gridOptions: VxeGridProps<any> = {
   ],
 };
 
-const [Grid] = useVbenVxeGrid({ gridOptions, formOptions });
+const [Grid, gridApi] = useVbenVxeGrid({ gridOptions, formOptions });
 
 const [Modal, modalApi] = useVbenModal({
   fullscreenButton: false,
   closeOnClickModal: false,
   closeOnPressEscape: false,
-  connectedComponent: CustomerForm,
+  connectedComponent: OrdersForm,
 });
 
 /* 创建 */
 function handleCreate() {
-  modalApi.setData({ create: true }).open();
+  modalApi.setData({ formType: 'create' }).open();
 }
 
 /* 编辑 */
 function handleEdit(row: any) {
-  modalApi.setData({ row }).open();
+  modalApi.setData({ formType: 'edit', row }).open();
 }
 
 /* 详情 */
 function handleDetail(row: any) {
-  modalApi.setData({ row }).open();
-  // router.push(`/system/users/detail/${row.userName}`);
+  modalApi.setData({ formType: 'detail', row }).open();
+}
+
+function handleFinish() {
+  gridApi.reload();
 }
 </script>
 
@@ -142,6 +137,6 @@ function handleDetail(row: any) {
         />
       </template>
     </Grid>
-    <Modal />
+    <Modal @finish="handleFinish" />
   </Page>
 </template>

+ 1 - 0
packages/types/src/index.ts

@@ -1,6 +1,7 @@
 export type * from './base';
 export type * from './coupon1';
 export type * from './coupon2';
+export type * from './orders';
 export type * from './product';
 export type * from './scqy';
 export type * from './subsidyapplications';

+ 51 - 0
packages/types/src/orders.ts

@@ -0,0 +1,51 @@
+/** 订单信息*/
+// CREATE TABLE `orders` (
+//   `ordersid` varchar(50) NOT NULL COMMENT '订单id',
+//   `ordersnumber` varchar(50) DEFAULT NULL COMMENT '订单号',
+//   `ordersuserid` varchar(50) DEFAULT NULL COMMENT '订单关联用户id',
+//   `ordersproductid` varchar(50) DEFAULT NULL COMMENT '订单关联产品id',
+//   `ordersproductname` varchar(50) DEFAULT NULL COMMENT '产品名称',
+//   `ordersproductsn` varchar(50) DEFAULT NULL COMMENT '产品sn',
+//   `orderstotalprice` decimal(10,2) DEFAULT NULL COMMENT '订单总金额',
+//   `ordersdiscountprice` decimal(10,2) DEFAULT NULL COMMENT '订单优惠后金额',
+//   `ordersyhprice` decimal(10,2) DEFAULT NULL COMMENT '优惠金额',
+//   `orderscouponid` varchar(50) DEFAULT NULL COMMENT '优惠卷id',
+//   `ordersorderstatus` tinyint(2) DEFAULT NULL COMMENT '订单状态(0:待审核,1:已支付,2:已完成)',
+//   `ordersorderdate` datetime DEFAULT NULL COMMENT '下单时间',
+//   PRIMARY KEY (`ordersid`),
+//   KEY `ordersuserid` (`ordersuserid`),
+//   KEY `ordersproductid` (`ordersproductid`),
+//   KEY `orderscouponid` (`orderscouponid`),
+//   CONSTRAINT `orderscouponid` FOREIGN KEY (`orderscouponid`) REFERENCES `coupon2` (`coupon2sid`) ON UPDATE NO ACTION,
+//   CONSTRAINT `ordersproductid` FOREIGN KEY (`ordersproductid`) REFERENCES `products` (`productsid`) ON UPDATE NO ACTION,
+//   CONSTRAINT `ordersuserid` FOREIGN KEY (`ordersuserid`) REFERENCES `users` (`usersid`) ON UPDATE NO ACTION
+// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单信息';
+
+interface OrdersEntity {
+  /** 订单id */
+  ordersid: string;
+  /** 订单号 */
+  ordersnumber: string;
+  /** 订单关联用户id */
+  ordersuserid: string;
+  /** 订单关联产品id */
+  ordersproductid: string;
+  /** 产品名称 */
+  ordersproductname: string;
+  /** 产品sn */
+  ordersproductsn: string;
+  /** 订单总金额 */
+  orderstotalprice: number;
+  /** 订单优惠后金额 */
+  ordersdiscountprice: number;
+  /** 优惠金额 */
+  ordersyhprice: number;
+  /** 优惠卷id */
+  orderscouponid: string;
+  /** 订单状态 */
+  ordersorderstatus: number;
+  /** 下单时间 */
+  ordersorderdate: string;
+}
+
+export type { OrdersEntity };