<template>
  <div class="productDetails" v-if="goodsInfo.picUrl">
    <img :src="goodsInfo.picUrl" alt="">
    <div class="type" :class="`type`+goodsInfo.type">{{ $dict.getLabel('integralSGType', goodsInfo.type) }}</div>
    <div class="product-info">
      <p>{{goodsInfo.title}}</p>
      <h3>{{goodsInfo.integralPrice}}积分<span v-if="goodsInfo.type == 1">+￥{{goodsInfo.payMoney}}<span v-if="goodsInfo.type == 1">（兑换后再付）</span></span></h3>
      <div>零售单价¥{{goodsInfo.retailPrice}}</div>
      <span class="tips" v-if="goodsInfo.type == 1">兑换成功后，点击「去购买」前往京东低价购买</span>
      <span class="tips" v-else>免费兑换商品，可到固定的兑换点进行「核销兑换」</span>
    </div>
    <div class="product-content">
      <p>商品描述：</p>
      <p v-html="goodsInfo.description"></p>
    </div>
    <div class="btn" @click="toOrder()" v-if="goodsInfo.shopStatus == 1">
      <div :class="total >= goodsInfo.integralPrice ? 'status1' : 'status0'" v-if="goodsInfo.stock > 0">{{total >= goodsInfo.integralPrice ? '立即兑换' : '积分不足'}}</div>
      <div class="status0" v-else>商品缺货</div>
    </div>
    <div class="btn" v-else>
      <div class="status0">店铺停用</div>
    </div>
  </div>
</template>

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

export default {
  name: 'productDetails',
  appName: '兑换商品',
  data() {
    return {
      shopGoodsId: '',
      goodsInfo: {},
      total: 0
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad(option) {
    this.shopGoodsId = option.shopGoodsId
    this.total = option.total
    this.$dict.load(['integralSGType']).then(() => {
      this.getDetail()
    })
  },
  methods: {
    getDetail() {
      this.$instance.post(`/app/appintegralsupermarketshop/queryGoodsInfoXCX?shopGoodsId=${this.shopGoodsId}`).then(res => {
        if (res.code === 0) {
          this.goodsInfo = res.data
        }
      })
    },
    toOrder() {
      if(this.total >= this.goodsInfo.integralPrice && this.goodsInfo.stock > 0 && this.goodsInfo.status == 1) {
        uni.navigateTo({url: `./placeOrder?shopGoodsId=${this.goodsInfo.shopGoodsId}&total=${this.total}&backLevel=4`})
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.productDetails {
  background-color: #f3f6f9;
  position: relative;
  img {
    width: 100%;
    height: 750px;
  }
  .type {
    position: absolute;
    top: 0;
    right: 0;
    line-height: 42px;
    font-family: PingFangSC-SNaNpxibold;
    font-weight: 600;
    font-size: 30px;
    color: #FFF;
    padding: 16px 16px 16px 36px;
    border-bottom-left-radius: 40px;
  }
  .type1 {
    background-color: #E64E39;
  }
  .type0 {
    background-color: #FF6900;
  }
  .product-info {
    padding: 32px;
    background-color: #fff;
    margin-bottom: 24px;
    p {
      word-break: break-all;
      font-family: PingFangSC-SNaNpxibold;
      font-weight: 600;
      font-size: 48px;
      color: #222;
      letter-spacing: 0;
      line-height: 76px;
      margin-bottom: 8px;
    }
    h3 {
      font-family: PingFangSC-SNaNpxibold;
      font-weight: 600;
      font-size: 44px;
      color: #FF6900;
      margin-bottom: 8px;
      span {
        font-size: 44px;
        color: #4181FF;
        margin-left: 8px;
        span {
          font-weight: 400;
          font-family: PingFangSC-Regular;
          font-size: 32px;
        }
      }
    }
    div {
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 24px;
      color: #999;
      line-height: 34px;
      margin-bottom: 24px;
      text-decoration: line-through;
    }
    .tips {
      display: inline-block;
      padding: 12px;
      line-height: 36px;
      background: #F5FCF5;
      border-radius: 16px;
      font-family: PingFangSC-Regular;
      font-size: 24px;
      color: #3BBC37;
    }
  }
  .product-content {
    padding: 34px 64px 162px;
    background-color: #fff;
    p {
      font-family: PingFangSC-Regular;
      font-size: 32px;
      color: #666;
      line-height: 60px;
    }
  }
  .btn {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    background-color: #fff;
    padding: 20px 32px;
    box-sizing: border-box;
    div {
      width: 100%;
      height: 88px;
      line-height: 88px;
      text-align: center;
      border-radius: 44px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
    }
    .status1 {
      color: #FFF;
      background: #4181FF;
    }
    .status0 {
      color: #666;
      background: #E2E2E2;
    }
  }
}
</style>
