gaoshp
2024-06-02 b46e6d2306515f94bf77c06e8d80ac76267e3ddb
src/views/mdc/time-analysis.vue
@@ -2,7 +2,7 @@
 * @Author: lzhe lzhe@example.com
 * @Date: 2024-04-26 09:36:18
 * @LastEditors: lzhe lzhe@example.com
 * @LastEditTime: 2024-04-30 10:03:05
 * @LastEditTime: 2024-05-14 18:30:07
 * @FilePath: /smart-web/src/views/mdc/status-record.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
@@ -83,6 +83,7 @@
                                    <template #title>
                                        <el-icon size="16" color="#3b8e8e"><Memo /></el-icon>
                                        <span class="collr-title">{{item.name}}</span>
                                        <el-button size="small" v-if="index != 0">{{item.indexName}}</el-button>
                                    </template>
                                    <div>
                                        <el-button-group>
@@ -135,6 +136,7 @@
           btnLeftList: [{title: "按工位统计",id:"1"},{title: "按工位组统计",id:"2"}],
           btnLeftctive: "1",
            isshowempty: true,
            getGlobalColorList: [],
            shortcuts: [
                {
                    text: '最近3天',
@@ -179,6 +181,7 @@
                        params.forEach(item=> {
                            dom += `<div>${item.marker}${item.seriesName}:${item.data}%</div>`
                        })
                        console.log(params)
                        return dom;
                    }
                },
@@ -233,7 +236,7 @@
                    show: true,
                    axisLabel: {
                        formatter: function (value) {
                            return value + "%";
                            return value * 100 + "%";
                        }
                    },
                    data: [2,20,40,60,80,100]
@@ -269,7 +272,7 @@
                    show: true,
                    axisLabel: {
                        formatter: function (value) {
                            return value + "%";
                            return value * 100 + "%";
                        }
                    },
                    data: [2,20,40,60,80,100]
@@ -305,7 +308,7 @@
                    show: true,
                    axisLabel: {
                        formatter: function (value) {
                            return value + "%";
                            return value * 100 + "%";
                        }
                    },
                    data: [2,20,40,60,80,100]
@@ -321,24 +324,28 @@
        this.init();
        this.getTree2List();  //按工位统计树
        this.getDataA();
        this.getGlobal(); //获取颜色
    },
    methods: {
        getGlobal() {
            this.$HTTP.get(`/api/blade-cps/global_wcs/list`).then(res=> {
                if(res.code == 200) {
                    this.getGlobalColorList = res.data;
                }
            })
        },
       getDataA() {
          var ids = [];
          this.treeChecked.forEach(item=> {
             ids.push(item.id);
          })
            if(this.btnLeftctive == 1) {  //按工位统计
                var obj = {
                    ids: ids,
                    ids: this.ids,
                    localDate: this.date,
                    type: 0
                }
            }else if(this.btnLeftctive == 1) { //按工位组统计
            }else if(this.btnLeftctive == 2) { //按工位组统计
                var obj = {
                    groupCategory: 1,
                    groupType: "group_workstation",
                    ids: ids,
                    ids: this.ids,
                    localDate: this.date,
                    type: 1
                }
@@ -372,17 +379,43 @@
            
            // 排除运行时间为0的情况  
            var totalRunTime = timeSums[0] || 1;  
            // 计算每个状态的百分比数据  
            var lastData = Object.keys(resultObject).map(key => {
                var data = resultObject[key].map((item, index) => {
                    if (index === 0) { // 只计算时间的百分比
                        return item == 0?0:Number((item / totalRunTime * 100).toFixed(2));
                    } else {
                        return item; // 计数保持不变
                    }
                });
                return {
            // var lastData = Object.keys(resultObject).map(key => {
            //     var data = resultObject[key].map((item, index) => {
            //         if (index === 0) { // 只计算时间的百分比
            //             return item == 0?0:Number((item / totalRunTime * 100).toFixed(2));
            //         } else {
            //             return item; // 计数保持不变
            //         }
            //     });
            //     return {
            //         name: key,
            //         type: 'bar',
            //         stack: 'total',
            //         label: {
            //             show: false
            //         },
            //         emphasis: {
            //             focus: 'series'
            //         },
            //         barWidth: 60,
            //         data
            //     }
            // });
            var lastData = [];
            var colorObj = {};  //设置颜色
            this.getGlobalColorList.forEach(item=> {
                colorObj[item.name] = item.color;
            })
            Object.keys(resultObject).map(key => {
                resultObject[key].forEach((item,index)=> {
                    if(item != 0) {
                        var num = item/timeSums[index]* 100;
                        item = num.toFixed(2);
                    }
                    resultObject[key][index] = item;
                })
                lastData.push({
                    name: key,
                    type: 'bar',
                    stack: 'total',
@@ -392,11 +425,14 @@
                    emphasis: {
                        focus: 'series'
                    },
                    itemStyle: {
                        "color": colorObj[key]
                    },
                    barWidth: 60,
                    data
                }
            });
            return lastData;
                    data: resultObject[key]
                })
            })
            return lastData.reverse();
        },
        getDataChartsA(index) {
            var obj = {
@@ -413,7 +449,7 @@
            }
            if(this.btnLeftctive == 1) {  //按工位统计
                obj.type = 0;
            }else if(this.btnLeftctive == 1) { //按工位组统计
            }else if(this.btnLeftctive == 2) { //按工位组统计
                obj.type = 1;
            }
            this.$HTTP.post(`/api/blade-mdc/time-used-analysis/work-stations?current=${this.current}&size=${this.size}`,obj).then(res=> {
@@ -425,13 +461,13 @@
                    this.chartOptionA.xAxis.data = xAxis;
                    var recordDom = document.getElementById('recordwork' + index);
                    this.chartOptionA.series = this.formatChartData(res.data.countStatus);
                    console.log(this.chartOptionA.series)
                    var myChart = echarts.init(recordDom);
                    myChart.setOption(this.chartOptionA);
                    console.log(JSON.stringify(this.chartOptionA))
                }
            })
        },
        getDataChartsB(enums) {
        getDataChartsB(enums,month) {
            var obj = {
                enums: enums,
                groupCategory: 1,
@@ -443,14 +479,19 @@
                week: moment(this.date).get('week'),
                year: moment(this.date).get('year')
            }
            if(month) {
                obj.month = month;
            }
            if(this.btnLeftctive == 1) {  //按工位统计
                obj.type = 0;
            }else if(this.btnLeftctive == 1) { //按工位组统计
            }else if(this.btnLeftctive == 2) { //按工位组统计
                obj.type = 1;
            }
            this.$HTTP.post(`/api/blade-mdc/time-used-analysis/work-stations?current=${this.current}&size=${this.size}`,obj).then(res=> {
                if(res.code == 200) {
                    var xAxis = [];
                    res.data.workStationDetails == null ? res.data.workStationDetails = [] : res.data.workStationDetails;
                    res.data.countStatus == null ? res.data.countStatus = [] : res.data.countStatus;
                    res.data.workStationDetails.forEach(item=> {
                        xAxis.push(item.name);
                    })
@@ -498,26 +539,41 @@
                        statisticalMethod: "WEEK"
                    }
                    this.$HTTP.post(`/api/blade-mdc/efficiency-analysis/interval`,obj).then(res=> {
                        console.log(res)
                        if(res.code == 200) {
                            var dateInJuly = moment(this.btnList[0].id);
                            // 获取该月份的第一天
                            var firstDayOfJuly = dateInJuly.startOf('month').format('YYYY-MM-DD');
                            // 获取该月份的最后一天
                            var lastDayOfJuly = dateInJuly.endOf('month').format('YYYY-MM-DD');
                            //跨月
                            var startDate = moment(res.data[0].startDate).month() + 1;
                            var endDate = moment(res.data[0].endDate).month() + 1;
                            var arrMonth = [];
                            for (var i = startDate; i <= endDate; i++) {
                                arrMonth.push({title: (i + "月"),id: (i + "月")});
                            }
                            var arr = [];
                            arr.push({
                                btnList: this.btnList,
                                name: '按日查看',
                                btnListActive: this.btnList[0].id
                            },{
                                btnList: [{title:moment(this.date).get('week') + "周",id: moment(this.date).get('week') + "周"}],
                                name: '按周查看',
                                btnListActive: moment(this.date).get('week') + "周",
                                indexName : res.data[0].startDate + "至" + res.data[0].endDate
                            },{
                                btnList: arrMonth.reverse(),
                                name: '按月查看',
                                btnListActive: moment(this.date).get('month') + 1 + "月",
                                indexName : firstDayOfJuly + "至" + lastDayOfJuly
                            });
                            this.setTitle1 = arr;
                            this.getDataChartsB("DAY");
                            this.getDataChartsB("MONTH");
                            this.getDataChartsB("WEEK");
                        }
                    })
                    var arr = [];
                    arr.push({
                        btnList: this.btnList,
                        name: '按日查看',
                        btnListActive: this.btnList[0].id
                    },{
                        btnList: [{title:moment(this.date).get('week') + "周",id: moment(this.date).get('week') + "周"}],
                        name: '按周查看',
                        btnListActive: moment(this.date).get('week') + "周"
                    },{
                        btnList: [{title:moment(this.date).get('month') + 1 + "月",id: moment(this.date).get('month') + 1 + "月"}],
                        name: '按月查看',
                        btnListActive: moment(this.date).get('month') + 1 + "月"
                    });
                    this.setTitle1 = arr;
                    this.getDataChartsB("DAY");
                    this.getDataChartsB("MONTH");
                    this.getDataChartsB("WEEK");
                }
            }else if(val == "shift") {  //按班次统计
@@ -542,10 +598,16 @@
        },
        changeTabB(item,index,index1) {
            this.setTitle1[index].btnListActive = item.id;
            this.date = item.id;
            this.getDataChartsB("DAY");
            this.getDataChartsB("MONTH");
            this.getDataChartsB("WEEK");
            this.date = this.setTitle1[0].btnListActive;
            if(index == 0) {
                this.getDataChartsB("DAY");
            }
            if(index == 1) {
                this.getDataChartsB("WEEK");
            }
            if(index == 2) {  //月
                this.getDataChartsB("MONTH",this.setTitle1[2].btnListActive.split("月")[0]);
            }
        },
        getTime(data) {
            this.$HTTP.post('/api/blade-mdc/efficiency-analysis/interval', {
@@ -573,21 +635,26 @@
            this.date = this.time[1];
        },
        query() {
            console.log(this.activeName)
            this.getTime({endDate: this.time[1],startDate: this.time[0],statisticalMethod: 'SHIFT'});
            this.date = this.time[1];
            this.ids = [];
            console.log(this.btnLeftctive)
            if(this.btnLeftctive == 1) {  //按工位统计
                this.treeChecked.forEach(item=> {
                    this.ids.push(item.id);
                })
            }else if(this.btnLeftctive == 1) { //按工位组统计
            }else if(this.btnLeftctive == 2) { //按工位组统计
                this.treeListNodeList.forEach(item=> {
                    this.ids.push(item.id);
                })
            }
            console.log(this.ids,2)
            this.getTime({endDate: this.time[1],startDate: this.time[0],statisticalMethod: 'SHIFT'});
            this.date = this.time[1];
            this.getDataA();
            if(this.activeName == "shift") {  //按班次统计
                this.getDataA();
            }else if(this.activeName == "time") { //按周期统计
                this.getDataChartsB("DAY");
                this.getDataChartsB("WEEK");
                this.getDataChartsB("MONTH",this.setTitle1[2].btnListActive.split("月")[0]);
            }
        }
    }
}