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

fix 不良统计增减省份查询和不良率变成平均

ylong 3 hónapja
szülő
commit
1f83abd749

+ 92 - 70
src/views/statistic/defect/components/page-search.vue

@@ -1,87 +1,109 @@
 <!-- 搜索表单 -->
 <template>
     <ele-card :body-style="{ paddingBottom: '8px' }">
-        <ProSearch
-            :items="formItems"
-            ref="searchRef"
-            @search="search"
-            :initKeys="initKeys"
-            :offset="1"
-        />
+        <ProSearch :items="formItems" ref="searchRef" @search="search" :initKeys="initKeys" :offset="1" />
     </ele-card>
 </template>
 
 <script setup>
-    import {
-        reactive,
-        ref,
-        defineEmits,
-        computed,
-        getCurrentInstance
-    } from 'vue';
-    import ProSearch from '@/components/CommonPage/ProSearch2.vue';
+import {
+    reactive,
+    ref,
+    defineEmits,
+    computed,
+    getCurrentInstance
+} from 'vue';
+import ProSearch from '@/components/CommonPage/ProSearch2.vue';
 
-    let { proxy } = getCurrentInstance();
-    const emit = defineEmits(['search']);
+let { proxy } = getCurrentInstance();
+const emit = defineEmits(['search']);
 
-    const godownList = ref([]);
-    const formItems = computed(() => {
-        return [
-            {
-                type: 'select',
-                label: '收货仓库',
-                prop: 'godownId',
-                options: godownList.value.map((item) => ({
-                    label: item.godownName,
-                    value: item.id
-                })),
-                props: {
-                    placeholder: '请选择收货仓库',
-                    clearable: true
+const godownList = ref([]);
+const provinceList = ref([]);
+function getProviceList(id = 1) {
+    return proxy.$http.get(`/baseinfo/districtInfo/findInfo/${id}`);
+}
+getProviceList().then((res) => {
+    provinceList.value = res.data.data;
+});
+
+
+const formItems = computed(() => {
+    return [
+        {
+            type: 'select',
+            label: '省份',
+            prop: 'provinceId',
+            options: provinceList.value.map((d) => {
+                return { label: d.district, value: d.id };
+            }),
+            props: {
+                filterable: true,
+                multiple: true,
+                onChange: (value) => {
+                    searchRef.value?.setData({
+                        provinceIdList: value
+                    });
                 }
-            },
-            {
-                type: 'daterange',
-                label: '统计日期',
-                prop: 'time',
-                props: {
-                    format: 'YYYY-MM-DD',
-                    valueFormat: 'YYYY-MM-DD',
-                    onChange: (value) => {
-                        searchRef.value?.setData({
-                            statDateStart: value ? value[0] : '',
-                            statDateEnd: value ? value[1] : ''
-                        });
-                    }
-                },
-                colProps: {
-                    span: 6
+            }
+        },
+        {
+            type: 'select',
+            label: '收货仓库',
+            prop: 'godownId',
+            options: godownList.value.map((item) => ({
+                label: item.godownName,
+                value: item.id
+            })),
+            props: {
+                placeholder: '请选择收货仓库',
+                clearable: true
+            }
+        },
+        {
+            type: 'daterange',
+            label: '统计日期',
+            prop: 'time',
+            props: {
+                format: 'YYYY-MM-DD',
+                valueFormat: 'YYYY-MM-DD',
+                onChange: (value) => {
+                    searchRef.value?.setData({
+                        statDateStart: value ? value[0] : '',
+                        statDateEnd: value ? value[1] : ''
+                    });
                 }
+            },
+            colProps: {
+                span: 6
             }
-        ];
-    });
+        }
+    ];
+});
 
-    const initKeys = reactive({
-        statDateStart: '',
-        statDateEnd: '',
-        godownId: ''
-    });
+const initKeys = reactive({
+    statDateStart: '',
+    statDateEnd: '',
+    godownId: '',
+    provinceIdList: []
+});
 
-    function getStoreList(name = '') {
-        return proxy.$http.post(`/baseinfo/godown/searchGodown?name=${name}`);
-    }
-    getStoreList().then((res) => {
-        godownList.value = res.data.data;
-    });
+function getStoreList(name = '') {
+    return proxy.$http.post(`/baseinfo/godown/searchGodown?name=${name}`);
+}
+getStoreList().then((res) => {
+    godownList.value = res.data.data;
+});
 
-    const searchRef = ref(null);
-    /** 搜索 */
-    const search = (data) => {
-        const searchParams = {
-            godownId: data.godownId,
-            statDateStart: data.statDateStart || initKeys.statDateStart,
-            statDateEnd: data.statDateEnd || initKeys.statDateEnd
-        };
-        emit('search', searchParams);
+const searchRef = ref(null);
+/** 搜索 */
+const search = (data) => {
+    const searchParams = {
+        godownId: data.godownId,
+        statDateStart: data.statDateStart || initKeys.statDateStart,
+        statDateEnd: data.statDateEnd || initKeys.statDateEnd,
+        provinceIdList: data.provinceIdList.join(',') || initKeys.provinceIdList.join(',')
     };
+    emit('search', searchParams);
+};
 </script>

+ 48 - 3
src/views/statistic/defect/index.vue

@@ -2,7 +2,7 @@
     <ele-page flex-table>
         <page-search @search="reload" />
         <common-table ref="pageRef" :pageConfig="pageConfig" :columns="columns" :tools="false" show-summary
-            :flex-table="false">
+            :flex-table="false" :summary-method="getSummaries">
             <template #toolbar="{ row }">
                 <div>
                     <el-button type="success" plain v-permission="'statistic:defect:export'"
@@ -16,10 +16,10 @@
 </template>
 
 <script setup>
-import { ref, reactive } from 'vue';
+import { ref, reactive, getCurrentInstance } from 'vue';
 import CommonTable from '@/components/CommonPage/CommonTable.vue';
 import pageSearch from './components/page-search.vue';
-
+const { proxy } = getCurrentInstance();
 defineOptions({ name: 'StatisticDefect' });
 
 /** 表格列配置 */
@@ -45,9 +45,54 @@ const pageConfig = reactive({
     cacheKey: 'statisticDefectTable'
 });
 
+//获取不良率平均值
+function getBadRatioAverage(params = {}) {
+    proxy.$http.get('/order/ordercheck/stat/badRationAverage', { params }).then((res) => {
+        if (res.data.code === 200) {
+            badRatio.value = res.data.data;
+        }
+    });
+}
+
+getBadRatioAverage()
+
 //刷新表格
+const badRatio = ref('-');
 function reload(where) {
     pageRef.value?.reload(where);
+    getBadRatioAverage(where)
+}
+
+/**
+    * 自定义表格汇总计算方法
+    * @param {Object} param0 - 表格数据和列信息
+    * @returns {Array} - 汇总行显示的数据
+    */
+function getSummaries({ columns, data }) {
+    const sums = [];
+    columns.forEach((column, index) => {
+        if (index === 0) {
+            sums[index] = '平均';
+            return;
+        }
+
+        const values = data.map((item) => Number(item[column.property]));
+
+        if (!values.length) {
+            sums[index] = 'N/A';
+            return;
+        }
+
+        switch (column.property) {
+            case 'badRatio':
+                sums[index] = badRatio.value;
+                break;
+            default:
+                sums[index] = '';
+        }
+    });
+
+    return sums;
 }
 
 //导出excel