Explorar el Código

feat: 新增:订单审核功能

laiqi hace 11 meses
padre
commit
479045b806

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

@@ -88,3 +88,14 @@ export async function editOrdersApi(data: OrdersEntity) {
 export async function deleteOrdersApi(data: { 'ordersid.value': string }) {
   return requestClient.post<any>('/api/del?pagevalue=55', { ...data });
 }
+
+/**
+ * 订单信息_审核
+ */
+export async function auditOrdersApi(data: {
+  'ordersid.value': string;
+  ordersshbz?: string;
+  ordsesshzt: number;
+}) {
+  return requestClient.post<any>('/api/up?pagevalue=114', { ...data });
+}

+ 193 - 0
apps/web-ele/src/views/order-manage/audit-form.vue

@@ -0,0 +1,193 @@
+<script lang="ts" setup>
+import type { Recordable } from '@vben/types';
+
+import type { VbenFormSchema } from '#/adapter/form';
+
+import { computed, reactive, ref } from 'vue';
+
+import { useVbenModal } from '@vben/common-ui';
+
+import { ElMessage } from 'element-plus';
+
+import { useVbenForm, z } from '#/adapter/form';
+import { auditOrdersApi, getOrdersDetailApi } from '#/api/orders';
+
+interface Emits {
+  (event: 'finish'): void;
+}
+
+const emit = defineEmits<Emits>();
+
+// 存储行数据
+const auditData = ref<null | Recordable<any>>(null);
+
+// 本地ref跟踪审核状态,用于条件逻辑
+const currentOrdsesshzt = ref<number | undefined>(undefined);
+
+const computedSchema = computed<VbenFormSchema[]>(() => {
+  const schemas: VbenFormSchema[] = [
+    {
+      label: '订单ID',
+      fieldName: 'ordersid',
+      component: 'Input',
+      componentProps: {
+        disabled: true,
+      },
+    },
+    {
+      label: '优惠劵id',
+      fieldName: 'ordersnumber',
+      component: 'Input',
+      componentProps: {
+        disabled: true,
+      },
+    },
+    {
+      label: '产品名称',
+      fieldName: 'ordersproductname',
+      component: 'Input',
+      componentProps: {
+        disabled: true,
+      },
+    },
+    {
+      label: '审核状态',
+      fieldName: 'ordersorderstatus',
+      component: 'RadioGroup',
+      componentProps: {
+        options: [
+          { label: '审核通过', value: 2 },
+          { label: '审核不通过', value: 3 },
+        ],
+        onChange: (value: number | undefined) => {
+          currentOrdsesshzt.value = value;
+        },
+      },
+      defaultValue: 2,
+      rules: z
+        .number({
+          invalid_type_error: '请选择审核状态',
+          required_error: '请选择审核状态',
+        })
+        .refine((val) => val === 2 || val === 3, { message: '请选择审核状态' }),
+    },
+    {
+      label: '审核备注',
+      fieldName: 'ordersshbz',
+      component: 'Input',
+      // @ts-ignore ifShow在运行时工作,但类型可能缺失
+      ifShow: ({ values }: { values: Recordable<any> }) =>
+        values.ordersorderstatus === 3,
+      componentProps: {
+        type: 'textarea',
+        placeholder: '请输入审核备注',
+        rows: 3,
+      },
+      rules:
+        currentOrdsesshzt.value === 2
+          ? z.string().min(1, { message: '审核不通过时,审核备注不能为空' })
+          : z.string().optional(),
+    },
+  ];
+  return schemas;
+});
+
+const [AuditVForm, auditFormApi] = useVbenForm(
+  reactive({
+    schema: computedSchema,
+    showDefaultActions: false,
+  }),
+);
+
+async function internalHandleSubmit() {
+  const validationResult = await auditFormApi.validate();
+  if (!validationResult.valid) {
+    return false;
+  }
+  try {
+    const formValues = await auditFormApi.getValues();
+    const dataToSubmit = {
+      'ordersid.value': auditData.value?.ordersid,
+      ordersshbz: formValues.ordersshbz,
+      ordersorderstatus: formValues.ordersorderstatus,
+    };
+    await auditOrdersApi(dataToSubmit as any);
+    ElMessage.success('审核操作成功');
+    emit('finish');
+    return true;
+  } catch (error) {
+    console.error('表单提交失败', error);
+    ElMessage.error('审核操作失败');
+    return false;
+  }
+}
+
+const [Modal, modalApi] = useVbenModal({
+  title: '审核订单',
+  showCancelButton: true,
+  fullscreenButton: false,
+  closeOnClickModal: false,
+  closeOnPressEscape: false,
+  async onConfirm() {
+    const success = await internalHandleSubmit();
+    if (success) {
+      modalApi.close();
+    }
+  },
+  onCancel() {
+    modalApi.close();
+  },
+  async onOpenChange(isOpen: boolean) {
+    if (isOpen) {
+      const modalData = modalApi.getData();
+      auditData.value = modalData?.row || {}; // 存储行数据
+      currentOrdsesshzt.value = undefined;
+      auditFormApi.resetForm({ values: {} });
+
+      if (auditData.value?.ordersid) {
+        try {
+          const detailData = await getOrdersDetailApi({
+            ordersid: auditData.value.ordersid,
+          });
+          const initialValues = { ...auditData.value, ...detailData };
+          delete initialValues.ordersorderstatus;
+          delete initialValues.ordersshbz;
+          auditFormApi.setValues(initialValues);
+          auditFormApi.setValues({
+            ordersorderstatus: undefined,
+            ordersshbz: '',
+          });
+          currentOrdsesshzt.value = undefined;
+        } catch (error) {
+          console.error('获取订单详情失败', error);
+          auditFormApi.resetForm({ values: {} });
+          currentOrdsesshzt.value = undefined;
+        }
+      } else {
+        auditFormApi.resetForm({ values: {} });
+        currentOrdsesshzt.value = undefined;
+      }
+    } else {
+      // 关闭弹窗时清除数据
+      auditData.value = null;
+      currentOrdsesshzt.value = undefined;
+      auditFormApi.resetForm({ values: {} });
+    }
+  },
+});
+
+function openAuditModal(rowData: Recordable<any>) {
+  modalApi.setData({ row: rowData });
+  modalApi.open();
+}
+
+defineExpose({
+  openAuditModal,
+});
+</script>
+
+<template>
+  <Modal>
+    <AuditVForm />
+  </Modal>
+</template>

+ 70 - 19
apps/web-ele/src/views/order-manage/index.vue

@@ -7,15 +7,18 @@ import type { OrdersQueryParams } from '#/api/orders';
 import { h, onMounted, ref } from 'vue';
 
 import { Page, useVbenModal } from '@vben/common-ui';
-import { MdiDelete, MdiDetail } from '@vben/icons';
+import { MdiCheckboxMultipleMarked, MdiDetail } from '@vben/icons';
 
-import { ElMessage, ElMessageBox, ElTag } from 'element-plus';
+// import { ElMessage, ElMessageBox, ElTag } from 'element-plus';
+import { ElTag } from 'element-plus';
 
 import { useVbenVxeGrid } from '#/adapter/vxe-table';
-import { deleteOrdersApi, getOrdersListApi } from '#/api/orders';
+// import { deleteOrdersApi, getOrdersListApi } from '#/api/orders';
+import { getOrdersListApi } from '#/api/orders';
 import { getCustomerListApi } from '#/api/user';
 import { $t } from '#/locales';
 
+import OrdersAuditForm from './audit-form.vue';
 import OrdersForm from './form.vue';
 
 const dealerOptions = ref<Array<{ label: string; value: string }>>([]);
@@ -153,6 +156,7 @@ const gridOptions: VxeGridProps<any> = {
             0: { text: '待审核', type: 'info' },
             1: { text: '已支付', type: 'success' },
             2: { text: '已完成', type: 'warning' },
+            3: { text: '审核不通过', type: 'danger' },
           } as const;
           return h(
             ElTag,
@@ -162,13 +166,33 @@ const gridOptions: VxeGridProps<any> = {
         },
       },
     },
+    // {
+    //   title: '审核状态',
+    //   field: 'ordsesshzt',
+    //   sortable: true,
+    //   slots: {
+    //     default: ({ row }) => {
+    //       const type = row.ordsesshzt as 0 | 1 | 2;
+    //       const typeMap = {
+    //         0: { text: '待审核', type: 'info' },
+    //         1: { text: '审核通过', type: 'success' },
+    //         2: { text: '审核不通过', type: 'danger' },
+    //       } as const;
+    //       return h(
+    //         ElTag,
+    //         { type: typeMap[type]?.type },
+    //         () => typeMap[type]?.text,
+    //       );
+    //     },
+    //   },
+    // },
     { title: '下单时间', field: 'ordersorderdate', sortable: true },
     {
       title: '操作',
       field: 'action',
       fixed: 'right',
       slots: { default: 'action' },
-      width: 150,
+      width: 200,
     },
   ],
 };
@@ -192,6 +216,13 @@ const [Modal, modalApi] = useVbenModal({
   connectedComponent: OrdersForm,
 });
 
+const [AuditModal, auditModalApi] = useVbenModal({
+  fullscreenButton: false,
+  closeOnClickModal: false,
+  closeOnPressEscape: false,
+  connectedComponent: OrdersAuditForm,
+});
+
 /* 创建 */
 function handleCreate() {
   modalApi.setState({ showCancelButton: true });
@@ -214,21 +245,26 @@ function handleFinish() {
   gridApi.reload();
 }
 
-/* 删除 */
-async function handleDelete(row: any) {
-  try {
-    await ElMessageBox.confirm('确认要删除该订单吗?', '提示', {
-      confirmButtonText: '确定',
-      cancelButtonText: '取消',
-      type: 'warning',
-    });
-    await deleteOrdersApi({ 'ordersid.value': row.ordersid });
-    ElMessage.success('删除成功');
-    gridApi.reload();
-  } catch (error) {
-    console.error(error);
-  }
+/* 审核 */
+function handleAudit(row: any) {
+  auditModalApi.setData({ row }).open();
 }
+
+/* 删除 */
+// async function handleDelete(row: any) {
+//   try {
+//     await ElMessageBox.confirm('确认要删除该订单吗?', '提示', {
+//       confirmButtonText: '确定',
+//       cancelButtonText: '取消',
+//       type: 'warning',
+//     });
+//     await deleteOrdersApi({ 'ordersid.value': row.ordersid });
+//     ElMessage.success('删除成功');
+//     gridApi.reload();
+//   } catch (error) {
+//     console.error(error);
+//   }
+// }
 </script>
 
 <template>
@@ -267,6 +303,20 @@ async function handleDelete(row: any) {
         <el-tooltip
           class="box-item"
           effect="dark"
+          content="审核"
+          placement="top"
+        >
+          <el-button
+            round
+            @click="() => handleAudit(row)"
+            :icon="MdiCheckboxMultipleMarked"
+            class="!p-2"
+            :disabled="row.ordersorderstatus !== 0"
+          />
+        </el-tooltip>
+        <!-- <el-tooltip
+          class="box-item"
+          effect="dark"
           content="删除"
           placement="top"
         >
@@ -276,9 +326,10 @@ async function handleDelete(row: any) {
             :icon="MdiDelete"
             class="!p-2"
           />
-        </el-tooltip>
+        </el-tooltip> -->
       </template>
     </Grid>
     <Modal @finish="handleFinish" />
+    <AuditModal @finish="handleFinish" />
   </Page>
 </template>

+ 19 - 5
packages/types/src/orders.ts

@@ -3,6 +3,8 @@
 //   `ordersid` varchar(50) NOT NULL COMMENT '订单id',
 //   `ordersnumber` varchar(50) DEFAULT NULL COMMENT '订单号',
 //   `ordersuserid` varchar(50) DEFAULT NULL COMMENT '订单关联用户id',
+//   `ordersuserid1` varchar(50) DEFAULT NULL COMMENT '订单关联渠道',
+//   `ordersopenid` varchar(50) DEFAULT NULL COMMENT '订单关联openid',
 //   `ordersproductid` varchar(50) DEFAULT NULL COMMENT '订单关联产品id',
 //   `ordersproductname` varchar(50) DEFAULT NULL COMMENT '产品名称',
 //   `ordersproductsn` varchar(50) DEFAULT NULL COMMENT '产品sn',
@@ -10,15 +12,17 @@
 //   `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:已完成)',
+//   `ordersorderstatus` tinyint(2) DEFAULT NULL COMMENT '订单状态(0:待审核,1:已支付,2:已完成, 3:审核不通过)',
 //   `ordersorderdate` datetime DEFAULT NULL COMMENT '下单时间',
+//   `ordersshuser` varchar(50) DEFAULT NULL COMMENT '审核人',
+//   `ordersshdate` datetime DEFAULT NULL COMMENT '审核时间',
+//   `ordersshbz` varchar(500) DEFAULT NULL COMMENT '审核备注',
+//   `ordsesshzt` tinyint(2) DEFAULT '0' COMMENT '审核状态(废弃)',
+//   `ordersphone` varchar(50) 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
+//   KEY `orderscouponid` (`orderscouponid`)
 // ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单信息';
 
 interface OrdersEntity {
@@ -46,6 +50,16 @@ interface OrdersEntity {
   ordersorderstatus: number;
   /** 下单时间 */
   ordersorderdate: string;
+  /** 审核人 */
+  ordersshuser: string;
+  /** 审核时间 */
+  ordersshdate: string;
+  /** 审核备注 */
+  ordersshbz: string;
+  /** 审核状态(废弃) */
+  ordsesshzt: number;
+  /** 下单手机号 */
+  ordersphone: string;
 }
 
 export type { OrdersEntity };