<template>
    <div class="main">
        <div class="yesterday">
            <div class="top">
                <image class="icon" src="/static/images/commercial/money.svg"></image>
                <p class="title">客单均价<text class="unit">/元</text></p>
            </div>
            <div class="bottom">
                <div class="item">
                    <p class="price">18.3</p>
                    <p class="text">该服务区</p>
                </div>
                <div class="item">
                    <p class="price">17.6</p>
                    <p class="text">省级平均</p>
                </div>
            </div>
        </div>
        <div class="month">
            <div class="top">
                <image class="icon" src="/static/images/commercial/converRate.svg"></image>
                <p class="title">消费转化率<text class="unit">/%</text></p>
            </div>
            <div class="bottom">
                <div class="item">
                    <p class="price">37.9</p>
                    <p class="text">该服务区</p>
                </div>
                <div class="item">
                    <p class="price">52.8</p>
                    <p class="text">省级平均</p>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
    name: "transactionAnalysis",
    data() {
        return {
        }
    },
    props: {
        data: {
            type: Array,
            default: () => []
        }
    },
    watch: {
        data: {
            handler(value) {
                console.log('carDatawatch', value)
                this.handleCarData(value)
            }
        }
    },
    methods: {
        // 处理传入的数据
        handleCarData(value) {
            let res = []
            this.drawCharts('carNum', res)
        },
        drawCharts(id, data) {
            const ctx = uni.createCanvasContext(id, this);
            let _this = this
            uChartsInstance[id] = new uCharts({
                type: "ring",
                context: ctx,
                width: 178,
                height: 208,
                series: data.series,
                animation: true,
                rotate: false,
                rotateLock: false,
                background: "#FFFFFF",
                color: ["#CAD0DA", "#1E80FF"],
                padding: [5, 5, 5, 5],
                dataLabel: false,
                enableScroll: false,
                title: {
                    name: _this.carNumAll,
                    fontSize: 16,
                    color: "#341D00"
                },
                subtitle: {
                    name: "昨日入区车流",
                    fontSize: 12,
                    color: "#786B6C",
                },
                legend: {
                    show: true,
                    position: "bottom",
                    lineHeight: 25,
                    float: 'center'

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

<style scoped lang="scss">
.main{
  width: 100%;
  .yesterday,.month{
    margin-top: 12px;
    width: 100%;
    box-sizing: border-box;
    background: #F2F1F1;
    border-radius: 4px;
    padding: 12px;
    .top{
      display: flex;
      .icon{
        width: 18px;
        height: 18px;
        margin-right: 9px;
      }
      .title{
        font-size: 14px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #160002;
        line-height: 20px;
          .unit{
              font-size: 14px;
              font-family: PingFangSC-Regular, PingFang SC;
              font-weight: 400;
              color: #A69E9F;
              line-height: 20px;
              margin-left: 2px;
          }
      }
    }
    .bottom{
      margin-top: 12px;
      width: 100%;
      display: flex;
      box-sizing: border-box;
      .item{
        width:50%;
        padding-left: 22px;
        .price{
          font-size: 16px;
          font-family: DINAlternate-Bold, DINAlternate;
          font-weight: bold;
          color: #341D00;
          line-height: 20px;
          margin-bottom: 2px;
        }
        .text{
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #786B6C;
            line-height: 20px;
          .unit{
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #A69E9F;
            line-height: 20px;
          }
        }
      }
    }
  }
}
</style>