empAna.vue 8.24 KB
Newer Older
godwithdh's avatar
godwithdh committed
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
<style lang="less">
    @import url("../../../styles/common.less");
    #empAna{
        background:#dce9fe;
        >.CONTENT{
            .iCard{
                height:260px;
                >p{
                    margin:0;
                    height:30px;
                    line-height: 30px;
                    background: linear-gradient(90deg,#708bf6, #2d8cf0, #00B2EE);
                    color: #fff;
                    text-align: center;
                }
                &:last-child{
                    margin-bottom:8px;
                }
            }
        }
        .noData{
            height:calc(100% - 30px);
            width:100%;
            img{
                width:100%;
            }
        }
    }
</style>
<template>
    <div id="empAna">
        <div class="HEADER">
godwithdh's avatar
godwithdh committed
33
            <dateMonth @month="searchData" />
godwithdh's avatar
godwithdh committed
34 35 36 37
        </div>
        <div class="CONTENT">
            <div class="iCard" ref="chart1">
                <p>前十名员工(联动)</p>
godwithdh's avatar
godwithdh committed
38
                <canvas id="chart1" v-if="chartData1.length > 0" width="400" height="260" style="width:100%;height:240px; touch-action: pan-y; user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></canvas>
godwithdh's avatar
godwithdh committed
39 40 41 42 43 44
                <div class="noData" v-if="chartData1.length <= 0">
                    <img src="@/assets/noData.jpg" class="_img" alt="">
                </div>
            </div>
            <div class="iCard" ref="chart2">
                <p>{{title}}每月回款率</p>
godwithdh's avatar
godwithdh committed
45
                <canvas id="chart2" v-if="chartData2.length > 0" width="400" height="260" style="width:100%;height:240px;"></canvas>
godwithdh's avatar
godwithdh committed
46 47 48 49 50 51
                <div class="noData" v-if="chartData2.length <= 0">
                    <img src="@/assets/noData.jpg" class="_img" alt="">
                </div>
            </div>
            <div class="iCard" ref="chart3">
                <p>{{title}}按月统计订单金额</p>
godwithdh's avatar
godwithdh committed
52
                <canvas id="chart3" v-if="chartData3.length > 0" width="400" height="260" style="width:100%;height:240px;"></canvas>
godwithdh's avatar
godwithdh committed
53 54 55 56 57 58 59 60 61
                <div class="noData" v-if="chartData3.length <= 0">
                    <img src="@/assets/noData.jpg" class="_img" alt="">
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import Util from '@/libs/util.js'
godwithdh's avatar
godwithdh committed
62
import dateMonth from '@/components/dateMonth'
godwithdh's avatar
godwithdh committed
63 64 65 66 67 68
import { employees } from '@/view/shopVersion/form/empAna/mixins/employees'
import { receivable } from '@/view/shopVersion/form/empAna/mixins/receivable'
import { orderAmount } from '@/view/shopVersion/form/empAna/mixins/orderAmount'
import { setTimeout } from 'timers';
export default {
    name:"empAna",
godwithdh's avatar
godwithdh committed
69
    components:{dateMonth},
godwithdh's avatar
godwithdh committed
70 71 72
    mixins: [employees,receivable,orderAmount],
    data(){
        return{
godwithdh's avatar
godwithdh committed
73 74 75
            searchValue:{
                dBeginDate:null,
                dEndDate:null,
godwithdh's avatar
godwithdh committed
76 77 78 79 80 81 82 83 84
            },
            typeList:{time:true},
            direction:'vertical',
            tempChartData2:[],
            tempChartData3:[],
            title:"",
        }
    },
    async mounted(){
godwithdh's avatar
godwithdh committed
85
        window.em=this
godwithdh's avatar
godwithdh committed
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
        window.addEventListener("resize",()=>{
            setTimeout(async ()=>{
                this.renderResize();
                if(this.chartData1.length>0){
                    this.chart1.changeSize(this.$refs['chart1'].offsetWidth);
                    this.chart1.destroy();
                }
                if(this.chartData2.length > 0){
                    this.chart2.changeSize(this.$refs['chart2'].offsetWidth); // 清除
                    this.chart2.destroy();
                }
                if(this.chartData3.length > 0){
                    this.chart3.changeSize(this.$refs['chart3'].offsetWidth); // 清除
                    this.chart3.destroy();
                }

                if(this.chartData1.length > 0){
                    await this.renderChart1();
                }
                if(this.chartData2.length > 0){
                    await this.renderChart2();
                }
                if(this.chartData3.length > 0){
                    await this.renderChart3();
                }
            })
        })

        this.$nextTick(async ()=>{
            this.renderResize();
godwithdh's avatar
godwithdh committed
116 117 118 119 120 121 122 123 124 125
            // await this.getData();
            // if(this.chartData1.length>0){
            //     await this.renderChart1()
            // }
            // if(this.chartData2.length>0){
            //     await this.renderChart2()
            // }
            // if(this.chartData3.length>0){
            //     await this.renderChart3()
            // }
godwithdh's avatar
godwithdh committed
126 127
        })

godwithdh's avatar
godwithdh committed
128 129 130 131 132
        // this.global.$off("searchData");
        // this.global.$on("searchData",async ()=>{
        //     this.chartData1=[]
        //     this.chartData2=[]
        //     this.chartData3=[]
godwithdh's avatar
godwithdh committed
133
            
godwithdh's avatar
godwithdh committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
        //     if(this.chartData1.length > 0){
        //         await this.chart1.destroy();
        //     }
        //     if(this.chartData2.length > 0){
        //         await this.chart2.destroy();
        //     }
        //     if(this.chartData3.length > 0){
        //         await this.chart3.destroy();
        //     }
        //     await this.getData();
        //     if(this.chartData1.length > 0){
        //         await this.renderChart1();
        //     }
        //     if(this.chartData2.length > 0){
        //         await this.renderChart2();
        //     }
        //     if(this.chartData3.length > 0){
        //         await this.renderChart3();
        //     }
godwithdh's avatar
godwithdh committed
153

godwithdh's avatar
godwithdh committed
154
        // });
godwithdh's avatar
godwithdh committed
155 156
    },
    methods:{
godwithdh's avatar
godwithdh committed
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
        searchData(start,end){
            this.searchValue.dBeginDate=start
            this.searchValue.dEndDate=end
            this.$nextTick(async ()=>{
                this.chartData1=[]
                this.chartData2=[]
                this.chartData3=[]
                
                if(this.chartData1.length > 0){
                    await this.chart1.destroy();
                }
                if(this.chartData2.length > 0){
                    await this.chart2.destroy();
                }
                if(this.chartData3.length > 0){
                    await this.chart3.destroy();
                }

                await this.getData();
                if(this.chartData1.length > 0){
                    await this.renderChart1();
                }
                if(this.chartData2.length > 0){
                    await this.renderChart2();
                }
                if(this.chartData3.length > 0){
                    await this.renderChart3();
                }
            })
        },
godwithdh's avatar
godwithdh committed
187 188 189 190 191 192 193 194 195 196
        renderResize(){
            let width = document.documentElement.clientWidth;
            let height = document.documentElement.clientHeight;
            if(width > height) {
                this.direction = 'cross';
            }else{
                this.direction = 'vertical';
            }
        },
        async getData(){
godwithdh's avatar
godwithdh committed
197
            var res=await this.request("getTiipSalesinfo",{
godwithdh's avatar
godwithdh committed
198
                data:{
godwithdh's avatar
godwithdh committed
199 200
                    dStartDate:this.searchValue.dBeginDate,
                    dEndDate:this.searchValue.dEndDate,
godwithdh's avatar
godwithdh committed
201 202
                }
            },"加载中",{})
godwithdh's avatar
godwithdh committed
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
            if(res.set1.length>0){
                this.title=res.set1[0].sSalesName
                this.chartData1=res.set1.map(v=>{
                    return{
                        sSalesName:v.sSalesName,
                        nAmount:v.nAmount,
                        iSalesId:v.sSalesName,
                    }
                })
            }
            if(res.set2.length>0){
                this.tempChartData2 = res.set2.map(v=>{
                    return{
                        nPaydAmount:v.nPaydAmount,
                        sMonth:v.sMonth,
                        iSalesId:v.sSalesName,
                    }
                })
                this.chartData2=this.tempChartData2.filter(v=>this.chartData1.length>0&&v.iSalesId==this.chartData1[0].iSalesId)
            }
            if(res.set3.length>0){
                this.tempChartData3 = res.set3.map(v=>{
                    return{
                        iSalesId:v.sSalesName,
                        sMonth:v.sMonth,
                        nAmount:v.nAmount,
                    }
                })
                this.chartData3=this.tempChartData3.filter(v=>this.chartData1.length>0&&v.iSalesId==this.chartData1[0].iSalesId)
            }
godwithdh's avatar
godwithdh committed
233 234 235 236
        },
    },
}
</script>