index.vue 7.88 KB
Newer Older
godwithdh's avatar
godwithdh committed
1 2 3
<style lang="less" scoped>
    #chartIncome{
        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="chartIncome">
    <searchComponent :search="search" />
张锡奇's avatar
张锡奇 committed
49 50 51 52 53 54 55 56 57 58 59 60
    <div class="Content">
        <div>
            <h2 style="margin-top:0.2rem;">应收-应付</h2>
            <div id="myChart1" :style="{width: '100vw', height: '300%',display:payable.length > 0 ? 'block' : 'none'}"></div>
            <img v-if="payable.length <= 0" src="@/assets/noData.jpg" class="_img" alt="">
        </div>
        <div>
            <h2>实收-实付</h2>
            <div id="myChart2" :style="{width: '100vw', height: '300%',display:receivepay.length > 0 ? 'block' : 'none'}"></div>
            <img v-if="receivepay.length <= 0" src="@/assets/noData.jpg" class="_img" alt="">
        </div>
    </div>
godwithdh's avatar
godwithdh committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  </div>
</template>

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

export default {
  name: 'chartIncome',
  data () {
    return {
        payable:[],
        receivepay:[],
        search:{
            dBeginDate:Util.dateFormat(new Date(),'yyyy-MM-01'),
            dEndDate:Util.dateFormat(new Date(),'yyyy-MM-dd'),
        },
张锡奇's avatar
张锡奇 committed
79
        iProjectId:5599,
godwithdh's avatar
godwithdh committed
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
        toUrl:{
            "myChart20":"/shopVersion/pages/form/revenue",
            "myChart21":"/shopVersion/pages/form/expenditure",
            "myChart10":"/shopVersion/pages/form/receipts",
            "myChart11":"/shopVersion/pages/form/payment",
        },
        myChart1:null,
        myChart2:null,
    }
  },
  activated(){
        setTimeout(()=>{
            this.myChart1.resize()
            this.myChart2.resize()
        })
  },
  async mounted(){
    this.createChart('myChart1')
    this.createChart('myChart2')
    window.addEventListener('resize',()=>{
        setTimeout(()=>{
            this.myChart1.resize()
            this.myChart2.resize()
        })
    })

张锡奇's avatar
张锡奇 committed
106 107
    this.iProjectId = this.$route.params.iProjectId;
    this.$store.dispatch('setIproject',this.iProjectId);
godwithdh's avatar
godwithdh committed
108 109 110
    
    await this.getPayable();
    await this.getReceivepay();
张锡奇's avatar
张锡奇 committed
111 112
    
    this.global.$off('searchData');
godwithdh's avatar
godwithdh committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    this.global.$on('searchData',async ()=>{
        await this.getPayable();
        await this.getReceivepay();
    });

  },
  components:{
      searchComponent,
      Confirm
  },
  
  methods:{
      createChart(name){
            let time=null
            // 基于准备好的dom,初始化echarts实例
            var charts=this.$echarts.init(document.getElementById(name))
            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(()=>{
张锡奇's avatar
张锡奇 committed
134 135
                        console.log(index)
                        if(index == 2) return;
godwithdh's avatar
godwithdh committed
136 137 138 139 140 141 142
                        var options=charts.getOption()
                        options.tooltip[0].show=false
                        charts.setOption(options)
                        this.$vux.confirm.show({
                            title:"提示",
                            content:"是否查看详情",
                            onConfirm:()=>{
张锡奇's avatar
张锡奇 committed
143
                                console.log(name + index)
godwithdh's avatar
godwithdh committed
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
                                wx.miniProgram.navigateTo({
                                    url:this.toUrl[name+index]
                                })
                                options.tooltip[0].show=true
                                charts.setOption(options)
                            },
                            onCancel(){
                                options.tooltip[0].show=true
                                charts.setOption(options)
                            }
                        })
                    },500)
                }
            })
            
            charts.getZr().on('mousemove',()=>{
                clearTimeout(time)
            })
            charts.getZr().on('mouseup',()=>{
                clearTimeout(time)
            })
            this[name]=charts
      },
    async getPayable(){
        let result = await this.request('getPayable',{
            params:this.search
张锡奇's avatar
张锡奇 committed
170
        },true,{iProjectId:this.iProjectId})
godwithdh's avatar
godwithdh committed
171 172 173 174 175 176
        this.payable = result;
        this.drawLine1('myChart1');
    },
    async getReceivepay(){
        let result= await this.request('getReceivepay',{
            params:this.search
张锡奇's avatar
张锡奇 committed
177
        },true,{iProjectId:this.iProjectId})
godwithdh's avatar
godwithdh committed
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
        this.receivepay = result;
        this.drawLine2('myChart2');
    },
    drawLine1(id){
        // 绘制图表
        this.setChart(this.myChart1,'myChart1')
    },
    drawLine2(id){
        // 绘制图表
        this.setChart(this.myChart2,'myChart2')
    },
    setChart(myChart,id){
        let seriesData = [];
        let xAxisData = [];
        let data = id == 'myChart1' ? this.payable[0] : this.receivepay[0];
        let fieldNames = ['nSumReceive','nSumPay','nAmountYE']
        for(let x of fieldNames){
            let fieldName;
            if(x == 'nSumPay'){
                fieldName = id == 'myChart1' ? '应付' : '实付';
            }else if(x == 'nSumReceive'){
                fieldName = id == 'myChart1' ? '应收' : '实收';
            }else if(x == 'nAmountYE'){
                fieldName = '差价'
            }
            xAxisData.push(fieldName);

            if(data[x] > 0){
                seriesData.push(data[x]||0)
            }else{
                seriesData.push(data[x]||0)
            }
        }
       let options = {
           tooltip : {
                trigger: 'axis',
                axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                    type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                }
            },
            legend: {
                data:seriesData
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type : 'category',
                axisTick : {show: false},
                data : xAxisData
            },
            yAxis: {
                type : 'value',
                position: 'top',
                splitLine: {lineStyle:{type:'dashed'}},
            },
            series : [
                {
                    name:'',
                    type:'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            show: false,
                            formatter: '{b}'
                        }
                    },
                    barMaxWidth:40,
张锡奇's avatar
张锡奇 committed
249 250 251 252 253 254
                    data:seriesData,
                    itemStyle:{
                        normal:{
                            color:id == 'myChart1' ? '#708bf6' : '#00B2EE'
                        }
                    }
godwithdh's avatar
godwithdh committed
255 256 257 258 259 260 261 262 263 264
                }
            ]
       }
        myChart.setOption(options);
    }
  }
}
</script>