<template>
  <div class="sale">
    <div style="height: 3.75vw"></div>
    <div class="banner">
      <img :src="weChatUrl">
    </div>

    <div>
      <div class="shop-block" v-for="data in user_goods_list" @click="goToBuy(data)">
        <div class="shop">
          <div class="img-block">
            <img :src="data.goods_desc.img[0].url">
          </div>
          <div>
            <div class="title">
              {{data.name}}
            </div>
            <div class="content">
              {{data.goods_desc.desc}}
            </div>
            <div class="price">
              >>立即购买<<
            </div>
          </div>
        </div>
      </div>
    </div>


  </div>
</template>

<script>
  import weChatUrl from '../../assets/shop/sale.png'
  import {getOrderDetailApi,getGoodsDetailApi,getGoodsListApi} from "../../service/api";
  export default {
    name: "saleSuccess",
    data(){
      return {
        invite_code:'',
        weChatUrl:weChatUrl,
        orderNo:this.$route.query.out_trade_no,
        goods_id:'',
        user_goods_list:[]
      }
    },
    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}`;
          getGoodsDetailApi(this.goods_id).then(res=>{
            let user_goods_id = JSON.parse(res.desc).use_goods_ids;
            getGoodsListApi({goods_ids:user_goods_id}).then(res=>{
              this.user_goods_list = [];
              for(let i = 0; i < res.list.length ; i ++){
                res.list[i].desc = JSON.parse(res.list[i].desc);
                res.list[i].goods_desc = JSON.parse(res.list[i].goods_desc);
                res.list[i].share_desc = JSON.parse(res.list[i].share_desc)
                this.user_goods_list.push(res.list[i])
              }
            });
          })
        })
      },
      goToBuy(data){
        this.$router.push({name:'buyDetail',query:{shopId:data.id,invite_code:this.invite_code}})
      }
    }
  }
</script>

<style scoped lang="less">
  @import "../../util/public";
  .sale{
    background: #eeeeee;
    .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;
        }
      }
    }
    .banner{
      margin: 0 0 10 * @toVw 0;
      background: white;
      padding: 10 * @toVw;
      img{
        width: 100%;
      }
    }
  }

</style>
