import { productTypeQuery } from '@/api/productType'
const ProductType = {
  template: `
      <a-cascader
        @change="handleChange"
        change-on-select
        :value="defaultVal"
        expand-trigger="hover"
        :options="productTypeList"
        :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
        :id="id"
        placeholder="请选择结算方式"
        allowClear />
    `,
  props: {
    value: {
      type: Array,
      defatut: function () {
        return []
      }
    },
    id: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      defaultVal: this.value,
      productTypeList: []
    }
  },
  watch: {
    value (newValue, oldValue) {
      this.defaultVal = newValue
    }
  },
  mounted () {
    this.getProductType()
  },
  methods: {
    handleChange (value) {
      this.defaultVal = value
      this.$emit('change', this.defaultVal)
    },
    //  产品分类列表
    getProductType () {
      productTypeQuery({}).then(res => {
        if (res.status == 200) {
          this.productTypeList = res.data
        } else {
          this.productTypeList = []
        }
      })
    }
  }
}

export default ProductType
