size-select-sheet.vue 5.6 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">
          <img-size class="title-thumbnail" :src="imageList[0] && imageList[0].image_url" :width="70" :height="70"/>
          <div class="product">
            <div>¥{{product.least_price||''}}</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" />
        <div class="footer">
          <cube-button v-if="config.type === 'sell'" @click="convertToCash" :class="{active: isMarketable}">变现<span> <i>¥</i>{{cashPrice}}</span></cube-button>
          <cube-button @click="select" :class="{active: isTradable }">{{config.title}}</cube-button>
        </div>
      </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 ImgSize from '../../../components/img-size';
import SizeList from './size-list';

const { mapActions, mapGetters } = 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: {
    SizeList,
    ImgSize,
    'cube-button': Button,
    'cube-scroll': Scroll,
    'action-sheet': ActionSheet,
  },
  computed: {
    ...mapGetters(['selectedSize']),
    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);
    },

    /**
     * 可交易(购买|出售)
     */
    isTradable() {
      return this.selectedSize && this.selectedSize.size_id;
    },

    /**
     * 变现价格,使用bid_moster_price
     */
    cashPrice() {
      if (this.selectedSize && this.selectedSize.hasOwnProperty('bid_moster_price')) {
        return this.selectedSize.bid_moster_price;
      }

      return '-';
    },

    /**
     * 是否可变现
     */
    isMarketable() {
      return this.cashPrice !== '-' && this.cashPrice > 0;
    }
  },
  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,
      });
    },
    convertToCash() {
      if (!this.isMarketable) {
        return;
      }
      this.hide();

      // TODO: TBD
    },
  },
};
</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;
      }
    }
  }
</style>