222
schangxiang@126.com
2024-12-14 f3a78b9ef7ec02b255dc52bf2b85f52c1cefa777
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<template>
  <div class="wmsStockBoardabc-container">   
    <el-card class="full-table" shadow="hover" style="margin-top: 5px">
        <el-tabs v-model="activeName" @tab-click="handleClick" :lazy="true"  class="task_echrts">    
            <!-- <el-tab-pane
                v-for="item in editableTabs"
                :key="item.name"
                :label="item.title"
                :name="item.name"
                >
                <div class="home-card-item" >                    
                    <div style="height: 100%" ref="homeBarRef" id="homeBarRef"></div>
                </div>
            </el-tab-pane>             -->
            <el-tab-pane label="日" name="1">
                <div class="task_echrts" ref="inOutLine" id="inOutLine" v-if="activeName=='1'"></div>
            </el-tab-pane>
            <el-tab-pane label="周" name="2">
                <div class="task_echrts" ref="inOutLine" id="inOutLine" v-if="activeName=='2'"></div>
            </el-tab-pane>
            <el-tab-pane label="月" name="3">
                <div class="task_echrts" ref="inOutLine" id="inOutLine" v-if="activeName=='3'"></div>
            </el-tab-pane>
        </el-tabs>
    </el-card>
  </div>
</template>
 
<script lang="ts" setup="" name="wmsStockBoardabc">
  import { ref,onMounted, nextTick, reactive, onUnmounted ,markRaw,onActivated,watch} from "vue";
  import * as echarts from 'echarts';
  import { ElMessageBox, ElMessage } from "element-plus";
  import { wmsStockPassMap, } from '/@/api/main/inventoryWarning/inventoryWarning';
    import type { TabsPaneContext } from 'element-plus'
  
  /***************************************************[出入库库存推移图操作]开始***************************************************/
 
  const loadingwmsStockBoardabc = ref(false);
  const disabled_btnwmsStockBoardabc = ref(false);
  
  import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
  import { storeToRefs } from 'pinia';
  const storesTagsViewRoutes = useTagsViewRoutes();
  const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes); 
 
/***************************************************[出入库库存推移图]开始***************************************************/
const activeName = ref('1')
const handleClick = (tab: TabsPaneContext, event: Event) => {
    handleQuerywmsStockBoardabc(tab.props.name);
}
// 查询出入库库存推移图
const handleQuerywmsStockBoardabc = async (val:any) => {
    loadingwmsStockBoardabc.value = true;
    disabled_btnwmsStockBoardabc.value = true;
    let para = {DayOrWeekOrMonth:Number(val)}
    var res = await wmsStockPassMap(para);
    if(res.data.type=="success"){        
        let arr1: any[] = [];
        let arr2: any = [];
        let arr3: any = [];
        let arr4: any[] = [];
        let arr5: any[] = [];
        let result = res.data.result || [];
        result.forEach((item:any) => {
            arr1.push({value:item.inWare,stationName:'s'+item.time})
            arr2.push({value:item.outWare,stationName:'s'+item.time})
            arr3.push({value:item.stockNum,stationName:'s'+item.time})
            arr4.push({value:item.aveStockNum,stationName:'s'+item.time})            
            arr5.push(item.date)        
        })
        nextTick(() => {
            setTimeout(() => {
                initBarChart(arr1,arr2,arr3,arr4,arr5);
            }, 500);
        });
    }
    loadingwmsStockBoardabc.value = false;
    disabled_btnwmsStockBoardabc.value = false;
  };
  handleQuerywmsStockBoardabc('1');
 
// 折线图
const state = reactive({
    global: {
        homeChartOne: null,
        dispose: [null, '', undefined],
    } as any,
    myCharts: [] as EmptyArrayType,
    charts: {
        theme: '',
        bgColor: '',
        color: '#303133',
    },
});
const inOutLine = ref();
// tab页
const editableTabs = ref([
  {
    title: '日',
    name: 1,
    content: 'Tab 1 content',
  },
  {
    title: '周',
    name: 2,
    content: 'Tab 2 content',
  },
  {
    title: '月',
    name: 3,
    content: 'Tab 2 content',
  },
])
 
const initBarChart = (arr1:any,arr2:any,arr3:any,arr4:any,arr5:any) => {    
    if(arr1==null||arr2==null||arr3==null||arr4==null||arr5==null) return false
    if (!state.global.dispose.some((b: any) => b === state.global.homeChartOne)) state.global.homeChartOne.dispose();
    state.global.homeChartOne = markRaw(echarts.init(inOutLine.value, state.charts.theme));
    const option = {
        backgroundColor: state.charts.bgColor,
        title: {
            text: '上下架推移图',
            x: 'left',
            textStyle: { fontSize: '12', color: state.charts.color },
        },
        tooltip: { trigger: 'axis' },
        //legend: { data: ['上架','下架', '库存', '平均'], right: 0 },
        legend: { data: ['上架','下架'], right: 0 },
        grid: { top: 50, right: 80, bottom: 100, left: 60 },
        // grid: { top: 70, right: 80, bottom: 30, left: 80 },
        xAxis: [
            {
                type: 'category',
                // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                data: arr5,
                boundaryGap: true,
                axisTick: { show: false },
            },
        ],
        yAxis: [
            {
                name: '单位',
                nameLocation: 'middle',
                nameTextStyle: { padding: [3, 4, 50, 6] },
                splitLine: { show: true, lineStyle: { type: 'dashed', color: '#f5f5f5' } },
                axisLine: { show: false },
                axisTick: { show: false },
                axisLabel: { color: state.charts.color, formatter: '{value} ' },
            },
            // {
            //     name: '平均',
            //     nameLocation: 'middle',
            //     nameTextStyle: { padding: [50, 4, 5, 6] },
            //     splitLine: { show: false },
            //     axisLine: { show: false },
            //     axisTick: { show: false },
            //     axisLabel: { color: state.charts.color, formatter: '{value} ' },
            // },
        ],
        series: [
            {
                name: '上架',
                type: 'line',
                smooth: true,
                showSymbol: true,
                // 矢量画五角星
                symbol: 'path://M150 0 L80 175 L250 75 L50 75 L220 175 Z',
                symbolSize: 12,
                yAxisIndex: 0,
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: 'rgba(250,180,101,0.3)' },
                        { offset: 1, color: 'rgba(250,180,101,0)' },
                    ]),
                    shadowColor: 'rgba(250,180,101,0.2)',
                    shadowBlur: 20,
                },
                itemStyle: { color: '#FF8000' },
                // data中可以使用对象,value代表相应的值,另外可加入自定义的属性
                // data: [
                //     { value: 1, stationName: 's1' },
                //     { value: 3, stationName: 's2' },
                //     { value: 4, stationName: 's3' },
                //     { value: 9, stationName: 's4' },
                //     { value: 3, stationName: 's5' },
                //     { value: 2, stationName: 's6' },
                // ],
                data:arr1
            },
            {
                name: '下架',
                type: 'line',
                smooth: true,
                showSymbol: true,
                symbol: 'emptyCircle',
                symbolSize: 12,
                yAxisIndex: 0,
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(
                        0,
                        0,
                        0,
                        1,
                        [
                            { offset: 0, color: 'rgba(199, 237, 250,0.5)' },
                            { offset: 1, color: 'rgba(199, 237, 250,0.2)' },
                        ],
                        false
                    ),
                },
                itemStyle: {
                    color: '#3bbc86',
                },
                data:arr2
            },
            // {
            //     name: '平均',
            //     type: 'bar',
            //     barWidth: 30,
            //     yAxisIndex: 1,
            //     itemStyle: {
            //         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            //             { offset: 0, color: 'rgba(108,80,243,0.3)' },
            //             { offset: 1, color: 'rgba(108,80,243,0)' },
            //         ]),
            //         //柱状图圆角
            //         borderRadius: [30, 30, 0, 0],
            //     },
            //     data:arr3
            // },
            // {
            //     name: '库存',
            //     type: 'line',
            //     smooth: true,
            //     showSymbol: true,
            //     symbol: 'emptyCircle',
            //     symbolSize: 12,
            //     yAxisIndex: 0,
            //     // fe9a8b
            //     lineStyle: { color: '#51A3FC' },
            //     itemStyle: { color: '#51A3FC', borderColor: '#51A3FC' },
            //     areaStyle: {
            //         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            //             { offset: 0, color: '#51A3FCb3' },
            //             { offset: 1, color: '#51A3FC03' },
            //         ]),
            //     },
            //     data:arr4
            // },
        ],
    };
    state.global.homeChartOne.setOption(option);
    state.myCharts.push(state.global.homeChartOne);
};
// 批量设置 echarts resize
const initEchartsResizeFun = () => {
    nextTick(() => {
        for (let i = 0; i < state.myCharts.length; i++) {
            setTimeout(() => {
                state.myCharts[i].resize();
            }, i * 1000);
        }
    });
};
// 批量设置 echarts resize
const initEchartsResize = () => {
    window.addEventListener('resize', initEchartsResizeFun);
};
 
// 定时器
let timeInter: any = null;
// 页面加载时
onMounted(() => {
    // initEchartsResize();
 
    // timeInter = setInterval(() => {
    //     nextTick(() => {
    //         handleQuerywmsStockBoardabc('1');
    //     });
    // }, 15000); //调用频率改为 15秒一次查询。
});
 
 
onUnmounted(() => {
  clearInterval(timeInter); //销毁
  timeInter = null;
});
 
 
// 由于页面缓存原因,keep-alive
onActivated(() => {
    initEchartsResizeFun();
});
 
 
// 监听 pinia 中的 tagsview 开启全屏变化,重新 resize 图表,防止不出现/大小不变等
watch(
    () => isTagsViewCurrenFull.value,
    () => {
        initEchartsResizeFun();
    }
);
 
</script>
<style scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
    width: 100%;
}
.task_echrts {
        width: 100%;
        height: 700px;
        background: #fff;
        border-radius: 10px;
      }
</style>