<template>
  <div :class="inline ? 'inline' : ''" class="QdmCascader">
    <span :style="'width:' + colSpan + 'px;text-align:' + align + ';'"><i v-if="must">*</i>{{ name }}</span>
    <el-cascader
    :class="col"
    v-model="newValue"
    :options="list"
    :props="props"
    clearable
    filterable
    :disabled="disabled"
    :placeholder="placeholder"
    @change="handleChange"></el-cascader>
  </div>
</template>
<script>
export default {
  name: "QdmCascader",
  props: {
    name: {
      type: String,
      default: ''
    },
    value: {
      type: Array,
      default: () => {
        return []
      }
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    col: {
      type: String,
      default: 'small'
    },
    colSpan: {
      type: Number,
      default: 60
    },
    align: {
    	type: String,
      default: 'right'
    },
    inline: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    must: {
      type: Boolean,
      default: false
    },
    list: {
      type: Array,
      default: () => {
        return []
      }
    },
    props: {
      type: Object,
      default: () => {
        return {
          value: 'value',
          label: 'label',
          children: 'children',
          checkStrictly: false
        }
      }
    }
  },
  data() {
    return {
      newValue: this.value
    }
  },
  methods: {
    handleChange(val) {
      this.$emit('cascaderReturn', val)
    }
  },
  watch: {
  	value(val) {
  		this.newValue = val
  	}
  }
}
</script>
<style lang="less">
.inline {
  float: left;
}
.QdmCascader {
  margin-right: 10px;
  height: 30px;
  margin-bottom: 8px;
  >span {
    display: block;
    height: 30px;
    float: left;
    line-height: 30px;
    padding-right: 8px;
    font-size: 12px;
    >i {
      color: #F5222D;
      margin-right: 5px;
      padding-left: 3px;
    }
  }
  .el-input, .el-cascader {
    float: left;
    font-size: 12px;
    line-height: 30px;
    .el-input__inner {
      height: 30px;
      line-height: 30px;
    }
    .el-input__icon {
      line-height: 30px;
    }
    &.large {
      width: 320px;
    }
    &.medium {
      width: 250px;
    }
    &.small {
      width: 180px;
    }
    &.mini {
      width: 100px;
    }
  }
}
</style>