statistics.vue 17.7 KB
Newer Older
godwithdh's avatar
godwithdh committed
1 2 3
<style lang="less" scoped>
    #statistics{
        background:#f2f2f2;
张锡奇's avatar
张锡奇 committed
4 5 6 7 8 9 10 11 12 13 14
        height:100%;
        display: flex;
        flex-direction: column;
        .Content{
            height:100%;
            // height:1px;
            // flex-grow: 1;
            // overflow: auto;
            // -webkit-overflow-scrolling: touch;
        }
        .Content>.double{
godwithdh's avatar
godwithdh committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
            display:flex;
            >.card{
                flex-grow:1;
                width:50%;
            }
        }
        .card{
            border-radius: 6px;
            background:#fff;
            box-shadow: 1px 1px 10px -1px #888;
            overflow: hidden;
            margin:6px;
            position:relative;
            .imgBC{
                position:absolute;
                top:32px;
            }
            img{
                max-height: 80%;
                left: 50%;
                transform: translate(-50%,0);
            }
            >.head{
张锡奇's avatar
张锡奇 committed
38
                background: linear-gradient(90deg,#708bf6, #2d8cf0, #00B2EE);
godwithdh's avatar
godwithdh committed
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
                padding:5px 0;
                color:#fff;
                text-align: center;
            }
            >.foot{
                display:flex;
                font-size:10px;
                >div{
                    flex-grow:1;
                    width:50%;
                    margin:4px 0;
                    text-align: center;
                    >p{
                        margin:2px 0;
                        &:last-child{
                            color:#009BDE;
                        }
                    }
                }
            }
        }
    }
</style>
<template>
    <div id="statistics">
        <searchComponent :search='search' />
张锡奇's avatar
张锡奇 committed
65 66 67 68 69 70 71 72 73 74 75 76
        <div class="Content">
            <div class='double'>
                <div class="card">
                    <div class="head">月总订单金额同比率</div>
                    <div  ref='chart1' style="width:100%;height:150px;"/>
                </div>
                <div class="card">
                    <div class="head">月总订单金额环比率</div>
                    <div  ref='chart2' style="width:100%;height:150px;"/>
                </div>
            </div>

godwithdh's avatar
godwithdh committed
77
            <div class="card">
张锡奇's avatar
张锡奇 committed
78 79 80 81 82 83 84 85 86 87 88 89 90
                <div class="head">销售排行</div>
                <div ref='chart3' :style="{width:'100%',height:'180px',opacity:chartData.set3.length>0?'1':'0'}" />
                <img v-if="chartData.set3.length==0" src="@/assets/noData.jpg" class="imgBC" />
                <div class="foot">
                    <div style="border-right:1px solid #009BDE;">
                        <p>销售笔数</p>
                        <p >{{chartData.set4.iSellCount}}</p>
                    </div>
                    <div>
                        <p>销售额</p>
                        <p>{{chartData.set4.nSellAmount}}</p>
                    </div>
                </div>
godwithdh's avatar
godwithdh committed
91 92
            </div>
            <div class="card">
张锡奇's avatar
张锡奇 committed
93 94 95
                <div class="head">产品颜色销售排行</div>
                <div ref='chart5' :style="{width:'100%',height:'230px',opacity:chartData.set5.length>0?'1':'0'}" />
                <img v-if="chartData.set5.length==0" src="@/assets/noData.jpg" class="imgBC" />
godwithdh's avatar
godwithdh committed
96
            </div>
张锡奇's avatar
张锡奇 committed
97 98 99 100
            <div class="card">
                <div class="head">产品销售排行</div>
                <div ref='chart6' :style="{width:'100%',height:'230px',opacity:chartData.set6.length>0?'1':'0'}" />
                <img v-if="chartData.set6.length==0" src="@/assets/noData.jpg" class="imgBC" />
godwithdh's avatar
godwithdh committed
101 102
            </div>
        </div>
张锡奇's avatar
张锡奇 committed
103
        
godwithdh's avatar
godwithdh committed
104 105 106 107 108 109 110 111
    </div>
</template>
<script>
import Util from '@/libs/util.js'
import searchComponent from '@/components/search'
import { Confirm } from 'vux'
import { clearTimeout, setTimeout } from 'timers';
import { toUnicode } from 'punycode';
张锡奇's avatar
张锡奇 committed
112
import echarts from 'echarts';
godwithdh's avatar
godwithdh committed
113 114 115 116 117 118 119 120 121 122

export default {
    name:"statistics",
    components:{searchComponent},
    data(){
        return{
            search:{
                dBeginDate:Util.dateFormat(new Date(),'yyyy-MM-01'),
                dEndDate:Util.dateFormat(new Date(),'yyyy-MM-dd'),
            },
张锡奇's avatar
张锡奇 committed
123
            iProjectId:5599,
godwithdh's avatar
godwithdh committed
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
            chartData:{
                set3:[],
                set4:{
                    iSellCount:0,
                    nSellAmount:0,
                },
                set5:[],
                set6:[],
            },
            chart1:null,
            chart2:null,
            chart3:null,
            chart5:null,
            chart6:null,
        }
    },
    created(){
        window.s=this
    },
    activated(){
        setTimeout(()=>{
            this.chart1.resize()
            this.chart2.resize()
            this.resize(this.chart3,1.15)
            this.resize(this.chart5,1.35)
            this.resize(this.chart6,1.35)
        })
    },
    mounted(){
        window.h=this

        this.createChart('chart1')
        this.createChart('chart2')
        this.createChart('chart3')
        this.createChart('chart5','set5',true)
        this.createChart('chart6','set6',true)
        window.addEventListener('resize',()=>{
            setTimeout(()=>{
                this.chart1.resize()
                this.chart2.resize()
                this.resize(this.chart3,1.15)
                this.resize(this.chart5,1.35)
                this.resize(this.chart6,1.35)
            })
        })

张锡奇's avatar
张锡奇 committed
170 171
        this.iProjectId= this.$route.params.iProjectId;
        this.$store.dispatch('setIproject',this.iProjectId);
张锡奇's avatar
张锡奇 committed
172 173 174
        this.searchData();
        
        this.global.$off('searchData');
godwithdh's avatar
godwithdh committed
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
        this.global.$on('searchData',()=>{
            this.searchData()
        })
    },
    methods:{
        createChart(name,kield,isLinstener){
            var myChart=this.$echarts.init(this.$refs[name])
            if(isLinstener){
                let time=0
                myChart.getZr().on('mousedown',param=>{
                    const pointInPixel = [param.offsetX, param.offsetY]
                    if (myChart.containPixel('grid', pointInPixel)) {
                        let index = myChart.convertFromPixel({ seriesIndex: 0 }, [param.offsetX, param.offsetY])[0]
                        time=setTimeout(()=>{
                            var data=this.chartData[kield]
                            var options=myChart.getOption()
                            options.tooltip[0].show=false
                            myChart.setOption(options)
                            this.$vux.confirm.show({
                                title:"提示",
                                content:"是否查看详情",
                                onConfirm:()=>{
                                    this.$store.dispatch('setChartHearData',data[index]).then(()=>{
                                        this.$router.push({name:"chartMmcolorsaleDetail"});
                                    })
                                    options.tooltip[0].show=true
                                    myChart.setOption(options)
                                },
                                onCancel(){
                                    options.tooltip[0].show=true
                                    myChart.setOption(options)
                                }
                            })
                        },500)
                    }
                })
                myChart.getZr().on('mousemove',()=>{
                    clearTimeout(time)
                })
                myChart.getZr().on('mouseup',()=>{
                    clearTimeout(time)
                })
            };
            this[name]=myChart
        },
        resize(chart,rate){
            var options=chart.getOption()
            if(!options)return;
            options.dataZoom[0].end=options.dataZoom[0].start+(window.innerWidth*rate)/options.xAxis[0].data.length
            chart.setOption(options)
            chart.resize()
        },

        async searchData(){//搜索数据
            await this.chart1Data()
            await this.chart2Data()
            this.showValue()
        },
        async chart1Data(){
            var value =await this.request('sellinfo',{
                params:{
                    dStartDate:this.search.dBeginDate,
                    dEndDate:this.search.dEndDate
                }
张锡奇's avatar
张锡奇 committed
239
            },true,{iProjectId:this.iProjectId})
godwithdh's avatar
godwithdh committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
            Object.assign(this.chartData,{
                nOrderSameRatio:Math.round((value.set1&&value.set1[0]&&value.set1[0].nOrderSameRatio||0)*100)/100,
                nOrderRingRatio:Math.round((value.set2&&value.set2[0]&&value.set2[0].nOrderRingRatio||0)*100)/100,
                set4:{
                    iSellCount:value.set4&&value.set4[0]&&value.set4[0].iSellCount||0,
                    nSellAmount:Math.round((value.set4&&value.set4[0]&&value.set4[0].nSellAmount||0)/100)/100
                }
            })
            console.log()
            this.chartData.set3=typeof value.set3=='object'&&value.set3.length>0&&value.set3.map(v=>{
                v.value=Math.round(v.nAmount/100)/100
                return v
            })||[]
        },
        async chart2Data(){
            var value=await this.request('getMmcolorsaletop',{
                params:this.search
张锡奇's avatar
张锡奇 committed
257
            },true,{iProjectId:this.iProjectId})
godwithdh's avatar
godwithdh committed
258 259 260 261 262 263

            this.chartData.set5=typeof value=='object'&&value.length>0&&value||[]
            this.chartData.set5.forEach(v=>v.type='mmcolorsaletop')

            var value=await this.request('getMmsaletop',{
                params:this.search
张锡奇's avatar
张锡奇 committed
264
            },true,{iProjectId:this.iProjectId})
godwithdh's avatar
godwithdh committed
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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395

            this.chartData.set6=typeof value=='object'&&value.length>0&&value||[]
            this.chartData.set6.forEach(v=>v.type='mmsaletop')
        },
        showValue(){
            this.drawRing({
                e:this.chart1,
                value:this.chartData.nOrderSameRatio
            })
            this.drawRing({
                e:this.chart2,
                value:this.chartData.nOrderRingRatio
            })
            this.drawLing({
                e:this.chart3,
                value:this.chartData.set3
            })
            this.drawLing2({
                e:this.chart5,
                value:this.chartData.set5
            })
            this.drawLing2({
                e:this.chart6,
                value:this.chartData.set6
            })
        },
        drawRing(data){//仪表盘
            data.e.setOption({
                tooltip : {
                    show:false,
                },
                series: [
                    {
                        type: 'gauge',
                        data: [{value: data.value, name: '比例'}],
                        radius:"90%",
                        min:-100,
                        max:100,
                        title:{
                            fontSize:10
                        },
                        detail:{
                            fontSize:11,
                            formatter:'{value}%',
                            padding:[50,0,0,0],
                        },
                        axisLine:{
                            show:false,
                            lineStyle:{
                                color:[[0.5,'red'],[0.75,'#1CB712'],[0.90,'#156F8E'],[1,'#152989']],
                                width:15
                            }
                        },
                        splitLine:{
                            length:15
                        },
                        axisLabel:{
                            fontSize:9,
                            distance:1,
                        },
                        itemStyle:{
                            opacity:0.3,
                        },
                    }
                ]
            })
        },
        drawLing(data){//折线
            data.e.setOption({
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: '#111'
                        }
                    },
                    formatter:val=>{
                        return data.value[val[0].dataIndex].nAmount
                    }
                },
                toolbox: {
                    feature: {
                        restore: {show: true},
                    },
                },
                grid: {
                    top:30,
                    height:130,
                    right:10,
                },
                xAxis: {
                    type:"category",
                    data:data.value.map(v=>v.sYearMonth),
                    axisPointer:{
                        type:"shadow"
                    },
                    axisTick:{
                        alignWithLabel: true
                    },
                    axisLabel: {
                        interval:0 
                    },
                    minInterval:10,
                },
                yAxis: {
                    type: 'value',
                    name:"金额(万)",
                    offset:-10,
                },
                dataZoom: [{
                    type: 'inside',
                    xAxisIndex: 0,
                    show: false, //flase直接隐藏图形
                    filterMode: 'empty',
                    start: 0,//滚动条的起始位置
                    end: (window.innerWidth*1.15)/data.value.length //滚动条的截止位置(按比例分割你的柱状图x轴长度)
                }],
                series: [
                    {
                        id: 'a',
                        type: 'line',
                        smooth: true,
                        symbolSize: 10,
                        data: data.value.map(v=>v.value),
                        label:{
                            show:true,
                            formatter:val=>{
                                return `${val.data}万`
                            }
                        },
张锡奇's avatar
张锡奇 committed
396 397 398 399 400
                        itemStyle:{
                            normal:{
                                color:'#708bf6'
                            }
                        }
godwithdh's avatar
godwithdh committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
                    }
                ]
            })
        },
        drawLing2(data){
            data.e.setOption({
                color:['#5cadff','#1c2438'],
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: '#111'
                        }
                    }
                },
                toolbox: {
                    feature: {
                        // dataView: {show: true, readOnly: false},
                        // magicType: {show: true, type: ['line', 'bar']},
                        restore: {show: true},
                        // saveAsImage: {show: true}
                    },
                },
                grid: {
                    left: '2%',   // 与容器左侧的距离
                    right: '2%', // 与容器右侧的距离
                    height:160,
                    containLabel: true
                },
                legend: {
                    data:['金额','数量'],
                    x: 'left'
                },
                xAxis: [{
                    type: 'category',
                    data: data.value.map(v=>`${v.sMaterialNo}\n${v.sColorNo || ''}\n${v.sUnit || ''}`),
                    axisPointer: {
                        type: 'shadow'
                    },
                    axisTick: {
                        alignWithLabel: true
                    },
                    axisLabel: {
                        interval:0 
                    },
                }],
                yAxis: [
                    {
                        type: 'value',
                        name: '金额',
                        axisLabel: {
                            formatter: '{value}'
                        },
                        scale:true,
                        axisLine:{
                            lineStyle:{
                                color:'#5CADFF',
                            }
                        }
                    },
                    {
                        type: 'value',
                        name: '数量',
                        scale:true,
                        axisLabel: {
                            formatter: '{value}'
                        }
                    }
                ],
                series: [
                    {
                        name:'金额',
                        type:'bar',
                        data:data.value.map(v=>v.nAmount),
                        barWidth:32,
张锡奇's avatar
张锡奇 committed
477 478 479 480 481 482 483
                        color:new echarts.graphic.LinearGradient(0.5, 0, 0.5, 1, [{
                                offset: 0,
                                color: '#708bf6'
                            }, {
                                offset: 1,
                                color: '#00B2EE'
                        }])
godwithdh's avatar
godwithdh committed
484 485 486 487 488 489
                    },
                    {
                        name:'数量',
                        type:'line',
                        yAxisIndex: 1,
                        data:data.value.map(v=>v.nQty),
张锡奇's avatar
张锡奇 committed
490 491 492 493 494
                        itemStyle:{
                            normal:{
                                color:'#708bf6'
                            }
                        }
godwithdh's avatar
godwithdh committed
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
                    }
                ],
                dataZoom: [{
                    type: 'inside',
                    show: true, //flase直接隐藏图形
                    xAxisIndex: [0],
                    left: '9%', //滚动条靠左侧的百分比
                    start: 0,//滚动条的起始位置
                    end: (window.innerWidth*1.35)/data.value.length //滚动条的截止位置(按比例分割你的柱状图x轴长度)
                }],
            })
        }
    },
}
</script>