<template>
  <el-select v-model="value1" placeholder="选择优惠券" ref="couponSelect" @change="handleCouponChange" clearable>
    <el-option v-for="it in options" :key="it.id" :value="it.id" :label="it.stockName">{{it.stockName}}</el-option>
  </el-select>
</template>

<script>
import {mapGetters} from "vuex";

export default {
  name: "CouponSelect",
  props: ['value'],
  computed: {
    ...mapGetters(['couponList']),
    value1: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v);
      }
    },
    options() {
      return this.couponList
    }
  },
  methods:{
    handleCouponChange (id) {
      if (this.value1) {       
        let coupon=this.couponList.find(item=>{
          return item.id==id
        })
        this.$emit('change', coupon.stockName);
      }
    },
  },
  created() {
    this.$store.dispatch('mall/loadCouponList')
  }
}
</script>

<style scoped>

</style>
