<template>
    <div class="businessType">
        <canvas class="business" canvas-id="businessType" id="businessType" @tap="handleTap"/>
    </div>
</template>

<script>
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
    name: "businessType",
    data() {
        return {
            width:0
        }
    },
    props: {
        data: {
            type: Array,
            default: () => []
        }
    },
    watch: {
        data: {
            handler(value) {
                this.handleCarData(value)
            },
            immediate: true
        }
    },
    methods: {
      //点击事件
      handleTap(e){
        uChartsInstance[e.target.id].showToolTip(e,{
          formatter: (item, category, index, opts) =>{
            return item.name;
          }
        });
      },
        // 处理传入的数据
        handleCarData(value) {
            let res = {
                series:value
            }
            this.drawCharts('businessType', res)
        },
        drawCharts(id, data) {
            const ctx = uni.createCanvasContext(id, this);
            let _this = this
            let phoneInfo = uni.getStorageSync('phoneInfo')
            this.width =  phoneInfo.screenWidth - 32
            uChartsInstance[id] = new uCharts({
                type: "ring",
                context: ctx,
                width: _this.width,
                height: 180,
                series: data.series,
                animation: false,
                rotate: false,
                rotateLock: false,
                background: "#FFFFFF",
                color: ["#1E80FF", "#00C2FF","#6B6FFF","#38C275","#74839D","#B8C7DE"],
                padding: [5, 5, 5, 5],
                dataLabel: false,
                enableScroll: false,
                legend: {
                    show: true,
                    position: "right",
                    lineHeight: 25,
                    float: 'center'

                },
                extra: {
                    ring: {
                        ringWidth: 20,
                        activeOpacity: 0.5,
                        activeRadius: 10,
                        offsetAngle: -45,
                        labelWidth: 15,
                        border: false,
                        borderWidth: 3,
                        borderColor: "#FFFFFF"
                    }
                }
            });
        },
    }
}
</script>

<style scoped lang="scss">
.businessType{
    width: 100%;
    .business{
        width: 100%;
        height: 170px;
    }
}
</style>
