li-guang
2021-01-05 01b55d7e82c3b13554a412e9c5be0fc96a4906a3
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
<template>
    <view class="container">
        <view class="wrap">
            <view class="title">
                {{beginTime}} 至 {{endTime}}
            </view>
            <canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" @touchstart="touchLineA"></canvas>
            <view class="total">
                总计:¥{{total | formatNum}}
            </view>
        </view>
        <view class="wrap">
            <view class="list-item" v-for="item in list">
                <template v-for="(value, key) in item">
                    <text>{{key}}</text>
                    <text>¥{{value | formatNum}}</text>
                </template>
            </view>
        </view>
        <fillter :isShow="isShowFilter" @change="changeFilter"></fillter>
    </view>
</template>
 
<script>
    import uCharts from '../../../components/u-charts/u-charts/u-charts.js';
    import fillter from './filter'
    let canvaLineA = null;
    export default {
        components:{
            fillter
        },
        data() {
            return {
                prePage: 1,//公司门店收益分析,2 员工收益分析
                type: 1, //1-营业收入 2-现金收入 3-余额划扣 4-本金消耗 5-赠送消耗 6-现金退款 7-卡项退款 8-欠款
                shopId: '',
                staffId: '',
                isShowFilter: false,
                unit: '日',
                beginTime: '',
                endTime: '',
                list: []
            }
        },
        computed:{
            total(){
                let total = 0;
                this.list.forEach((item) => {
                    total += Number(Object.values(item)[0]);
                });
                return total
            }
        },
        onLoad(options) {
            this.beginTime = this.$utils.formmatTime('YY-mm')+'-01';
            this.endTime = this.$utils.formmatTime('YY-mm-dd')
            this.shopId = options.shopId;
            this.staffId = options.staffId;
            if(options.type){
                this.type = Number(options.type)
            }
            if(options.page){
                this.prePage = options.page;
            }
            uni.setNavigationBarTitle({
                title: '专项分析-'+ options.title
            });
            this.getlineData();
        },
        onNavigationBarButtonTap() {
            this.isShowFilter = !this.isShowFilter;
        },
        methods: {
            changeFilter(obj){
                this.beginTime = obj.beginTime;
                this.endTime = obj.endTime;
                this.unit = obj.unit;
                this.getlineData();
            },
            getlineData(){
                let url = '';
                let param = {
                    beginTime: this.beginTime,
                    endTime: this.endTime,
                    statisticsUnit: this.unit,
                    type: this.type
                }
                if(this.prePage == 1){
                    url = '/api/statistics/findBusinessInCome'
                    Object.assign(param, {shopId: this.shopId})
                }else{
                    url = '/api/statistics/findVipBusinessData'
                    Object.assign(param, {staffId: this.staffId})
                }
                this.$httpUtils.request(url, {
                    beginTime: this.beginTime,
                    endTime: this.endTime,
                    shopId: this.shopId,
                    statisticsUnit: this.unit,
                    type: this.type
                }, 'POST').then((res) => {
                    if(res.status == 200){
                        this.list = res.rows;
                        let result = res.mapInfo;
                        let xAxis = result.xAxis;
                        if(this.unit == '日' && xAxis.length){
                            xAxis = xAxis.map((item) => {
                                return item.slice(5)
                            })
                        }
                        this.initLine("canvasLineA", {categories: xAxis, series: result.series});
                    }
                });
            },
            initLine(canvasId,chartData){
                canvaLineA=new uCharts({
                    $this:this,
                    canvasId: canvasId,
                    type: 'area',
                    fontSize:10,
                    legend:{
                        show:false
                    },
                    background:'#ffffff',
                    dataLabel:false,
                    dataPointShape:true,
                    dataPointShapeType: 'hollow',
                    padding: [10, 28, 10, 0],
                    categories: chartData.categories,
                    series: chartData.series,
                    animation: true,
                    xAxis: {
                        type:'grid',
                        disableGrid:true,
                        fontColor:'#333333',
                        axisLine: false,
                        labelCount: 8
                    },
                    yAxis: {
                        gridType:'dash',
                        gridColor:'#EDEAF4',
                        dashLength:8,
                        data: [
                            {
                                fontColor:'#333333',
                                axisLine: false,
                                min: 0
                            }
                        ]
                    },
                    width: uni.upx2px(710),
                    height: uni.upx2px(360),
                    extra: {
                        area:{
                            type: 'curve',
                            opacity:0.2,
                            addLine:true,
                            width:2
                        },
                        tooltip:{
                            gridType:'dash',//辅助线类型(虚线)
                            dashLength:7,//虚线单段长度
                            gridColor:'#EDEAF4',//辅助线颜色
                        }
                    }
                });
                
            },
            touchLineA(e){
                canvaLineA.showToolTip(e, {
                    format: function (item, category) {
                        return category + ':' + item.data 
                    }
                });
            }
        }
    }
</script>
 
<style>
    page{
        background: #F6F6F8;
    }
    .container{
        padding: 10px;
    }
    .wrap{
        border: 1px solid #EDEAF4;
        border-radius: 4px;
        background: #FFFFFF;
        margin-bottom: 10px;
        padding: 0 10px;
        font-size: 14px;
    }
    .title{
        text-align: center;
        padding: 10px 0 5px;
    }
    .charts{
        width: 100%;
        height: 200px;
    }
    .total{
        padding: 10px 0 15px;
        text-align: right;
        font-size: 16px;
        font-weight: bold;
    }
    .list-item{
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #EDEAF4;
        padding: 10px 0;
    }
    .list-item:nth-last-child(1){
        border: 0;
    }
</style>