ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<template>
    <!-- 编号3 -->
    <div class="screen1-stock module-block">
        <block-title title="库存情况" />
        <div class="module-content">
            <div class="chart-view" ref="chart" id="chartID"></div>
            <div class="desc-view">
                <table>
                    <thead>
                        <tr>
                            <th>总库位数</th>
                            <th>满库位</th>
                            <!-- <th>托盘货位</th> -->
                            <th>空库位数</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ obj[0] }}</td>
                            <!-- <td>234{{obj.Material_Count}}</td> -->
                            <td>{{ obj[1] }}</td>
                            <td>{{ obj[2] }}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</template>
 
<script>
import BlockTitle from './BlockTitle.vue'
import * as echarts from 'echarts';
export default {
    name: 'screen1Stock',
    components: { BlockTitle },
    props: {
        obj: {
            type: Object,
            default: function () {
                return {}
            }
        }
    },
    data() {
        return {
            $dom: null,
            chart: null,
            defaultOption: {
                tooltip: {
                    trigger: 'item'
                },
                series: [
                    {
                        name: '库存情况',
                        type: 'pie',
                        selectedMode: 'single',
                        radius: '50%',
                        label: {
                            formatter: '{fc|{b}}\n{hr|}\n{fc|{d}%} ',
                            rich: {
                                fc: {
                                    color: '#afd7da',
                                    fontSize: 12,
                                    lineHeight: 20,
                                    align: 'center'
                                },
                                hr: {
                                    borderColor: '#afd7da',
                                    width: '100%',
                                    borderWidth: 1,
                                    height: 0
                                }
                            }
                        },
                        labelLine: {
                            length: 5,
                            length2: 5
                        },
                        data: [
                            // { value: 0, name: '总库位数', itemStyle: { color: '#00ff12' } },
                            // { value: 0, name: '空库位数', selected: true, itemStyle: { color: '#fc3321' } },
                            { value: 0, name: '空库位数', itemStyle: { color: '#00ff12' } },
                            { value: 0, name: '满库位', itemStyle: { color: '#f56c6c' } }
                        ],
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            }
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.init();
        })
    },
    beforeDestroy() {
        this.destoryChart()
    },
    methods: {
        init() {
            this.createChart();
            this.drawChart();
        },
        createChart() {
            // if (!this.$dom) {
            this.$dom = this.$refs.chart;
            // this.chart = echarts.init(this.$dom)
            this.chart = echarts.init(document.getElementById("chartID"))
            // }
        },
        drawChart() {
            let opt = { ...this.defaultOption }
            opt.series[0].data[0].value = this.obj[2] || 0;
            opt.series[0].data[1].value = this.obj[1] || 0;
            // opt.series[0].data[2].value = this.obj[2] || 0;
            this.chart.setOption(opt)
            window.addEventListener("resize", () => {
                this.chart.resize();
            });
        },
        destoryChart() {
            try {
                this.chart.dispose();
                this.$dom.innerHTML = '';
                this.$dom = null;
            } catch (e) {
                //TODO handle the exception
            }
        }
    }
}
</script>
 
<style lang="scss" scoped>
.screen1-stock {
    height: 100%;
 
    .module-content {
        display: flex;
        flex-direction: column;
    }
 
    .desc-view {
        height: 70px;
        flex-shrink: 0;
        table {
            width: 100%;
 
            td,
            th {
                text-align: center;
                vertical-align: middle;
                padding: 4px;
            }
 
            th {
                color: #1792b6;
                font-size: 14px;
                padding-bottom: 5px;
            }
 
            td {
                color: #d3ffff;
                font-size: 20px;
            }
        }
    }
 
    .chart-view {
        flex-grow: 1;
    }
}
</style>