2 Commits 8c2c509497 ... 8cebcb7f07

Auteur SHA1 Bericht Datum
  ylong 8cebcb7f07 refactor(CommonTable): 重构表格数据源逻辑以支持自定义数据源 2 weken geleden
  ylong 8b5ccd8d0d refactor(订单复审): 修改复审状态字段为静态选项并调整代码格式 1 maand geleden
2 gewijzigde bestanden met toevoegingen van 262 en 244 verwijderingen
  1. 180 166
      src/components/CommonPage/CommonTable.vue
  2. 82 78
      src/views/recycleOrder/components/order-review-search.vue

+ 180 - 166
src/components/CommonPage/CommonTable.vue

@@ -1,9 +1,10 @@
 <template>
 <template>
     <ele-card :body-style="{ paddingTop: '8px', ...bodyStyle }" :flex-table="flexTable">
     <ele-card :body-style="{ paddingTop: '8px', ...bodyStyle }" :flex-table="flexTable">
         <!-- 表格 -->
         <!-- 表格 -->
-        <ele-pro-table ref="tableRef" :row-key="pageConfig.rowKey || 'id'" :columns="columns" :datasource="datasource"
-            :show-overflow-tooltip="true" v-model:selections="selections" highlight-current-row
-            :export-config="{ fileName: pageConfig.fileName }" :cache-key="pageConfig.cacheKey" border v-bind="$attrs">
+        <ele-pro-table ref="tableRef" :row-key="pageConfig.rowKey || 'id'" :columns="columns"
+            :datasource="finalDatasource" :show-overflow-tooltip="true" v-model:selections="selections"
+            highlight-current-row :export-config="{ fileName: pageConfig.fileName }" :cache-key="pageConfig.cacheKey"
+            border v-bind="$attrs">
             <template v-for="(val, key) in slotArray" #[key]="{ row }">
             <template v-for="(val, key) in slotArray" #[key]="{ row }">
                 <slot :name="key" :row="row"></slot>
                 <slot :name="key" :row="row"></slot>
             </template>
             </template>
@@ -12,100 +13,162 @@
 </template>
 </template>
 
 
 <script setup>
 <script setup>
-import { ref, getCurrentInstance, useSlots } from "vue";
-import { ElMessageBox } from "element-plus/es";
-import { EleMessage } from "ele-admin-plus/es";
-import { useDictData } from "@/utils/use-dict-data";
-import { download, toFormData, checkDownloadRes } from "@/utils/common";
-
-const slotArray = useSlots();
-
-let props = defineProps({
-    pageConfig: {
-        type: Object,
-        default: () => ({
-            cacheKey: "recycleOrderTable",
-            fileName: "回收订单查询",
-            rowKey: "id",
-        }),
-    },
-    pageUrl: { type: String, default: "" },
-    columns: { type: Array, default: () => [] },
-    bodyStyle: { type: Object, default: () => ({}) },
-    flexTable: { type: Boolean, default: true },
-    sortFunction: { type: Function },
-});
-let { proxy } = getCurrentInstance();
-
-/** 表格实例 */
-const tableRef = ref(null);
-
-/** 表格选中数据 */
-const selections = ref([]);
-
-async function queryPage(params) {
-    let url = props.pageConfig.pageUrl || props.pageUrl;
-    if (!url) {
-        return Promise.reject(new Error("请配置页面URL"));
-    }
-    const res = await proxy.$http.get(url, { params });
-    if (res.data.code === 200) {
-        return res.data;
-    }
-    return Promise.reject(new Error(res.data.msg));
-}
-
-/** 表格数据源 */
-const whereCache = ref({});
-const datasource = (table) => {
-    let { pages, where, orders, sorter } = table;
-    let initKeys = props.pageConfig.params || {};
-    whereCache.value = where;
-
-    let tempOrders = {};
-    console.log('orders', orders);
-    if (orders && orders.orderByColumn) {
-        tempOrders.orderType = sorter.column.columnKey;
-        tempOrders.orderWay = orders.isAsc === "ascending" ? "asc" : "desc";
+    import { ref, getCurrentInstance, useSlots } from "vue";
+    import { ElMessageBox } from "element-plus/es";
+    import { EleMessage } from "ele-admin-plus/es";
+    import { useDictData } from "@/utils/use-dict-data";
+    import { download, toFormData, checkDownloadRes } from "@/utils/common";
+
+    const slotArray = useSlots();
+
+    let props = defineProps({
+        pageConfig: {
+            type: Object,
+            default: () => ({
+                cacheKey: "recycleOrderTable",
+                fileName: "回收订单查询",
+                rowKey: "id",
+            }),
+        },
+        pageUrl: { type: String, default: "" },
+        columns: { type: Array, default: () => [] },
+        bodyStyle: { type: Object, default: () => ({}) },
+        flexTable: { type: Boolean, default: true },
+        sortFunction: { type: Function },
+        datasource: { type: Function },
+    });
+    let { proxy } = getCurrentInstance();
+
+    /** 表格实例 */
+    const tableRef = ref(null);
+
+    /** 表格选中数据 */
+    const selections = ref([]);
+
+    async function queryPage(params) {
+        let url = props.pageConfig.pageUrl || props.pageUrl;
+        if (!url) {
+            return Promise.reject(new Error("请配置页面URL"));
+        }
+        const res = await proxy.$http.get(url, { params });
+        if (res.data.code === 200) {
+            return res.data;
+        }
+        return Promise.reject(new Error(res.data.msg));
     }
     }
-    // 兼容激活码排序
-    if (props.sortFunction) {
-        tempOrders = props.sortFunction(orders);
+
+    /** 表格数据源 */
+    const whereCache = ref({});
+    const defaultDatasource = (table) => {
+        let { pages, where, orders, sorter } = table;
+        let initKeys = props.pageConfig.params || {};
+        whereCache.value = where;
+
+        let tempOrders = {};
+        console.log('orders', orders);
+        if (orders && orders.orderByColumn) {
+            tempOrders.orderType = sorter.column.columnKey;
+            tempOrders.orderWay = orders.isAsc === "ascending" ? "asc" : "desc";
+        }
+        // 兼容激活码排序
+        if (props.sortFunction) {
+            tempOrders = props.sortFunction(orders);
+        }
+
+        return queryPage({ ...initKeys, ...where, ...tempOrders, ...pages });
+    };
+
+    const finalDatasource = (table) => {
+        if (props.datasource) {
+            return props.datasource(table);
+        }
+        return defaultDatasource(table);
+    };
+
+    /** 搜索 */
+    const reload = (where = {}) => {
+        let data = where && where.search ? { page: 1, where } : { where: { ...whereCache.value, ...where } };
+        delete data.where?.search;
+        delete data.where?.isReset;
+        tableRef.value?.reload?.(data);
+    };
+
+    /** 批量操作 */
+    const operatBatch = ({ method, row, url, title, data = {} }) => {
+        const rows = row == null ? selections.value : [row];
+        if (!rows.length) {
+            EleMessage.error("请至少选择一条数据");
+            return;
+        }
+        title = title || "是否确认当前操作?";
+        ElMessageBox.confirm(title, "提示", {
+            type: "warning",
+            draggable: true,
+        })
+            .then(() => {
+                const loading = EleMessage.loading({
+                    message: "请求中..",
+                    plain: true,
+                });
+                proxy.$http[method](url, data)
+                    .then((res) => {
+                        if (res.data.code === 200) {
+                            EleMessage.success("操作成功");
+                            reload();
+                        } else {
+                            EleMessage.error(res.data.msg);
+                        }
+                        loading.close();
+                    })
+                    .catch((e) => {
+                        loading.close();
+                        EleMessage.error(e.message);
+                    });
+            })
+            .catch(() => { });
+    };
+
+    /// 导出数据
+    async function exportPage(params, name, method = "POST") {
+        const res = await proxy.$http({
+            url: props.pageConfig.exportUrl,
+            method,
+            data: toFormData(params),
+            responseType: "blob",
+        });
+        await checkDownloadRes(res);
+        download(
+            res.data,
+            name ? `${name}_${Date.now()}.xlsx` : `post_${Date.now()}.xlsx`
+        );
     }
     }
-    
-    return queryPage({ ...initKeys, ...where, ...tempOrders, ...pages });
-};
-
-/** 搜索 */
-const reload = (where = {}) => {
-    let data = where && where.search ? { page: 1, where } : { where: { ...whereCache.value, ...where } };
-    delete data.where?.search;
-    delete data.where?.isReset;
-    tableRef.value?.reload?.(data);
-};
-
-/** 批量操作 */
-const operatBatch = ({ method, row, url, title, data = {} }) => {
-    const rows = row == null ? selections.value : [row];
-    if (!rows.length) {
-        EleMessage.error("请至少选择一条数据");
-        return;
+
+    //导出数据 进导出记录
+    function exportRecord(params, method = "POST") {
+        let data = method === "POST" ? { data: params } : { params };
+        return proxy.$http({
+            url: props.pageConfig.exportUrl,
+            method,
+            ...data,
+        }); // 导出记录
     }
     }
-    title = title || "是否确认当前操作?";
-    ElMessageBox.confirm(title, "提示", {
-        type: "warning",
-        draggable: true,
-    })
-        .then(() => {
-            const loading = EleMessage.loading({
-                message: "请求中..",
-                plain: true,
-            });
-            proxy.$http[method](url, data)
+
+    /** 导出数据 */
+    const exportData = (name, method = "POST") => {
+        const loading = EleMessage.loading({
+            message: "请求中..",
+            plain: true,
+        });
+        tableRef.value?.fetch?.(({ where, orders }) => {
+            let initKeys = props.pageConfig.params || {};
+            console.log('where', where);
+            console.log('orders', orders);
+            console.log('initKeys', initKeys);
+
+            exportRecord({ ...where, ...orders, ...initKeys }, method)
                 .then((res) => {
                 .then((res) => {
                     if (res.data.code === 200) {
                     if (res.data.code === 200) {
-                        EleMessage.success("操作成功");
-                        reload();
+                        EleMessage.success("操作成功,请前往导出记录下载");
                     } else {
                     } else {
                         EleMessage.error(res.data.msg);
                         EleMessage.error(res.data.msg);
                     }
                     }
@@ -115,85 +178,36 @@ const operatBatch = ({ method, row, url, title, data = {} }) => {
                     loading.close();
                     loading.close();
                     EleMessage.error(e.message);
                     EleMessage.error(e.message);
                 });
                 });
-        })
-        .catch(() => { });
-};
-
-/// 导出数据
-async function exportPage(params, name, method = "POST") {
-    const res = await proxy.$http({
-        url: props.pageConfig.exportUrl,
-        method,
-        data: toFormData(params),
-        responseType: "blob",
-    });
-    await checkDownloadRes(res);
-    download(
-        res.data,
-        name ? `${name}_${Date.now()}.xlsx` : `post_${Date.now()}.xlsx`
-    );
-}
-
-//导出数据 进导出记录
-function exportRecord(params, method = "POST") {
-    return proxy.$http({
-        url: props.pageConfig.exportUrl,
-        method,
-        data: params,
-    }); // 导出记录
-}
-
-/** 导出数据 */
-const exportData = (name, method = "POST") => {
-    const loading = EleMessage.loading({
-        message: "请求中..",
-        plain: true,
-    });
-    tableRef.value?.fetch?.(({ where, orders }) => {
-        let initKeys = props.pageConfig.params || {};
-        exportRecord({ ...where, ...orders, ...initKeys }, method)
-            .then((res) => {
+        });
+    };
+
+    function messageBoxConfirm({ message, fetch }) {
+        ElMessageBox.confirm(message, "提示", {
+            confirmButtonText: "确定",
+            cancelButtonText: "关闭",
+            type: "warning",
+        }).then(() => {
+            fetch().then((res) => {
                 if (res.data.code === 200) {
                 if (res.data.code === 200) {
-                    EleMessage.success("操作成功,请前往导出记录下载");
+                    EleMessage.success("操作成功");
+                    reload();
                 } else {
                 } else {
                     EleMessage.error(res.data.msg);
                     EleMessage.error(res.data.msg);
                 }
                 }
-                loading.close();
-            })
-            .catch((e) => {
-                loading.close();
-                EleMessage.error(e.message);
             });
             });
-    });
-};
-
-function messageBoxConfirm({ message, fetch }) {
-    ElMessageBox.confirm(message, "提示", {
-        confirmButtonText: "确定",
-        cancelButtonText: "关闭",
-        type: "warning",
-    }).then(() => {
-        fetch().then((res) => {
-            if (res.data.code === 200) {
-                EleMessage.success("操作成功");
-                reload();
-            } else {
-                EleMessage.error(res.data.msg);
-            }
         });
         });
+    }
+
+    function getSelections() {
+        console.log(selections.value, "selections.value");
+        return selections.value;
+    }
+
+    defineExpose({
+        reload,
+        exportData,
+        operatBatch,
+        getSelections,
+        messageBoxConfirm,
     });
     });
-}
-
-function getSelections() {
-    console.log(selections.value, "selections.value");
-    return selections.value;
-}
-
-defineExpose({
-    reload,
-    exportData,
-    operatBatch,
-    getSelections,
-    messageBoxConfirm,
-});
 </script>
 </script>

+ 82 - 78
src/views/recycleOrder/components/order-review-search.vue

@@ -11,86 +11,90 @@
 </template>
 </template>
 
 
 <script setup>
 <script setup>
-import { reactive, ref, defineEmits } from 'vue';
-import { useFormData } from '@/utils/use-form-data';
-import ProSearch from '@/components/CommonPage/ProSearch2.vue';
-import request from '@/utils/request';
+    import { reactive, ref, defineEmits } from 'vue';
+    import { useFormData } from '@/utils/use-form-data';
+    import ProSearch from '@/components/CommonPage/ProSearch2.vue';
+    import request from '@/utils/request';
 
 
-const emit = defineEmits(['search']);
-const columns = ref([
-    {
-        type: 'dictSelect',
-        label: '复审状态',
-        prop: 'reviewStatus',
-        props: { code: 'recycle_refund_status' }
-    },
-    {
-        type: 'input',
-        label: '用户名',
-        prop: 'userName'
-    },
-    {
-        type: 'input',
-        label: '订单编号(多个以中文逗号、空格或换行分割)',
-        prop: 'orderIds',
-        colProps: { span: 8 }
-    },
-    {
-        type: 'input',
-        label: '物流单号(多个以中文逗号、空格或换行分割)',
-        prop: 'waybillCodes',
-        colProps: { span: 8 }
-    },
-    {
-        type: 'select',
-        label: '收货仓库',
-        prop: 'godownId',
-        options: []
-    },
-    {
-        type: 'datetime',
-        label: '提交复审时间(开始时间)',
-        prop: 'applyTimeStart',
-        props: {
-            format: 'YYYY-MM-DD HH:mm:ss',
-            valueFormat: 'YYYY-MM-DD HH:mm:ss'
-        }
-    },
-    {
-        type: 'datetime',
-        label: '提交复审时间(结束时间)',
-        prop: 'applyTimeEnd',
-        props: {
-            valueFormat: 'YYYY-MM-DD HH:mm:ss'
-        }
-    },
-]);
+    const emit = defineEmits(['search']);
+    const columns = ref([
+        {
+            type: 'select',
+            label: '复审状态',
+            prop: 'reviewStatus',
+            options: [
+                { label: '未复审', value: '1' },
+                { label: '已复审', value: '2' },
+                { label: '复审终止', value: '3' }
+            ]
+        },
+        {
+            type: 'input',
+            label: '用户名',
+            prop: 'userName'
+        },
+        {
+            type: 'input',
+            label: '订单编号(多个以中文逗号、空格或换行分割)',
+            prop: 'orderIds',
+            colProps: { span: 8 }
+        },
+        {
+            type: 'input',
+            label: '物流单号(多个以中文逗号、空格或换行分割)',
+            prop: 'waybillCodes',
+            colProps: { span: 8 }
+        },
+        {
+            type: 'select',
+            label: '收货仓库',
+            prop: 'godownId',
+            options: []
+        },
+        {
+            type: 'datetime',
+            label: '提交复审时间(开始时间)',
+            prop: 'applyTimeStart',
+            props: {
+                format: 'YYYY-MM-DD HH:mm:ss',
+                valueFormat: 'YYYY-MM-DD HH:mm:ss'
+            }
+        },
+        {
+            type: 'datetime',
+            label: '提交复审时间(结束时间)',
+            prop: 'applyTimeEnd',
+            props: {
+                valueFormat: 'YYYY-MM-DD HH:mm:ss'
+            }
+        },
+    ]);
 
 
-//获取仓库数据
-function getGodownList() {
-    request.post('/baseinfo/godown/searchGodown?name=').then((res) => {
-        if (res.data.code === 200) {
-            let item = columns.value.find(
-                (item) => item.prop === 'godownId'
-            );
-            item.options = res.data.data.map((item) => ({
-                label: item.godownName,
-                value: item.id
-            }));
-        }
-    });
-}
-getGodownList();
+    //获取仓库数据
+    function getGodownList() {
+        request.post('/baseinfo/godown/searchGodown?name=').then((res) => {
+            if (res.data.code === 200) {
+                let item = columns.value.find(
+                    (item) => item.prop === 'godownId'
+                );
+                item.options = res.data.data.map((item) => ({
+                    label: item.godownName,
+                    value: item.id
+                }));
+            }
+        });
+    }
+    getGodownList();
 
 
-const searchRef = ref(null);
-/** 搜索 */
-const search = (data) => {
-    emit('search', { ...data });
-};
+    const searchRef = ref(null);
+    /** 搜索 */
+    const search = (data) => {
+        emit('search', { ...data });
+    };
 
 
-/** 重置 */
-const reset = () => {
-    resetFields();
-    search();
-};
+    /** 重置 */
+    const reset = () => {
+        resetFields();
+        search();
+    };
 </script>
 </script>