jinx 3 年 前
コミット
7571d6a347
3 ファイル変更38 行追加17 行削除
  1. 11 0
      src/api/customer/index.ts
  2. 1 0
      src/api/customer/model.ts
  3. 26 17
      src/views/customer/modal/InfoModal.vue

+ 11 - 0
src/api/customer/index.ts

@@ -5,6 +5,7 @@ import { Result } from '/#/axios';
 enum Api {
   companyList = '/newV4/service/manage/company/list',
   companyAdd = '/newV4/service/manage/company/add',
+  companyUpdate = '/newV4/service/manage/company/update',
   companyDelete = '/newV4/service/manage/company/delete',
   cameraList = '/newV4/service/manage/camera/list',
   companyUploadExcel = '/newV4/service/manage/excel/uploadExcel',
@@ -31,6 +32,16 @@ export const companyAdd = (params: addParams) =>
       ignoreCancelToken: true,
     },
   });
+export const companyUpdate = (params: addParams) =>
+  defHttp.post<Result>({
+    url: Api.companyUpdate,
+    params: params,
+    // data: params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
 export const companyDelete = (params: deleteParams) =>
   defHttp.post<Result>({
     url: Api.companyDelete,

+ 1 - 0
src/api/customer/model.ts

@@ -8,6 +8,7 @@ export interface deleteParams {
   id?: number;
 }
 export interface addParams {
+  id?: number;
   companyName: string;
   companydesc: string;
   topLogo: string;

+ 26 - 17
src/views/customer/modal/InfoModal.vue

@@ -22,7 +22,7 @@
   import { BasicModal, useModalInner } from '/@/components/Modal';
   import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
   import { useMessage } from '/@/hooks/web/useMessage';
-  import { companyAdd } from '/@/api/customer';
+  import { companyAdd, companyUpdate } from '/@/api/customer';
   import { useI18n } from '/@/hooks/web/useI18n';
   import { uploadApi } from '/@/api/product/index';
   import { useModalInner } from '/@/components/Modal';
@@ -34,7 +34,7 @@
     },
     emits: ['update', 'register'],
     setup(props, { emit }) {
-      const modelRef = ref({});
+      const modelRef = ref(null);
       const fileFlow = reactive({
         file: null,
       });
@@ -135,7 +135,7 @@
             maxNumber: 1,
             maxSize: 5,
             accept: ['jpg', 'png'],
-            afterFetch: function (data) {              
+            afterFetch: function (data) {
               Reflect.set(data, 'url', data.data);
               return data;
             },
@@ -167,16 +167,16 @@
           field: 'showLogo',
           component: 'RadioGroup',
           label: '初始LOGO',
-          defaultValue: '1',
+          defaultValue: 1,
           componentProps: {
             options: [
               {
                 label: '显示',
-                value: '1',
+                value: 1,
               },
               {
                 label: '不显示',
-                value: '2',
+                value: 2,
               },
             ],
           },
@@ -198,13 +198,12 @@
       let addListFunc = () => {};
       const [register, { closeModal }] = useModalInner((data) => {
         if (data) {
-          console.log(data);
           modelRef.value = data;
           setFieldsValue({
             ...data,
-            floorLogo:data.floorLogo?[data.floorLogo]:[],
-            qrLogo:data.qrLogo?[data.qrLogo]:[],
-            topLogo:data.topLogo?[data.topLogo]:[],
+            floorLogo: data.floorLogo ? [data.floorLogo] : [],
+            qrLogo: data.qrLogo ? [data.qrLogo] : [],
+            topLogo: data.topLogo ? [data.topLogo] : [],
           });
         }
       });
@@ -219,17 +218,27 @@
       const handleSubmit = async () => {
         try {
           const params = await validate();
-          const apiData = { 
+          const apiData = {
             ...params,
-            floorLogo:params.floorLogo && params.floorLogo[0],
-            qrLogo:params.qrLogo && params.qrLogo[0],
-            topLogo:params.topLogo && params.topLogo[0],
-           };
-          await companyAdd(apiData);
+            floorLogo: params.floorLogo && params.floorLogo[0],
+            qrLogo: params.qrLogo && params.qrLogo[0],
+            topLogo: params.topLogo && params.topLogo[0],
+          };
+          console.log(modelRef.value);
+          let tips: string;
+          if (modelRef.value) {
+            apiData.id = modelRef.value.id;
+            await companyUpdate(apiData);
+            tips = '修改成功。';
+          } else {
+            tips = '添加成功。';
+            await companyAdd(apiData);
+          }
+
           closeModal();
           resetFields();
           emit('update');
-          createMessage.success('添加成功。');
+          createMessage.success(tips);
         } catch (error) {
           console.log('not passing', error);
         }