size-select-sheet.vue 5.2 KB
<template>
  <action-sheet @hidden="onHidden" ref="popup">
    <div class="size-select-sheet">
      <div class="select-size" v-if="type === 'size'">
        <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"></size-list>
      </div>
      <div class="select-type" v-else>
        <div class="info">
          <div class="back" @click="goBack"></div>
          <h2>请选择出售方式</h2>
          <div class="sub-title">
            {{goods_name}}
            <template v-if="goods_name && sizeName">,</template>
            {{sizeName}}
          </div>
        </div>
        <div class="select-content type-list">
          <cube-scroll>
            <div class="type-wrap" @click="selectType">
              <div class="trade-type">
                <div class="title">
                  <div class="type">现货</div>
                  <div class="desc">现货好价, 36小时发货</div>
                </div>
                <div class="price">
                  ¥{{selectedSize.least_price}}
                  <i class="cubeic-arrow"></i>
                </div>
              </div>
            </div>
          </cube-scroll>
        </div>
      </div>
    </div>
  </action-sheet>
</template>

<script>
import { Scroll } 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,
    }
  },
  components: {
    SizeList,
    ImgSize,
    'cube-scroll': Scroll,
    'action-sheet': ActionSheet,
  },
  data() {
    return {
      selectedType: {},
      type: 'size',
    };
  },
  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);
    }
  },
  mounted() {
    this.$refs.popup.show();
  },
  methods: {
    ...mapActions(['updateTradeInfo']),
    onHidden() {
      this.$emit('hidden');
    },
    onSelectSize({selected: sizeInfo}) {
      this.updateTradeInfo({
        productId: this.product.product_id,
        sizeInfo,
      }).then(() => {
        this.type = 'type';
      });
    },
    onAdd() {
      this.$emit('add');
    },
    goBack() {
      this.type = 'size';
    },
    selectType() {
      this.updateTradeInfo({
        productId: this.product.product_id,
        tradeTypeInfo: {tradeTypeId: 1},
      }).then((data) => {
        this.$emit('select', data);
      });
    },
  },
};
</script>

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

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

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

    .product {
      margin-left: 40px;
      display: flex;
      flex-direction: column;
      justify-content: space-evenly;

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

      div:first-child {
        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;
  }
</style>