Selaa lähdekoodia

feat: users(经销创建,编辑)增加一个选择生产企业,单选,必选(usersscqyid)

laiqi 10 kuukautta sitten
vanhempi
commit
732c8993da
2 muutettua tiedostoa jossa 47 lisäystä ja 29 poistoa
  1. 45 29
      apps/web-ele/src/views/customer-manage/form.vue
  2. 2 0
      packages/types/src/user.ts

+ 45 - 29
apps/web-ele/src/views/customer-manage/form.vue

@@ -1,13 +1,14 @@
 <script lang="ts" setup>
 import type { CustomerEntity } from '@vben/types';
 
-import { computed, ref } from 'vue';
+import { computed, onMounted, ref } from 'vue';
 
 import { useVbenModal } from '@vben/common-ui';
 
 import { ElMessage } from 'element-plus';
 
 import { useVbenForm, z } from '#/adapter/form';
+import { getScqyListApi } from '#/api/scqy';
 import {
   addCustomerApi,
   editCustomerApi,
@@ -17,6 +18,7 @@ import {
 const emit = defineEmits(['finish']);
 const data = ref();
 const formType = ref<'create' | 'detail' | 'edit'>('create');
+const scqyOptions = ref<{ label: string; value: string }[]>([]);
 
 const titleMap = {
   create: '新增客户',
@@ -26,6 +28,25 @@ const titleMap = {
 
 const getTitle = computed(() => titleMap[formType.value]);
 
+const scqySelectOptions = computed(() => scqyOptions.value);
+
+// 获取生产企业列表
+const fetchScqyList = async () => {
+  try {
+    const { Total, Data } = await getScqyListApi({ pageindex: 1, rows: 999 });
+    const list = Data || [];
+    if (Total > 0) {
+      scqyOptions.value = list.map((item: any) => ({
+        label: item.scqyinfomc,
+        value: item.scqyinfoid,
+      }));
+    }
+    console.log('获取生产企业列表:', scqyOptions.value);
+  } catch (error) {
+    console.error('获取生产企业列表失败:', error);
+  }
+};
+
 const [BaseForm, baseFormApi] = useVbenForm({
   showDefaultActions: false,
   // 所有表单项共用,可单独在表单内覆盖
@@ -182,6 +203,24 @@ const [BaseForm, baseFormApi] = useVbenForm({
         triggerFields: ['userstype'],
       },
     },
+    // 生产企业选择
+    {
+      component: 'Select',
+      fieldName: 'usersscqyid',
+      label: '生产企业',
+      componentProps: {
+        placeholder: '请选择生产企业',
+        allowClear: true,
+        options: scqySelectOptions,
+      },
+      rules: z.string().min(1, { message: '请选择生产企业' }),
+      dependencies: {
+        if(values) {
+          return values.usersnature === '经销商';
+        },
+        triggerFields: ['usersnature'],
+      },
+    },
     // 通用字段
     {
       component: 'Input',
@@ -232,34 +271,6 @@ const [BaseForm, baseFormApi] = useVbenForm({
         allowClear: true,
       },
     },
-    // {
-    //   component: 'Input',
-    //   fieldName: 'userscontactphone',
-    //   label: '联系手机号',
-    //   componentProps: {
-    //     placeholder: '请输入联系手机号',
-    //     allowClear: true,
-    //   },
-    // },
-    // {
-    //   component: 'Input',
-    //   fieldName: 'userscontactemail',
-    //   label: '联系邮箱',
-    //   componentProps: {
-    //     placeholder: '请输入联系邮箱',
-    //     allowClear: true,
-    //   },
-    //   rules: z.string().email({ message: '请输入正确的邮箱格式' }),
-    // },
-    // {
-    //   component: 'Input',
-    //   fieldName: 'userscontactaddress',
-    //   label: '联系地址',
-    //   componentProps: {
-    //     placeholder: '请输入联系地址',
-    //     allowClear: true,
-    //   },
-    // },
     {
       component: 'Input',
       fieldName: 'userscz',
@@ -352,6 +363,11 @@ const [Modal, modalApi] = useVbenModal({
     }
   },
 });
+
+// 组件挂载时获取生产企业列表
+onMounted(() => {
+  fetchScqyList();
+});
 </script>
 
 <template>

+ 2 - 0
packages/types/src/user.ts

@@ -89,6 +89,8 @@ interface CustomerEntity {
   userscz: string;
   /** 备注 */
   usersbz: string;
+  /** 关联生产企业id */
+  usersscqyid: string;
 }
 
 export type { CustomerEntity, UserAuthStatusType, UserInfo };