Преглед на файлове

feat: 新增优惠券审核功能,更新相关字段名称,调整用户性质为购机者和经销商

laiqi преди 1 година
родител
ревизия
f03c77904c

+ 7 - 0
apps/web-ele/src/api/coupon/coupon2.ts

@@ -46,3 +46,10 @@ export async function addCoupon2Api(data: Coupon2Entity) {
 export async function editCoupon2Api(data: Coupon2Entity) {
   return requestClient.post<any>('/api/up?pagevalue=41', { ...data });
 }
+
+/**
+ * 我的优惠券信息_审核
+ */
+export async function auditCoupon2Api(data: Coupon2Entity) {
+  return requestClient.post<any>('/api/up?pagevalue=104', { ...data });
+}

+ 2 - 2
apps/web-ele/src/views/customer-manage/index.vue

@@ -49,8 +49,8 @@ const formOptions: VbenFormProps = {
         placeholder: $t('ui.placeholder.select'),
         allowClear: true,
         options: [
-          { label: '用户', value: '用户' },
-          { label: '渠道', value: '渠道' },
+          { label: '购机者', value: '购机者' },
+          { label: '经销商', value: '经销商' },
         ],
       },
     },

+ 182 - 0
apps/web-ele/src/views/examine-manage/examine-coupon/audit-form.vue

@@ -0,0 +1,182 @@
+<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 { auditCoupon2Api, getCoupon2DetailApi } from '#/api/coupon/coupon2';
+
+interface Emits {
+  (event: 'finish'): void;
+}
+
+const emit = defineEmits<Emits>();
+
+// To store the row data when modal opens
+const auditData = ref<null | Recordable<any>>(null);
+
+// Local ref to track coupon2sype for conditional logic in schema
+const currentCoupon2Sype = ref<number | undefined>(undefined);
+
+const computedSchema = computed<VbenFormSchema[]>(() => {
+  const schemas: VbenFormSchema[] = [
+    {
+      label: '优惠券ID',
+      fieldName: 'coupon2sid',
+      component: 'Input',
+      componentProps: {
+        disabled: true,
+      },
+    },
+    {
+      label: '优惠券代码',
+      fieldName: 'coupon2code',
+      component: 'Input',
+      componentProps: {
+        disabled: true,
+      },
+    },
+    {
+      label: '审核状态',
+      fieldName: 'coupon2sype',
+      component: 'RadioGroup',
+      componentProps: {
+        options: [
+          { label: '审核通过', value: 1 },
+          { label: '审核不通过', value: 2 },
+        ],
+        onChange: (value: number | undefined) => {
+          currentCoupon2Sype.value = value;
+        },
+      },
+      defaultValue: 1,
+      rules: z
+        .number({
+          invalid_type_error: '请选择审核状态',
+          required_error: '请选择审核状态',
+        })
+        .refine((val) => val === 1 || val === 2, { message: '请选择审核状态' }),
+    },
+    {
+      label: '审核备注',
+      fieldName: 'coupon2shbz',
+      component: 'Input',
+      // @ts-ignore ifShow is working in runtime but type might be missing
+      ifShow: ({ values }: { values: Recordable<any> }) =>
+        values.coupon2sype === 2,
+      componentProps: {
+        type: 'textarea',
+        placeholder: '请输入审核备注',
+        rows: 3,
+      },
+      rules:
+        currentCoupon2Sype.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 = {
+      'coupon2sid.value': auditData.value?.coupon2sid,
+      coupon2shbz: formValues.coupon2shbz,
+      coupon2sype: formValues.coupon2sype,
+    };
+    await auditCoupon2Api(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 || {}; // Store the row data
+      currentCoupon2Sype.value = undefined;
+      auditFormApi.resetForm({ values: {} });
+
+      if (auditData.value?.coupon2sid) {
+        try {
+          const detailData = await getCoupon2DetailApi({
+            coupon2sid: auditData.value.coupon2sid,
+          });
+          const initialValues = { ...auditData.value, ...detailData };
+          delete initialValues.coupon2sype;
+          delete initialValues.coupon2shbz;
+          auditFormApi.setValues(initialValues);
+          auditFormApi.setValues({ coupon2sype: undefined, coupon2shbz: '' });
+          currentCoupon2Sype.value = undefined;
+        } catch (error) {
+          console.error('Failed to fetch coupon details for audit', error);
+          auditFormApi.resetForm({ values: {} });
+          currentCoupon2Sype.value = undefined;
+        }
+      } else {
+        auditFormApi.resetForm({ values: {} });
+        currentCoupon2Sype.value = undefined;
+      }
+    } else {
+      // Clear data when modal closes
+      auditData.value = null;
+      currentCoupon2Sype.value = undefined;
+      auditFormApi.resetForm({ values: {} });
+    }
+  },
+});
+
+function openAuditModal(rowData: Recordable<any>) {
+  modalApi.setData({ row: rowData });
+  modalApi.open();
+}
+
+defineExpose({
+  openAuditModal,
+});
+</script>
+
+<template>
+  <Modal>
+    <AuditVForm />
+  </Modal>
+</template>

+ 26 - 7
apps/web-ele/src/views/examine-manage/examine-coupon/index.vue

@@ -3,10 +3,10 @@ import type { VbenFormProps } from '@vben/common-ui';
 
 import type { VxeGridListeners, VxeGridProps } from '#/adapter/vxe-table';
 
-import { h } from 'vue';
+import { h, ref } from 'vue';
 
 import { Page, useVbenModal } from '@vben/common-ui';
-import { MdiDetail, MdiEdit } from '@vben/icons';
+import { MdiCheckboxMultipleMarked, MdiDetail, MdiEdit } from '@vben/icons';
 
 import { ElTag } from 'element-plus';
 
@@ -14,6 +14,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
 import { getCoupon2ListApi } from '#/api/coupon/coupon2';
 import { $t } from '#/locales';
 
+import AuditForm from './audit-form.vue';
 import Coupon1Form from './form.vue';
 
 const formOptions: VbenFormProps = {
@@ -121,7 +122,7 @@ const gridOptions: VxeGridProps<any> = {
       field: 'action',
       fixed: 'right',
       slots: { default: 'action' },
-      width: 140,
+      width: 160,
     },
   ],
 };
@@ -145,10 +146,8 @@ const [Modal, modalApi] = useVbenModal({
   connectedComponent: Coupon1Form,
 });
 
-/* 创建 */
-// function handleCreate() {
-//   modalApi.setData({ formType: 'create' }).open();
-// }
+// Add ref for audit-form.vue
+const auditFormRef = ref<any>(null);
 
 /* 编辑 */
 function handleEdit(row: any) {
@@ -162,6 +161,11 @@ function handleDetail(row: any) {
   modalApi.setData({ formType: 'detail', row }).open();
 }
 
+/* 审核 */
+function handleAudit(row: any) {
+  auditFormRef.value?.openAuditModal(row);
+}
+
 function handleFinish() {
   gridApi.reload();
 }
@@ -200,8 +204,23 @@ function handleFinish() {
             class="!p-2"
           />
         </el-tooltip>
+        <el-tooltip
+          v-if="row.coupon2sype === 0"
+          class="box-item"
+          effect="dark"
+          content="审核"
+          placement="top"
+        >
+          <el-button
+            round
+            @click="() => handleAudit(row)"
+            :icon="MdiCheckboxMultipleMarked"
+            class="!p-2"
+          />
+        </el-tooltip>
       </template>
     </Grid>
     <Modal @finish="handleFinish" />
+    <AuditForm ref="auditFormRef" @finish="handleFinish" />
   </Page>
 </template>

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

@@ -23,7 +23,7 @@ const dealerOptions = ref<Array<{ label: string; value: string }>>([]);
 const fetchDealerOptions = async () => {
   try {
     const result = await getCustomerListApi({
-      usersnature: '渠道',
+      usersnature: '经销商',
       pageindex: 1,
       rows: 999,
     });

+ 1 - 1
apps/web-ele/src/views/product-manage/form.vue

@@ -29,7 +29,7 @@ const fetchChannelOptions = async () => {
     channelOptions.value = [];
 
     const response = await getCustomerListApi({
-      'usersnature.value': '渠道',
+      'usersnature.value': '经销商',
       pageindex: 1,
       rows: 100,
     });

+ 1 - 1
apps/web-ele/src/views/system-manage/worker-manage/form.vue

@@ -22,7 +22,7 @@ async function fetchChannelOptions() {
     const res = await getCustomerListApi({
       pageindex: 1,
       rows: 1000,
-      'usersnature.value': '渠道', // 只获取用户性质为"渠道"的数据
+      'usersnature.value': '经销商', // 只获取用户性质为"渠道"的数据
     });
 
     if (res && res.Data) {

+ 6 - 0
packages/icons/src/iconify/index.ts

@@ -22,3 +22,9 @@ export const MdiDelete = createIconifyIcon('mdi:delete');
 export const MdiDetail = createIconifyIcon('mdi:eye');
 
 export const MdiPlus = createIconifyIcon('mdi:plus');
+
+export const MdiMinus = createIconifyIcon('mdi:minus');
+
+export const MdiCheckboxMultipleMarked = createIconifyIcon(
+  'mdi:checkbox-multiple-marked',
+);

+ 19 - 2
packages/types/src/coupon2.ts

@@ -1,16 +1,23 @@
-/** 我的优惠券信息*/
 // CREATE TABLE `coupon2` (
 //   `coupon2sid` varchar(50) NOT NULL COMMENT '优惠券id',
 //   `coupon2code` varchar(50) DEFAULT NULL COMMENT '优惠券代码',
+//   `coupon2mc` varchar(50) DEFAULT NULL COMMENT '优惠券名称',
 //   `coupon2adddatetime` datetime DEFAULT NULL COMMENT '优惠券申请时间',
 //   `coupon2reviewdatetime` datetime DEFAULT NULL COMMENT '优惠券审核时间',
 //   `coupon2userid` varchar(50) DEFAULT NULL COMMENT '关联申请人id',
+//   `coupon2openid` varchar(50) DEFAULT NULL COMMENT '关联申请人openid',
 //   `coupon2sype` tinyint(2) DEFAULT NULL COMMENT '优惠券(0:申请中,1:审核通过,2:审核失败)',
 //   `coupon2isused` tinyint(2) DEFAULT NULL COMMENT '是否已使用(0:未使用,1:已使用)',
+//   `coupon2merchantid` varchar(50) DEFAULT NULL COMMENT '对应渠道id',
 //   `coupon2productids` varchar(5000) DEFAULT NULL COMMENT '可用产品id',
 //   `coupon2coupon1id` varchar(50) DEFAULT NULL COMMENT '关联主券id',
+//   `coupon2phone` varchar(50) DEFAULT NULL COMMENT '领取手机号',
+//   `coupon2shuser` varchar(50) DEFAULT NULL COMMENT '优惠券审核人',
+//   `coupon2shdate` datetime DEFAULT NULL COMMENT '优惠券审核时间',
+//   `coupon2shbz` varchar(255) DEFAULT NULL COMMENT '优惠券审核备注',
 //   PRIMARY KEY (`coupon2sid`) USING BTREE,
-//   KEY `couponsid` (`coupon2sid`)
+//   KEY `couponsid` (`coupon2sid`),
+//   KEY `coupon2code` (`coupon2code`)
 // ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='我的优惠券信息';
 
 interface Coupon2Entity {
@@ -32,6 +39,16 @@ interface Coupon2Entity {
   coupon2productids: string;
   /** 关联主券id */
   coupon2coupon1id: string;
+  /** 领取手机号 */
+  coupon2phone: string;
+  /** 优惠券审核人 */
+  coupon2shuser: string;
+  /** 优惠券审核时间 */
+  coupon2shdate: string;
+  /** 优惠券审核备注 */
+  coupon2shbz: string;
+  /** 优惠券名称 */
+  coupon2mc: string;
 }
 
 export type { Coupon2Entity };

+ 1 - 1
packages/types/src/user.ts

@@ -9,7 +9,7 @@ interface UserInfo extends BasicUserInfo {
 // CREATE TABLE `users` (
 //   `usersid` varchar(50) NOT NULL COMMENT '用户id',
 //   `usersname` varchar(50) DEFAULT NULL COMMENT '用户名称',
-//   `usersnature` varchar(50) DEFAULT NULL COMMENT '用户性质(用户/渠道)',
+//   `usersnature` varchar(50) DEFAULT NULL COMMENT '用户性质(购机者/经销商)',
 //   `userssuperiorid` varchar(50) DEFAULT NULL COMMENT '用户关联上级id',
 //   `usersidcardnumber` varchar(50) DEFAULT NULL COMMENT '用户证件号码',
 //   `usersbankname` varchar(50) DEFAULT NULL COMMENT '用户开户银行名称',