Forráskód Böngészése

fix(bugs): 修改问题

tangning 3 éve
szülő
commit
7b499469b2

+ 52 - 0
src/api/staff/list.ts

@@ -1,8 +1,14 @@
 import { defHttp } from '/@/utils/http/axios';
 import { PageParams, ListGetResultModel } from './model';
+import { Result } from '/#/axios';
 
 enum Api {
   pageList = '/zfb-api/zfb/shop/sys/user/staffList',
+  del = '/zfb-api/zfb/shop/sys/user/preDeleteStaff',
+  roleList = '/zfb-api/zfb/shop/sys/user/roleList',
+  staffSave = '/zfb-api/zfb/shop/sys/user/save',
+  update = '/zfb-api/zfb/shop/sys/user/update',
+  checkUser = '/zfb-api/zfb/user/checkUserExists',
 }
 
 /**
@@ -19,3 +25,49 @@ export const ListApi = (params: PageParams) =>
       ignoreCancelToken: true,
     },
   });
+export const delApi = (params: number) =>
+  defHttp.post<Result>({
+    url: Api.del,
+    params: { userId: params },
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
+export const roleLIstApi = (params) =>
+  defHttp.post<Result>({
+    url: Api.roleList,
+    params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
+export const checkUserApi = (params) =>
+  defHttp.post<boolean>({
+    url: Api.checkUser,
+    params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
+
+export const saveApi = (params) =>
+  defHttp.post<Result>({
+    url: Api.staffSave,
+    params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });
+export const updateApi = (params) =>
+  defHttp.post<Result>({
+    url: Api.update,
+    params,
+    headers: {
+      // @ts-ignore
+      ignoreCancelToken: true,
+    },
+  });

+ 5 - 4
src/utils/http/axios/index.ts

@@ -87,10 +87,11 @@ const transform: AxiosTransform = {
         if (message) {
           timeoutMsg = message;
         }
-      //TODO 由于后端HACKCODE error当信息string
-      // if (error) {
-      //   timeoutMsg = error;
-      // }
+        //TODO 由于后端HACKCODE error当信息string
+        if (error) {
+          timeoutMsg = error;
+        }
+        break;
     }
 
     // errorMessageMode=‘modal’的时候会显示modal错误弹窗,而不是消息提示,用于一些比较重要的错误

+ 163 - 0
src/views/staff/detailsModal.vue

@@ -0,0 +1,163 @@
+<template>
+  <BasicModal
+    v-bind="$attrs"
+    @cancel="resetFields"
+    @register="register"
+    title="新 增"
+    @ok="handleOk"
+  >
+    <div class="pt-3px pr-3px">
+      <BasicForm @register="registerForm" :model="model" />
+    </div>
+  </BasicModal>
+</template>
+<script lang="ts">
+  import { defineComponent, ref, computed } from 'vue';
+  import { roleLIstApi, checkUserApi, saveApi, updateApi } from '/@/api/staff/list';
+  import { BasicModal, useModalInner } from '/@/components/Modal';
+  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
+  import { useI18n } from '/@/hooks/web/useI18n';
+  import { useUserStore } from '/@/store/modules/user';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  const { t } = useI18n();
+  const schemas: FormSchema[] = [
+    {
+      field: 'phone',
+      component: 'Input',
+      label: '手机号',
+      colProps: {
+        span: 18,
+      },
+      helpMessage: '手机号需在指房宝APP注册后才可新增',
+      required: true,
+      rules: [
+        {
+          required: true,
+          // @ts-ignore
+          validator: async (rule, value) => {
+            var reg_tel =
+              /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
+            // var reg = /\S+@\S+\.\S+/;
+            if (!value) {
+              return Promise.reject(t('common.phone'));
+            }
+            if (!reg_tel.test(value)) {
+              /* eslint-disable-next-line */
+              return Promise.reject(t('common.phoneError'));
+            }
+            try {
+              let res = await checkUserApi({ phone: value });
+              console.log('res', res);
+              if (res == true) {
+                return Promise.resolve();
+              } else {
+                return Promise.reject('手机号未在指房宝APP中进行注册');
+              }
+            } catch (err) {
+              return Promise.reject(err);
+            }
+          },
+          trigger: 'change',
+        },
+      ],
+    },
+    {
+      field: 'nickName',
+      component: 'Input',
+      label: '员工名称',
+      required: true,
+      colProps: {
+        span: 22,
+      },
+      componentProps: {
+        maxLength: 25,
+      },
+    },
+    {
+      field: 'roleId',
+      component: 'ApiRadioGroup',
+      label: '角色',
+      required: true,
+      itemProps: {
+        validateTrigger: 'blur',
+      },
+      componentProps: {
+        api: roleLIstApi,
+        labelField: 'roleName',
+        valueField: 'roleId',
+      },
+    },
+    {
+      field: 'status',
+      label: '状态',
+      component: 'RadioButtonGroup',
+      required: true,
+      defaultValue: 1,
+      itemProps: {
+        validateTrigger: 'blur',
+      },
+      componentProps: {
+        options: [
+          { label: '是', value: 1 },
+          { label: '否', value: 0 },
+        ],
+      },
+    },
+    {
+      field: 'id',
+      component: 'Input',
+      label: 'id',
+      show: false,
+    },
+  ];
+  export default defineComponent({
+    components: { BasicModal, BasicForm },
+    props: {
+      userData: { type: Object },
+    },
+    setup(_, context) {
+      const modelRef = ref({});
+      const userStore = useUserStore();
+      const userinfo = computed(() => userStore.getUserInfo);
+      const { createMessage } = useMessage();
+      const [registerForm, { setFieldsValue, validate, resetFields }] = useForm({
+        labelWidth: 120,
+        schemas,
+        showActionButtonGroup: false,
+        actionColOptions: {
+          span: 24,
+        },
+      });
+
+      const [register, { closeModal }] = useModalInner((data) => {
+        data && onDataReceive(data);
+      });
+      function onDataReceive(data) {
+        // 方式1;
+        setFieldsValue({
+          ...data,
+        });
+      }
+
+      async function handleOk() {
+        let data = await validate();
+        const { companyId } = userinfo.value;
+        const requestApi = data.id ? updateApi : saveApi;
+        let res = await requestApi({
+          userName: data.phone,
+          phone: data.phone,
+          nickName: data.nickName,
+          roleId: data.roleId,
+          companyId,
+        });
+        console.log('res', res);
+        context && context.emit('ok', res);
+        createMessage.success(t('common.optSuccess'));
+        closeModal();
+        resetFields();
+      }
+
+      return { register, schemas, registerForm, model: modelRef, handleOk, resetFields };
+    },
+  });
+</script>

+ 48 - 50
src/views/staff/list.vue

@@ -1,7 +1,9 @@
 <template>
   <div class="p-4">
     <BasicTable @register="registerTable">
-      <template #toolbar> </template>
+      <template #toolbar>
+        <a-button type="primary" @click="handleCreate">新增</a-button>
+      </template>
       <template #role="{ record }">
         {{ renderRoleType(record.role) }}
       </template>
@@ -11,32 +13,29 @@
       <template #createTime="{ record }">
         <Time :value="record.createTime" mode="datetime" />
       </template>
+      <!-- {
+        label: t('routes.staff.setpaswd'),
+        onClick: handleOpenModal.bind(null, record),
+      }, -->
       <template #action="{ record }">
         <TableAction
           :actions="[
             {
+              label: '编辑',
               icon: 'mdi:information-outline',
-              label: t('common.details'),
-              onClick: () => {
-                go(`/order/list/detail/${record.orderNo}`);
-              },
+              onClick: handleEdit.bind(null, record),
             },
             {
-              icon: 'mdi:printer-outline',
-              label: t('common.print'),
+              label: '删除',
               color: 'error',
-              onClick: () => {
-                createMessage.info(t('common.notConnect'));
-              },
-            },
-            {
-              label: t('routes.staff.setpaswd'),
-              onClick: handleOpenModal.bind(null, record),
+              icon: 'ant-design:delete-outlined',
+              onClick: handleDelete.bind(null, record),
             },
           ]"
         />
       </template>
     </BasicTable>
+    <DetailsModal @register="registerDetail" />
     <SetpaswordModal @register="register" />
   </div>
 </template>
@@ -47,43 +46,20 @@
   import { useModal } from '/@/components/Modal';
   import { uploadApi } from '/@/api/sys/upload';
   import SetpaswordModal from './setpaswordModal.vue';
+  import DetailsModal from './detailsModal.vue';
   // import { Switch } from 'ant-design-vue';
   // import { h } from 'vue';
-  import { ListApi } from '/@/api/staff/list';
+  import { ListApi, delApi } from '/@/api/staff/list';
   import { useI18n } from '/@/hooks/web/useI18n';
   // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
   import { useGo } from '/@/hooks/web/usePage';
   import { Time } from '/@/components/Time';
-
-  //   appid: null
-  // companyId: 1107
-  // companyName: "南山居"
-  // createTime: 1644801035000
-  // createUser: "11111111111"
-  // fdkkPassword: null
-  // fdkkUser: null
-  // head: null
-  // id: 20356
-  // memoName: "顶顶顶顶"
-  // message: null
-  // nickName: "用户13822221234"
-  // phone: "13822221234"
-  // roleIdList: null
-  // roleList: null
-  // roleName: "公司员工"
-  // state: null
-  // token: null
-  // type: 1
-  // updateTime: 1644801035000
-  // updateUser: "11111111111"
-  // userName: "13822221234"
-  // userPassword: "2a22bac40f44af4d3b5fdc20ea706fc5"
-
   export default defineComponent({
-    components: { BasicTable, TableAction, Time, SetpaswordModal },
+    components: { BasicTable, TableAction, Time, SetpaswordModal, DetailsModal },
     setup() {
-      const { createMessage } = useMessage();
       const [register, { openModal }] = useModal();
+      const [registerDetail, { openModal: openDetaileModal }] = useModal();
+      const { createConfirm, createMessage } = useMessage();
       const go = useGo();
       const { t } = useI18n();
       const columns: BasicColumn[] = [
@@ -135,13 +111,13 @@
           slots: { customRender: 'createTime' },
           width: 130,
         },
-        // {
-        //   title: '操作',
-        //   dataIndex: '',
-        //   slots: { customRender: 'action' },
-        //   fixed: 'right',
-        //   width: 140,
-        // },
+        {
+          title: '操作',
+          dataIndex: '',
+          slots: { customRender: 'action' },
+          fixed: 'right',
+          width: 140,
+        },
       ];
 
       const searchForm: Partial<FormProps> = {
@@ -159,7 +135,7 @@
         ],
       };
 
-      const [registerTable] = useTable({
+      const [registerTable, { reload }] = useTable({
         title: t('routes.staff.staffList'),
         api: ListApi,
         columns: columns,
@@ -196,15 +172,37 @@
       function handleOpenModal(record: Recordable) {
         openModal(true, record);
       }
+      function handleCreate() {
+        openDetaileModal(true);
+      }
+      function handleEdit(record: Recordable) {
+        openDetaileModal(true, record);
+      }
+      function handleDelete(record) {
+        console.log('handleDelete', record);
+        createConfirm({
+          iconType: 'warning',
+          title: '警告',
+          content: `此操作将对${record.userName}进行删除, 是否继续?`,
+          onOk: async () => {
+            await delApi(record.id);
+            reload();
+          },
+        });
+      }
       return {
         registerTable,
+        registerDetail,
         createMessage,
         t,
         go,
         renderRoleType,
         renderStatus,
+        handleCreate,
         handleOpenModal,
         register,
+        handleEdit,
+        handleDelete,
         uploadApi: uploadApi as any,
       };
     },