<template>
  <div :style="{'width':width,'height':height,'line-height':height}" style="font-size: 0;">
<!--    <span class="label" v-if="label" :style="{'width':labelWidth,'line-height':height}">{{label}}</span>-->
    <!--label-->
    <al-label
      :label="label"
      :labelWidth="labelWidth"
      :labelOption="labelOption"
      :value="labelActiveIndex"
      @input="labelChange"
      :style="{textAlign: placement=='reverse'?'left':'right'}"
      :height="height">{{label}}</al-label>


    <al-form-item :class="{'autoWidth':label}" :prop="prop"
                  :style="{width:label||labelOption.length?'calc( 100% - '+labelWidth+')':'100%','height':height,'line-height':height,textAlign: placement=='reverse'?'right':'left'}">
      <el-switch
        :value="value"
        @input="onInput"
        @change="onChange"
        :active-text="activeText"
        :inactive-text="inactiveText"
        :disabled="disabled">
      </el-switch>
    </al-form-item>
  </div>
</template>

<script>
    import AlFormItem from '../AlFormItem'

    export default {
        name: "index",
        data() {
            return {}
        },
        props: {
            placement:{
                type:String,
                default:''
            },
            //labelOption 激活值
            labelActiveIndex:{
                type:Number,
                default:0
            },
            //label下拉框的选项
            labelOption: {
                type: Array,
                default() {
                    return []
                }
            },
            prop: {
                type: String,
                default: ''
            },
            //输入值
            value: {
                type: Boolean,
                default: false
            },
            //标签
            label: {
                type: String,
                default: ""
            },
            //开关文字
            activeText: {
                type: String,
                default: ""
            },
            inactiveText: {
                type: String,
                default: ""
            },
            //宽度
            width: {
                type: String,
                default: '200px'
            },
            //标签宽度
            labelWidth: {
                type: String,
                default: "100px"
            },
            //组件高度
            height: {
                type: String,
                default: '36px'
            },
            //组件禁用
            disabled: {
                type: Boolean,
                default: false
            }
        },
        methods: {
            labelChange(v){
                this.$emit('labelChange',v)
            },
            onInput(newValue) {
                this.$emit("input", newValue)
            },
            onChange(newValue) {
                this.$emit("change", newValue)
            },
        },
        components:{
            AlFormItem
        }
    }
</script>

<style scoped lang="scss">
  /deep/ {
    .el-switch__label--left {
      background: transparent !important;
    }
  }

  .label {
    display: inline-block;
    font-size: 14px;
    text-align: right;
    padding-right: 12px;
    box-sizing: border-box;
    vertical-align: top;

    /deep/ {
      .el-icon--right {
        margin-left: 2px;
      }
    }
  }
</style>
