GoodsBox.vue 6.45 KB
<template>
  <view class="goods-content">
    <template v-if="goodsList.length">
      <scroll-view scroll-y class="content-scroll-box" id="content-scroll" :style="{ height: contentHeight }"
        :scroll-top="flagObject.scrollTop">
        <template v-for="(i, index) in goodsList">
          <view :class="['goods-item', goodsIndex == index ? 'active' : '', `status-${i.isMainPush}`]" :key="index"
            @click="changeGoods(i, index)">
            <view :class="['goods-status flex']">{{ statusText(i.isMainPush) }}</view>
            <image class="goods-image" :src="i.thumbImageUrl"></image>
            <view class="goods-title">{{ i.tabName }}</view>
            <view class="goods-description">
              <rich-text :nodes="i.tabDescription"></rich-text>
            </view>
            <view class="goods-price">
              ¥ {{ i.discountPrice }}
              <view class="old-price">¥ {{ i.currentPrice }}</view>
            </view>
          </view>
        </template>
      </scroll-view>
    </template>
  </view>
</template>

<script type='text/ecmascript-6'>
export default {
  name: 'SkuBox',
  props: {
    currentCar: [Number, String],
    show: Boolean,
    activityData: Array,
    tabIndex: Number,
    hasBeforeActivity: Boolean,
    hasAfterActivity: Boolean,
    tabListId: Number,
  },

  data() {
    return {
      blockIndex: 0,
      secondIndex: 0,
      thirdlyIndex: 0,
      goodsIndex: -1,
      contentHeight: '0',
      currentItem: {},
      goodsList: [],
      requested: false,
      flagObject: {
        goodsFlag: false,
        scrollTop: 0
      }
    }
  },
  watch: {
    /**切换车型 */
    currentCar: {
      immediate: true,
      handler(newval) {
        if (this.show && this.requested) this.changeCar(newval)
      }
    },
    show: {
      immediate: true,
      handler(newval) {
        if (newval && !this.requested) {
          this.requested = true
          this.init()
        }
      }
    },
    watchStatus: {
      immediate: true,
      handler(newval) {
      }
    },
  },
  computed: {
    watchStatus() {
      return this.$store.state.user.historyStatus;
    },
  },
  mounted() {
  },
  methods: {
    init() {
      this.changeCar(this.currentCar)
    },
    changeCar(newval) {
      this.goodsList = []
      let { activityData, tabListId } = this,
        list = activityData.find(e => e.marketingStage == tabListId)
      if(!list) return
      let carSeriesList = list.carSeriesList,
        data = carSeriesList.find(e => e.carSeriesId == newval)
      if (data) {
        this.goodsIndex = -1
        this.setGoodsList(data.productList)
        this.$emit('noActivity', false)
      } else this.$emit('noActivity', true)

    },
    setScrollHeight() {
      this.$nextTick(() => {
        let query = uni.createSelectorQuery()
        query.select(`#content-scroll`).boundingClientRect(data => {
          this.contentHeight = `calc(100% - ${data.top - 72}px)`
          this.flagObject.scrollTop = 0
        }).exec()
      })
    },
    changeGoods(item, index, filter = true) {
      if (filter && this.goodsIndex == index) return
      this.goodsIndex = index
      this.currentItem = item
      this.changePreView()
    },
    setGoodsList(data) {
      this.goodsList = []
      this.flagObject.goodsFlag = false
      data.map(e => {
        if (e.tabDescription) e.tabDescription = e.tabDescription.replace(/<\/?br\s*\/?>|\\n|\n/g, '<br>')
      })
      this.goodsList = data
      this.flagObject.goodsFlag = true
      this.flagObject.scrollTop = -100
      setTimeout(() => {
        this.setScrollHeight()
        this.changeGoods(data[0], 0, false)
      }, 200)
    },
    changePreView() {
      this.$emit('changePreView', this.currentItem)
    },
    statusText(status) {
      return status == 1 ? '主推' : '次推'
    },
  }
}
</script>

<style scoped lang='scss'>
.goods-content {
  width: 100%;
  height: 100%;

  .content-scroll-box {
    .goods-item {
      position: relative;
      width: calc(100% - #{toRpx(64)});
      border: toRpx(3) solid #292D3333;
      min-height: toRpx(296);
      border-radius: toRpx(16);
      padding: toRpx(24) toRpx(32) toRpx(24) toRpx(232);
      margin-bottom: toRpx(24);
      transition: all 0.15s;

      .goods-status {
        position: absolute;
        right: 0;
        top: 0;
        height: toRpx(36);
        color: #FFFFFF;
        font-size: toRpx(24);
        justify-content: center;
        background: linear-gradient(90deg, #5C8AFF 0%, #49B6FF 100%);
        padding: 0 toRpx(20);
        border-radius: 0 toRpx(16) 0 toRpx(16);
      }

      .goods-image {
        position: absolute;
        width: toRpx(176);
        height: toRpx(240);
        top: toRpx(24);
        left: toRpx(32);
        border-radius: toRpx(12);
        overflow: hidden;
      }

      .goods-title {
        font-weight: 500;
        font-size: toRpx(30);
        color: #1A1A2E;
        line-height: toRpx(36);
        word-break: break-all;
      }

      .goods-description {
        margin-top: toRpx(8);
        font-size: toRpx(26);
        color: #6C6F75;
        line-height: toRpx(36);
        max-height: toRpx(144);
        overflow: hidden;
        word-break: break-all;
      }

      .goods-price {
        margin-top: toRpx(8);
        font-size: toRpx(36);
        color: #F24724;
        line-height: toRpx(44);
        display: flex;
        align-items: baseline;

        .old-price {
          font-size: toRpx(26);
          color: #999EA8;
          text-decoration: line-through;
          margin-left: toRpx(12);
        }
      }
    }

    .status-1 {
      .goods-status {
        background: linear-gradient(270deg, #FF6748 0%, #F24724 100%);
      }

      &::after {
        position: absolute;
        content: '';
        width: toRpx(296);
        height: toRpx(228);
        top: 0;
        right: 0;
        background: url('https://img02.glsx.com.cn/weapp/resource/app-tape/common/goods-status-1.webp') no-repeat center center;
        background-size: 100% 100%;
        z-index: -1;
      }
    }

    .active {
      border-color: #292D33;

      .goods-description {
        max-height: none;
        overflow: auto;
      }
    }
  }

  .nothing {
    flex-direction: column;
    padding-top: toRpx(136);
    font-size: toRpx(28);
    color: #999999;
    line-height: toRpx(40);

    &-icon {
      width: toRpx(676);
      height: toRpx(284);
      margin-bottom: toRpx(24);
      background-image: url('@/assets/images/boutique/nothing.webp');
      background-size: 100%;
    }
  }
}
</style>