size-select-sheet.vue 5.74 KB
<template>
  <action-sheet @hidden="onHidden" ref="popup">
    <div class="size-select-sheet">
      <div class="select-size">
        <div class="title" @click="hide">{{config.title}}<i class="cubeic-close"></i></div>
        <div class="selected-info">
          <div class="title-thumbnail">
            <square-img :src="imageList[0] && imageList[0].image_url" :width="70" :height="70"/>
          </div>
          <div class="product">
            <div>
              <template v-if="product.least_price >= 0"> ¥{{product.least_price}}</template>
              <template v-else>&nbsp;</template>
            </div>
            <div>
              {{goods_name}}
              <template v-if="goods_name && sizeName">,</template>
              {{sizeName}}
            </div>
          </div>
        </div>
        <size-list class="select-content size-list" :list="list" :addSize="canAddSize" :selected="selectedSize"
                   @select="onSelectSize"
                   @add="onAdd" />
        <transition name="slide-up">
          <div class="footer" v-if="isTradable">
            <cube-button @click="select" class="active">{{config.title}}</cube-button>
          </div>
        </transition>
      </div>
    </div>
  </action-sheet>
</template>

<script>
import { Scroll, Button } from 'cube-ui';
import { get } from 'lodash';
import { createNamespacedHelpers } from 'vuex';

import ActionSheet from './action-sheet';
import SizeList from './size-list';
import SquareImg from './square-img';

const { mapActions, mapState } = createNamespacedHelpers('product');

export default {
  name: 'SizeSelectSheet',
  props: {
    list: {
      type: Array,
      required: true,
    },
    imageList: {
      type: Array,
      required: true,
    },
    product: { // 获取productId, goods_name
      type: Object,
      required: true,
    },

    /**
     * config.type sell|buy
     * config.title
     */
    config: {
      type: Object,
      required: true,
    }
  },
  components: {
    SquareImg,
    SizeList,
    'cube-button': Button,
    'cube-scroll': Scroll,
    'action-sheet': ActionSheet,
  },
  computed: {
    ...mapState(['selectedProductInfo']),
    selectedSize() {
      if (this.selectedProductInfo.productId === this.product.product_id) {
        return this.selectedProductInfo.size;
      }

      return {};
    },
    goods_name() {
      return get(this.product, 'goods_list[0].goods_name', '');
    },
    sizeName() {
      if (this.selectedSize && this.selectedSize.name) {
        return this.selectedSize.name + '码';
      }

      return null;
    },
    canAddSize() {
      return get(this.product, 'goods_list[0].canAddSize', false);
    },

    isAvailable() {
      return this.selectedSize && this.selectedSize.size_id > 0;
    },

    /**
     * 可交易(购买|出售)
     */
    isTradable() {
      return this.isAvailable && this.selectedSize.storage_num > 0 && this.selectedSize.least_price !== '-';
    },
  },
  mounted() {
    this.$refs.popup.show();
  },
  methods: {
    ...mapActions(['updateTradeInfo']),
    onHidden() {
      this.$emit('hidden');
    },
    onSelectSize({selected: sizeInfo}) {
      this.updateTradeInfo({
        productId: this.product.product_id,
        sizeInfo,
      });
    },
    hide() {
      this.$refs.popup.hide();
    },
    onAdd() {
      this.$emit('add');
    },
    select() {
      if (!this.isTradable) {
        return;
      }
      this.$emit('select', {
        productId: this.product.product_id,
        storageId: this.selectedSize.storage_id,
        skup: this.selectedSize.skup,
        bid_skup: this.selectedSize.bid_skup,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
  @import "../product-detail";

  .title {
    font-size: 40px;
    line-height: 96px;

    i {
      float: right;
    }
  }

  .size-select-sheet {
    padding: 0 40px 16px;
  }

  .select-size, .select-type {
    display: flex;
    flex-direction: column;
    height: 60vh;
  }

  .selected-info {
    display: flex;
    padding-bottom: 20px;

    .product {
      margin-left: 40px;

      div {
        font-size: 24px;
        color: #999;
      }

      div:first-child {
        padding-top: 30px;
        font-size: 32px;
        color: #000;
      }
    }
  }

  .title-thumbnail {
    width: 140px;
    height: 140px;
  }

  .select-content {
    flex: 1;
    overflow: auto;
  }

  .select-type {
    overflow: scroll;

    .info {
      position: relative;
      padding: 20px 40px 40px;
      text-align: center;
    }

    .back {
      position: absolute;
      top: 20px;
      left: 0px;
      width: 48px;
      height: 48px;
      background: url(~statics/image/order/back@3x.png) no-repeat;
      background-size: cover;
    }

    h2 {
      font-size: 32px;
    }

    .sub-title {
      font-size: 24px;
      color: #ccc;
      line-height: 1.8;
    }
  }

  .trade-type {
    background: $primary-color;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 32px;
    padding: 40px;
    margin-bottom: 40px;

    .title {
      line-height: 1.8;
    }

    .desc {
      font-size: 24px;
      color: #999;
    }

    .price {
      display: flex;
      align-items: center;
      color: $sub-color;

      i {
        display: inline-block;
        margin-left: 5px;
        color: #999;
      }
    }
  }

  .type-wrap {
    overflow: scroll;
  }

  .footer {
    padding: 16px 0;
    display: flex;
    justify-content: space-between;

    @include cube-ufo-btn;

    span {
      font-size: 28px;

      i {
        font-size: 20px;
        font-style: normal;
      }
    }
  }
  .slide-up-enter,
  .slide-up-leave-to {
    transform: translateY(60%);
    opacity: 0;
  }

  .slide-up-enter-active,
  .slide-up-leave-active {
    transition: all 0.3s ease-in;
  }
</style>