entry-detail.vue 6.76 KB
<template>
  <LayoutApp :title="title" :class="classes">
    <ScrollView ref="scroll" :options="scrollOption" @pulling-up="onPullingUp" @pulling-down="onPullingDown">
      <div class="order-page">
<!--        <div class="title">出售中</div>-->
        <!--商品详情-->
        <div class="product" @click="onClickProduct">
          <div class="pro-img">
            <ImgSize :src="productInfo.imageUrl" :width="200"></ImgSize>
          </div>
          <div class="pro-info">
            <p class="pro-name">{{productInfo.productName}}</p>
            <p class="stock-info">
<!--              <Logo :text="`有货UFO`" class="logo-wrapper"></Logo>-->
              <p class="stock-text">{{productInfo.colorName}}, {{productInfo.sizeNum}}个尺码, {{productInfo.storageNum}}个商品库存<p>
            </p>
          </div>
        </div>
        <!--尺码列表-->
        <ProductList
          ref="productList"
          :skcs="skcs"
          @on-change-price="onChangePrice"
          @on-no-sale="onNoSale"
        ></ProductList>
      </div>
    </ScrollView>
    <ModalUnstock
      v-if="modalLoad"
      ref="modalUnstock"
      @on-no-sale="onNoSaleSure"
    ></ModalUnstock>
    <ModalPrice
      v-if="modalLoad"
      ref="modalPrice"
      @on-change-price="onChangePriceSure"
    ></ModalPrice>
  </LayoutApp>
</template>

<script>
import LayoutApp from '../../../components/layout/layout-app';
import ScrollView from '../../../components/layout/scroll-view';
import Logo from './components/logo';

import {createNamespacedHelpers} from 'vuex';
import ImgSize from '../../../components/img-size';
import ProductList from './components/product-list';
import Modal from './components/modal';
import ModalUnstock from './components/modal-unstock';
import {get} from 'lodash';
import ModalPrice from './components/modal-price';

const {mapState, mapActions, mapMutations} = createNamespacedHelpers('order/priceChange')

export default {
  components: {ModalPrice, ModalUnstock, Modal, ProductList, ImgSize, ScrollView, LayoutApp, Logo},
  name: 'PriceChange',
  data() {
    return {
      title: '订单',
      classes: {},
      scrollOption: {
        pullDownRefresh: {
          threshold: 70,
          stop: 90
        },
        observeDOM: false,
        pullUpLoad: true
      },
      page: 1,
      modalLoad: false,
      pageSize: 10,
    };
  },
  asyncData({store, router}) {
    // 测试用orderId 10000064 10001026 10001266 10000072
    return store.dispatch('order/priceChange/fetchProduct', {productId: router.params.orderId});
  },
  mounted() {
    this.modalLoad = true;
    console.log(this.$route.params);
  },
  computed: {
    ...mapState(['productInfo', 'skcs']),
  },
  methods: {
    ...mapMutations(['MERGE_CHANGEPRICE_DATA']),
    ...mapActions(['fetchProduct', 'postNoSale', 'postChangePrice']),
    async onPullingUp() {
      const beginCount = this.skcs.length;

      const result = await this.fetchProduct({
        productId: this.$route.params.orderId,
        page: this.page + 1,
        pageSize: this.pageSize
      });
      const afterCount = this.skcs.length;

      if (afterCount > beginCount) {
        this.page++;
      }
      const noMore = get(result, 'data.data', []).length;

      this.$refs.scroll.forceUpdate(noMore > 0);
    },
    onPullingDown() {
      this.page = 1;
      this.fetchProduct({
        productId: this.$route.params.orderId,
        page: 1,
        pageSize: this.pageSize,
        refresh: true
      }).then(() => {
        this.$refs.scroll.forceUpdate();
      });
    },

    /**
     * 刷新商品及尺码信息
     * @param isNoSale 是否为点击不卖了之后的刷新
     * @returns {Promise<void>}
     */
    async refreshProduct(isNoSale) {
      const result = await this.fetchProduct({
        productId: this.$route.params.orderId,
        page: this.page,
        pageSize: this.pageSize,
        refresh: true
      });

      if (isNoSale && !get(result, 'data.productInfo')) {
        this.$yoho.finishPage({});
      }
    },
    onClickProduct() {

    },
    onChangePrice(skc) {
      this.$refs.modalPrice.show({skc, product: this.productInfo});
    },
    onNoSale(skc) {
      this.$refs.modalUnstock.show({skc});
    },
    async onNoSaleSure({skc, num}) {
      console.log(skc, num);
      const result = await this.postNoSale({
        product_id: this.productInfo.productId,
        storage_id: skc.storageId,
        old_price: skc.price,
        num: num,
        skupType: skc.attributes
      });

      if (result.code === 200) {
        this.$refs.modalUnstock.hide();
        this.$createToast({
          txt: '下架成功',
          type: 'correct'
        }).show();
        this.refreshProduct(true);
      } else {
        this.$createToast({
          txt: result.message || '下架失败',
          type: 'warn'
        }).show();
      }
    },
    async onChangePriceSure({skc, price}) {
      console.log(skc, price);
      const result = await this.postChangePrice({
        product_id: this.productInfo.productId,
        storage_id: skc.storageId,
        new_price: price,
        old_price: skc.price,
        num: skc.storageNum,
        skupType: skc.attributes
      });

      if (result && result.code === 200) {
        this.$refs.modalPrice.hide();
        this.$createToast({
          txt: '调价成功',
          type: 'success'
        }).show();
        this.refreshProduct();
      } else {
        this.$createToast({
          txt: result.message || '调价失败',
          type: 'warn',
        }).show();
      }
    }
  }
};
</script>

<style lang="scss" scoped>
  .order-page {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-font-smoothing: antialiased;

    .title {
      line-height: 82px;
      font-size: 68px;
      font-weight: bold;
      padding: 2px 40px 0 40px;
    }

    .product {
      margin: 20px auto;
      padding: 0 30px;
      height: 200px;
      display: flex;

      .pro-img {
        width: 200px;
        height: 200px;
        overflow: hidden;
        display: flex;
        align-items: center;

        img {
          width: 100%;
          height: auto;
        }
      }

      .logo-wrapper {
        position: absolute;
        left: 0;
        top: 4px;
        transform: scale(0.95);
      }

      .pro-info {
        padding: 44px 40px 0 40px;
        line-height: 32px;
        overflow: hidden;

        .pro-name {
          font-size: 24px;
          color: #999;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }

        .stock-info {
          position: relative;
          color: #000;
          margin-top: 24px;
        }

        .stock-text {
          /*text-indent: 128px;*/
          font-size: 28px;
          font-weight: 600;
          line-height: 44px;
        }
      }
    }
  }
</style>