<template>
  <div class="point-detail">
    <div class="good">
      <img :src="ware.waresPic" alt="" srcset="" />
    </div>
    <div class="title">
      <div class="text">{{ ware.waresName }}</div>
      <div class="price">
        <span class="icon"></span>
        <span class="amount">{{ ware.saleIntegral }}</span>
      </div>
      <div class="sold">已兑换 {{ ware.waresOutCount }}</div>
    </div>
    <!-- <div class="selected">
      <div class="text">已选</div>
      <div class="content">儿童情商课+智慧课堂,1</div>
      <div class="icon"></div>
    </div> -->
    <!-- <div class="pictures">
      <div class="text">- 图文详情 -</div>
    </div> -->
    <div class="buy">
      <button @click="exchange">立刻兑换</button>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState, mapGetters } from "vuex";
export default {
  validate({ params }) {
    // 必须是number类型
    return /^\d{1,}$/.test(params.id);
  },
  head() {
    return {
      title: "积分商品详情页",
    };
  },
  data() {
    return {
      ware: {},
      id: this.$route.params.id,
    };
  },
  mounted() {
    this.getPointInfo();
    this.init();
  },
  computed: {
    ...mapState({
      pointInfo:state=>state.point.pointInfo
    }),
    ...mapGetters({
      findWare: "point/findWare",
    }),
  },
  methods: {
    ...mapActions({
      getPointInfo: "point/getPointInfo",
    }),
    init() {
      this.ware = this.findWare(this.id);
    },
    exchange() {
      if (this.ware.waresCount <= 0) {
        alert("该商品库存不足");
      } else if (this.ware.saleIntegral > this.pointInfo.points) {
        alert("您的积分不足");
      } else {
        this.$router.push({
          path: "/point/pay/" + this.id,
        });
      }
    },
  },
};
</script>

<style>
.point-detail {
  display: flex;
  width: 100vw;
  flex-direction: column;
  box-sizing: border-box;
  background: #f8f8f8;
}
.point-detail .good {
  box-sizing: border-box;
  width: 100vw;
  height: 100vw;
  padding: 15vw;
  background: #ffffff;
}
.point-detail .good img {
  width: 100%;
  height: 100%;
}
.point-detail .title {
  width: 100%;
  height: 26.66vw;
  padding: 4vw;
  background: #ffffff;
  position: relative;
  box-sizing: border-box;
}
.point-detail .title .text {
  width: 3.6rem;
  height: 0.5rem;
  font-size: 0.36rem;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 800;
  color: #111111;
  line-height: 0.5rem;
  position: absolute;
  left: 0.3rem;
  top: 0.3rem;
}
.point-detail .title .price {
  height: 0.7rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  color: #fe9700;
  line-height: 0.7rem;
  position: absolute;
  left: 0.57rem;
  bottom: 0.27rem;
}
.point-detail .title .price .icon {
  display: inline-block;
  width: 0.3rem;
  height: 0.3rem;
  background: url("../../../static/common/a01_jifen@2x.png") no-repeat;
  background-size: cover;
  margin-right: 0.1rem;
}
.point-detail .title .price .amount {
  display: inline-block;
  font-size: 0.5rem;
}
.point-detail .title .sold {
  height: 0.4rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #666666;
  line-height: 0.4rem;
  position: absolute;
  right: 0.45rem;
  bottom: 0.3rem;
}
.point-detail .selected {
  width: 100%;
  height: 1.1rem;
  background: #ffffff;
  margin-top: 0.2rem;
  position: relative;
}
.point-detail .selected .text {
  width: 0.56rem;
  height: 1.1rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #aaaaaa;
  line-height: 1.1rem;
  position: absolute;
  left: 0.31rem;
  top: 0rem;
}
.point-detail .selected .content {
  width: 3.09rem;
  height: 1.1rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 500;
  color: #111111;
  line-height: 1.1rem;
  position: absolute;
  left: 1.17rem;
}
.point-detail .selected .icon {
  width: 0.42rem;
  height: 0.1rem;
  background: url("../../../static/point/6_d02_more.png") no-repeat 0px 0px;
  background-size: cover;
  position: absolute;
  left: 6.3rem;
  top: 0.49rem;
}
.point-detail .pictures {
  width: 100%;
  height: 3.2rem;
  background: #ffffff;
  margin-top: 0.21rem;
  position: relative;
}

.point-detail .pictures .text {
  width: 1.74rem;
  height: 1.1rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #aaaaaa;
  line-height: 1.1rem;
  position: absolute;
  top: 0rem;
  left: 2.88rem;
}
.point-detail .buy {
  position: fixed;
  bottom: 0.83rem;
  left: 0;
  right: 0;
  height: 1.03rem;
}

.point-detail .buy button {
  border: none;
  background-color: transparent;
  outline: none;
  display: block;
  width: 6.9rem;
  height: 0.8rem;
  background: #fe9700;
  border-radius: 0.45rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 0.4rem;
  margin: 0 auto;
}
</style>
