livedGoodsDia.vue 8.04 KB
Newer Older
李嘉林 committed
1 2 3 4 5
<template>
  <div class="livedGoodsList">
    <van-popup
      :show="showDia"
      position="bottom"
程智春 committed
6
      custom-style="height: 50vh;border-top-left-radius:10px;border-top-right-radius:10px;"
李嘉林 committed
7 8 9
      :close-on-click-overlay="true"
      @close="closeDia"
    >
程智春 committed
10 11 12 13 14 15 16 17

      <div class="tit" v-if="list.length>0">
          <span>商品列表</span>
          <span>({{list.length}})</span>
        </div>
        
        <div class="list" v-if="list.length>0">
        
程智春 committed
18 19
          <div class="item" v-for="(item,index) in list" :key="index" @click="toGoodsInfo(item)">
            <div class="img" >
程智春 committed
20 21 22 23 24
              <div class="num">{{item.number}}</div>
              <!-- <img v-if="item.productImgUrl" :src="item.productImgUrl" alt /> -->
              <image v-if="item.productImgUrl" :src="item.productImgUrl" mode="aspectFill" alt=""></image>
            </div>
            <div class="info">
程智春 committed
25
              <div class="name text-overflow2">{{item.productName}}</div>
程智春 committed
26 27
              <div class="bottom">
                <div class="price">
程智春 committed
28
                  <div>
程智春 committed
29 30
                    <span></span>
                    <span>{{item.minPrice}}</span>
程智春 committed
31
                  </div>
程智春 committed
32 33 34 35 36
                  <!-- <p class="del">
                    <span></span>
                    <span>{{999}}</span>
                  </p>-->
                </div>
程智春 committed
37
                <div class="icon" @click.stop="isLogin(item)">
程智春 committed
38 39
                  <img src="../../../static/images/lived/shopCart.png" alt="">
                </div>
李嘉林 committed
40 41 42 43
              </div>
            </div>
          </div>
        </div>
程智春 committed
44 45
      
      
李嘉林 committed
46
      <div style="text-align:center;font-size:16px;padding-top:10px;" v-else>暂无商品</div>
李嘉林 committed
47
    </van-popup>
李嘉林 committed
48
    <!-- 选择规格弹层 -->
李嘉林 committed
49 50 51 52 53 54 55 56 57 58 59 60
    <livedSelectionSpe
      v-if="showSpe"
      :show="showSpe"
      :productInfoId="itemGoods.productId"
      :minSale="itemGoods.minSale"
      :maxSale="itemGoods.maxSale"
      :goodsImg="itemGoods.goodsImg"
      :minSuggestedRetailPrice="itemGoods.minSuggestedRetailPrice"
      :maxSuggestedRetailPrice="itemGoods.maxSuggestedRetailPrice"
      :goodsLowerShelf="itemGoods.goodsLowerShelf"
      @closeSpeDia="closeSpeDia"
    ></livedSelectionSpe>
李嘉林 committed
61 62 63 64
  </div>
</template>

<script type="text/ecmascript-6">
李嘉林 committed
65
import livedSelectionSpe from "@/components/livedModel/livedSelectionSpe";
李嘉林 committed
66 67
import { DFSImg } from "@/utils/index";
import live from "@/api/live";
李嘉林 committed
68
export default {
李嘉林 committed
69
  props:["showDia","updateGoods","goodsList"],
李嘉林 committed
70 71 72
  name: "",
  data() {
    return {
李嘉林 committed
73
      liveId: 0,
李嘉林 committed
74
      list: [],
李嘉林 committed
75
      itemGoods: {}, //选中商品
李嘉林 committed
76
      showSpe: false
李嘉林 committed
77 78
    };
  },
李嘉林 committed
79 80 81
  components: {
    livedSelectionSpe
  },
李嘉林 committed
82 83 84 85
  watch:{
    updateGoods(){
      this.list=this.goodsList;
      this.list.forEach((item, index) => {
程智春 committed
86
        item.minPrice = Number(item.minPrice).toFixed(2);
李嘉林 committed
87 88 89
      });
    },
  },
李嘉林 committed
90 91
  computed: {},
  created() {},
李嘉林 committed
92
  onLoad(options) {
程智春 committed
93 94 95 96 97 98 99 100 101 102
    if(options.params){
      let params = JSON.parse(options.params);
      this.liveId = params.liveId;  
    }else if(options.scene){
      var scene = decodeURIComponent(options.scene); //参数二维码传递过来的参数
      console.log(scene)
      let sceneInfo = scene.split(',')
      console.log('sceneInfo',sceneInfo)
      this.liveId = sceneInfo[0].split('=')[1]
    }
李嘉林 committed
103
  },
李嘉林 committed
104 105 106 107 108
  mounted() {},
  methods: {
    //   关闭
    closeDia() {
      this.$emit("changeStatus");
李嘉林 committed
109
    },
李嘉林 committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    // 是否登录
    isLogin(val) {
      let _this = this;
      wx.getStorage({
        key: "sessionid",
        success(res) {
          _this.showSpeDia(val);
        },
        fail(res) {
          console.log("未登录------150");
          // 跳转登录页
          let backUrl = "/lived/main";
          let query = {
            liveId: _this.liveId,
            fromType: "mini"
          };
          let url = `/pages/login/main?back=${backUrl}&params=${JSON.stringify(
            query
          )}`;
          wx.navigateTo({
            url: url
          });
        }
      });
    },
李嘉林 committed
135
    showSpeDia(val) {
李嘉林 committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
      if (val.multiSpecificationFlag != 1) {
        // 不是多规格直接加入购物车
        live
          .addCart([{ productGoodsId: val.productGoodsId, qty: 1}])
          .then(res => {
            if (res.data.code == 200) {
              wx.showToast({
                title: "加入成功",
                icon: "success"
              });
              this.showSize = false;
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: "none"
              });
            }
          });
        return;
      }
李嘉林 committed
156 157
      let productId = val.productId;
      this.itemGoods.productId = productId;
李嘉林 committed
158
      wx.showLoading({
李嘉林 committed
159 160 161
        title: "加载中..."
      });
      live.getProductInfo(productId).then(res => {
李嘉林 committed
162
        wx.hideLoading();
李嘉林 committed
163 164 165 166 167 168 169 170 171 172 173 174 175
        if (res.data.code == 200) {
          this.itemGoods.maxSale = Number(
            res.data.data.maxSuggestedRetailPrice
          );
          this.itemGoods.minSale = Number(
            res.data.data.minSuggestedRetailPrice
          );
          this.itemGoods.maxDiscountPrice = Number(
            res.data.data.maxDiscountPrice
          );
          this.itemGoods.minDiscountPrice = Number(
            res.data.data.minDiscountPrice
          );
李嘉林 committed
176
          this.itemGoods.productNature = res.data.data.productNature;
李嘉林 committed
177 178 179 180 181 182 183 184 185 186
          this.itemGoods.goodsLowerShelf =
            res.data.data.saleStatus != 1 ? true : false; //1 上架  0下架  true 下架
          if (
            res.data.data.productPictures &&
            res.data.data.productPictures.length > 0
          ) {
            this.itemGoods.goodsImg = DFSImg(
              res.data.data.productPictures[0].url
            );
          }
李嘉林 committed
187
          this.showSpe = true;
李嘉林 committed
188
        } else {
李嘉林 committed
189 190
          wx.showToast({
            title: res.data.msg,
李嘉林 committed
191 192
            icon: "none"
          });
李嘉林 committed
193
        }
李嘉林 committed
194
      });
李嘉林 committed
195
    },
李嘉林 committed
196 197
    closeSpeDia() {
      this.showSpe = false;
李嘉林 committed
198 199
    },
    // 到商品详情
李嘉林 committed
200
    toGoodsInfo(val) {
李嘉林 committed
201 202 203 204 205 206
      // 点击商品埋点
      let info={
        liveBroadcastId:Number(this.liveId),
        liveBroadcastGoodsId:Number(val.productId),
      }
      live.addLiveUserGoodsByUser(info).then(res=>{});
李嘉林 committed
207 208 209 210
      let query = {
        fromLived: 1,
        liveId: this.liveId
      };
李嘉林 committed
211
      let backPath = `/goods/${val.productId}`;
李嘉林 committed
212
      wx.reLaunch({
李嘉林 committed
213
        url: `../index/main?from=livedToGoodsInfo&backpath=${
李嘉林 committed
214
          backPath
李嘉林 committed
215 216
        }&params=${JSON.stringify(query)}`
      });
李嘉林 committed
217 218 219 220 221 222
    }
  }
};
</script>

<style lang="scss" scoped>
李嘉林 committed
223 224 225
img{
  display: block;
}
李嘉林 committed
226
.livedGoodsList {
程智春 committed
227 228
  .tit {
      font-size: 16px;
程智春 committed
229
      padding: 10px 10px;
程智春 committed
230
    }
李嘉林 committed
231
  .list {
程智春 committed
232 233
    overflow-y:auto;
    max-height: 44vh;
李嘉林 committed
234 235 236 237
    .item {
      padding: 10px 4px;
      display: flex;
      align-items: center;
程智春 committed
238 239 240
      padding: 14px;
      box-sizing: border-box;
      border-bottom: 1rpx solid #EEEEED;
李嘉林 committed
241 242 243 244 245
      .img {
        width: 70px;
        height: 70px;
        border-radius: 6px;
        overflow: hidden;
李嘉林 committed
246
        background: #999;
李嘉林 committed
247
        position: relative;
程智春 committed
248
        image {
李嘉林 committed
249 250 251 252
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
李嘉林 committed
253 254 255 256 257 258 259 260 261 262
        .num {
          position: absolute;
          top: 0;
          left: 0;
          color: #fff;
          font-size: 12px;
          background: #666;
          padding: 2px 6px;
          border-bottom-right-radius: 6px;
        }
李嘉林 committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
      }
      .info {
        flex: 1;
        height: 80px;
        margin-left: 16px;
        color: #333;
        font-size: 16px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .name {
          text-align: left;
        }
        .bottom {
          display: flex;
          justify-content: space-between;
          align-items: center;
          span {
            color: #ff0000;
          }
          .price {
            font-size: 18px;
李嘉林 committed
285
            .del {
李嘉林 committed
286 287 288 289 290 291 292 293
              font-size: 16px;
              text-decoration: line-through;
              span {
                color: #666;
              }
            }
          }
          .icon {
李嘉林 committed
294 295 296 297
            img{
              width: 30px;
              height: 26px;
            }
李嘉林 committed
298 299 300 301 302 303 304
          }
        }
      }
    }
  }
}
</style>