<template>
  <div class="contain">
    <div class="box"  v-for="(item,index) in list" :key="index" @click="handleCoupon(item.id)">
      <div class="left" >
        <div class="price">¥{{ item.unit }}</div>
        <div class="type">{{ item.type }}</div>
      </div>
      <div class="right">
        <div>满{{ item.salesUnit }}元可用</div>
        <div class="time">
          <div>有效期:</div>
          <span>{{ item.begin_date }}</span>~
          <span>{{ item.end_date }}</span>
        </div>
      </div>
    </div>
    <div class="btn-plus" @click="handleAddCoupon"><span>+</span></div>
  </div>
</template>

<script>
import { getCouponList } from "@/api/sidebar/voucher"
export default {
  data() {
    return {
      form: {
        unit: '100',
        type: '老用户回馈券',
        usageAmount: '500',
        begin_date: '2020/2/3',
        end_date: '2020/4/5'
      },
      deptId: '',
      list: []
    }
  },
  mounted() {
    this.deptId = sessionStorage.getItem('oyStallCode')
    // this.deptId = 3
    this.getList()
  },
  methods: {
    getList() {
      let params = {
        deptId: this.deptId
      }
      getCouponList(params).then(res => {
        this.list = res.data
        res.data.forEach(item => {
          item.begin_date = item.begin_date.substr(0,4)+'-'+item.begin_date.substr(4,2)+'-'+item.begin_date.substr(6,2)
          item.end_date = item.end_date.substr(0,4)+'-'+item.end_date.substr(4,2)+'-'+item.end_date.substr(6,2)
        })
      })
    },
    handleCoupon(id) {
      this.$router.push({
        path: "yhqDetail",
        query: {
          id: id
        }
      })
    },
    handleAddCoupon() {
      this.$router.push("couponAdd")
    }
  }
}
</script>

<style scoped>
.contain {
  background-color: rgb(237, 239, 243);
  height: 100%;
  flex-direction: column;
  justify-content: flex-start;
}
.left,.right {
  font-size: 16px;
}
.box {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 20px;
  height: 22%;
  background-color: #fff;
  border: 1px solid #777;
  margin-top: 18px;
}
.left {
  width: 35%;
}
.price {
  font-size: 32px;
  font-weight: 800;
}
.right {
  width: 65%;
  padding: 10px 0 0 10px;
}
.type {
  margin-top: 17px;
}
.time {
  margin-top: 20px;
}
.btn-plus {
  position: fixed;
  right: 30px;
  bottom: 30px;
  font-size: 40px;
  font-weight: bold;
  width: 50px;
  height: 50px;
  border: 2px solid #ccc;
  border-radius: 50%;
  text-align: center;
  color: green;
  line-height: 1;
}
</style>