<template>
  <div :class="inline ? (tags ? 'inline QdmSelect' : 'inline QdmSelectNoTags') : (tags ? 'QdmSelect' : 'QdmSelectNoTags')"
  	:style="multiple ? 'height: auto;' : 'height: 30px;'">
	  <span :style="'width:' + colSpan + 'px;text-align:' + align + ';'"><i v-if="must">*</i>{{ name }}</span>
	  <el-select
	  v-if="remote"
	  :class="newvalue.length > 1 ? 'listCol ' + col : col"
	  v-model="newvalue"
	  :disabled="disabled"
	  :filterable="filterable"
	  :placeholder="placeholder"
	  :remote="true"
	  :multiple="multiple"
	  :loading="loading"
	  :remote-method="remoteMethod"
	  @change="selectChange"
	  clearable>
	    <el-option
	      v-for="(item, index) in newRemoteList"
	      :key="index"
	      :label="item.label"
	      :value="item.value">
	    </el-option>
	  </el-select>
	  <el-select
	  v-else="remote"
	  :class="newvalue.length > 1 ? 'listCol ' + col : col"
	  v-model="newvalue"
	  :disabled="disabled"
	  :collapse-tags="tags"
	  :multiple="multiple"
	  :filterable="filterable"
	  :placeholder="placeholder"
	  @change="selectChange"
	  clearable>
	    <el-option v-if="allStatus" label="全部" :value="allValue"></el-option>
	    <el-option
	      v-for="(item, index) in list"
	      :key="index"
	      :label="item.label"
	      :value="item.value">
	    </el-option>
	  </el-select>
	</div>
</template>
<script>
export default {
  name: "QdmSelect",
  props: {
    name: {
      type: String,
      default: ''
    },
    list: {
      type: Array,
      default: () => {
        return []
      }
    },
    value: {
      type: [ String, Array ],
      default: ''
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    col: {
      type: String,
      default: 'small'
    },
    colSpan: {
      type: Number,
      default: 60
    },
    align: {
    	type: String,
      default: 'right'
    },
    inline: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: 'text'
    },
    disabled: {
      type: Boolean,
      default: false
    },
    multiple: {
      type: Boolean,
      default: false
    },
    filterable: {
      type: Boolean,
      default: false
    },
    must: {
      type: Boolean,
      default: false
    },
    allStatus: {
      type: Boolean,
      default: false
    },
    allValue: {
      type: String,
      default: ''
    },
    tags: {
    	type: Boolean,
      default: true
    },
    remote: {
    	type: Boolean,
      default: false
    },
    remoteList: {
    	type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      newvalue: this.value,
      loading: false,
      newRemoteList: []
    }
  },
  methods: {
    selectChange() {
      this.$emit('selectReturn', this.newvalue)
    },
    remoteMethod(query) {
    	if (query !== '') {
	      this.loading = true
	      this.$emit('remoteMethod', query)
	    } else {
	      this.newRemoteList = []
	    }
    }
  },
  watch: {
  	value(val) {
  		this.newvalue = val
  	},
  	remoteList(arr) {
  		if(arr) {
  			this.loading = false
  			this.newRemoteList = arr
  		}
  	}
  }
}
</script>
<style lang="less">
.inline {
  float: left;
}
.QdmSelectNoTags {
	margin-right: 10px;
  margin-bottom: 8px;
  >span {
    display: block;
    float: left;
    line-height: 30px;
    padding-right: 8px;
    font-size: 12px;
    >i {
      color: #F5222D;
      margin-right: 5px;
      padding-left: 3px;
    }
  }
  .el-select, .el-input {
    float: left;
    font-size: 12px;
    line-height: 30px;
    .el-input__inner {
      line-height: 30px;
      font-size: 12px;
    }
    .el-input__icon {
      line-height: 22px;
    }
    &.large {
      width: 320px;
    }
    &.medium {
      width: 250px;
    }
    &.small {
      width: 180px;
    }
    &.mini {
      width: 100px;
    }	
  }
}
.QdmSelect {
  margin-right: 10px;
  margin-bottom: 8px;
  height: 30px;
  >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-select, .el-input {
    float: left;
    font-size: 12px;
    line-height: 30px;
    .el-input__inner {
      height: 30px !important;
      line-height: 30px;
      font-size: 12px;
    }
    .el-input__icon {
      line-height: 22px;
    }
    &.large {
      width: 320px;
    }
    &.medium {
      width: 250px;
    }
    &.small {
      width: 180px;
    }
    &.mini {
      width: 100px;
    }
    &.listCol {
   		.el-tag {
			  &:last-child {
			  	width: 40px;
			  }
		  } 	
    }
    .el-tag {
    	width: 50%;
	  	overflow: hidden;
		  white-space: nowrap;
		  text-overflow: ellipsis;
	  } 	
  }
}
</style>