radio.vue 1.83 KB
Newer Older
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
/**
* @Author think
* @Date 2019-07-10 13:57
*/

<template>
  <section class="h-radio" @click="click">
    <div :class="{'disable':disable}" class="radio-icon">
      <i :class="icon" class="icon"/>
    </div>
    <span class="radio-title" v-text="title"/>
  </section>
</template>

<script>
let CHECKEDCLASS = 'ion-ios-checkmark'
let DEFAULTCLASS = 'ion-ios-circle-outline'
export default {
  name: 'Radio',
  props: {
    disable: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      default: '',
    },
    name: {
      type: String,
      default: '',
    },
    checked: {
      type: Boolean,
      default: false,
    },
  },
  data () {
    return {
      icon: DEFAULTCLASS,
    }
  },
  watch: {},
  mounted () {
    this.$parent && this.$parent.radioList.push(this)
    this.icon = this.checked ? CHECKEDCLASS : DEFAULTCLASS
    this.disable = this.disable ? this.disable : this.$parent.disable
  },
  destroyed () {
    this.$parent && this.$parent.radioList.splice(this.$parent.radioList.indexOf(this), 1)
  },
  methods: {
    click () {
      let vm = this
      if (!vm.disable) {
        vm.$parent.radioList.forEach(item => {
          item.icon = DEFAULTCLASS
        })
        vm.icon = CHECKEDCLASS
        this.$parent.click(this.name)
      }
    },
  },
}
</script>
<style lang="less">
Nature's avatar
Nature committed
67
  @import "../../common/styles/variables";
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
  .h-radio {
    display: flex;
    height: 100%;
    align-items: center;

    .radio-icon {
      width: 26px;
      height: 26px;
      .icon {
        font-size: 26px;
      }
      .ion-ios-circle-outline{
        color: #d9d9d9;
      }
      .ion-ios-checkmark{
        color: @radio-box-bg;
      }
    }
    .disable{
        opacity: .7;
    }
    .radio-title{
      line-height: 0.5rem;
      font-size: 16px;
      color: #333;
      margin-left: 6px;
    }
  }

</style>