livedExplainingCommodities.vue 8.45 KB
Newer Older
李嘉林 committed
1 2 3
<template>
  <!-- 讲解商品 -->
  <div class="livedExplainingCommodities">
程智春 committed
4
    <div class="goods clearfix" v-if="!showFixedGoods" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend">
李嘉林 committed
5 6 7 8 9
      <div
        class="goodsList"
        :class="{isEC:item.upperScreenState==1}"
        v-for="(item,index) in list"
        :key="index"
10
        @click="toGoodsInfo(item)"
李嘉林 committed
11
      >
程智春 committed
12 13
        <!-- <img :src="item.productImgUrl" alt /> -->
        <image :src="item.productImgUrl" mode="aspectFill" alt=""></image>
李嘉林 committed
14
        <p class="num">{{item.number}}</p>
李嘉林 committed
15
        <div class="explain" v-if="item.upperScreenState==1">讲解中</div>
李嘉林 committed
16 17 18
      </div>
    </div>
    <!-- 左上角展示讲解中商品 -->
程智春 committed
19
    <div class="fixedGoods" v-else-if="showFixedGoods&&fixedGoodsList&&fixedGoodsList.length>0&&!isFocusComments">
20
      <div class="goodsList" v-for="(item,index) in fixedGoodsList" :key="index" @click="toGoodsInfo(item)">
李嘉林 committed
21
        <div class="explain" v-if="item.upperScreenState==1">讲解中</div>
程智春 committed
22 23
        <image :src="item.productImgUrl" mode="aspectFill" alt=""></image> 
        <div class="price" v-if="item.minPrice">
李嘉林 committed
24
          <span></span> <span>{{item.minPrice}}</span>
程智春 committed
25
        </div>
李嘉林 committed
26 27 28 29 30 31
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
李嘉林 committed
32
import { DFSImg } from "@/utils/index";
33
import live from "@/api/live";
李嘉林 committed
34
export default {
程智春 committed
35
  props: ["updateGoods", "goodsList","isFocusComments"],
李嘉林 committed
36 37 38 39
  name: "",
  data() {
    return {
      showFixedGoods: false, //展示讲解中商品方式  false底部|true左侧固定
李嘉林 committed
40
      list: [],
李嘉林 committed
41
      // 讲解中浮动商品
李嘉林 committed
42
      fixedGoodsList: [],
程智春 committed
43 44
      firstCom: true, //首次进入
      liveId: 0,
程智春 committed
45 46 47 48

      fixedGoodsTimer : null, //讲解商品隐藏的定时器

      reserveList : []
李嘉林 committed
49 50
    };
  },
李嘉林 committed
51 52
  watch: {
    updateGoods() {
李嘉林 committed
53
      console.log(this.goodsList,'---------------------------------46goodsList')
程智春 committed
54 55 56
      this.goodsList.forEach((item,index) => {
        this.$set(this.goodsList[index],'minPrice',Number(item.minPrice).toFixed(2))
      })
程智春 committed
57
      console.log(this.firstCom,'this.firstCom----------')
李嘉林 committed
58 59 60 61 62 63 64
      if (this.firstCom == true) {
        this.list = [];
        this.firstCom = false;
        let arr1 = [];
        let arr2 = [];
        this.goodsList.forEach((item, index) => {
          if (item.upperScreenState == 1) {
李嘉林 committed
65
            arr1.push(item);
程智春 committed
66
          } else if (item.upperScreenState == 0 || item.upperScreenState == 2) {
李嘉林 committed
67 68 69
            arr2.push(item);
          }
        });
程智春 committed
70 71 72


        
李嘉林 committed
73
        this.list = [...arr1, ...arr2];
程智春 committed
74
        this.reserveList = arr1;
程智春 committed
75
        console.log(this.list,'--------------------------------this.list1212')
程智春 committed
76
        this.fixedGoodsTimer = setTimeout(() => {
程智春 committed
77
          console.log('这是上屏商品',arr1)
李嘉林 committed
78 79 80
          this.fixedGoodsList = arr1 ? arr1 : [];
          this.showFixedGoods = true;
        }, 5000);
李嘉林 committed
81 82 83 84 85
      } else {
        if (!this.equalsObj(this.list, this.goodsList)) {
          let newArr = [];
          newArr = this.goodsList.filter((item, index) => {
            if (item.upperScreenState == 1) {
李嘉林 committed
86 87 88
              return item;
            }
          });
李嘉林 committed
89
          if (newArr) {
程智春 committed
90
            console.log('这是上屏商品',newArr)
李嘉林 committed
91
            this.fixedGoodsList = newArr;
李嘉林 committed
92
          }
李嘉林 committed
93 94 95 96
        }
      }
    }
  },
李嘉林 committed
97 98 99
  components: {},
  computed: {},
  created() {},
程智春 committed
100
  onLoad(options) {
程智春 committed
101 102 103 104 105 106 107 108 109 110
    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
111
  },
李嘉林 committed
112 113 114 115 116
  onUnload() {
    this.fixedGoodsList = [];
    this.showFixedGoods = false;
  },
  mounted() {},
李嘉林 committed
117
  methods: {
程智春 committed
118
    
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    // 到商品详情
    toGoodsInfo(val) {
      // 点击商品埋点
      let info={
        liveBroadcastId:Number(this.liveId),
        liveBroadcastGoodsId:Number(val.productId),
      }
      live.addLiveUserGoodsByUser(info).then(res=>{});
      let query = {
        fromLived: 1,
        liveId: this.liveId
      };
      let backPath = `/goods/${val.productId}`;
      wx.reLaunch({
        url: `../index/main?from=livedToGoodsInfo&backpath=${
          backPath
        }&params=${JSON.stringify(query)}`
      });
    },
李嘉林 committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    /**
     * 判断此对象是否是Object类型
     * @param {Object} obj
     */
    isObject(obj) {
      return Object.prototype.toString.call(obj) === "[object Object]";
    },
    /**
     * 判断此类型是否是Array类型
     * @param {Array} arr
     */
    isArray(arr) {
      return Object.prototype.toString.call(arr) === "[object Array]";
    },

    /**
     *  深度比较两个对象是否相同
     * @param {Object} oldData
     * @param {Object} newData
     */
    equalsObj(oldData, newData) {
      // 类型为基本类型时,如果相同,则返回true
      if (oldData === newData) return true;
      if (
        this.isObject(oldData) &&
        this.isObject(newData) &&
        Object.keys(oldData).length === Object.keys(newData).length
      ) {
        // 类型为对象并且元素个数相同

        // 遍历所有对象中所有属性,判断元素是否相同
        for (const key in oldData) {
          if (oldData.hasOwnProperty(key)) {
            if (!this.equalsObj(oldData[key], newData[key]))
              // 对象中具有不相同属性 返回false
              return false;
          }
        }
      } else if (
        this.isArray(oldData) &&
        this.isArray(oldData) &&
        oldData.length === newData.length
      ) {
        // 类型为数组并且数组长度相同

        for (let i = 0, length = oldData.length; i < length; i++) {
          if (!this.equalsObj(oldData[i], newData[i]))
            // 如果数组元素中具有不相同元素,返回false
            return false;
        }
      } else {
        // 其它类型,均返回false
        return false;
      }

      // 走到这里,说明数组或者对象中所有元素都相同,返回true
      return true;
程智春 committed
195 196 197 198 199 200 201 202 203 204 205 206 207
    },
    touchstart(){
      clearTimeout(this.fixedGoodsTimer)
    },
    touchmove(){
      clearTimeout(this.fixedGoodsTimer)
    },
    touchend(){
      this.fixedGoodsTimer = setTimeout(() => {
        this.fixedGoodsList = this.reserveList
        this.showFixedGoods = true;
      },5000)
    },
李嘉林 committed
208
  }
李嘉林 committed
209 210 211 212
};
</script>

<style lang="scss" scoped>
李嘉林 committed
213
img {
李嘉林 committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
  display: block;
}
.fl {
  float: left;
}
/*清除浮动*/
.clearfix {
  zoom: 1;
}

.clearfix:after {
  clear: both;
  content: ".";
  display: block;
  width: 0;
  height: 0;
  visibility: hidden;
}
.livedExplainingCommodities {
  width: 100%;
  padding: 0 12px;
  overflow-x: auto;
  .goods {
    overflow-x: auto;
    white-space: nowrap;
    overflow-y: hidden;
    margin-bottom: 10px;
    .goodsList {
      display: inline-block;
      position: relative;
      width: 30vw;
      height: 30vw;
      border: 1px solid #949494;
      margin-right: 10px;
      overflow: hidden;
程智春 committed
249 250 251
      image {
        width: 30vw;
        height: 30vw;
李嘉林 committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
      }
      .num {
        position: absolute;
        top: 0;
        left: 0;
        color: #fff;
        font-size: 12px;
        background: #666;
        padding: 2px 4px;
        border-bottom-right-radius: 6px;
      }
      .explain {
        position: absolute;
        top: 0;
        right: 0;
        color: #fff;
        font-size: 12px;
        background: #ff3334;
        padding: 2px 4px;
        border-bottom-left-radius: 6px;
      }
    }
  }
  .isEC {
    border-color: #ff3334;
  }
  .fixedGoods {
    position: fixed;
程智春 committed
280
    top: 22vh;
李嘉林 committed
281
    left: 12px;
李嘉林 committed
282
    .goodsList {
程智春 committed
283 284 285 286 287 288
       width: 78px;
        margin-bottom: 15px;
        border-radius: 2px;
        overflow: hidden;
        position: relative;
        background-color: white;
程智春 committed
289
      image {
李嘉林 committed
290
        width: 22vw;
程智春 committed
291
        height: 78px;
李嘉林 committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305
      }
      .num {
        position: absolute;
        top: 0;
        left: 0;
        color: #fff;
        font-size: 12px;
        background: #666;
        padding: 2px 4px;
        border-bottom-right-radius: 6px;
      }
      .explain {
        position: absolute;
        top: 0;
李嘉林 committed
306
        left: 0;
李嘉林 committed
307 308 309 310
        color: #fff;
        font-size: 12px;
        background: #ff3334;
        padding: 2px 4px;
李嘉林 committed
311 312 313 314 315 316 317
        border-bottom-right-radius: 6px;
      }
      .price{
        width: 100%;
        color: #FA7018;
        background: #fff;
        text-align: center;
程智春 committed
318
        height: 21px;
李嘉林 committed
319
        font-size: 16px;
程智春 committed
320
        line-height: 17px;
李嘉林 committed
321 322 323 324 325
      }
    }
  }
}
</style>