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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
| <template>
| <div class="home-index-module-c-compontent">
| <div class="top-title">库存统计</div>
| <div class="module-c-contianer">
| <div class="pie-chart-block" ref="chart"></div>
| <div class="info-block">
| <div class="num-item-row">
| <div class="label">总库位:</div>
| <div class="num">{{chartData.total}}</div>
| </div>
| <div class="num-item-row" v-for="(item,index) in chartData.list" :key="'num-item-'+index">
| <div class="label">{{item.text}}:</div>
| <div class="num">{{item.num}}</div>
| </div>
| </div>
| </div>
| </div>
| </template>
|
| <script>
| import * as echarts from 'echarts';
| import { GetPalceNumbers} from '@/api/modular/system/homeManage'
| export default {
| name:'homeIndexModuleCCompontent',
| data(){
| return {
| $dom:null,
| chart:null,
| defaultOption:{
| tooltip: {
| trigger: 'item',
| formatter: "{a} <br/>{b}: {c} ({d}%)"
| },
| legend: {
| show: false
| },
| title:{
| text:"80.02%",
| left:"center",
| top:"45%",
| textStyle:{
| color:"#000",
| fontSize:30,
| align:"center"
| }
| },
| graphic:{
| type:"text",
| left:"center",
| top:"38%",
| style:{
| text:"存货占比",
| textAlign:"center",
| fill:"#929292",
| fontSize:18
| }
| },
| series: [
| {
| name: '库存占比',
| type: 'pie',
| radius: ['60px', '80px'],
| avoidLabelOverlap: false,
| itemStyle: {
| borderRadius: 4,
| borderColor: '#fff',
| borderWidth: 2
| },
| label:{
| formatter: '{fc|{b}}\n{hr|}\n{fc|{d}%} ',
| rich: {
| fc: {
| color: '#333',
| fontSize:12,
| lineHeight:16,
| align: 'center'
| },
| hr: {
| borderColor: '#666',
| width: '100%',
| borderWidth: 1,
| height: 0
| }
| }
| },
| labelLine:{
| length:10,
| length2:5
| },
| data: []
| }
| ]
| },
| chartData:{
| total:0,
| list:[],
| totalRate:'1%'
| }
| }
| },
| methods:{
| init(){
| this.getData((f)=>{
| if (f) {
| this.createChart();
| this.drawChart();
| }
| })
| },
| getData(callback){
| GetPalceNumbers().then((d)=>{
| let _arr = [], _obj={};
| _obj = {text:'空库位',num:(d.data.emptyNum||0),color:['#5988e5','#36cfdc']}
| _arr.push(_obj)
| _obj = {text:'有货库位',num:(d.data.cunhuoNum||0),color:['#f9cf21','#f84302']}
| _arr.push(_obj)
| _obj = {text:'空托库位',num:(d.data.emptyContainerNum||0),color:['#66b53d','#d4f9a6']}
| _arr.push(_obj)
| this.chartData.list = _arr;
| let _total = 0;
| this.chartData.list.forEach((item)=>{
| _total = _total + item.num
| })
| this.chartData.total = _total
| let _hasNum = d.data.cunhuoNum||0
| this.chartData.totalRate = _total?(Number(((_hasNum/_total)*100).toFixed(2)) + '%'):'0%';
| callback && callback(true)
| }).catch(()=>{
| callback && callback(false)
| })
| },
| drawChart(){
| let arr = [];
| this.chartData.list.forEach((item)=>{
| arr.push({
| value:item.num,
| name:item.text,
| itemStyle:{
| normal:{
| color:new echarts.graphic.LinearGradient(1, 0, 0, 0,[{offset:0,color:item.color[0]},{offset:1,color:item.color[1]}])
| }
| }
| })
| })
| let opt = {...this.defaultOption}
| opt.series[0].data = arr;
| opt.title.text = this.chartData.totalRate;
| this.chart.setOption(opt)
| },
| createChart(){
| if (!this.$dom) {
| this.$dom = this.$refs.chart;
| this.chart = echarts.init(this.$dom)
| }
| },
| destoryChart(){
| try{
| this.chart.dispose();
| this.$dom.innerHTML = '';
| this.$dom = null;
| }catch(e){
| //TODO handle the exception
| }
| }
| },
| mounted(){
| this.init()
| },
| beforeDestroy(){
| this.destoryChart()
| }
| }
| </script>
|
| <style lang="less" scoped>
| .home-index-module-c-compontent{
| background-color: #F0F8FF;
| border-radius: 10px;
| height:100%;
| overflow: hidden;
| display: flex;
| flex-direction: column;
| .top-title{
| flex-shrink: 0;
| background-color: #fff;
| padding:8px 16px;
| font-size: 18px;
| }
| .module-c-contianer{
| flex-grow: 1;
| display: flex;
| flex-direction: column;
| .pie-chart-block{
| height:240px;
| flex-shrink: 0;
| }
| .info-block{
| flex-grow: 1;
| overflow: auto;
| .num-item-row{
| display: flex;
| font-size: 28px;
| padding:4px 16px;
| .label{
| width:200px;
| flex-shrink: 0;
| color:#999;
| white-space:nowrap;
| overflow: hidden;
| }
| .num{
| flex-grow:1;
| text-align: right;
| color:#333;
| white-space:nowrap;
| overflow: hidden;
| }
| }
| }
| }
|
| }
| </style>
|
|