<template>
<div class="progress-wrap" :style="wrapStyle">
  <div class="lc-progress"
       :style="runWayStyle"
       :accessible="true"
       :aria-label="`进度为百分之${value}`">
    <div class="progress" :style="progressStyle"></div>
  </div>
  <div class="progress-ball" :style="progressBallStyle"></div>

</div>
  
</template>

<style scoped>
.progress-wrap{
  height: 30px;
  align-items: center;
  justify-content: center;
}
  .lc-progress {
    position: relative;
    border-width: 1px;
    border-style: solid;
    border-radius: 8px;
  }

  .progress {
    position: absolute;
    top: -0.5px;
    border-radius: 8px;
  }
  .progress-ball{
    width: 30px;
    height: 30px;
    position: absolute;
    top: -0.5px;
    border-radius: 15px;
    background-color: #4790df;
  }
</style>

<script>
  export default {
    props: {
      barColor: {
        type: String,
        default: '#d6ecfb'
      },
      bgColor: {
        type: String,
        default: '#ebebeb'
      },
      borderColor: {
        type: String,
        default: '#ebebeb'
      },
      barWidth: {
        type: Number,
        default: 700
      },
      barHeight: {
        type: Number,
        default: 8
      },
      value: {
        type: Number,
        default: 0
      }
    },
    computed: {
      wrapStyle () {
        const { barWidth} = this;
        return {
          width: (barWidth+30) + 'px'
        }
      },
      runWayStyle () {
        const { barWidth, barHeight, bgColor, borderColor} = this;
        return {
          width: barWidth + 'px',
          height: barHeight + 'px',
          borderColor: borderColor,
          backgroundColor: bgColor
        }
      },
      progressStyle () {
        const { value, barWidth, barHeight, barColor } = this;
        const newValue = value < 0 ? 0 : (value > 100 ? 100 : value);
        return {
          backgroundColor: barColor,
          height: barHeight + 'px',
          width: newValue / 100 * barWidth + 'px'
        }
      },
      progressBallStyle () {
        const { value, barWidth, barHeight, barColor } = this;
        const newValue = value < 0 ? 0 : (value > 100 ? 100 : value);
        return {
          left: ( newValue / 100 * barWidth +15 ) + 'px'
        }
      }
    }
  }
</script>
