Blame view

apps/pages/order/price-change/entry-detail.vue 7.16 KB
邱骏 authored
1 2 3 4
<template>
  <LayoutApp :title="title" :class="classes">
    <ScrollView ref="scroll" :options="scrollOption" @pulling-up="onPullingUp" @pulling-down="onPullingDown">
      <div class="order-page">
邱骏 authored
5
<!--        <div class="title">出售中</div>-->
邱骏 authored
6
        <!--商品详情-->
邱骏 authored
7
        <div class="product" @click="onClickProduct">
邱骏 authored
8 9 10
          <div class="pro-img">
            <ImgSize :src="productInfo.imageUrl" :width="200"></ImgSize>
          </div>
邱骏 authored
11 12 13
          <div class="pro-info">
            <p class="pro-name">{{productInfo.productName}}</p>
            <p class="stock-info">
邱骏 authored
14
<!--              <Logo :text="`有货UFO`" class="logo-wrapper"></Logo>-->
邱骏 authored
15 16 17
              <p class="stock-text">{{productInfo.colorName}}, {{productInfo.sizeNum}}个尺码, {{productInfo.storageNum}}个商品库存<p>
            </p>
          </div>
邱骏 authored
18
        </div>
邱骏 authored
19 20 21 22 23 24 25
        <!--尺码列表-->
        <ProductList
          ref="productList"
          :skcs="skcs"
          @on-change-price="onChangePrice"
          @on-no-sale="onNoSale"
        ></ProductList>
邱骏 authored
26 27
      </div>
    </ScrollView>
邱骏 authored
28 29 30 31 32 33 34 35 36 37
    <ModalUnstock
      v-if="modalLoad"
      ref="modalUnstock"
      @on-no-sale="onNoSaleSure"
    ></ModalUnstock>
    <ModalPrice
      v-if="modalLoad"
      ref="modalPrice"
      @on-change-price="onChangePriceSure"
    ></ModalPrice>
邱骏 authored
38 39 40 41 42 43
  </LayoutApp>
</template>

<script>
import LayoutApp from '../../../components/layout/layout-app';
import ScrollView from '../../../components/layout/scroll-view';
邱骏 authored
44
import Logo from './components/logo';
邱骏 authored
45 46 47

import {createNamespacedHelpers} from 'vuex';
import ImgSize from '../../../components/img-size';
邱骏 authored
48
import ProductList from './components/product-list';
邱骏 authored
49 50 51 52
import Modal from './components/modal';
import ModalUnstock from './components/modal-unstock';
import {get} from 'lodash';
import ModalPrice from './components/modal-price';
邱骏 authored
53 54 55 56

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

export default {
邱骏 authored
57
  components: {ModalPrice, ModalUnstock, Modal, ProductList, ImgSize, ScrollView, LayoutApp, Logo},
邱骏 authored
58 59 60 61 62 63
  name: 'PriceChange',
  data() {
    return {
      title: '订单',
      classes: {},
      scrollOption: {
邱骏 authored
64
        pullDownRefresh: false,
邱骏 authored
65
        observeDOM: false,
66
        pullUpLoad: false // 关闭了上拉加载
邱骏 authored
67 68 69
      },
      page: 1,
      modalLoad: false,
邱骏 authored
70
      pageSize: 50,
邱骏 authored
71 72 73
    };
  },
  asyncData({store, router}) {
邱骏 authored
74
    // 测试用orderId 10000064 10001026 10001266 10000072
75
    return store.dispatch('order/priceChange/fetchProduct', {productId: router.params.orderId, refresh: true});
邱骏 authored
76 77 78 79 80 81 82
  },
  mounted() {
    this.modalLoad = true;
  },
  computed: {
    ...mapState(['productInfo', 'skcs']),
  },
83 84 85 86
  beforeRouteLeave(from, to, next) {
    this.$refs.modalPrice.hide();
    next();
  },
邱骏 authored
87
  methods: {
邱骏 authored
88
    ...mapMutations(['MERGE_CHANGEPRICE_DATA']),
邱骏 authored
89
    ...mapActions(['fetchProduct', 'postNoSale', 'postChangePrice']),
邱骏 authored
90
    async onPullingUp() {
邱骏 authored
91 92 93 94 95 96 97
      const beginCount = this.skcs.length;

      const result = await this.fetchProduct({
        productId: this.$route.params.orderId,
        page: this.page + 1,
        pageSize: this.pageSize
      });
邱骏 authored
98
邱骏 authored
99
      // console.log(result);
邱骏 authored
100 101 102 103 104 105
      const afterCount = this.skcs.length;

      if (afterCount > beginCount) {
        this.page++;
      }
      const noMore = get(result, 'data.data', []).length;
邱骏 authored
106
邱骏 authored
107
      this.$refs.scroll.forceUpdate(noMore > 0);
108
邱骏 authored
109
    },
邱骏 authored
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    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
      });
邱骏 authored
134
135 136 137 138 139
      // 全部下架后回到出售中列表
      let data = get(result, 'data.data')
      if(data.length === 0) {
        this.$router.back()
      }
邱骏 authored
140 141 142
      if (isNoSale && !get(result, 'data.productInfo')) {
        this.$yoho.finishPage({});
      }
邱骏 authored
143 144
    },
    onClickProduct() {
145 146 147 148 149
      this.$router.push({
        name: 'ProductDetail',
        params: {
          productId: this.productInfo.productId
        }
邱骏 authored
150
      });
邱骏 authored
151 152
    },
    onChangePrice(skc) {
邱骏 authored
153
      this.$refs.modalPrice.show({skc, product: this.productInfo});
邱骏 authored
154 155
    },
    onNoSale(skc) {
邱骏 authored
156 157
      this.$refs.modalUnstock.show({skc});
    },
邱骏 authored
158
    async onNoSaleSure({skc, num}) { // 商品下架确认
邱骏 authored
159
      // console.log(skc, num);
邱骏 authored
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
      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}) {
邱骏 authored
183
      // console.log(skc, price);
邱骏 authored
184 185 186 187 188 189 190 191
      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
      });
邱骏 authored
192
邱骏 authored
193 194 195 196 197 198 199 200 201 202 203 204 205
      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();
      }
邱骏 authored
206 207 208 209 210 211 212
    }
  }
};
</script>

<style lang="scss" scoped>
  .order-page {
邱骏 authored
213
    position: relative;
邱骏 authored
214
    width: 100%;
邱骏 authored
215
    /*height: 100%;*/
邱骏 authored
216 217
    -webkit-font-smoothing: antialiased;
邱骏 authored
218
    .title {
邱骏 authored
219
      line-height: 82px;
邱骏 authored
220 221
      font-size: 68px;
      font-weight: bold;
邱骏 authored
222 223 224 225 226 227 228 229 230 231 232 233
      padding: 2px 40px 0 40px;
    }

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

      .pro-img {
        width: 200px;
        height: 200px;
邱骏 authored
234 235 236 237 238 239 240 241
        overflow: hidden;
        display: flex;
        align-items: center;

        img {
          width: 100%;
          height: auto;
        }
邱骏 authored
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
      }

      .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 {
邱骏 authored
271
          /*text-indent: 128px;*/
邱骏 authored
272 273 274 275 276
          font-size: 28px;
          font-weight: 600;
          line-height: 44px;
        }
      }
邱骏 authored
277 278 279
    }
  }
</style>