<template>
  <el-select v-model="classificationid_code" placeholder="请选择分类" @change="choseGoodsType($event)">
    <el-option v-for="(item,index) in goodsType" :key="index" :value="item.goodsClassificationID" :label="item.goodsClassificationName" />
  </el-select>
</template>
<script>
export default {
  props: {
    classificationid: {
      type: String,
      default: ''
    }
  },

  data() {
    return {
      goodsType: [],
      classificationid_code: ''
    }
  },
  watch: {
    classificationid: {
      immediate: true,
      handler(val) {
        this.classificationid_code = val
      },
      deep: true
    }
  },
  created() {
    this.getgoodsType()
  },
  methods: {
    getgoodsType() {
      const params = {
        type: 'getGoodsClassification',
        data: {
          parentID: '0'
        }
      }

      this.$http
        .post(this.$api.getGoodsClassification, params)
        .then((res) => {
          this.goodsType = res.goodsClassifications
        })
    },
    choseGoodsType(event) {
      let obj = {}
      obj = this.goodsType.find((item) => {
        return item.goodsClassificationID === event
      })
      this.$emit('choseGoodsType', obj)
    }

  }
}
</script>
