<template>
  <div id="cmp5">
    <div class="left">
      <div class="d-flex pt-2 pl-2">
        <span style="color:#5cd9e8">
          <icon name="align-left"></icon>
        </span>
        <span class="fs-xl text mx-2">机构养老</span>
      </div>
      <div class="up">
        <div class="item" v-for="item in titleItem" :key="item.title">
            <p class="ml-3 colorBlue fw-b">{{item.title}} : </p>
            <dv-digital-flop :config="item.number" style="display: block;width:1.5rem;height:100%;" />
        </div>
      </div>
    </div>
    <div class="right">
      <Echart
        :options="options"
        id="cmp1"
        style="width: 100%;height: 100%;"
      ></Echart>
    </div>
  </div>
</template>

<script>
  var timer = null;
  import Echart from '../../common/echart'
  export default{
    components:{
      Echart
    },
    data(){
      return{
        titleItem: [
          {
            title: "机构总数",
            number: {
              number: [49],
              content: "{nt}",
              textAlign:'left',
              style: {
                fontSize: 20,
                fontWeight:'bold',
                fill: '#3de7c9',
              }
            }
          },{
            title: "养老床位数",
            number: {
              number: [12089],
              content: "{nt}",
              textAlign:'left',
              style: {
                fontSize: 20,
                fontWeight:'bold',
                fill: '#32c5e9'
              }
            }
          },{
            title: "床位数",
            number: {
              number: [2611],
              content: "{nt}",
              textAlign:'left',
              style: {
                fontSize: 20,
                fontWeight:'bold',
                fill: '#67e0e3'
              }
            }
          },{
            title: "机构老人数",
            number: {
              number: [12611],
              content: "{nt}",
              textAlign:'left',
              style: {
                fontSize: 20,
                fontWeight:'bold',
                fill: '#67e0e3'
              }
            }
          }
      ],
        options:{},
      }
    },
    mounted() {
      this.initLine()
    },
    methods:{
      initLine(){
        //职称结构取数
        var getname = ['公建公营', '公建民营', '民建民营'];
        var getvalue = [300, 200, 100];
        var data = [];
        for (var i = 0; i < getname.length; i++) {
            data.push({
                name: getname[i],
                value: getvalue[i]
            })
        }
        var colorList = ['#503EFF', '#3E82FF', '#8BF39A', '#00FCFD'];
        var rich = {
            name: {
                color: "#FFF",
                fontSize: 10,
                padding: [0, 0, 0, 0],
                fontWeight: '400',
                align: 'left'
            },
            value: {
                color: "#FFF",
                fontSize: 10,
                padding: [0, 10, 0, 10],
                fontWeight: '500',
                align: 'right'
            },
            percent: {
                color: "#FFF",
                align: 'right',
                fontSize: 10,
                fontWeight: '500',
                //padding: [0, 5]
            },
            hr: {
                width: '100%',
                height: 0,
            },
            cir: {
                fontSize: 26,
            }
        }
        //职称结构图表

        let option = {
            tooltip: {
                trigger: 'axis',
            },
            title:{
              text:'机构类型占比',
              bottom:0,
              left:'center',
              textStyle:{
                fontSize:10
              }
            },
            series: [{
                tooltip: {
                    trigger: 'item',
                    formatter: function(params) {
                        return params.name + '：' + params.value + '<br>占比：' + params.percent.toFixed(2) + '%'
                    }
                },
                itemStyle: {
                    normal: {
                        borderColor: '#0A1934',
                        borderWidth: 5,
                        color: function(params) {
                            return colorList[params.dataIndex]
                        }
                    }
                },
                type: 'pie',
                radius: ['40%', '60%'],
                center: ["50%", "50%"],
                label: {
                    normal: {
                        show: false,
                        position: 'inner',
                        formatter: params => {
                            return (
                                '{percent|' + params.percent.toFixed(0) + '%}'
                            );
                        },
                        rich: rich,
                    }
                },
                data: data
            }, {
                itemStyle: {
                    normal: {
                        borderColor: '#0A1934',
                        borderWidth: 5,
                        color: function(params) {
                            return colorList[params.dataIndex]
                        }
                    }
                },
                type: 'pie',
                silent: true, //取消高亮
                radius: ['40%', '60%'],
                center: ["50%", "50%"],
                labelLine: {
                    normal: {
                        length: 10,
                        length2: 0,
                        lineStyle: {
                            color: 'transparent'
                        }
                    }
                },
                label: {
                    normal: {

                        formatter: params => {
                            return '{name|' + params.name + '}{value|' + params.percent.toFixed(0) + '%}\n{hr|————————}';
                        },
                        rich: rich,
                        padding: [0, 20, 0, 25]
                    }
                },
                data: data,
                z: -1
            }, {
                itemStyle: {
                    normal: {
                        borderColor: '#0A1934',
                        borderWidth: 5,
                        color: function(params) {
                            return colorList[params.dataIndex]
                        }
                    }
                },
                type: 'pie',
                silent: true, //取消高亮
                radius: ['40%', '60%'],
                center: ["50%", "50%"],
                labelLine: {
                    normal: {
                        length: 10,
                        length2: 0,
                        lineStyle: {
                            color: 'transparent'
                        },
                    }
                },
                label: {
                    normal: {
                        formatter: params => {
                            return '\n{cir|●}\n';
                        },
                        rich: rich,
                        padding:[10,0,0,0]
                    }
                },
                data: data,
                z: -1
            }]
        };
        this.options = option
      }
    },

  }
</script>

<style lang="less" scoped="scoped">
  #cmp5{
    width: 100%;
        height: 100%;
        display: flex;
        .left,.right{
          height:100%;
          display: flex;
          flex-direction: column;
          justify-content: center;
        }
        .left{
          width: 40%;
        }
        .right{
          width: 60%;
        }
        .up {
          width: 100%;
          box-sizing: border-box;
          .item {
            display: flex;
            align-items: center;
            border-radius: 0.0625rem;
            height: 0.6rem;
            margin-left: .25rem;
          }
        }
  }
</style>
