<template>
  <div class="gift-container">
    <h3 class="title">选择礼品券</h3>
    <scroll-view :scroll-y="true" class="gift-list">
      <div v-for="(item, idx) in list" :key="idx" class="item1">
        <GiftCard
          :checked="item.checked"
          :show-record="false"
          :card-item="item"
          @bind-gift-click="bindGiftClick"
        />
      </div>
    </scroll-view>
    <div class="gift-button">
      <button class="btn" type="primary" @click="handleGiftOk">确定</button>
    </div>
  </div>
</template>
<script>
import GiftCard from "@/components/giftCard.vue";
export default {
  name: "GiftList",
  components: {
    GiftCard
  },
  props: {
    giftList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    let giftList = this.giftList;
    return {
      list: giftList
    };
  },
  methods: {
    bindGiftClick(item) {
      this.list = this.giftList.map(g => {
        if (item.id === g.id) {
          g.checked = !g.checked;
        } else {
          g.checked = false;
        }
        return g;
      });
    },
    handleGiftOk() {
      const checkedList = this.giftList.filter(item => item.checked);
      this.$emit("handleGiftOk", checkedList);
    }
  }
};
</script>
<style scoped lang="scss">
.gift-list {
  height: 50vh;
  box-sizing: border-box;
  padding: 0 10px;
}
.title {
  font-size: $font-lg;
  color: $font-color-dark;
  text-align: center;
  padding-top: 36rpx;
  margin-bottom: 24rpx;
}
.gift-button {
  padding: 20rpx 40rpx 30rpx;
  position: relative;
}
.btn {
  background-image: linear-gradient(269deg, #ff5d00 12%, #ff1900 86%);
  border-radius: 160rpx;
  height: 80rpx;
  font-size: 28rpx;
  line-height: 80rpx;
  color: #fff;
  border: 0;
}
</style>
