Browse Source

Merge branch 'dev' into sit

xiaodai2017 2 years ago
parent
commit
11a688fdca

+ 8 - 0
src/api/parameter/invoiceheader/index.ts

@@ -15,3 +15,11 @@ export const httpDelete = (id: number): any => {
     }
   });
 };
+
+export const httpAdd = (data: Record<string, any>): any => {
+  return http.request("post", `${yewuApi}invoiceadd`, { data });
+};
+
+export const httpUpdate = (data: Record<string, any>): any => {
+  return http.request("post", `${yewuApi}invoicesave`, { data });
+};

+ 5 - 13
src/views/parameter/clients/components/detail-dialog.vue

@@ -1,10 +1,11 @@
 <script setup lang="ts">
-import { mapKeyToName } from "../map";
 import { ref } from "vue";
+import { mapKeyToLabel, helper } from "./../utils/dialog-helper";
 import type { IClinetsDetail } from "../types";
 
 const isShow = ref(false);
 const detail = ref<Partial<IClinetsDetail>>({});
+const { getLabel, getDetail } = helper();
 
 //显示
 function show(clinetsDetail: IClinetsDetail) {
@@ -12,15 +13,6 @@ function show(clinetsDetail: IClinetsDetail) {
   detail.value = clinetsDetail;
 }
 
-const helper = {
-  getLabel(key: string) {
-    return mapKeyToName[key];
-  },
-  getDetail(key: string) {
-    return detail.value[key];
-  }
-};
-
 defineExpose({
   show
 });
@@ -30,10 +22,10 @@ defineExpose({
   <el-dialog v-model="isShow">
     <el-descriptions>
       <el-descriptions-item
-        v-for="(key, index) in Object.keys(mapKeyToName)"
-        :label="helper.getLabel(key)"
+        v-for="(key, index) in Object.keys(mapKeyToLabel)"
+        :label="getLabel(key)"
         :key="index"
-        >{{ helper.getDetail(key) }}</el-descriptions-item
+        >{{ getDetail(key, detail) }}</el-descriptions-item
       >
     </el-descriptions>
   </el-dialog>

+ 16 - 12
src/views/parameter/clients/index.vue

@@ -3,12 +3,12 @@ import { useColumns } from "./columns";
 import { httpList } from "/@/api/parameter/clients";
 import { reactive, ref, onMounted } from "vue";
 import { type FormInstance } from "element-plus";
-import { ElMessage } from "element-plus";
 import { TableProBar } from "/@/components/ReTable";
 import { type PaginationProps } from "@pureadmin/table";
 import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
 import { useNav } from "/@/layout/hooks/nav";
 import DetailDialog from "./components/detail-dialog.vue";
+import { responseHandle } from "/@/utils/responseHandle";
 const { logout } = useNav();
 defineOptions({
   name: "clients"
@@ -52,19 +52,23 @@ function handleSelectionChange(val) {
 async function onSearch() {
   loading.value = true;
   const { code, data, message } = await httpList(form);
-  if (code === 0) {
-    const { list, count } = data;
-    dataList.value = list ?? [];
-    pagination.total = count ?? 0;
-    pagination.pageSize = form.size;
-    pagination.currentPage = form.page;
-  } else if (code > 100 && code < 140) {
-    logout();
-  } else {
-    ElMessage.error(message);
-  }
+
+  responseHandle({
+    code,
+    message,
+    logout,
+    handler: () => {
+      const { list, count } = data;
+      dataList.value = list ?? [];
+      pagination.total = count ?? 0;
+      pagination.pageSize = form.size;
+      pagination.currentPage = form.page;
+    }
+  });
+
   loading.value = false;
 }
+
 async function resetSearch() {
   form.page = 1;
   await onSearch();

+ 0 - 8
src/views/parameter/clients/map.ts

@@ -1,8 +0,0 @@
-export const mapKeyToName: Record<string, string> = {
-  companyName: "客户名称",
-  companyNo: "客户编号",
-  addtime: "创建时间",
-  contactor: "联系人",
-  mobile: "联系方式",
-  parent: "归属集团"
-};

+ 19 - 0
src/views/parameter/clients/utils/dialog-helper.ts

@@ -0,0 +1,19 @@
+export const mapKeyToLabel: Record<string, string> = {
+  companyName: "客户名称",
+  companyNo: "客户编号",
+  addtime: "创建时间",
+  contactor: "联系人",
+  mobile: "联系方式",
+  parent: "归属集团"
+};
+
+export function helper() {
+  return {
+    getLabel(key: string) {
+      return mapKeyToLabel[key];
+    },
+    getDetail(key: string, detail: any) {
+      return detail[key];
+    }
+  };
+}

+ 2 - 1
src/views/parameter/invoiceheader/columns.tsx

@@ -16,6 +16,7 @@ export function useColumns() {
 
     {
       label: "业务公司",
+      
       prop: "invoice_title"
     },
     {
@@ -55,7 +56,7 @@ export function useColumns() {
     {
       label: "操作",
       fixed: "right",
-      width: 145,
+      width: 80,
       slot: "operation"
     }
   ]);

+ 4 - 4
src/views/parameter/invoiceheader/components/action-table.vue

@@ -6,7 +6,7 @@ import { httpList, httpDelete } from "/@/api/parameter/invoiceheader";
 import { TableProBar } from "/@/components/ReTable";
 import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
 import { useNav } from "/@/layout/hooks/nav";
-import { actionWithSuccess } from "../utils/actionWithSuccess";
+import { responseHandle } from "/@/utils/responseHandle";
 import { PaginationProps } from "@pureadmin/table";
 
 const dataList = ref([]);
@@ -44,7 +44,7 @@ const handleDelete = async row => {
   const { id } = row;
   const { code, message } = await httpDelete(id);
 
-  actionWithSuccess({
+  responseHandle({
     code,
     message,
     logout,
@@ -62,7 +62,7 @@ async function onSearch(form: any = {}) {
     size: pageSize
   });
 
-  actionWithSuccess({
+  responseHandle({
     code,
     message,
     logout,
@@ -75,7 +75,7 @@ async function onSearch(form: any = {}) {
   loading.value = false;
 }
 
-//编辑
+//编辑/新增 操作
 function editItem(type: "create" | "edit", item) {
   emit(type, item);
 }

+ 79 - 7
src/views/parameter/invoiceheader/components/edit-dialog.vue

@@ -1,21 +1,93 @@
 <script setup lang="ts">
+import { ElForm } from "element-plus";
 import { ref } from "vue";
-// import { mapPropToLabel, defaultFormData, helper } from "../utils/map";
+import { responseHandle } from "/@/utils/responseHandle";
+import { useNav } from "/@/layout/hooks/nav";
+import { create, edit } from "../utils/dialog-handler";
+import { createRules } from "../utils/create-rules";
+import {
+  mapPropToLabel,
+  defaultFormData,
+  helper
+} from "../utils/dialog-helper";
 
-// const visible = ref(true);
-// const formData = ref({ ...defaultFormData });
+enum DIALOG_TYPE {
+  create = "create",
+  edit = "edit"
+}
+
+const emit = defineEmits(["reload"]);
+
+const visible = ref(false);
+const editId = ref("");
+const formData = ref({ ...defaultFormData });
+const formRef = ref<InstanceType<typeof ElForm>>(null);
+const FROM_TYPE = ref<DIALOG_TYPE>(DIALOG_TYPE.create);
+const loading = ref(false);
+
+const rules = createRules();
+const { logout } = useNav();
+
+//显示dialog
+function show(item: any) {
+  visible.value = true;
+  const keys = Object.keys(formData.value);
+  const isCreate = Object.keys(item).length === 0;
+
+  editId.value = isCreate ? "" : item.id;
+
+  keys.forEach(key => {
+    formData.value[key] = isCreate ? "" : item[key];
+  });
+
+  FROM_TYPE.value = isCreate ? DIALOG_TYPE.create : DIALOG_TYPE.edit;
+}
+
+//创建/编辑 请求
+function handleSave() {
+  formRef.value.validate(async valid => {
+    if (!valid) return;
+    const handler = FROM_TYPE.value === DIALOG_TYPE.create ? create : edit;
+    const { data, api } = handler(formData.value, editId.value);
+    loading.value = true;
+    const { code, message } = await api(data);
+
+    responseHandle({
+      code,
+      message,
+      logout,
+      handler: () => emit("reload")
+    });
+
+    visible.value = false;
+    loading.value = false;
+  });
+}
+
+defineExpose({
+  show
+});
 </script>
 
 <template>
-  <el-dialog v-model="visible">
-    <el-form>
+  <el-dialog v-model="visible" destroy-on-close @close="loading = false">
+    <el-form ref="formRef" :model="formData" :rules="rules">
       <el-form-item
         v-for="(key, index) in Object.keys(mapPropToLabel)"
-        :label="helper.getLabel(key)"
+        :label="helper.getLabel(key) + ':'"
+        label-width="150px"
+        :prop="key"
         :key="index"
       >
-        <el-input />
+        <el-input v-model="formData[key]" />
       </el-form-item>
+
+      <div class="flex justify-end">
+        <el-button @click="visible = false">取消</el-button>
+        <el-button :loading="loading" type="primary" @click="handleSave"
+          >保存</el-button
+        >
+      </div>
     </el-form>
   </el-dialog>
 </template>

+ 13 - 2
src/views/parameter/invoiceheader/index.vue

@@ -9,6 +9,7 @@ defineOptions({
 });
 
 const tableRef = ref<InstanceType<typeof ActionTable>>(null);
+const dialogRef = ref<InstanceType<typeof EditDialog>>(null);
 
 //搜索
 function handleSearch(data: any) {
@@ -16,13 +17,23 @@ function handleSearch(data: any) {
   resetPagination();
   onSearch(data);
 }
+
+function handleDialogVisible(item: any) {
+  dialogRef.value.show(item);
+}
 </script>
 
 <template>
   <div class="main role">
     <SearchForm @search="handleSearch" />
-    <ActionTable ref="tableRef" />
-    <EditDialog />
+
+    <ActionTable
+      ref="tableRef"
+      @create="handleDialogVisible"
+      @edit="handleDialogVisible"
+    />
+
+    <EditDialog ref="dialogRef" @reload="tableRef.onSearch()" />
   </div>
 </template>
 

+ 0 - 22
src/views/parameter/invoiceheader/utils/actionWithSuccess.ts

@@ -1,22 +0,0 @@
-import { ElMessage } from "element-plus";
-
-export function actionWithSuccess({
-  code,
-  message,
-  logout,
-  handler
-}: {
-  code: number;
-  message: string;
-  logout: any;
-  handler: () => void;
-}) {
-  const c = Number(code);
-  if (c === 0) {
-    handler();
-  } else if (c > 100 && c < 140) {
-    logout();
-  } else {
-    ElMessage.error(message);
-  }
-}

+ 17 - 0
src/views/parameter/invoiceheader/utils/create-rules.ts

@@ -0,0 +1,17 @@
+import { FormRules } from "element-plus";
+import { mapPropToLabel, helper } from "./dialog-helper";
+
+export function createRules() {
+  const rules: FormRules = {};
+  Object.keys(mapPropToLabel).forEach(key => {
+    rules[key] = [
+      {
+        required: true,
+        trigger: "blur",
+        message: `请输入${helper.getLabel(key)}`
+      }
+    ];
+  });
+
+  return rules;
+}

+ 18 - 0
src/views/parameter/invoiceheader/utils/dialog-handler.ts

@@ -0,0 +1,18 @@
+import { httpAdd, httpUpdate } from "/@/api/parameter/invoiceheader";
+
+export function create(form: Record<string, any>) {
+  return {
+    data: form,
+    api: httpAdd
+  };
+}
+
+export function edit(form: Record<string, any>, id: string) {
+  return {
+    data: {
+      id: id,
+      ...form
+    },
+    api: httpUpdate
+  };
+}

+ 0 - 0
src/views/parameter/invoiceheader/utils/map.ts → src/views/parameter/invoiceheader/utils/dialog-helper.ts


+ 15 - 12
src/views/parameter/supplierPay/index.vue

@@ -3,11 +3,11 @@ import { reactive, ref, onMounted } from "vue";
 import { useColumns } from "./columns";
 import { httpList } from "/@/api/system/updates";
 import { type FormInstance } from "element-plus";
-import { ElMessage } from "element-plus";
 import { TableProBar } from "/@/components/ReTable";
 import { type PaginationProps } from "@pureadmin/table";
 import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
 import { useNav } from "/@/layout/hooks/nav";
+import { responseHandle } from "/@/utils/responseHandle";
 const { logout } = useNav();
 defineOptions({
   name: "supplierPay"
@@ -49,19 +49,22 @@ function handleSelectionChange(val) {
 async function onSearch() {
   loading.value = true;
   const { code, data, message } = await httpList(form);
-  if (code === 0) {
-    const { list, count } = data;
-    dataList.value = list ?? [];
-    pagination.total = count ?? 0;
-    pagination.pageSize = form.size;
-    pagination.currentPage = form.page;
-  } else if (code > 100 && code < 140) {
-    logout();
-  } else {
-    ElMessage.error(message);
-  }
+
+  responseHandle({
+    code,
+    message,
+    logout,
+    handler: () => {
+      const { list, count } = data;
+      dataList.value = list ?? [];
+      pagination.total = count ?? 0;
+      pagination.pageSize = form.size;
+      pagination.currentPage = form.page;
+    }
+  });
   loading.value = false;
 }
+
 async function resetSearch() {
   form.page = 1;
   await onSearch();

+ 7 - 4
src/views/system/setBtn/components/action-table.vue

@@ -6,7 +6,7 @@ import { httpList, httpStatus, httpDelete } from "/@/api/system/buttonOperator";
 import { TableProBar } from "/@/components/ReTable";
 import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
 import { useNav } from "/@/layout/hooks/nav";
-import { actionWithSuccess } from "../utils/actionWithSuccess";
+import { responseHandle } from "/@/utils/responseHandle";
 
 const dataList = ref([]);
 const loading = ref(false);
@@ -23,7 +23,8 @@ const handleUpdate = async row => {
     id,
     status: status + "" === "1" ? "0" : "1"
   });
-  actionWithSuccess({
+
+  responseHandle({
     code,
     message,
     logout,
@@ -35,7 +36,8 @@ const handleUpdate = async row => {
 const handleDelete = async row => {
   const { id } = row;
   const { code, message } = await httpDelete({ id });
-  actionWithSuccess({
+
+  responseHandle({
     code,
     message,
     logout,
@@ -46,7 +48,8 @@ const handleDelete = async row => {
 async function onSearch(id: string) {
   loading.value = true;
   const { code, data, message } = await httpList(id);
-  actionWithSuccess({
+
+  responseHandle({
     code,
     message,
     logout,

+ 2 - 2
src/views/system/setBtn/components/edit-dialog.vue

@@ -3,9 +3,9 @@ import { FormRules, ElForm } from "element-plus";
 import { computed, reactive, ref } from "vue";
 import btnList from "/@/utils/btnList";
 import { httpUpdate, httpAdd } from "/@/api/system/buttonOperator";
-import { actionWithSuccess } from "../utils/actionWithSuccess";
 import { useNav } from "/@/layout/hooks/nav";
 import { IMenuTree } from "../types";
+import { responseHandle } from "/@/utils/responseHandle";
 
 enum FROM_TYPE {
   create = "create",
@@ -84,7 +84,7 @@ function handleSave() {
 
       const { message, code } = await api(data);
 
-      actionWithSuccess({
+      responseHandle({
         code,
         message,
         logout,

+ 16 - 2
src/views/system/setBtn/components/menu-tree.vue

@@ -13,6 +13,7 @@ const emit = defineEmits(["treeSelectChange", "initTableData"]);
 
 const treeData = ref<Array<IMenuTree>>([]);
 const treeRef = ref<InstanceType<typeof ElTree>>(null);
+const defaultExpandedKeys = ref<Array<string>>([]);
 
 //获取菜单树列表
 async function initMenuList() {
@@ -20,6 +21,7 @@ async function initMenuList() {
   treeData.value = list;
   const menu = list[0];
   const page = menu.child[0];
+  defaultExpandedKeys.value = [menu.id];
 
   nextTick(() => {
     treeRef.value.setCurrentKey(page.id);
@@ -33,6 +35,10 @@ function handleSelect(node) {
   emit("treeSelectChange", node);
 }
 
+function handleTreeExpaned() {
+  // treeRef.value
+}
+
 initMenuList();
 </script>
 
@@ -40,14 +46,22 @@ initMenuList();
   <div
     class="max-w-280px w-[280px] h-full min-h-780px bg-white p-2 mt-24px mr-10px"
   >
+    <div class="flex justify-between mb-1 font-bold">
+      <h1>菜单列表</h1>
+
+      <!-- <div>
+        <el-button size="small" type="primary">展开</el-button>
+        <el-button size="small" type="primary">折叠</el-button>
+      </div> -->
+    </div>
     <el-tree
       ref="treeRef"
+      accordion
       node-key="id"
       highlight-current
-      current-node-key="45"
-      default-expand-all
       :props="defaultProps"
       :data="treeData"
+      :default-expanded-keys="defaultExpandedKeys"
       @current-change="handleSelect"
     />
   </div>

+ 0 - 22
src/views/system/setBtn/utils/actionWithSuccess.ts

@@ -1,22 +0,0 @@
-import { ElMessage } from "element-plus";
-
-export function actionWithSuccess({
-  code,
-  message,
-  logout,
-  handler
-}: {
-  code: number;
-  message: string;
-  logout: any;
-  handler: () => void;
-}) {
-  const c = Number(code);
-  if (c === 0) {
-    handler();
-  } else if (c > 100 && c < 140) {
-    logout();
-  } else {
-    ElMessage.error(message);
-  }
-}