<template>
  <div class="buy-success">
    <div class="banner">
      <img :src="img.weChat">
    </div>
    <div>
      <div class="shop-block" v-if="goodsDetail">
        <div class="shop">
          <div class="img-block">
            <img :src="goodsDetail.goods_desc.img[0].url">
          </div>
          <div>
            <div class="title">
              {{goodsDetail.name}}
            </div>
            <div class="content">
              {{goodsDetail.goods_desc.desc}}
            </div>
            <div class="price">
              价格 ￥{{money/100}}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="button-block">
      <mt-button type="danger" size="large" @click="goIndex()">进入课程</mt-button>
    </div>
  </div>
</template>

<script>
  import {shopSuccess} from "../../util/imgUrl";
  import {getOrderDetailApi,getGoodsDetailApi} from "../../service/api";
  export default {
    name: "buySuccess",
    data(){
      return {
        img:shopSuccess,
        orderNo: this.$route.query.out_trade_no,
        goods_id:0,
        money:0,
        invite_code:'',
        goodsDetail:null
      }
    },
    mounted(){
      this.initPage()
    },
    methods:{
      initPage(){
        getOrderDetailApi(this.orderNo).then(res=>{
          this.goods_id = res.goods_id;
          this.invite_code = `CC-${res.invite_type}-${res.invite_id}`
          this.money = res.money;
          getGoodsDetailApi(this.goods_id).then(data=>{
            data.desc = JSON.parse(data.desc);
            data.goods_desc = JSON.parse(data.goods_desc);
            data.share_desc = JSON.parse(data.share_desc);
            this.goodsDetail = data;
          })
        })
      },
      goIndex(){
        this.$router.push({name:'index'})
      }
    }
  }
</script>

<style scoped lang="less">
  @import "../../util/public";
  .buy-success{
    background: #eee;
    .banner{
      padding: 20 * @toVw;
      background: white;
      text-align: center;
      margin-bottom: 10 * @toVw;
      img{
        width: 100%;
      }
    }
    .shop-block{
      background: white;
      .shop{
        padding: 20/7.5vw;
        border-bottom: 1px solid #d8d8d8;
        position: relative;
        &:after{
          content:'';
          display: block;
          clear: both;
        }
        .img-block{
          float: left;
          margin-right: 20/7.5vw;
          img{
            width: 250/7.5vw;
          }
          min-height: 120px;
        }

        .title{
          font-size: 18px;
          overflow: hidden;
          text-overflow:ellipsis;
          white-space: nowrap;
          color: #333333;
          margin-bottom: 5/7.5vw;
        }
        .content{
          font-size: 12px;
          line-height: 1.4em;
          color: #CCCCCC;
          height: 4.2em;
          overflow: hidden;

        }
        .price{
          font-size: 18px;
          color: #FF001F;
          position: absolute;
          right: 20/7.5vw;
          bottom: 20/7.5vw;
        }
      }
    }
    .button-block{
      position: fixed;
      bottom: 10*@toVw;
      width: 315 * @toVw;
      padding: 0 30 * @toVw;
      border-radius: 100px;
      overflow: hidden;
      button{
        border-radius: 1000px;
      }
    }
  }
</style>
