goodsList.vue 4.12 KB
<template>
  <div>
    <template v-for="(item,index) in list">
      <div
        :class="['goods',{'false':!defaultType}]"
        :key="index"
      >
        <img
          :src="item.goodsImage"
          class="icon"
        >
        <div class="info">
          <div class="flex">
            <template v-if="defaultType">
              <div class="label">
                商品名称:
              </div>
            </template>
            <div class="text-hide">
              {{item.goodsName}}
            </div>
          </div>
          <template v-if="defaultType">
            <div class="flex">
              <div class="label">
                众筹价:
              </div>
              <div class="price">
                {{item.crowdFundingPrice}}
              </div>
            </div>
          </template>
          <div class="flex">
            <div class="label">
              定金:
            </div>
            <div class="price">
              {{item.activityPrice}}
            </div>
          </div>
        </div>
        <div class="stepper flex">
          <div
            :class="['minus count-box',{'opacity': item.goodsNumber == 0}]"
            @click="change(index)"
          ></div>
          {{item.goodsNumber}}
          <div
            :class="['add count-box', {'opacity':item.goodsNumber == item.goodsStock }]"
            @click="change(index,true)"
          ></div>
        </div>
      </div>
    </template>
  </div>
</template>

<script type='text/ecmascript-6'>
export default {
  name: 'goodsList',
  props: {
    list: Array,
    defaultType: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {

    }
  },

  mounted () {
  },
  methods: {
    change (index, add) {
      const { list } = this,
        num = add ? 1 : -1
      let {
        goodsNumber,
        goodsStock
      } = list[index]
      if (goodsNumber == 0 && !add) return
      if (goodsNumber == goodsStock && add) return
      goodsNumber += num
      this.bus.$emit('changeUserSelectGoodsList', {
        index,
        goodsNumber
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.flex {
  display: flex;
  align-items: center;
}

.text-hide {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.goods {
  padding: 10px;
  background: #ffffff;
  margin-bottom: 8px;
  display: flex;
  position: relative;

  &:last-of-type {
    margin-bottom: 0;
  }

  .icon {
    width: 72px;
    height: 72px;
    flex-shrink: 0;
  }

  .info {
    margin-left: 10px;
    flex: 1;
    font-size: 14px;
    color: #333333;
    line-height: 20px;
    width: calc(100% - 82px);

    > .flex {
      margin-bottom: 4px;
    }

    .text-hide {
      width: calc(100% - 70px);
    }

    .label {
      width: 70px;
      flex-shrink: 0;
      text-align: right;
    }

    .price {
      font-weight: 600;
      color: #f13c3d;
    }
  }

  .stepper {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    font-size: 16px;
    color: #333333;

    .count-box {
      width: 14px;
      height: 14px;
      background-color: #f4f4f4;
      margin: 0 10px;
      font-size: 13px;
      border-radius: 2px;
      position: relative;
    }

    .add {
      margin-right: 0;
      background-color: #f13c3d;
    }

    .opacity::after,
    .opacity::before {
      opacity: 0.25;
    }

    .minus::after,
    .add::after,
    .add::before {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      content: '';
      background-color: #999999;
      border-radius: 8px;
    }

    .minus::after,
    .add::before {
      width: 7.5px;
      height: 1.5px;
    }

    .add::after {
      width: 1.5px;
      height: 7.5px;
    }

    .add::before,
    .add::after {
      background-color: #fff;
    }
  }
}

.goods.false {
  align-items: center;
  border-bottom: 2rpx solid rgba(195, 195, 195, 0.3);
  margin-bottom: 0;
  padding: 10px 16px;
  .icon {
    width: 60px;
    height: 60px;
  }

  .info {
    > .flex {
      margin-bottom: 6px;
    }

    .text-hide {
      width: 100%;
    }

    .label {
      width: auto;
    }
  }
}
</style>