index.vue 10.3 KB
Newer Older
godwithdh's avatar
godwithdh committed
1 2 3
<style lang="less" scoped>
    #chartCustom{
        font-size:12px;
张锡奇's avatar
张锡奇 committed
4 5 6 7 8 9 10 11 12 13
        height:100%;
        display: flex;
        flex-direction: column;
        .Content{
            height:100%;
            // height:1px;
            // flex-grow: 1;
            // overflow: auto;
            // -webkit-overflow-scrolling: touch;
        }
godwithdh's avatar
godwithdh committed
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
        h2{
            text-align: center;
        }
        .center{
            text-align: center;
        }
        /deep/ .weui-cells{
            margin-top:0;
        }
        /deep/ .vux-datetime{
            div>p{
                margin-bottom: 0;
            }
        }
        /deep/ .weui-cell_access{
            padding-right: 10px;
        }
        /deep/ .weui-cell_access .weui-cell__ft:after{
            height: 10px;
            width: 10px;
            margin-top: -4px;
            right: 0;
        }
        /deep/ .weui-dialog{
            max-width:60px;
        }
        img{
            width:100%;
        }
    }
</style>

<template>
  <div id="chartCustom">
    <searchComponent :search="search" />
张锡奇's avatar
张锡奇 committed
49 50 51 52 53 54 55 56 57 58 59 60 61
    <div class="Content">
        <div>
            <h2>客户</h2>
            <div ref="myChart1" :style="{width: '100vw', height: '300%',display:pbcustomer.length > 0 ? 'block' : 'none'}"></div>
            <img v-if="pbcustomer.length <= 0" src="@/assets/noData.jpg" class="_img" alt="">
        </div>
        
        <div>
            <h2>销售员</h2>
            <div ref="myChart2" :style="{width: '100vw', height: '300%',display:pbsales.length > 0 ? 'block' : 'none'}"></div>
            <img v-if="pbsales.length <= 0" src="@/assets/noData.jpg" class="_img" alt="">
        </div>
    </div>
godwithdh's avatar
godwithdh committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  </div>
</template>

<script>
import Util from '@/libs/util.js'
import searchComponent from '@/components/search'
import { Confirm } from 'vux'
import { clearTimeout, setTimeout } from 'timers';

export default {
  name: 'chartCustom',
  data () {
    return {
        pbcustomer:[],
        pbsales:[],
        search:{
            dBeginDate:Util.dateFormat(new Date(),'yyyy-MM-01'),
            dEndDate:Util.dateFormat(new Date(),'yyyy-MM-dd'),
        },
张锡奇's avatar
张锡奇 committed
81
        iProjectId:5599,
godwithdh's avatar
godwithdh committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

        myChart1:null,
        myChart2:null,
    }
  },
  async mounted(){
        window.c=this

        this.createChart('myChart1')
        this.createChart('myChart2')
        window.addEventListener("resize",()=>{
            setTimeout(()=>{
                this.resize(this.myChart1)
                this.resize(this.myChart2)
            })
        });
        // this.myChart1 = this.$echarts.init(document.getElementById('myChart1'))
        // this.myChart2 = this.$echarts.init(document.getElementById('myChart2'))
        // this.initChart(this.myChart1,'myChart1');
        // this.initChart(this.myChart2,'myChart2');


张锡奇's avatar
张锡奇 committed
104 105
    this.iProjectId = this.$route.params.iProjectId;
    this.$store.dispatch('setIproject',this.iProjectId);
godwithdh's avatar
godwithdh committed
106 107 108

    await this.getPbcustomer();
    await this.getPbsales();
张锡奇's avatar
张锡奇 committed
109 110
    
    this.global.$off('searchData');
godwithdh's avatar
godwithdh committed
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
    this.global.$on('searchData',async ()=>{
        await this.getPbcustomer();
        await this.getPbsales();
    });
    
  },
  activated(){
      setTimeout(()=>{
            this.resize(this.myChart1)
            this.resize(this.myChart2)
      })
  },
  components:{
      searchComponent,
      Confirm
  },
  
  methods:{
    createChart(name){
        var charts=this.$echarts.init(this.$refs[name])
        let time=0
        charts.getZr().on('mousedown', param=> {
            const pointInPixel = [param.offsetX, param.offsetY]
            if (charts.containPixel('grid', pointInPixel)) {
                let index = charts.convertFromPixel({ seriesIndex: 0 }, [param.offsetX, param.offsetY])[0]
                time = setTimeout(()=>{
                    this.$vux.confirm.show({
                        title: '提示',
                        content: '是否查看详情',
                        onConfirm : () => {
                            let data = {};
                            if(name == 'myChart1'){
                                data = Object.assign(this.pbcustomer[index],{type:'pbcustomer'})
                            }else{
                                data = Object.assign(this.pbsales[index],{type:'pbsales'});
                            }
                            this.$store.dispatch('setChartHearData',data).then(()=>{
                                this.$router.push({name:'chartCustomDetail'});
                            });
                        }
                    })
                },500);
            }
        });
        charts.getZr().on('mousemove',  (param)=> {
            clearTimeout(time);
        });
        
        charts.getZr().on('mouseup', (param)=> {
            clearTimeout(time);
        });

        this[name]=charts
    },
    resize(chart){
        var option=chart.getOption()
        if(!option)return;
        option.dataZoom[0].end=option.dataZoom[0].start+(window.innerWidth*0.9)/option.xAxis[0].data.length
        chart.setOption(option)
        chart.resize()
    },

    async getPbcustomer(){
        let result = await this.request('getPbcustomer',{
            params:this.search
张锡奇's avatar
张锡奇 committed
176
        },true,{iProjectId:this.iProjectId})
godwithdh's avatar
godwithdh committed
177 178 179 180
        this.pbcustomer = typeof result=='object'&&result.length>0&&result.map(v=>{
            v.name=`${v.sCustomerName||''}\n${v.sCustomerNo||''}`
            return v
        })||[];
张锡奇's avatar
张锡奇 committed
181
        this.setChart(this.myChart1,this.pbcustomer,'pbcustomer')
godwithdh's avatar
godwithdh committed
182 183 184 185
    },
    async getPbsales(){
        let result= await this.request('getPbsales',{
            params:this.search
张锡奇's avatar
张锡奇 committed
186
        },true,{iProjectId:this.iProjectId})
godwithdh's avatar
godwithdh committed
187 188 189 190
        this.pbsales = typeof result=='object'&&result.length>0&&result.map(v=>{
            v.name=`${v.sSalesName||''}\n${v.sSalesNo||''}`
            return v
        })||[];
张锡奇's avatar
张锡奇 committed
191
        this.setChart(this.myChart2,this.pbsales,'pbsales')
godwithdh's avatar
godwithdh committed
192
    },
张锡奇's avatar
张锡奇 committed
193
    setChart(myChart,value,id){
张锡奇's avatar
张锡奇 committed
194
        let options = {
godwithdh's avatar
godwithdh committed
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
           title:{
               subtext:"长按查看详情",
               subtextStyle:{
                   color:"red",
                   verticalAlign:"top",
               },
               padding:[0,0,0,25],
               right:6,
           },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            // toolbox: {
            //     feature: {
            //         // dataView: {show: true, readOnly: false},
            //         magicType: {show: true, type: ['line', 'bar']},
            //         restore: {show: true},
            //         // saveAsImage: {show: true}
            //     },

            // },
            grid: {
                left: '2%',   // 与容器左侧的距离
                right: '2%', // 与容器右侧的距离
                containLabel: true
            },
            // legend: {
            //     data:['金额'],
            //     x: 'left'
            // },
            xAxis: [
                {
                    type: 'category',
                    data: value.map(x => x.name) ,
                    axisPointer: {
                        type: 'shadow'
                    },
                    axisTick: {
                        alignWithLabel: true
                    },
                    axisLabel: {
                        interval:0 
                    }
                },
            ],
            yAxis: [
                {
                    type: 'value',
                    name: '金额',
                    axisLabel: {
                        formatter: '{value}'
                    },
                    scale:true
                }
            ],
            series: [
                {
                    name:'金额',
                    type:'bar',
                    data: value.map(x => `${x.nAmount}`) ,
                    barMaxWidth:40,
                    label:{
                        show:true,
                        position:"top",
                        color:'#6B9BF7',
                        formatter:val=>{
                            return `${val.data}`
                        }
                    },
                    itemStyle:{
张锡奇's avatar
张锡奇 committed
271 272 273
                        normal:{
                            color:id == 'pbcustomer' ? '#708bf6' : '#00B2EE'
                        }
godwithdh's avatar
godwithdh committed
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
                    }
                }
            ],
            dataZoom: [{
                type: 'inside',
                show: true, //flase直接隐藏图形
                xAxisIndex: [0],
                left: '9%', //滚动条靠左侧的百分比
                start: 0,//滚动条的起始位置
                end: (window.innerWidth*0.9)/value.length //滚动条的截止位置(按比例分割你的柱状图x轴长度)
            }] 
        };
        myChart.setOption(options);
    },

    initChart(myChart,id){
        myChart.getZr().on('mousedown', (param)=> {
            this.timer = setTimeout(()=>{
                longPress(param)
            },500);
        });
        myChart.getZr().on('mousemove',  (param)=> {
            window.clearTimeout(this.timer);
        });
        
        myChart.getZr().on('mouseup', (param)=> {
            console.log(this.timer)
            window.clearTimeout(this.timer);
        });
        

        var that = this;
        function longPress(param){
            that.$vux.confirm.show({
                title: '提示',
                content: '是否查看详情',
                // 组件除show外的属性
                onCancel : () => {
                    // options.tooltip.show = true;
                    // myChart.setOption(options);
                },
                onConfirm : () => {
                    let index = param.dataIndex;
                    let data = {};
                    if(id == 'myChart1'){
                        data = Object.assign(that.pbcustomer[index],{type:'pbcustomer'})
                    }else{
                        data = Object.assign(that.pbsales[index],{type:'pbsales'});
                    }
                    that.$store.dispatch('setChartHearData',data).then(()=>{
                        that.$router.push({name:'chartCustomDetail'});
                    });
                    // options.tooltip.show = true;
                    // myChart.setOption(options);
                }
            })
        }
    }
  }
}
</script>