size-select-sheet.vue 8.17 KB
<template>
  <action-sheet @hidden="onHidden" @hide="onHide" @shown="onShown" 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" ref="sizeList"
                   :list="list"
                   :addSize="canAddSize"
                   :selected="selectedSize"
                   :config="config"
                   @select="onSelectSize"
                   @add="onAdd" />
        <transition name="slide-up">

          <div class="footer" v-if="isAvailable">
            <cube-button v-if="isMarketable" @click="convertToCash" :class="{active: isMarketable}">变现<span> <i>¥</i>{{cashPrice}}</span></cube-button>
            <cube-button @click="select" :class="{active: isTradable}">{{config.title}}</cube-button>
          </div>
        </transition>
      </div>
    </div>
  </action-sheet>
</template>

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

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

const { mapActions: mapProductActions, 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) && this.config.type === 'sell';
    },

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

    /**
     * 可交易(购买|出售)
     */
    isTradable() {
      return this.isAvailable && (
        (this.config.type === 'buy' && this.selectedSize.storage_num > 0 && this.selectedSize.least_price !== '-') ||
        this.config.type === 'sell'
      );
    },

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

      return '-';
    },

    /**
     * 可变现
     * 通过bid_moster_price或bid_skup判断
     */
    isMarketable() {
      return this.config.type === 'sell' && this.cashPrice > 0;
    }
  },
  mounted() {
    this.$refs.popup.show();
  },
  methods: {
    ...mapActions('order/sellerAskOrder', [
      'SELLER_ASK_SET_PRODUCTINFO'
    ]),
    ...mapProductActions(['updateTradeInfo']),
    onHidden() {
      this.$emit('hidden');
    },
    onHide() {
      this.$emit('hide');
    },
    onShown() {
      if (this.$refs.sizeList) {
        this.$refs.sizeList.refreshScroll();
      }
    },
    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', {
        size_name: this.selectedSize.size_name,
        productId: this.product.product_id,
        storageId: this.selectedSize.storage_id,
        skup: this.selectedSize.skup,
        bid_skup: this.selectedSize.bid_skup,
      });
    },
    convertToCash() {
      if (!this.isMarketable) {
        return;
      }
      this.hide();

      if (get(this.selectedSize, 'bid_skup', 0) == 0) {
        return;
      }

      this.$yoho.auth()
        .then((res) => {
          if (res) {
            this.$store.commit('order/sellerAskOrder/SELLER_ASK_SET_PRODUCTINFO', {
              goodImg: get(this.product, 'goods_list[0].image_list[0].image_url', ''),
              colorName: get(this.product, 'goods_list[0].color_name', ''),
              sizeName: get(this.selectedSize, 'size_name', '') ? get(this.selectedSize, 'size_name', '') + '码' : '',
              goodPrice: get(this.selectedSize, 'bid_moster_price', ''),
              productId: this.product.product_id,
              bid_moster_price: get(this.selectedSize, 'bid_moster_price', ''),
            });

            // 跳转变现
            this.$router.push({
              name: 'sellAskOrder',
              query: {
                skup: get(this.selectedSize, 'bid_skup', 0),
                price: get(this.selectedSize, 'bid_moster_price', 0),
              }
            });
          }

        });

    },
  },
};
</script>

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

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

    i {
      float: right;
      color: #999;
    }
  }

  .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;
        @include num
      }
    }
  }

  .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;
  }

  .crash-info {
    @include num;
  }

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

    @include cube-ufo-btn;

    span {
      font-size: 28px;
      margin-left: 8px;

      i {
        font-size: 20px;
        font-style: normal;
        @include num
      }
    }
  }
  .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>